summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorruki <[email protected]>2020-07-17 16:02:19 +0800
committerGitHub <[email protected]>2020-07-17 16:02:19 +0800
commitf9a4493f60eeb9078c00a112734d8caa7e29604e (patch)
tree9fd76a4b3ee0fea7eaa28dbf0df3976c3db36b34 /core
parentc3dd85b98492c012fc4eb1b46fac824051a1b92a (diff)
parent6b3cf4e5239f3f041501d0d8ee32471f33010708 (diff)
Merge pull request #894 from xmake-io/json
Add Json Support
Diffstat (limited to 'core')
-rw-r--r--core/src/demo/makefile4
m---------core/src/lua-cjson/lua-cjson0
-rw-r--r--core/src/lua-cjson/makefile30
-rw-r--r--core/src/lua-cjson/xmake.lua16
-rw-r--r--core/src/makefile2
-rw-r--r--core/src/xmake/engine.c9
-rw-r--r--core/src/xmake/xmake.lua2
-rw-r--r--core/xmake.lua8
8 files changed, 66 insertions, 5 deletions
diff --git a/core/src/demo/makefile b/core/src/demo/makefile
index 4ab0e2dba..160174661 100644
--- a/core/src/demo/makefile
+++ b/core/src/demo/makefile
@@ -14,9 +14,9 @@ demo_C_FILES += xmake
demo_PKGS-$(BASE) += base
# others
-demo_LIBS += xmake$(DTYPE) lcurses$(DTYPE) tbox$(DTYPE) luajit$(DTYPE) sv$(DTYPE) $(BASE_LIBS)
+demo_LIBS += xmake$(DTYPE) lcurses$(DTYPE) tbox$(DTYPE) luajit$(DTYPE) sv$(DTYPE) lua-cjson$(DTYPE) $(BASE_LIBS)
demo_INC_DIRS += ../ ../tbox/tbox/src ../tbox/inc/$(PLAT) ../luajit/luajit/src ../sv/sv/include
-demo_LIB_DIRS += ../xmake ../tbox ../luajit ../sv ../lcurses
+demo_LIB_DIRS += ../xmake ../tbox ../luajit ../sv ../lcurses ../lua-cjson
demo_CXFLAGS += -D__tb_prefix__=\"xmake\"
# suffix
diff --git a/core/src/lua-cjson/lua-cjson b/core/src/lua-cjson/lua-cjson
new file mode 160000
+Subproject ddd218d35f65a3e0a9f45de5e897f5c319ee4a8
diff --git a/core/src/lua-cjson/makefile b/core/src/lua-cjson/makefile
new file mode 100644
index 000000000..0a4263f03
--- /dev/null
+++ b/core/src/lua-cjson/makefile
@@ -0,0 +1,30 @@
+# prefix
+include $(PRO_DIR)/prefix.mak
+
+# module name
+NAMES = lua-cjson
+
+# module type
+lua-cjson_TYPE = LIB
+
+# config
+lua-cjson_CONFIG = n
+
+# core files
+lua-cjson_C_FILES += \
+ lua-cjson/dtoa \
+ lua-cjson/g_fmt \
+ lua-cjson/strbuf \
+ lua-cjson/lua_cjson
+
+# cflags
+# Use internal strtod() / g_fmt() code for performance and disable multi-thread
+lua-cjson_CFLAGS += -DNDEBUG -DUSE_INTERNAL_FPCONV
+
+# includes
+lua-cjson_INC_DIRS += \
+ ../luajit/luajit/src
+
+# suffix
+include $(PRO_DIR)/suffix.mak
+
diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua
new file mode 100644
index 000000000..b25640cae
--- /dev/null
+++ b/core/src/lua-cjson/xmake.lua
@@ -0,0 +1,16 @@
+target("lua-cjson")
+ set_kind("static")
+ set_warnings("all")
+ add_deps("luajit")
+ if is_plat("windows") then
+ set_languages("c89")
+ end
+ add_files("lua-cjson/*.c|fpconv.c")
+ -- Use internal strtod() / g_fmt() code for performance and disable multi-thread
+ add_defines("NDEBUG", "USE_INTERNAL_FPCONV")
+ if is_plat("windows") then
+ -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
+ add_defines("DISABLE_INVALID_NUMBERS")
+ add_defines("inline=__inline")
+ end
+
diff --git a/core/src/makefile b/core/src/makefile
index 5793c13b7..21a06ed5a 100644
--- a/core/src/makefile
+++ b/core/src/makefile
@@ -3,7 +3,7 @@ include $(PRO_DIR)/prefix.mak
# projects
SUB_PROS += demo
-DEP_PROS += lcurses sv luajit tbox xmake
+DEP_PROS += lcurses sv luajit lua-cjson tbox xmake
# suffix
include $(PRO_DIR)/suffix.mak
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index cf361a8c5..fb6205ac5 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -224,6 +224,11 @@ tb_int_t xm_semver_select(lua_State* lua);
tb_int_t xm_curses_register(lua_State* lua);
#endif
+// open cjson
+__tb_extern_c_enter__
+tb_int_t luaopen_cjson(lua_State *l);
+__tb_extern_c_leave__
+
/* //////////////////////////////////////////////////////////////////////////////////////
* globals
*/
@@ -849,6 +854,10 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c
lua_setglobal(engine->lua, "curses");
#endif
+ // bind json
+ luaopen_cjson(engine->lua);
+ lua_setglobal(engine->lua, "json");
+
// init host
xm_engine_init_host(engine);
diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua
index d85b2802f..eb2cc62b9 100644
--- a/core/src/xmake/xmake.lua
+++ b/core/src/xmake/xmake.lua
@@ -8,7 +8,7 @@ target("xmake")
if has_config("curses") or has_config("pdcurses") then
add_deps("lcurses")
end
- add_deps("sv", "luajit", "tbox")
+ add_deps("sv", "luajit", "lua-cjson", "tbox")
-- add defines
add_defines("__tb_prefix__=\"xmake\"")
diff --git a/core/xmake.lua b/core/xmake.lua
index 2f1f43957..4ce9c637b 100644
--- a/core/xmake.lua
+++ b/core/xmake.lua
@@ -15,6 +15,12 @@ set_languages("c99", "cxx11")
-- add release and debug modes
add_rules("mode.release", "mode.debug")
+if is_mode("release") then
+ set_optimize("smallest")
+ if is_plat("windows") then
+ add_ldflags("/LTCG")
+ end
+end
-- disable some compiler errors
add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing", "-Wno-error=nullability-completeness", "-Wno-error=parentheses-equality")
@@ -76,7 +82,7 @@ if is_plat("windows") then
end
-- add projects
-includes("src/lcurses", "src/sv","src/luajit", "src/tbox", "src/xmake", "src/demo")
+includes("src/lua-cjson", "src/lcurses", "src/sv","src/luajit", "src/tbox", "src/xmake", "src/demo")
if is_plat("windows") then
includes("src/pdcurses")
end