summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-01-19 23:12:14 +0800
committerruki <[email protected]>2023-01-19 23:12:14 +0800
commitc92a0248406711b5f1d6e27a22f45bab00dfc6b7 (patch)
tree8bc5814e7a3409bdf23448f0da2ff75485fbfa6d
parent17978855ebb374e21593129b52d3266db7715eb5 (diff)
improve lua-cjson
-rw-r--r--core/src/lua-cjson/xmake.lua1
-rwxr-xr-xcore/src/lua-cjson/xmake.sh1
-rw-r--r--core/src/xmake/engine.c2
-rwxr-xr-xcore/src/xmake/xmake.sh13
-rwxr-xr-xcore/xmake.sh22
5 files changed, 35 insertions, 4 deletions
diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua
index 74406d67e..fa7855150 100644
--- a/core/src/lua-cjson/xmake.lua
+++ b/core/src/lua-cjson/xmake.lua
@@ -8,6 +8,7 @@ target("lua-cjson")
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")
+ add_defines("XM_CONFIG_API_HAVE_LUA_CJSON", {public = true})
if is_plat("windows") then
-- Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
add_defines("DISABLE_INVALID_NUMBERS")
diff --git a/core/src/lua-cjson/xmake.sh b/core/src/lua-cjson/xmake.sh
index 134173051..f7d8b94b2 100755
--- a/core/src/lua-cjson/xmake.sh
+++ b/core/src/lua-cjson/xmake.sh
@@ -17,4 +17,5 @@ target "lua_cjson"
add_files "lua-cjson/g_fmt.c"
# Use internal strtod() / g_fmt() code for performance and disable multi-thread
add_defines "NDEBUG" "USE_INTERNAL_FPCONV"
+ add_defines "XM_CONFIG_API_HAVE_LUA_CJSON" "{public}"
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 0ecafd064..a0a019c33 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -1109,9 +1109,11 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c
xm_lua_curses_register(engine->lua, "curses");
#endif
+#ifdef XM_CONFIG_API_HAVE_LUA_CJSON
// bind cjson
luaopen_cjson(engine->lua);
lua_setglobal(engine->lua, "cjson");
+#endif
// init host
xm_engine_init_host(engine);
diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh
index f3fe92aa1..be0f6f911 100755
--- a/core/src/xmake/xmake.sh
+++ b/core/src/xmake/xmake.sh
@@ -5,7 +5,7 @@ target "xmake"
set_default false
# add deps
- local libs="lua_cjson lz4 sv tbox"
+ local libs="lz4 sv tbox"
for lib in $libs; do
if has_config "$lib"; then
add_options "$lib" "{public}"
@@ -14,10 +14,21 @@ target "xmake"
fi
done
if is_config "runtime" "luajit" && has_config "luajit"; then
+ if has_config "lua_cjson"; then
+ add_options "lua_cjson" "{public}"
+ else
+ add_deps "lua_cjson"
+ fi
add_options "luajit" "{public}"
elif has_config "lua"; then
+ if ! has_config "lua_cjson"; then
+ add_deps "lua_cjson"
+ fi
add_options "lua" "{public}"
else
+ if ! has_config "lua_cjson"; then
+ add_deps "lua_cjson"
+ fi
add_deps "lua"
fi
diff --git a/core/xmake.sh b/core/xmake.sh
index 759981225..c9e0db8a2 100755
--- a/core/xmake.sh
+++ b/core/xmake.sh
@@ -77,7 +77,8 @@ option_end
# the lua-cjson option
option "lua_cjson"
- add_links "lua5.1-cjson"
+ add_defines "XM_CONFIG_API_HAVE_LUA_CJSON"
+ before_check "option_find_lua_cjson"
add_csnippets "
int luaopen_cjson(void *l);\n
void test() {\n
@@ -86,6 +87,17 @@ void test() {\n
"
option_end
+option_find_lua_cjson() {
+ local ldflags=""
+ option "lua_cjson"
+ ldflags=`pkg-config --libs luajit 2>/dev/null`
+ if test_nz "${ldflags}"; then
+ ldflags="-llua5.1-cjson ${ldflags}"
+ fi
+ add_ldflags "${ldflags}"
+ option_end
+}
+
# the lua option
option "lua"
add_cfuncs "lua_pushstring"
@@ -116,8 +128,13 @@ option_end
option_find_luajit() {
local ldflags=""
+ local cflags=""
option "luajit"
- add_cflags `pkg-config --cflags luajit 2>/dev/null`
+ cflags=`pkg-config --cflags luajit 2>/dev/null`
+ if test_z "${cflags}"; then
+ cflags="/usr/include/luajit-2.1"
+ fi
+ add_cflags "${cflags}"
ldflags=`pkg-config --libs luajit 2>/dev/null`
if test_z "${ldflags}"; then
ldflags="-lluajit"
@@ -209,4 +226,3 @@ if ! has_config "tbox"; then
fi
includes "src/xmake"
includes "src/demo"
-