summaryrefslogtreecommitdiff
path: root/core/src/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-09 23:58:21 +0800
committerruki <[email protected]>2021-10-09 23:58:21 +0800
commit1af0820871a06217312fcee22b68e15954fc553a (patch)
tree5eb9e9b0f96089bebc18256ae3cc6644975d8112 /core/src/xmake
parentf35f6e15e13a4e5a360b94148534623b6a9c5feb (diff)
fix some errors for lua5.4
Diffstat (limited to 'core/src/xmake')
-rw-r--r--core/src/xmake/engine.c24
-rw-r--r--core/src/xmake/prefix.h16
-rw-r--r--core/src/xmake/sandbox/interactive.c5
3 files changed, 33 insertions, 12 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index dbea858c1..0793f426e 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -845,41 +845,41 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c
luaL_openlibs(engine->lua);
// bind os functions
- luaL_register(engine->lua, "os", g_os_functions);
+ xm_lua_register(engine->lua, "os", g_os_functions);
// bind io functions
- luaL_register(engine->lua, "io", g_io_functions);
+ xm_lua_register(engine->lua, "io", g_io_functions);
// bind path functions
- luaL_register(engine->lua, "path", g_path_functions);
+ xm_lua_register(engine->lua, "path", g_path_functions);
// bind hash functions
- luaL_register(engine->lua, "hash", g_hash_functions);
+ xm_lua_register(engine->lua, "hash", g_hash_functions);
// bind string functions
- luaL_register(engine->lua, "string", g_string_functions);
+ xm_lua_register(engine->lua, "string", g_string_functions);
// bind process functions
- luaL_register(engine->lua, "process", g_process_functions);
+ xm_lua_register(engine->lua, "process", g_process_functions);
// bind sandbox functions
- luaL_register(engine->lua, "sandbox", g_sandbox_functions);
+ xm_lua_register(engine->lua, "sandbox", g_sandbox_functions);
// bind windows functions
#ifdef TB_CONFIG_OS_WINDOWS
- luaL_register(engine->lua, "winos", g_winos_functions);
+ xm_lua_register(engine->lua, "winos", g_winos_functions);
#endif
#ifdef XM_CONFIG_API_HAVE_READLINE
// bind readline functions
- luaL_register(engine->lua, "readline", g_readline_functions);
+ xm_lua_register(engine->lua, "readline", g_readline_functions);
#endif
// bind semver functions
- luaL_register(engine->lua, "semver", g_semver_functions);
+ xm_lua_register(engine->lua, "semver", g_semver_functions);
// bind libc functions
- luaL_register(engine->lua, "libc", g_libc_functions);
+ xm_lua_register(engine->lua, "libc", g_libc_functions);
#ifdef XM_CONFIG_API_HAVE_CURSES
// bind curses
@@ -1059,7 +1059,7 @@ tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL
// do register
lua_pushstring(engine->lua, module);
lua_newtable(engine->lua);
- luaL_register(engine->lua, tb_null, funcs);
+ xm_lua_register(engine->lua, tb_null, funcs);
lua_rawset(engine->lua, -3);
}
tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv, xm_engine_lni_initalizer_cb_t lni_initalizer)
diff --git a/core/src/xmake/prefix.h b/core/src/xmake/prefix.h
index f78b61127..fabb775fb 100644
--- a/core/src/xmake/prefix.h
+++ b/core/src/xmake/prefix.h
@@ -114,6 +114,22 @@ static __tb_inline__ tb_pointer_t xm_lua_topointer(lua_State* lua, tb_int_t idx)
}
#endif
+static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const* libname, luaL_Reg const* l)
+{
+#if LUA_VERSION_NUM >= 504
+ lua_getglobal(lua, libname);
+ if (lua_isnil(lua, -1))
+ {
+ lua_pop(lua, 1);
+ lua_newtable(lua);
+ }
+ luaL_setfuncs(lua, l, 0);
+ lua_setglobal(lua, libname);
+#else
+ luaL_register(lua, libname, l);
+#endif
+}
+
#endif
diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c
index a62f6f77c..3b6ef3ff4 100644
--- a/core/src/xmake/sandbox/interactive.c
+++ b/core/src/xmake/sandbox/interactive.c
@@ -51,6 +51,11 @@
// buffer size for prompt
#define LUA_PROMPT_BUFSIZE 4096
+// for lua5.4
+#ifndef LUA_QL
+# define LUA_QL(x) "'" x "'"
+#endif
+
/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/