From b197ba40336206741b4f455cdbb1f12913da1e72 Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tsisyk.com>
Date: Mon, 17 Feb 2014 13:52:25 +0400
Subject: [PATCH] Convert third_party/lua-yaml/lyaml.c to C++ (to use try-catch
 block)

---
 cmake/BuildLibYAML.cmake                   | 6 +++++-
 third_party/lua-yaml/{lyaml.c => lyaml.cc} | 6 ++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
 rename third_party/lua-yaml/{lyaml.c => lyaml.cc} (99%)

diff --git a/cmake/BuildLibYAML.cmake b/cmake/BuildLibYAML.cmake
index 50e66a3586..01eb6116d7 100644
--- a/cmake/BuildLibYAML.cmake
+++ b/cmake/BuildLibYAML.cmake
@@ -1,7 +1,7 @@
 #
 # A macro to build the bundled liblua-yaml
 macro(libyaml_build)
-    set(yaml_src ${PROJECT_SOURCE_DIR}/third_party/lua-yaml/lyaml.c
+    set(yaml_src ${PROJECT_SOURCE_DIR}/third_party/lua-yaml/lyaml.cc
 	             ${PROJECT_SOURCE_DIR}/third_party/lua-yaml/api.c
 	             ${PROJECT_SOURCE_DIR}/third_party/lua-yaml/dumper.c
 	             ${PROJECT_SOURCE_DIR}/third_party/lua-yaml/emitter.c
@@ -14,6 +14,10 @@ macro(libyaml_build)
 
     set_source_files_properties(${yaml_src} PROPERTIES COMPILE_FLAGS
         "-std=c99")
+    set_source_files_properties(
+        ${PROJECT_SOURCE_DIR}/third_party/lua-yaml/lyaml.cc
+        PROPERTIES COMPILE_FLAGS
+        "-std=gnu++0x -D__STDC_FORMAT_MACROS=1 -D__STDC_LIMIT_MACROS=1")
 
     add_library(yaml STATIC ${yaml_src})
 
diff --git a/third_party/lua-yaml/lyaml.c b/third_party/lua-yaml/lyaml.cc
similarity index 99%
rename from third_party/lua-yaml/lyaml.c
rename to third_party/lua-yaml/lyaml.cc
index 17fc71b61d..c462b3a644 100644
--- a/third_party/lua-yaml/lyaml.c
+++ b/third_party/lua-yaml/lyaml.cc
@@ -31,6 +31,7 @@
 #include <stdbool.h>
 #include <inttypes.h>
 
+extern "C" {
 #include <lauxlib.h>
 #include <lua.h>
 #include <lualib.h>
@@ -42,6 +43,7 @@
 
 #include "yaml.h"
 #include "b64.h"
+} /* extern "C" */
 #include "lua/utils.h"
 
 /* configurable flags */
@@ -845,7 +847,7 @@ static int l_null(lua_State *L) {
    return 1;
 }
 
-LUALIB_API int luaopen_yaml(lua_State *L) {
+extern "C" int luaopen_yaml(lua_State *L) {
    const luaL_reg yamllib[] = {
       { "decode", l_load },
       { "encode", l_dump },
@@ -858,6 +860,6 @@ LUALIB_API int luaopen_yaml(lua_State *L) {
    return 1;
 }
 
-LUALIB_API int yamlL_encode(lua_State *L) {
+extern "C" int yamlL_encode(lua_State *L) {
 	return l_dump(L);
 }
-- 
GitLab