From 70748de03539eec10aafb9cb78178c275d6e9b47 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 3 Apr 2024 23:50:20 +0800 Subject: improve loadxmi --- core/src/xmake/engine.c | 13 ++++++++ core/src/xmake/package/loadxmi.c | 72 ++++++++++++++++++++++++++++++++++++++++ core/src/xmake/package/prefix.h | 32 ++++++++++++++++++ core/src/xmake/xmake.sh | 1 + 4 files changed, 118 insertions(+) create mode 100644 core/src/xmake/package/loadxmi.c create mode 100644 core/src/xmake/package/prefix.h (limited to 'core/src') diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 827d46d2e..b63dcf42b 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -294,6 +294,9 @@ tb_int_t xm_libc_setbyte(lua_State* lua); // the tty functions tb_int_t xm_tty_term_mode(lua_State* lua); +// the package functions +tb_int_t xm_package_loadxmi(lua_State* lua); + #ifdef XM_CONFIG_API_HAVE_CURSES // register curses functions tb_int_t xm_lua_curses_register(lua_State* lua, tb_char_t const* module); @@ -571,6 +574,13 @@ static luaL_Reg const g_tty_functions[] = , { tb_null, tb_null } }; +// the package functions +static luaL_Reg const g_package_functions[] = +{ + { "loadxmi", xm_package_loadxmi } +, { tb_null, tb_null } +}; + // the lua global instance for signal handler static lua_State* g_lua = tb_null; @@ -1158,6 +1168,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c // bind tty functions xm_lua_register(engine->lua, "tty", g_tty_functions); + // bind package functions + xm_lua_register(engine->lua, "package", g_package_functions); + #ifdef XM_CONFIG_API_HAVE_CURSES // bind curses xm_lua_curses_register(engine->lua, "curses"); diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c new file mode 100644 index 000000000..fcbecf72b --- /dev/null +++ b/core/src/xmake/package/loadxmi.c @@ -0,0 +1,72 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, TBOOX Open Source Group. + * + * @author ruki + * @file loadxmi.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "loadxmi" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ +typedef int (*xm_open_func_t)(lua_State* lua); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_package_loadxmi(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_check_return_val(path, 0); + + tb_char_t const* name = luaL_checkstring(lua, 2); + tb_check_return_val(name, 0); + + // load module library + tb_dynamic_ref_t lib = tb_dynamic_init(path); + if (!lib) + { + lua_pushnil(lua); + lua_pushfstring(lua, "load %s failed", path); + return 2; + } + + // get xmiopen_xxx function + xm_open_func_t func = (xm_open_func_t)tb_dynamic_func(path, name); + if (!func) + { + lua_pushnil(lua); + lua_pushfstring(lua, "cannot get symbol %s failed", name); + return 2; + } + + // load module + return func(lua); +} diff --git a/core/src/xmake/package/prefix.h b/core/src/xmake/package/prefix.h new file mode 100644 index 000000000..e710e526c --- /dev/null +++ b/core/src/xmake/package/prefix.h @@ -0,0 +1,32 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, TBOOX Open Source Group. + * + * @author ruki + * @file prefix.h + * + */ +#ifndef XM_PACKAGE_PREFIX_H +#define XM_PACKAGE_PREFIX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "../prefix.h" + + +#endif + + diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh index a813cf078..5a3cbe1d0 100755 --- a/core/src/xmake/xmake.sh +++ b/core/src/xmake/xmake.sh @@ -63,6 +63,7 @@ target "xmake" add_files "lz4/*.c" add_files "os/*.c" add_files "path/*.c" + add_files "package/*.c" add_files "process/*.c" add_files "readline/*.c" add_files "sandbox/*.c" -- cgit v1.3.1 From 953bb535caed3c53c8789e55c2f2a3208f1c4008 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 3 Apr 2024 23:51:02 +0800 Subject: fix loadxmi --- core/src/xmake/package/loadxmi.c | 2 +- tests/projects/other/native_module/modules/shared/zoo/src/zoo.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index fcbecf72b..d45fda3bb 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -59,7 +59,7 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // get xmiopen_xxx function - xm_open_func_t func = (xm_open_func_t)tb_dynamic_func(path, name); + xm_open_func_t func = (xm_open_func_t)tb_dynamic_func(lib, name); if (!func) { lua_pushnil(lua); diff --git a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c index 29e4a0e73..472d5f12d 100644 --- a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c +++ b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c @@ -1,4 +1,3 @@ -#include #include static int add(lua_State* lua) { @@ -20,7 +19,6 @@ static int sub(lua_State* lua) { } int xmiopen_zoo(lua_State* lua) { - printf("xxx\n"); static const luaL_Reg funcs[] = { {"add", add}, {"sub", sub}, -- cgit v1.3.1 From f716446fa869ef4dc9663d69a3e4364ef2dcbb6b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 3 Apr 2024 23:55:17 +0800 Subject: use xmi.h --- core/src/xmake/package/loadxmi.c | 8 ++++-- core/src/xmake/xmake.lua | 1 + core/src/xmake/xmake.sh | 1 + .../native_module/modules/shared/zoo/src/zoo.c | 2 +- xmake/scripts/module/xmi.h | 30 +++++++++++++++++----- 5 files changed, 32 insertions(+), 10 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index d45fda3bb..db4091431 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -29,11 +29,12 @@ * includes */ #include "prefix.h" +#include "xmi.h" /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -typedef int (*xm_open_func_t)(lua_State* lua); +typedef int (*xm_open_func_t)(xmi_lua_State* lua); /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -68,5 +69,8 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // load module - return func(lua); + xmi_lua_State xmi_lua = {0}; + xmi_lua._lua = lua; + xmi_lua._lua_createtable = &lua_createtable; + return func(&xmi_lua); } diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index 03e733c9a..15702c808 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -29,6 +29,7 @@ target("xmake") add_includedirs("..", {interface = true}) add_includedirs("$(buildir)/$(plat)/$(arch)/$(mode)", {public = true}) add_includedirs("../xxhash") + add_includedirs("$(projectdir)/../xmake/scripts/module") -- add header files add_headerfiles("../(xmake/*.h)") diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh index 5a3cbe1d0..62af5b2fa 100755 --- a/core/src/xmake/xmake.sh +++ b/core/src/xmake/xmake.sh @@ -50,6 +50,7 @@ target "xmake" add_includedirs ".." "{public}" add_includedirs "${buildir}/${plat}/${arch}/${mode}" "{public}" add_includedirs "../xxhash" + add_includedirs "${projectdir}/xmake/scripts/module" # add the common source files add_files "*.c" diff --git a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c index 472d5f12d..6b278fd25 100644 --- a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c +++ b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c @@ -24,8 +24,8 @@ int xmiopen_zoo(lua_State* lua) { {"sub", sub}, {NULL, NULL} }; -#if 0 lua_newtable(lua); +#if 0 luaL_setfuncs(lua, funcs, 0); #endif return 1; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 598d23ef3..c9a2d0a6f 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -26,19 +26,35 @@ */ #include +/* ////////////////////////////////////////////////////////////////////////////////////// + * macros + */ +#define xmi_lua_createtable(lua, narr, nrec) lua->_lua_createtable(lua->_lua, narr, nrec) +#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) + +#ifndef LUA_VERSION +# define lua_createtable xmi_lua_createtable +# define lua_newtable xmi_lua_newtable + +# define luaL_Reg xmi_luaL_Reg +# define lua_State struct xmi_lua_State_ +#endif + /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -struct lua_State_; -typedef struct luaL_Reg_ { +struct xmi_lua_State_; +typedef struct xmi_luaL_Reg_ { char const* name; - int (*func)(struct lua_State_* lua); -}luaL_Reg; + int (*func)(struct xmi_lua_State_* lua); +}xmi_luaL_Reg; + +typedef struct xmi_lua_State_ { + void* _lua; + void (*_lua_createtable)(lua_State* lua, int narr, int nrec); +}xmi_lua_State; -typedef struct lua_State_ { - void* ctx; -}lua_State; #endif -- cgit v1.3.1 From fee2d1b5106761728134c179375c73f9283a7ba1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 00:22:19 +0800 Subject: improve xmiopen --- core/src/xmake/package/loadxmi.c | 26 +++++++++++---- .../native_module/modules/shared/zoo/src/zoo.c | 2 +- xmake/scripts/module/xmi.h | 38 ++++++++++++++++++---- 3 files changed, 52 insertions(+), 14 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index db4091431..b79e8cee4 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -34,7 +34,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -typedef int (*xm_open_func_t)(xmi_lua_State* lua); +typedef int (*xm_open_func_t)(lua_State* lua); +typedef int (*xm_setup_func_t)(xmi_lua_ops_t* ops); /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -60,17 +61,28 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // get xmiopen_xxx function - xm_open_func_t func = (xm_open_func_t)tb_dynamic_func(lib, name); - if (!func) + xm_open_func_t luaopen = (xm_open_func_t)tb_dynamic_func(lib, name); + if (!luaopen) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get symbol %s failed", name); return 2; } + // get xmisetup function + xm_setup_func_t xmisetup = (xm_setup_func_t)tb_dynamic_func(lib, "xmisetup"); + if (!xmisetup) + { + lua_pushnil(lua); + lua_pushfstring(lua, "cannot get symbol xmisetup failed"); + return 2; + } + + // setup lua interfaces + xmi_lua_ops_t luaops = {0}; + luaops._lua_createtable = &lua_createtable; + xmisetup(&luaops); + // load module - xmi_lua_State xmi_lua = {0}; - xmi_lua._lua = lua; - xmi_lua._lua_createtable = &lua_createtable; - return func(&xmi_lua); + return luaopen(lua); } diff --git a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c index 6b278fd25..26b35f3bc 100644 --- a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c +++ b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c @@ -18,7 +18,7 @@ static int sub(lua_State* lua) { return 1; } -int xmiopen_zoo(lua_State* lua) { +int xmiopen(zoo, lua_State* lua) { static const luaL_Reg funcs[] = { {"add", add}, {"sub", sub}, diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index c9a2d0a6f..d20f8242f 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -29,7 +29,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ -#define xmi_lua_createtable(lua, narr, nrec) lua->_lua_createtable(lua->_lua, narr, nrec) +#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) #ifndef LUA_VERSION @@ -37,24 +37,50 @@ # define lua_newtable xmi_lua_newtable # define luaL_Reg xmi_luaL_Reg -# define lua_State struct xmi_lua_State_ +# define lua_State xmi_lua_State #endif +// define lua module entry function +#define xmiopen(name, lua) \ +__dummy = 1; \ +xmi_lua_ops_t* g_lua_ops; \ +int xmisetup(xmi_lua_ops_t* ops) { \ + g_lua_ops = ops; \ + return __dummy; \ +} \ +int xmiopen_##name(lua) + /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -struct xmi_lua_State_; +typedef struct xmi_lua_State_ { + int dummy; +}xmi_lua_State; + typedef struct xmi_luaL_Reg_ { char const* name; int (*func)(struct xmi_lua_State_* lua); }xmi_luaL_Reg; -typedef struct xmi_lua_State_ { - void* _lua; +typedef struct xmi_lua_ops_t_ { void (*_lua_createtable)(lua_State* lua, int narr, int nrec); -}xmi_lua_State; +}xmi_lua_ops_t; +/* ////////////////////////////////////////////////////////////////////////////////////// + * interfaces + */ + +#ifdef __cplusplus +extern "C" { +#endif + +// setup lua interfaces +int xmisetup(xmi_lua_ops_t* ops); + +#ifdef __cplusplus +} +#endif #endif -- cgit v1.3.1 From b0bc1ce397bb4b700c989df01d11b65b72ca800f Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 00:24:53 +0800 Subject: fix xmiopen --- core/src/xmake/package/loadxmi.c | 13 ++++++----- .../native_module/modules/shared/zoo/src/zoo.c | 4 +--- .../sandbox/modules/import/core/sandbox/module.lua | 27 +++++++++++----------- xmake/scripts/module/xmi.h | 15 ++++++++++-- 4 files changed, 35 insertions(+), 24 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index b79e8cee4..501c5d680 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -61,8 +61,8 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // get xmiopen_xxx function - xm_open_func_t luaopen = (xm_open_func_t)tb_dynamic_func(lib, name); - if (!luaopen) + xm_open_func_t luaopen_func = (xm_open_func_t)tb_dynamic_func(lib, name); + if (!luaopen_func) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get symbol %s failed", name); @@ -70,8 +70,8 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // get xmisetup function - xm_setup_func_t xmisetup = (xm_setup_func_t)tb_dynamic_func(lib, "xmisetup"); - if (!xmisetup) + xm_setup_func_t xmisetup_func = (xm_setup_func_t)tb_dynamic_func(lib, "xmisetup"); + if (!xmisetup_func) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get symbol xmisetup failed"); @@ -81,8 +81,9 @@ tb_int_t xm_package_loadxmi(lua_State* lua) // setup lua interfaces xmi_lua_ops_t luaops = {0}; luaops._lua_createtable = &lua_createtable; - xmisetup(&luaops); + luaops._luaL_setfuncs = &luaL_setfuncs; + xmisetup_func(&luaops); // load module - return luaopen(lua); + return luaopen_func(lua); } diff --git a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c index 26b35f3bc..02458467c 100644 --- a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c +++ b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c @@ -18,15 +18,13 @@ static int sub(lua_State* lua) { return 1; } -int xmiopen(zoo, lua_State* lua) { +int luaopen(zoo, lua_State* lua) { static const luaL_Reg funcs[] = { {"add", add}, {"sub", sub}, {NULL, NULL} }; lua_newtable(lua); -#if 0 luaL_setfuncs(lua, funcs, 0); -#endif return 1; } diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index 64698a504..1cf2ace5c 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -305,26 +305,27 @@ function core_sandbox_module._load_from_shared(module_fullpath, opt) end libraryfiles = {} end - local script local module if #libraryfiles == 0 then libraryfiles = os.files(path.join(moduleinfo.buildir, "*module_*")) end if #libraryfiles > 0 then - local errors1, errors2 + local script, errors1, errors2 for _, libraryfile in ipairs(libraryfiles) do local modulename = path.basename(libraryfile):match("module_(.+)") - if package.loadxmi then - script, errors1 = package.loadxmi(libraryfile, "xmiopen_" .. modulename) - end - if not script then - script, errors2 = package.loadlib(libraryfile, "luaopen_" .. modulename) - end - if not script then - return nil, errors1 or errors2 or string.format("xmiopen_%s and luaopen_%s not found!", modulename, modulename) - end - module = script() - if module then + if modulename then + if package.loadxmi then + module, errors1 = package.loadxmi(libraryfile, "xmiopen_" .. modulename) + end + if not module then + script, errors2 = package.loadlib(libraryfile, "luaopen_" .. modulename) + if script then + module = script() + end + end + if not module then + return nil, errors1 or errors2 or string.format("xmiopen_%s and luaopen_%s not found!", modulename, modulename) + end break end end diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index d20f8242f..aa45e9bb1 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -29,19 +29,29 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ + +// lua interfaces #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) +// luaL interfaces +#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) + +/* we cannot redefine lua functions in loadxmi.c, + * because original lua.h has been included + */ #ifndef LUA_VERSION # define lua_createtable xmi_lua_createtable # define lua_newtable xmi_lua_newtable +# define luaL_setfuncs xmi_luaL_setfuncs + # define luaL_Reg xmi_luaL_Reg # define lua_State xmi_lua_State #endif // define lua module entry function -#define xmiopen(name, lua) \ +#define luaopen(name, lua) \ __dummy = 1; \ xmi_lua_ops_t* g_lua_ops; \ int xmisetup(xmi_lua_ops_t* ops) { \ @@ -64,7 +74,8 @@ typedef struct xmi_luaL_Reg_ { }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { - void (*_lua_createtable)(lua_State* lua, int narr, int nrec); + void (*_lua_createtable)(lua_State* lua, int narr, int nrec); + void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); }xmi_lua_ops_t; /* ////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.3.1 From c04f30ad9010b58554554f925584ec97682a3f18 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 00:46:55 +0800 Subject: fix init luaops --- core/src/xmake/package/loadxmi.c | 21 +- .../native_module/modules/shared/zoo/src/zoo.c | 4 - .../sandbox/modules/import/core/sandbox/module.lua | 11 +- xmake/scripts/module/luaconf.h | 790 +++++++++++++++++++++ xmake/scripts/module/xmi.h | 23 +- 5 files changed, 830 insertions(+), 19 deletions(-) create mode 100644 xmake/scripts/module/luaconf.h (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 501c5d680..ebcec7469 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -34,7 +34,6 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -typedef int (*xm_open_func_t)(lua_State* lua); typedef int (*xm_setup_func_t)(xmi_lua_ops_t* ops); /* ////////////////////////////////////////////////////////////////////////////////////// @@ -61,7 +60,7 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // get xmiopen_xxx function - xm_open_func_t luaopen_func = (xm_open_func_t)tb_dynamic_func(lib, name); + lua_CFunction luaopen_func = (lua_CFunction)tb_dynamic_func(lib, name); if (!luaopen_func) { lua_pushnil(lua); @@ -79,11 +78,19 @@ tb_int_t xm_package_loadxmi(lua_State* lua) } // setup lua interfaces - xmi_lua_ops_t luaops = {0}; - luaops._lua_createtable = &lua_createtable; - luaops._luaL_setfuncs = &luaL_setfuncs; - xmisetup_func(&luaops); + static xmi_lua_ops_t s_luaops = {0}; + static tb_bool_t s_luaops_inited = tb_false; + if (!s_luaops_inited) + { + s_luaops._lua_createtable = &lua_createtable; + s_luaops._lua_tointegerx = &lua_tointegerx; + s_luaops._lua_pushinteger = &lua_pushinteger; + s_luaops._luaL_setfuncs = &luaL_setfuncs; + s_luaops_inited = tb_true; + } + xmisetup_func(&s_luaops); // load module - return luaopen_func(lua); + lua_pushcfunction(lua, luaopen_func); + return 1; } diff --git a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c index 02458467c..b297ee302 100644 --- a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c +++ b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c @@ -1,20 +1,16 @@ #include static int add(lua_State* lua) { -#if 0 int a = lua_tointeger(lua, 1); int b = lua_tointeger(lua, 2); lua_pushinteger(lua, a + b); -#endif return 1; } static int sub(lua_State* lua) { -#if 0 int a = lua_tointeger(lua, 1); int b = lua_tointeger(lua, 2); lua_pushinteger(lua, a - b); -#endif return 1; } diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index 1cf2ace5c..bddfb1524 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -315,15 +315,14 @@ function core_sandbox_module._load_from_shared(module_fullpath, opt) local modulename = path.basename(libraryfile):match("module_(.+)") if modulename then if package.loadxmi then - module, errors1 = package.loadxmi(libraryfile, "xmiopen_" .. modulename) + script, errors1 = package.loadxmi(libraryfile, "xmiopen_" .. modulename) end - if not module then + if not script then script, errors2 = package.loadlib(libraryfile, "luaopen_" .. modulename) - if script then - module = script() - end end - if not module then + if script then + module = script() + else return nil, errors1 or errors2 or string.format("xmiopen_%s and luaopen_%s not found!", modulename, modulename) end break diff --git a/xmake/scripts/module/luaconf.h b/xmake/scripts/module/luaconf.h new file mode 100644 index 000000000..e64d2ee39 --- /dev/null +++ b/xmake/scripts/module/luaconf.h @@ -0,0 +1,790 @@ +/* +** $Id: luaconf.h $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef luaconf_h +#define luaconf_h + +#include +#include + + +/* +** =================================================================== +** General Configuration File for Lua +** +** Some definitions here can be changed externally, through the compiler +** (e.g., with '-D' options): They are commented out or protected +** by '#if !defined' guards. However, several other definitions +** should be changed directly here, either because they affect the +** Lua ABI (by making the changes here, you ensure that all software +** connected to Lua, such as C libraries, will be compiled with the same +** configuration); or because they are seldom changed. +** +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +** {==================================================================== +** System Configuration: macros to adapt (if needed) Lua to some +** particular platform, for instance restricting it to C89. +** ===================================================================== +*/ + +/* +@@ LUA_USE_C89 controls the use of non-ISO-C89 features. +** Define it if you want Lua to avoid the use of a few C99 features +** or Windows-specific features on Windows. +*/ +/* #define LUA_USE_C89 */ + + +/* +** By default, Lua on Windows use (some) specific Windows features +*/ +#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) +#define LUA_USE_WINDOWS /* enable goodies for regular Windows */ +#endif + + +#if defined(LUA_USE_WINDOWS) +#define LUA_DL_DLL /* enable support for DLL */ +#define LUA_USE_C89 /* broadly, Windows is C89 */ +#endif + + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#endif + + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* MacOS does not need -ldl */ +#endif + + +/* +@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. +*/ +#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3) + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Number types. These options should not be +** set externally, because any other code connected to Lua must +** use the same configuration. +** =================================================================== +*/ + +/* +@@ LUA_INT_TYPE defines the type for Lua integers. +@@ LUA_FLOAT_TYPE defines the type for Lua floats. +** Lua should work fine with any mix of these options supported +** by your C compiler. The usual configurations are 64-bit integers +** and 'double' (the default), 32-bit integers and 'float' (for +** restricted platforms), and 'long'/'double' (for C compilers not +** compliant with C99, which may not have support for 'long long'). +*/ + +/* predefined options for LUA_INT_TYPE */ +#define LUA_INT_INT 1 +#define LUA_INT_LONG 2 +#define LUA_INT_LONGLONG 3 + +/* predefined options for LUA_FLOAT_TYPE */ +#define LUA_FLOAT_FLOAT 1 +#define LUA_FLOAT_DOUBLE 2 +#define LUA_FLOAT_LONGDOUBLE 3 + + +/* Default configuration ('long long' and 'double', for 64-bit Lua) */ +#define LUA_INT_DEFAULT LUA_INT_LONGLONG +#define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE + + +/* +@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. +*/ +#define LUA_32BITS 0 + + +/* +@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for +** C89 ('long' and 'double'); Windows always has '__int64', so it does +** not need to use this case. +*/ +#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) +#define LUA_C89_NUMBERS 1 +#else +#define LUA_C89_NUMBERS 0 +#endif + + +#if LUA_32BITS /* { */ +/* +** 32-bit integers and 'float' +*/ +#if LUAI_IS32INT /* use 'int' if big enough */ +#define LUA_INT_TYPE LUA_INT_INT +#else /* otherwise use 'long' */ +#define LUA_INT_TYPE LUA_INT_LONG +#endif +#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT + +#elif LUA_C89_NUMBERS /* }{ */ +/* +** largest types available for C89 ('long' and 'double') +*/ +#define LUA_INT_TYPE LUA_INT_LONG +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE + +#else /* }{ */ +/* use defaults */ + +#define LUA_INT_TYPE LUA_INT_DEFAULT +#define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT + +#endif /* } */ + + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Paths. +** =================================================================== +*/ + +/* +** LUA_PATH_SEP is the character that separates templates in a path. +** LUA_PATH_MARK is the string that marks the substitution points in a +** template. +** LUA_EXEC_DIR in a Windows path is replaced by the executable's +** directory. +*/ +#define LUA_PATH_SEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXEC_DIR "!" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +** Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +** C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ + +#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR +#if defined(_WIN32) /* { */ +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\" + +#if !defined(LUA_PATH_DEFAULT) +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ + LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ + ".\\?.lua;" ".\\?\\init.lua" +#endif + +#if !defined(LUA_CPATH_DEFAULT) +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.dll;" \ + LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ + LUA_CDIR"loadall.dll;" ".\\?.dll" +#endif + +#else /* }{ */ + +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" +#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" + +#if !defined(LUA_PATH_DEFAULT) +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + "./?.lua;" "./?/init.lua" +#endif + +#if !defined(LUA_CPATH_DEFAULT) +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" +#endif + +#endif /* } */ + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if !defined(LUA_DIRSEP) + +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Marks for exported symbols in the C code +** =================================================================== +*/ + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all auxiliary library functions. +@@ LUAMOD_API is a mark for all standard library opening functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) /* { */ + +#if defined(LUA_CORE) || defined(LUA_LIB) /* { */ +#define LUA_API __declspec(dllexport) +#else /* }{ */ +#define LUA_API __declspec(dllimport) +#endif /* } */ + +#else /* }{ */ + +#define LUA_API extern + +#endif /* } */ + + +/* +** More often than not the libs go together with the core. +*/ +#define LUALIB_API LUA_API +#define LUAMOD_API LUA_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +** exported to outside modules. +@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables, +** none of which to be exported to outside modules (LUAI_DDEF for +** definitions and LUAI_DDEC for declarations). +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. Not all elf targets support +** this attribute. Unfortunately, gcc does not offer a way to check +** whether the target offers that support, and those without support +** give a warning about it. To avoid these warnings, change to the +** default definition. +*/ +#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) /* { */ +#define LUAI_FUNC __attribute__((visibility("internal"))) extern +#else /* }{ */ +#define LUAI_FUNC extern +#endif /* } */ + +#define LUAI_DDEC(dec) LUAI_FUNC dec +#define LUAI_DDEF /* empty */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Compatibility with previous versions +** =================================================================== +*/ + +/* +@@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3. +** You can define it to get all options, or change specific options +** to fit your specific needs. +*/ +#if defined(LUA_COMPAT_5_3) /* { */ + +/* +@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated +** functions in the mathematical library. +** (These functions were already officially removed in 5.3; +** nevertheless they are still available here.) +*/ +#define LUA_COMPAT_MATHLIB + +/* +@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for +** manipulating other integer types (lua_pushunsigned, lua_tounsigned, +** luaL_checkint, luaL_checklong, etc.) +** (These macros were also officially removed in 5.3, but they are still +** available here.) +*/ +#define LUA_COMPAT_APIINTCASTS + + +/* +@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod +** using '__lt'. +*/ +#define LUA_COMPAT_LT_LE + + +/* +@@ The following macros supply trivial compatibility for some +** changes in the API. The macros themselves document how to +** change your code to avoid using them. +** (Once more, these macros were officially removed in 5.3, but they are +** still available here.) +*/ +#define lua_strlen(L,i) lua_rawlen(L, (i)) + +#define lua_objlen(L,i) lua_rawlen(L, (i)) + +#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) +#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) + +#endif /* } */ + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Numbers (low-level part). +** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* +** satisfy your needs. +** =================================================================== +*/ + +/* +@@ LUAI_UACNUMBER is the result of a 'default argument promotion' +@@ over a floating number. +@@ l_floatatt(x) corrects float attribute 'x' to the proper float type +** by prefixing it with one of FLT/DBL/LDBL. +@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. +@@ LUA_NUMBER_FMT is the format for writing floats. +@@ lua_number2str converts a float to a string. +@@ l_mathop allows the addition of an 'l' or 'f' to all math operations. +@@ l_floor takes the floor of a float. +@@ lua_str2number converts a decimal numeral to a number. +*/ + + +/* The following definitions are good for most cases here */ + +#define l_floor(x) (l_mathop(floor)(x)) + +#define lua_number2str(s,sz,n) \ + l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n)) + +/* +@@ lua_numbertointeger converts a float number with an integral value +** to an integer, or returns 0 if float is not within the range of +** a lua_Integer. (The range comparisons are tricky because of +** rounding. The tests here assume a two-complement representation, +** where MININTEGER always has an exact representation as a float; +** MAXINTEGER may not have one, and therefore its conversion to float +** may have an ill-defined value.) +*/ +#define lua_numbertointeger(n,p) \ + ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \ + (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ + (*(p) = (LUA_INTEGER)(n), 1)) + + +/* now the variable definitions */ + +#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */ + +#define LUA_NUMBER float + +#define l_floatatt(n) (FLT_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.7g" + +#define l_mathop(op) op##f + +#define lua_str2number(s,p) strtof((s), (p)) + + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */ + +#define LUA_NUMBER long double + +#define l_floatatt(n) (LDBL_##n) + +#define LUAI_UACNUMBER long double + +#define LUA_NUMBER_FRMLEN "L" +#define LUA_NUMBER_FMT "%.19Lg" + +#define l_mathop(op) op##l + +#define lua_str2number(s,p) strtold((s), (p)) + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */ + +#define LUA_NUMBER double + +#define l_floatatt(n) (DBL_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.14g" + +#define l_mathop(op) op + +#define lua_str2number(s,p) strtod((s), (p)) + +#else /* }{ */ + +#error "numeric float type not defined" + +#endif /* } */ + + + +/* +@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. +@@ LUAI_UACINT is the result of a 'default argument promotion' +@@ over a LUA_INTEGER. +@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. +@@ LUA_INTEGER_FMT is the format for writing integers. +@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. +@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. +@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. +@@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED. +@@ lua_integer2str converts an integer to a string. +*/ + + +/* The following definitions are good for most cases here */ + +#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" + +#define LUAI_UACINT LUA_INTEGER + +#define lua_integer2str(s,sz,n) \ + l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n)) + +/* +** use LUAI_UACINT here to avoid problems with promotions (which +** can turn a comparison between unsigneds into a signed comparison) +*/ +#define LUA_UNSIGNED unsigned LUAI_UACINT + + +#define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT) + + +/* now the variable definitions */ + +#if LUA_INT_TYPE == LUA_INT_INT /* { int */ + +#define LUA_INTEGER int +#define LUA_INTEGER_FRMLEN "" + +#define LUA_MAXINTEGER INT_MAX +#define LUA_MININTEGER INT_MIN + +#define LUA_MAXUNSIGNED UINT_MAX + +#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */ + +#define LUA_INTEGER long +#define LUA_INTEGER_FRMLEN "l" + +#define LUA_MAXINTEGER LONG_MAX +#define LUA_MININTEGER LONG_MIN + +#define LUA_MAXUNSIGNED ULONG_MAX + +#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */ + +/* use presence of macro LLONG_MAX as proxy for C99 compliance */ +#if defined(LLONG_MAX) /* { */ +/* use ISO C99 stuff */ + +#define LUA_INTEGER long long +#define LUA_INTEGER_FRMLEN "ll" + +#define LUA_MAXINTEGER LLONG_MAX +#define LUA_MININTEGER LLONG_MIN + +#define LUA_MAXUNSIGNED ULLONG_MAX + +#elif defined(LUA_USE_WINDOWS) /* }{ */ +/* in Windows, can use specific Windows types */ + +#define LUA_INTEGER __int64 +#define LUA_INTEGER_FRMLEN "I64" + +#define LUA_MAXINTEGER _I64_MAX +#define LUA_MININTEGER _I64_MIN + +#define LUA_MAXUNSIGNED _UI64_MAX + +#else /* }{ */ + +#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ + or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" + +#endif /* } */ + +#else /* }{ */ + +#error "numeric integer type not defined" + +#endif /* } */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Dependencies with C99 and other C details +** =================================================================== +*/ + +/* +@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89. +** (All uses in Lua have only one format item.) +*/ +#if !defined(LUA_USE_C89) +#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i) +#else +#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i)) +#endif + + +/* +@@ lua_strx2number converts a hexadecimal numeral to a number. +** In C99, 'strtod' does that conversion. Otherwise, you can +** leave 'lua_strx2number' undefined and Lua will provide its own +** implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_strx2number(s,p) lua_str2number(s,p) +#endif + + +/* +@@ lua_pointer2str converts a pointer to a readable string in a +** non-specified way. +*/ +#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p) + + +/* +@@ lua_number2strx converts a float to a hexadecimal numeral. +** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. +** Otherwise, you can leave 'lua_number2strx' undefined and Lua will +** provide its own implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_number2strx(L,b,sz,f,n) \ + ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n))) +#endif + + +/* +** 'strtof' and 'opf' variants for math functions are not valid in +** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the +** availability of these variants. ('math.h' is already included in +** all files that use these macros.) +*/ +#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) +#undef l_mathop /* variants not available */ +#undef lua_str2number +#define l_mathop(op) (lua_Number)op /* no variant */ +#define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) +#endif + + +/* +@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation +** functions. It must be a numerical type; Lua will use 'intptr_t' if +** available, otherwise it will use 'ptrdiff_t' (the nearest thing to +** 'intptr_t' in C89) +*/ +#define LUA_KCONTEXT ptrdiff_t + +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include +#if defined(INTPTR_MAX) /* even in C99 this type is optional */ +#undef LUA_KCONTEXT +#define LUA_KCONTEXT intptr_t +#endif +#endif + + +/* +@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point). +** Change that if you do not want to use C locales. (Code using this +** macro must include the header 'locale.h'.) +*/ +#if !defined(lua_getlocaledecpoint) +#define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) +#endif + + +/* +** macros to improve jump prediction, used mostly for error handling +** and debug facilities. (Some macros in the Lua API use these macros. +** Define LUA_NOBUILTIN if you do not want '__builtin_expect' in your +** code.) +*/ +#if !defined(luai_likely) + +#if defined(__GNUC__) && !defined(LUA_NOBUILTIN) +#define luai_likely(x) (__builtin_expect(((x) != 0), 1)) +#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#else +#define luai_likely(x) (x) +#define luai_unlikely(x) (x) +#endif + +#endif + + +#if defined(LUA_CORE) || defined(LUA_LIB) +/* shorter names for Lua's own use */ +#define l_likely(x) luai_likely(x) +#define l_unlikely(x) luai_unlikely(x) +#endif + + + +/* }================================================================== */ + + +/* +** {================================================================== +** Language Variations +** ===================================================================== +*/ + +/* +@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some +** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from +** numbers to strings. Define LUA_NOCVTS2N to turn off automatic +** coercion from strings to numbers. +*/ +/* #define LUA_NOCVTN2S */ +/* #define LUA_NOCVTS2N */ + + +/* +@@ LUA_USE_APICHECK turns on several consistency checks on the C API. +** Define it as a help when debugging C code. +*/ +#if defined(LUA_USE_APICHECK) +#include +#define luai_apicheck(l,e) assert(e) +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Macros that affect the API and must be stable (that is, must be the +** same when you compile Lua and when you compile code that links to +** Lua). +** ===================================================================== +*/ + +/* +@@ LUAI_MAXSTACK limits the size of the Lua stack. +** CHANGE it if you need a different limit. This limit is arbitrary; +** its only purpose is to stop Lua from consuming unlimited stack +** space (and to reserve some numbers for pseudo-indices). +** (It must fit into max(size_t)/32.) +*/ +#if LUAI_IS32INT +#define LUAI_MAXSTACK 1000000 +#else +#define LUAI_MAXSTACK 15000 +#endif + + +/* +@@ LUA_EXTRASPACE defines the size of a raw memory area associated with +** a Lua state with very fast access. +** CHANGE it if you need a different size. +*/ +#define LUA_EXTRASPACE (sizeof(void *)) + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@@ of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +*/ +#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number))) + + +/* +@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure +** maximum alignment for the other items in that union. +*/ +#define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l + +/* }================================================================== */ + + + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + + + +#endif + diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index aa45e9bb1..2f828e31d 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -24,7 +24,11 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ +#include #include +#ifndef LUA_VERSION +# include "luaconf.h" +#endif /* ////////////////////////////////////////////////////////////////////////////////////// * macros @@ -32,7 +36,10 @@ // lua interfaces #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) +#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) +#define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) +#define xmi_lua_tointeger(lua, i) lua_tointegerx(lua, (i), NULL) // luaL interfaces #define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) @@ -42,18 +49,22 @@ */ #ifndef LUA_VERSION # define lua_createtable xmi_lua_createtable +# define lua_tointegerx xmi_lua_tointegerx +# define lua_pushinteger xmi_lua_pushinteger # define lua_newtable xmi_lua_newtable +# define lua_tointeger xmi_lua_tointeger # define luaL_setfuncs xmi_luaL_setfuncs # define luaL_Reg xmi_luaL_Reg # define lua_State xmi_lua_State +# define lua_Integer xmi_lua_Integer #endif // define lua module entry function #define luaopen(name, lua) \ __dummy = 1; \ -xmi_lua_ops_t* g_lua_ops; \ +xmi_lua_ops_t* g_lua_ops = NULL; \ int xmisetup(xmi_lua_ops_t* ops) { \ g_lua_ops = ops; \ return __dummy; \ @@ -63,6 +74,7 @@ int xmiopen_##name(lua) /* ////////////////////////////////////////////////////////////////////////////////////// * types */ +typedef LUA_INTEGER xmi_lua_Integer; typedef struct xmi_lua_State_ { int dummy; @@ -70,14 +82,21 @@ typedef struct xmi_lua_State_ { typedef struct xmi_luaL_Reg_ { char const* name; - int (*func)(struct xmi_lua_State_* lua); + int (*func)(lua_State* lua); }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { void (*_lua_createtable)(lua_State* lua, int narr, int nrec); void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); + lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); + void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); }xmi_lua_ops_t; +/* ////////////////////////////////////////////////////////////////////////////////////// + * globals + */ +extern xmi_lua_ops_t* g_lua_ops; + /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces */ -- cgit v1.3.1 From f56b7ac57219564b9cf05aa5debc31642f02324a Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 21:03:08 +0800 Subject: add luaL_error --- core/src/xmake/package/loadxmi.c | 3 +++ .../modules/lua/cjson/src/cjson.c | 7 +++++ .../modules/lua/cjson/src/foo.c | 26 ------------------ .../modules/lua/cjson/xmake.lua | 1 + xmake/rules/module/xmake.lua | 3 +++ xmake/scripts/module/xmi.h | 31 +++++++++++++++++++--- 6 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c delete mode 100644 tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index ebcec7469..063703093 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -84,8 +84,11 @@ tb_int_t xm_package_loadxmi(lua_State* lua) { s_luaops._lua_createtable = &lua_createtable; s_luaops._lua_tointegerx = &lua_tointegerx; + s_luaops._lua_touserdata = &lua_touserdata; s_luaops._lua_pushinteger = &lua_pushinteger; + s_luaops._luaL_setfuncs = &luaL_setfuncs; + s_luaops._luaL_error = &luaL_error; s_luaops_inited = tb_true; } xmisetup_func(&s_luaops); diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c b/tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c new file mode 100644 index 000000000..d8c2e49ef --- /dev/null +++ b/tests/projects/other/native_module_cjson/modules/lua/cjson/src/cjson.c @@ -0,0 +1,7 @@ +#include + +int luaopen_cjson(lua_State* lua); + +int luaopen(cjson, lua_State* lua) { + return luaopen_cjson(lua); +} diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c b/tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c deleted file mode 100644 index 0555b071f..000000000 --- a/tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -static int add(lua_State* lua) { - int a = lua_tointeger(lua, 1); - int b = lua_tointeger(lua, 2); - lua_pushinteger(lua, a + b); - return 1; -} - -static int sub(lua_State* lua) { - int a = lua_tointeger(lua, 1); - int b = lua_tointeger(lua, 2); - lua_pushinteger(lua, a - b); - return 1; -} - -int luaopen(foo, lua_State* lua) { - static const luaL_Reg funcs[] = { - {"add", add}, - {"sub", sub}, - {NULL, NULL} - }; - lua_newtable(lua); - luaL_setfuncs(lua, funcs, 0); - return 1; -} diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua b/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua index 4455613bc..434746541 100644 --- a/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua +++ b/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua @@ -6,6 +6,7 @@ target("cjson") if is_plat("windows") then set_languages("c89") end + add_files("src/*.c") add_files("../../../../../../../core/src/lua-cjson/lua-cjson/*.c|fpconv.c") -- Use internal strtod() / g_fmt() code for performance and disable multi-thread add_defines("NDEBUG", "USE_INTERNAL_FPCONV") diff --git a/xmake/rules/module/xmake.lua b/xmake/rules/module/xmake.lua index 1667c5c2a..fb661dd7a 100644 --- a/xmake/rules/module/xmake.lua +++ b/xmake/rules/module/xmake.lua @@ -35,5 +35,8 @@ rule("module.shared") target:set("targetdir", config.buildir()) target:set("strip", "none") target:add("includedirs", path.join(os.programdir(), "scripts", "module")) + if xmake.luajit() then + target:add("defines", "XMI_USE_LUAJIT") + end end) diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index cfddb3aee..eb9608bd4 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -34,15 +34,32 @@ * macros */ +// pseudo-indices +#ifdef XMI_USE_LUAJIT +# define XMI_LUA_REGISTRYINDEX (-10000) +# define XMI_LUA_ENVIRONINDEX (-10001) +# define XMI_LUA_GLOBALSINDEX (-10002) +# define xmi_lua_upvalueindex(i) (XMI_LUA_GLOBALSINDEX - (i)) +#else +# define XMI_LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000) +# define xmi_lua_upvalueindex(i) (XMI_LUA_REGISTRYINDEX - (i)) +#endif + // lua interfaces #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) +#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) #define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) #define xmi_lua_tointeger(lua, i) lua_tointegerx(lua, (i), NULL) // luaL interfaces -#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) +#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) +#if defined(_MSC_VER) +# define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) +#else +# define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) +#endif /* we cannot redefine lua functions in loadxmi.c, * because original lua.h has been included @@ -50,11 +67,14 @@ #ifndef LUA_VERSION # define lua_createtable xmi_lua_createtable # define lua_tointegerx xmi_lua_tointegerx +# define lua_touserdata xmi_lua_touserdata # define lua_pushinteger xmi_lua_pushinteger # define lua_newtable xmi_lua_newtable # define lua_tointeger xmi_lua_tointeger +# define lua_upvalueindex xmi_lua_upvalueindex # define luaL_setfuncs xmi_luaL_setfuncs +# define luaL_error xmi_luaL_error # define luaL_Reg xmi_luaL_Reg # define lua_State xmi_lua_State @@ -98,10 +118,13 @@ typedef struct xmi_luaL_Reg_ { }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { - void (*_lua_createtable)(lua_State* lua, int narr, int nrec); - void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); + void (*_lua_createtable)(lua_State* lua, int narr, int nrec); lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); - void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); + void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); + void* (*_lua_touserdata)(lua_State* lua, int idx); + + void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); + int (*_luaL_error)(lua_State* lua, const char* fmt, ...); }xmi_lua_ops_t; /* ////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.3.1 From a23a38d88f15ca814033cad9771fd36282fc7265 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 22:23:41 +0800 Subject: improve loadxmi --- core/src/xmake/package/loadxmi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 063703093..fd83c3377 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -29,6 +29,9 @@ * includes */ #include "prefix.h" +#ifdef USE_LUAJIT +# define XMI_USE_LUAJIT +#endif #include "xmi.h" /* ////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.3.1 From 1b5a2aad9c872ae2f0d8641774502243a1a865ab Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 23:43:23 +0800 Subject: add more apis --- core/src/xmake/package/loadxmi.c | 17 +++-- .../sandbox/modules/import/core/sandbox/module.lua | 2 +- xmake/scripts/module/xmi.h | 73 ++++++++++++++++------ 3 files changed, 65 insertions(+), 27 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index fd83c3377..bc2c66e4e 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -85,13 +85,18 @@ tb_int_t xm_package_loadxmi(lua_State* lua) static tb_bool_t s_luaops_inited = tb_false; if (!s_luaops_inited) { - s_luaops._lua_createtable = &lua_createtable; - s_luaops._lua_tointegerx = &lua_tointegerx; - s_luaops._lua_touserdata = &lua_touserdata; - s_luaops._lua_pushinteger = &lua_pushinteger; + s_luaops._lua_createtable = &lua_createtable; + s_luaops._lua_tointegerx = &lua_tointegerx; + s_luaops._lua_touserdata = &lua_touserdata; + s_luaops._lua_pushinteger = &lua_pushinteger; + s_luaops._lua_gettop = &lua_gettop; + s_luaops._lua_pushnil = &lua_pushnil; + s_luaops._lua_type = &lua_type; - s_luaops._luaL_setfuncs = &luaL_setfuncs; - s_luaops._luaL_error = &luaL_error; + s_luaops._luaL_setfuncs = &luaL_setfuncs; + s_luaops._luaL_error = &luaL_error; + s_luaops._luaL_argerror = &luaL_argerror; + s_luaops._luaL_checkinteger = &luaL_checkinteger; s_luaops_inited = tb_true; } xmisetup_func(&s_luaops); diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index b5a717327..bddfb1524 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -241,7 +241,7 @@ function core_sandbox_module._build_module(moduleinfo) if ok ~= 0 then return nil, errors end - argv = {"-v"} + argv = {} core_sandbox_module._add_builtin_argv(argv, projectdir) ok, errors = os.execv(os.programfile(), argv, {envs = envs, curdir = projectdir}) if ok ~= 0 then diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index d69efcbe4..8838e9d8a 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -36,6 +36,21 @@ #define XMI_LUA_MULTRET (-1) +// basic types +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + +#define LUA_NUMTYPES 9 + // pseudo-indices #ifdef XMI_USE_LUAJIT # define XMI_LUA_REGISTRYINDEX (-10000) @@ -48,40 +63,46 @@ #endif // lua interfaces -#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) -#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) -#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) -#define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) +#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) +#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) +#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) +#define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) +#define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) +#define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) +#define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) // luaL interfaces -#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) +#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) #if defined(_MSC_VER) -# define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) +# define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) #else -# define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) +# define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) #endif +#define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) +#define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) // helper interfaces -#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) -#define xmi_lua_tointeger(lua, i) xmi_lua_tointegerx(lua, (i), NULL) -#define xmi_luaL_newlibtable(lua, l) xml_lua_createtable(lua, 0, sizeof(l)/sizeof((l)[0]) - 1) +#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) +#define xmi_lua_tointeger(lua, i) xmi_lua_tointegerx(lua, (i), NULL) +#define xmi_lua_isnil(lua, n) (xmi_lua_type(lua, (n)) == LUA_TNIL) +#define xmi_luaL_newlibtable(lua, l) xml_lua_createtable(lua, 0, sizeof(l)/sizeof((l)[0]) - 1) #define xmi_luaL_newlib(lua, l) \ (xmi_luaL_checkversion(lua), xmi_luaL_newlibtable(lua,l), xmi_luaL_setfuncs(lua,l,0)) #define xmi_luaL_argcheck(lua, cond, arg, extramsg) \ - ((void)(xmi_luai_likely(cond) || xmi_luaL_argerror(lua, (arg), (extramsg)))) + ((void)(luai_likely(cond) || xmi_luaL_argerror(lua, (arg), (extramsg)))) #define xmi_luaL_argexpected(lua, cond, arg, tname) \ - ((void)(xmi_luai_likely(cond) || xmi_luaL_typeerror(lua, (arg), (tname)))) -#define xmi_luaL_checkstring(lua, n) (xmi_luaL_checklstring(lua, (n), NULL)) -#define xmi_luaL_optstring(lua, n, d) (xmi_luaL_optlstring(lua, (n), (d), NULL)) -#define xmi_luaL_typename(lua, i) xmi_lua_typename(lua, lua_type(lua,(i))) + ((void)(luai_likely(cond) || xmi_luaL_typeerror(lua, (arg), (tname)))) +#define xmi_luaL_checkstring(lua, n) (xmi_luaL_checklstring(lua, (n), NULL)) +#define xmi_luaL_optstring(lua, n, d) (xmi_luaL_optlstring(lua, (n), (d), NULL)) +#define xmi_luaL_typename(lua, i) xmi_lua_typename(lua, lua_type(lua,(i))) #define xmi_luaL_dofile(lua, fn) \ (xmi_luaL_loadfile(lua, fn) || xmi_lua_pcall(lua, 0, XMI_LUA_MULTRET, 0)) #define xmi_luaL_dostring(lua, s) \ (xmi_luaL_loadstring(lua, s) || xmi_lua_pcall(lua, 0, XMI_LUA_MULTRET, 0)) -#define xmi_luaL_getmetatable(lua, n) (xmi_lua_getfield(lua, XMI_LUA_REGISTRYINDEX, (n))) -#define xmi_luaL_opt(lua, f, n, d) (xmi_lua_isnoneornil(lua,(n)) ? (d) : f(lua,(n))) -#define xmi_luaL_loadbuffer(lua, s, sz, n) xmi_luaL_loadbufferx(lua, s, sz, n, NULL) -#define xmi_luaL_pushfail(lua) xmi_lua_pushnil(lua) +#define xmi_luaL_getmetatable(lua, n) (xmi_lua_getfield(lua, XMI_LUA_REGISTRYINDEX, (n))) +#define xmi_luaL_opt(lua, f, n, d) (xmi_lua_isnoneornil(lua,(n)) ? (d) : f(lua,(n))) +#define xmi_luaL_loadbuffer(lua, s, sz, n) xmi_luaL_loadbufferx(lua, s, sz, n, NULL) +#define xmi_luaL_pushfail(lua) xmi_lua_pushnil(lua) /* we cannot redefine lua functions in loadxmi.c, * because original lua.h has been included @@ -93,12 +114,18 @@ # define lua_tointegerx xmi_lua_tointegerx # define lua_touserdata xmi_lua_touserdata # define lua_pushinteger xmi_lua_pushinteger +# define lua_gettop xmi_lua_gettop +# define lua_pushnil xmi_lua_pushnil +# define lua_type xmi_lua_type # define luaL_setfuncs xmi_luaL_setfuncs # define luaL_error xmi_luaL_error +# define luaL_argerror xmi_luaL_argerror +# define luaL_checkinteger xmi_luaL_checkinteger # define lua_newtable xmi_lua_newtable # define lua_tointeger xmi_lua_tointeger +# define lua_isnil xmi_lua_isnil # define luaL_newlibtable xmi_luaL_newlibtable # define luaL_newlib xmi_luaL_newlib # define luaL_argcheck xmi_luaL_argcheck @@ -157,11 +184,17 @@ typedef struct xmi_luaL_Reg_ { typedef struct xmi_lua_ops_t_ { void (*_lua_createtable)(lua_State* lua, int narr, int nrec); lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); - void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); void* (*_lua_touserdata)(lua_State* lua, int idx); + void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); + int (*_lua_gettop)(lua_State* lua); + void (*_lua_pushnil)(lua_State* lua); + int (*_lua_type)(lua_State* lua, int idx); void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); int (*_luaL_error)(lua_State* lua, const char* fmt, ...); + int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); + lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); + }xmi_lua_ops_t; /* ////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.3.1 From 7bcdab37b12330a61769343e318391bf9d050b41 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 4 Apr 2024 23:45:13 +0800 Subject: add toboolean --- core/src/xmake/package/loadxmi.c | 1 + xmake/scripts/module/xmi.h | 3 +++ 2 files changed, 4 insertions(+) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index bc2c66e4e..5d910b854 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -87,6 +87,7 @@ tb_int_t xm_package_loadxmi(lua_State* lua) { s_luaops._lua_createtable = &lua_createtable; s_luaops._lua_tointegerx = &lua_tointegerx; + s_luaops._lua_toboolean = &lua_toboolean; s_luaops._lua_touserdata = &lua_touserdata; s_luaops._lua_pushinteger = &lua_pushinteger; s_luaops._lua_gettop = &lua_gettop; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 0a8cb3e43..ecf338a0d 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -65,6 +65,7 @@ // lua interfaces #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) +#define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) #define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) #define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) #define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) @@ -121,6 +122,7 @@ # define lua_createtable xmi_lua_createtable # define lua_tointegerx xmi_lua_tointegerx +# define lua_toboolean xmi_lua_toboolean # define lua_touserdata xmi_lua_touserdata # define lua_pushinteger xmi_lua_pushinteger # define lua_gettop xmi_lua_gettop @@ -201,6 +203,7 @@ typedef struct xmi_luaL_Reg_ { typedef struct xmi_lua_ops_t_ { void (*_lua_createtable)(lua_State* lua, int narr, int nrec); lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); + int (*_lua_toboolean) (lua_State* lua, int idx); void* (*_lua_touserdata)(lua_State* lua, int idx); void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); int (*_lua_gettop)(lua_State* lua); -- cgit v1.3.1 From b8d9d415769e27da929c3582bcb893147cf836d5 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:06:04 +0800 Subject: add lua_pushxxx --- core/src/xmake/package/loadxmi.c | 42 ++++++++---- xmake/scripts/module/xmi.h | 140 +++++++++++++++++++++++++++++---------- 2 files changed, 133 insertions(+), 49 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 5d910b854..f3f5d5cec 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -85,20 +85,36 @@ tb_int_t xm_package_loadxmi(lua_State* lua) static tb_bool_t s_luaops_inited = tb_false; if (!s_luaops_inited) { - s_luaops._lua_createtable = &lua_createtable; - s_luaops._lua_tointegerx = &lua_tointegerx; - s_luaops._lua_toboolean = &lua_toboolean; - s_luaops._lua_touserdata = &lua_touserdata; - s_luaops._lua_pushinteger = &lua_pushinteger; - s_luaops._lua_gettop = &lua_gettop; - s_luaops._lua_pushnil = &lua_pushnil; - s_luaops._lua_type = &lua_type; + s_luaops._lua_createtable = &lua_createtable; + s_luaops._lua_gettop = &lua_gettop; + s_luaops._lua_type = &lua_type; - s_luaops._luaL_setfuncs = &luaL_setfuncs; - s_luaops._luaL_error = &luaL_error; - s_luaops._luaL_argerror = &luaL_argerror; - s_luaops._luaL_checkinteger = &luaL_checkinteger; - s_luaops_inited = tb_true; + // to functions + s_luaops._lua_tointegerx = &lua_tointegerx; + s_luaops._lua_toboolean = &lua_toboolean; + s_luaops._lua_touserdata = &lua_touserdata; + + // push functions + s_luaops._lua_pushnil = &lua_pushnil; + s_luaops._lua_pushinteger = &lua_pushinteger; + + s_luaops._lua_pushboolean = &lua_pushboolean; + s_luaops._lua_pushnumber = &lua_pushnumber; + s_luaops._lua_pushlstring = &lua_pushlstring; + s_luaops._lua_pushstring = &lua_pushstring; + s_luaops._lua_pushvfstring = &lua_pushvfstring; + s_luaops._lua_pushfstring = &lua_pushfstring; + s_luaops._lua_pushcclosure = &lua_pushcclosure; + s_luaops._lua_pushlightuserdata = &lua_pushlightuserdata; + s_luaops._lua_pushthread = &lua_pushthread; + + // luaL functions + s_luaops._luaL_setfuncs = &luaL_setfuncs; + s_luaops._luaL_error = &luaL_error; + s_luaops._luaL_argerror = &luaL_argerror; + s_luaops._luaL_checkinteger = &luaL_checkinteger; + s_luaops._luaL_checkoption = &luaL_checkoption; + s_luaops_inited = tb_true; } xmisetup_func(&s_luaops); diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index ecf338a0d..b6918ae98 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -26,6 +26,7 @@ */ #include #include +#include #ifndef LUA_VERSION # include "luawrap/luaconf.h" #endif @@ -62,30 +63,19 @@ # define xmi_lua_upvalueindex(i) (XMI_LUA_REGISTRYINDEX - (i)) #endif -// lua interfaces +// lua macros #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) -#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) -#define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) -#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) -#define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) +#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) #define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) -#define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) #define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) -// luaL interfaces -#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) -#if defined(_MSC_VER) -# define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) -#else -# define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) -#endif -#define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) -#define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) - -// helper interfaces -#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) +// to macros +#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) #define xmi_lua_tointeger(lua, i) xmi_lua_tointegerx(lua, (i), NULL) +#define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) +#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) +// is macros #define xmi_lua_isfunction(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TFUNCTION) #define xmi_lua_istable(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTABLE) #define xmi_lua_islightuserdata(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TLIGHTUSERDATA) @@ -95,6 +85,34 @@ #define xmi_lua_isnone(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TNONE) #define xmi_lua_isnoneornil(lua, n) (xmi_lua_type(lua, (n)) <= 0) +// push macros +#define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) +#define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) +#define xmi_lua_pushboolean(lua, b) (g_lua_ops)->_lua_pushboolean(lua, b) +#define xmi_lua_pushnumber(lua, b) (g_lua_ops)->_lua_pushnumber(lua, n) +#define xmi_lua_pushlstring(lua, s, len) (g_lua_ops)->_lua_pushlstring(lua, s, len) +#define xmi_lua_pushstring(lua, s) (g_lua_ops)->_lua_pushstring(lua, s) +#define xmi_lua_pushvfstring(lua, fmt, argp) (g_lua_ops)->_lua_pushvfstring(lua, fmt, argp) +#if defined(_MSC_VER) +# define xmi_lua_pushfstring(lua, fmt, ...) (g_lua_ops)->_lua_pushfstring(lua, fmt, __VA_ARGS__) +#else +# define xmi_lua_pushfstring(lua, fmt, arg ...) (g_lua_ops)->_lua_pushfstring(lua, fmt, ## arg) +#endif +#define xmi_lua_pushcclosure(lua, fn, n) (g_lua_ops)->_lua_pushcclosure(lua, fn, n) +#define xmi_lua_pushlightuserdata(lua, p) (g_lua_ops)->_lua_pushlightuserdata(lua, p) +#define xmi_lua_pushthread(lua) (g_lua_ops)->_lua_pushthread(lua) + +// luaL macros +#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) +#if defined(_MSC_VER) +# define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) +#else +# define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) +#endif +#define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) +#define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) +#define xmi_luaL_checkoption(lua, arg, def, lst) (g_lua_ops)->_luaL_checkoption(lua, arg, def, lst) + #define xmi_luaL_newlibtable(lua, l) xml_lua_createtable(lua, 0, sizeof(l)/sizeof((l)[0]) - 1) #define xmi_luaL_newlib(lua, l) \ (xmi_luaL_checkversion(lua), xmi_luaL_newlibtable(lua,l), xmi_luaL_setfuncs(lua,l,0)) @@ -119,23 +137,18 @@ */ #ifndef XM_PREFIX_H # define lua_upvalueindex xmi_lua_upvalueindex - # define lua_createtable xmi_lua_createtable -# define lua_tointegerx xmi_lua_tointegerx -# define lua_toboolean xmi_lua_toboolean -# define lua_touserdata xmi_lua_touserdata -# define lua_pushinteger xmi_lua_pushinteger # define lua_gettop xmi_lua_gettop -# define lua_pushnil xmi_lua_pushnil # define lua_type xmi_lua_type - -# define luaL_setfuncs xmi_luaL_setfuncs -# define luaL_error xmi_luaL_error -# define luaL_argerror xmi_luaL_argerror -# define luaL_checkinteger xmi_luaL_checkinteger - # define lua_newtable xmi_lua_newtable # define lua_tointeger xmi_lua_tointeger + +// to macros +# define lua_tointegerx xmi_lua_tointegerx +# define lua_toboolean xmi_lua_toboolean +# define lua_touserdata xmi_lua_touserdata + +// is macros # define lua_isfunction xmi_lua_isfunction # define lua_istable xmi_lua_istable # define lua_islightuserdata xmi_lua_islightuserdata @@ -145,6 +158,26 @@ # define lua_isnone xmi_lua_isnone # define lua_isnoneornil xmi_lua_isnoneornil +// push macros +# define lua_pushnil xmi_lua_pushnil +# define lua_pushinteger xmi_lua_pushinteger +# define lua_pushboolean xmi_lua_pushboolean +# define lua_pushnumber xmi_lua_pushnumber +# define lua_pushlstring xmi_lua_pushlstring +# define lua_pushstring xmi_lua_pushstring +# define lua_pushvfstring xmi_lua_pushvfstring +# define lua_pushfstring xmi_lua_pushfstring +# define lua_pushcclosure xmi_lua_pushcclosure +# define lua_pushlightuserdata xmi_lua_pushlightuserdata +# define lua_pushthread xmi_lua_pushthread + +// luaL macros +# define luaL_setfuncs xmi_luaL_setfuncs +# define luaL_error xmi_luaL_error +# define luaL_argerror xmi_luaL_argerror +# define luaL_checkinteger xmi_luaL_checkinteger +# define luaL_checkoption xmi_luaL_checkoption + # define luaL_newlibtable xmi_luaL_newlibtable # define luaL_newlib xmi_luaL_newlib # define luaL_argcheck xmi_luaL_argcheck @@ -159,9 +192,19 @@ # define luaL_loadbuffer xmi_luaL_loadbuffer # define luaL_pushfail xmi_luaL_pushfail +// types # define luaL_Reg xmi_luaL_Reg # define lua_State xmi_lua_State +# define lua_Number xmi_lua_Number # define lua_Integer xmi_lua_Integer +# define lua_Unsigned xmi_lua_Unsigned +# define lua_KContext xmi_lua_KContext +# define lua_CFunction xmi_lua_CFunction +# define lua_KFunction xmi_lua_KFunction +# define lua_Reader xmi_lua_Reader +# define lua_Writer xmi_lua_Writer +# define lua_Alloc xmi_lua_Alloc +# define lua_WarnFunction xmi_lua_WarnFunction #endif // extern c @@ -189,31 +232,56 @@ int xmiopen_##name(lua) /* ////////////////////////////////////////////////////////////////////////////////////// * types */ +typedef LUA_NUMBER xmi_lua_Number; typedef LUA_INTEGER xmi_lua_Integer; +typedef LUA_UNSIGNED xmi_lua_Unsigned; +typedef LUA_KCONTEXT xmi_lua_KContext; typedef struct xmi_lua_State_ { int dummy; }xmi_lua_State; +typedef int (*xmi_lua_CFunction)(lua_State* lua); +typedef int (*xmi_lua_KFunction)(lua_State* lua, int status, lua_KContext ctx); +typedef const char* (*xmi_lua_Reader)(lua_State* lua, void* ud, size_t* sz); +typedef int (*xmi_lua_Writer)(lua_State* lua, const void* p, size_t sz, void* ud); +typedef void* (*xmi_lua_Alloc)(void* ud, void* ptr, size_t osize, size_t nsize); +typedef void (*xmi_lua_WarnFunction)(void* ud, const char* msg, int tocont); + typedef struct xmi_luaL_Reg_ { - char const* name; - int (*func)(lua_State* lua); + char const* name; + xmi_lua_CFunction func; }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { void (*_lua_createtable)(lua_State* lua, int narr, int nrec); + int (*_lua_gettop)(lua_State* lua); + int (*_lua_type)(lua_State* lua, int idx); + + // to functions lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); int (*_lua_toboolean) (lua_State* lua, int idx); void* (*_lua_touserdata)(lua_State* lua, int idx); - void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); - int (*_lua_gettop)(lua_State* lua); - void (*_lua_pushnil)(lua_State* lua); - int (*_lua_type)(lua_State* lua, int idx); + // push functions + void (*_lua_pushnil)(lua_State* lua); + void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); + void (*_lua_pushboolean)(lua_State* lua, int b); + void (*_lua_pushnumber)(lua_State* lua, lua_Number n); + const char* (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); + const char* (*_lua_pushstring)(lua_State* lua, const char* s); + const char* (*_lua_pushvfstring)(lua_State* lua, const char* fmt, va_list argp); + const char* (*_lua_pushfstring)(lua_State* lua, const char* fmt, ...); + void (*_lua_pushcclosure)(lua_State* lua, lua_CFunction fn, int n); + void (*_lua_pushlightuserdata)(lua_State* lua, void* p); + int (*_lua_pushthread)(lua_State* lua); + + // luaL functions void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); int (*_luaL_error)(lua_State* lua, const char* fmt, ...); int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); + int (*_luaL_checkoption)(lua_State* lua, int arg, const char *def, const char *const lst[]); }xmi_lua_ops_t; -- cgit v1.3.1 From 5878db81b603afef02db2c53c57647c7bc6daf9f Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:08:59 +0800 Subject: add get functions --- core/src/xmake/package/loadxmi.c | 14 ++++++++++- xmake/scripts/module/xmi.h | 52 +++++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index f3f5d5cec..6b825e6df 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -85,10 +85,22 @@ tb_int_t xm_package_loadxmi(lua_State* lua) static tb_bool_t s_luaops_inited = tb_false; if (!s_luaops_inited) { - s_luaops._lua_createtable = &lua_createtable; s_luaops._lua_gettop = &lua_gettop; s_luaops._lua_type = &lua_type; + // get functions + s_luaops._lua_getglobal = &lua_getglobal; + s_luaops._lua_gettable = &lua_gettable; + s_luaops._lua_getfield = &lua_getfield; + s_luaops._lua_geti = &lua_geti; + s_luaops._lua_rawget = &lua_rawget; + s_luaops._lua_rawgeti = &lua_rawgeti; + s_luaops._lua_rawgetp = &lua_rawgetp; + s_luaops._lua_createtable = &lua_createtable; + s_luaops._lua_newuserdatauv = &lua_newuserdatauv; + s_luaops._lua_getmetatable = &lua_getmetatable; + s_luaops._lua_getiuservalue = &lua_getiuservalue; + // to functions s_luaops._lua_tointegerx = &lua_tointegerx; s_luaops._lua_toboolean = &lua_toboolean; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index b6918ae98..89a46a89c 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -64,18 +64,30 @@ #endif // lua macros -#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) #define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) #define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) +// get macros +#define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) +#define xmi_lua_gettable(lua, idx) (g_lua_ops)->_lua_gettable(lua, idx) +#define xmi_lua_getfield(lua, idx, k) (g_lua_ops)->_lua_getfield(lua, idx, k) +#define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) +#define xmi_lua_rawget(lua, idx) (g_lua_ops)->_lua_rawget(lua, idx) +#define xmi_lua_rawgeti(lua, idx, n) (g_lua_ops)->_lua_rawgeti(lua, idx, n) +#define xmi_lua_rawgetp(lua, idx, p) (g_lua_ops)->_lua_rawgetp(lua, idx, p) +#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) +#define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) +#define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) +#define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) + // to macros #define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) #define xmi_lua_tointeger(lua, i) xmi_lua_tointegerx(lua, (i), NULL) #define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) #define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) -// is macros +// access macros #define xmi_lua_isfunction(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TFUNCTION) #define xmi_lua_istable(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTABLE) #define xmi_lua_islightuserdata(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TLIGHTUSERDATA) @@ -137,18 +149,30 @@ */ #ifndef XM_PREFIX_H # define lua_upvalueindex xmi_lua_upvalueindex -# define lua_createtable xmi_lua_createtable # define lua_gettop xmi_lua_gettop # define lua_type xmi_lua_type # define lua_newtable xmi_lua_newtable -# define lua_tointeger xmi_lua_tointeger -// to macros +// get macros +# define lua_getglobal xmi_lua_getglobal +# define lua_gettable xmi_lua_gettable +# define lua_getfield xmi_lua_getfield +# define lua_geti xmi_lua_geti +# define lua_rawget xmi_lua_rawget +# define lua_rawgeti xmi_lua_rawgeti +# define lua_rawgetp xmi_lua_rawgetp +# define lua_createtable xmi_lua_createtable +# define lua_newuserdatauv xmi_lua_newuserdatauv +# define lua_getmetatable xmi_lua_getmetatable +# define lua_getiuservalue xmi_lua_getiuservalue + +// access macros +# define lua_tointeger xmi_lua_tointeger # define lua_tointegerx xmi_lua_tointegerx # define lua_toboolean xmi_lua_toboolean # define lua_touserdata xmi_lua_touserdata -// is macros +// access macros # define lua_isfunction xmi_lua_isfunction # define lua_istable xmi_lua_istable # define lua_islightuserdata xmi_lua_islightuserdata @@ -254,13 +278,25 @@ typedef struct xmi_luaL_Reg_ { }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { - void (*_lua_createtable)(lua_State* lua, int narr, int nrec); int (*_lua_gettop)(lua_State* lua); int (*_lua_type)(lua_State* lua, int idx); + // get functions + int (*_lua_getglobal)(lua_State* lua, const char *name); + int (*_lua_gettable)(lua_State* lua, int idx); + int (*_lua_getfield)(lua_State* lua, int idx, const char* k); + int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawget)(lua_State* lua, int idx); + int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); + void (*_lua_createtable)(lua_State* lua, int narr, int nrec); + void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); + int (*_lua_getmetatable)(lua_State* lua, int objindex); + int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); + // to functions lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); - int (*_lua_toboolean) (lua_State* lua, int idx); + int (*_lua_toboolean)(lua_State* lua, int idx); void* (*_lua_touserdata)(lua_State* lua, int idx); // push functions -- cgit v1.3.1 From 0dd39dca10801095fa1a57f1c7df56f44ceceaea Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:45:48 +0800 Subject: fix install --- core/src/demo/xmake.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'core/src') diff --git a/core/src/demo/xmake.sh b/core/src/demo/xmake.sh index a6342ce4e..05b1047ca 100755 --- a/core/src/demo/xmake.sh +++ b/core/src/demo/xmake.sh @@ -32,6 +32,7 @@ target "demo" add_installfiles "${projectdir}/(xmake/scripts/virtualenvs/**)" "share" add_installfiles "${projectdir}/(xmake/scripts/pac/**)" "share" add_installfiles "${projectdir}/(xmake/scripts/conan/**)" "share" + add_installfiles "${projectdir}/(xmake/scripts/module/**)" "share" add_installfiles "${projectdir}/(xmake/templates/**)" "share" add_installfiles "${projectdir}/scripts/xrepo.sh" "bin" "xrepo" -- cgit v1.3.1 From 18f0fd584bb13c915e8bf5958bc304c87c931472 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:48:02 +0800 Subject: add stack functions --- core/src/xmake/package/loadxmi.c | 12 ++++++++++-- xmake/scripts/module/xmi.h | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 6b825e6df..736dcf9cf 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -85,7 +85,6 @@ tb_int_t xm_package_loadxmi(lua_State* lua) static tb_bool_t s_luaops_inited = tb_false; if (!s_luaops_inited) { - s_luaops._lua_gettop = &lua_gettop; s_luaops._lua_type = &lua_type; // get functions @@ -109,7 +108,6 @@ tb_int_t xm_package_loadxmi(lua_State* lua) // push functions s_luaops._lua_pushnil = &lua_pushnil; s_luaops._lua_pushinteger = &lua_pushinteger; - s_luaops._lua_pushboolean = &lua_pushboolean; s_luaops._lua_pushnumber = &lua_pushnumber; s_luaops._lua_pushlstring = &lua_pushlstring; @@ -120,6 +118,16 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_pushlightuserdata = &lua_pushlightuserdata; s_luaops._lua_pushthread = &lua_pushthread; + // stack functions + s_luaops._lua_absindex = &lua_absindex; + s_luaops._lua_gettop = &lua_gettop; + s_luaops._lua_settop = &lua_settop; + s_luaops._lua_pushvalue = &lua_pushvalue; + s_luaops._lua_rotate = &lua_rotate; + s_luaops._lua_copy = &lua_copy; + s_luaops._lua_checkstack = &lua_checkstack; + s_luaops._lua_xmove = &lua_xmove; + // luaL functions s_luaops._luaL_setfuncs = &luaL_setfuncs; s_luaops._luaL_error = &luaL_error; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index b9e07c382..cda96bdff 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -65,8 +65,8 @@ // lua macros #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) -#define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) #define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) +#define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) // get macros #define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) @@ -113,6 +113,17 @@ #define xmi_lua_pushcclosure(lua, fn, n) (g_lua_ops)->_lua_pushcclosure(lua, fn, n) #define xmi_lua_pushlightuserdata(lua, p) (g_lua_ops)->_lua_pushlightuserdata(lua, p) #define xmi_lua_pushthread(lua) (g_lua_ops)->_lua_pushthread(lua) +#define xmi_lua_pushcfunction(lua, f) xmi_lua_pushcclosure(lua, (f), 0) + +// stack functions +#define xmi_lua_absindex(lua, idx) (g_lua_ops)->_lua_absindex(lua, idx) +#define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) +#define xmi_lua_settop(lua, idx) (g_lua_ops)->_lua_settop(lua, idx) +#define xmi_lua_pushvalue(lua, idx) (g_lua_ops)->_lua_pushvalue(lua, idx) +#define xmi_lua_rotate(lua, idx, n) (g_lua_ops)->_lua_rotate(lua, idx, n) +#define xmi_lua_copy(lua, fromidx, toidx) (g_lua_ops)->_lua_copy(lua, fromidx, toidx) +#define xmi_lua_checkstack(lua, n) (g_lua_ops)->_lua_checkstack(lua, n) +#define xmi_lua_xmove(from, to, n) (g_lua_ops)->_lua_xmove(from, to, n) // compatibility macros #define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) @@ -154,9 +165,9 @@ */ #ifndef XM_PREFIX_H # define lua_upvalueindex xmi_lua_upvalueindex -# define lua_gettop xmi_lua_gettop # define lua_type xmi_lua_type # define lua_newtable xmi_lua_newtable +# define lua_pop xmi_lua_pop // get macros # define lua_getglobal xmi_lua_getglobal @@ -199,11 +210,22 @@ # define lua_pushcclosure xmi_lua_pushcclosure # define lua_pushlightuserdata xmi_lua_pushlightuserdata # define lua_pushthread xmi_lua_pushthread +# define lua_pushcfunction xmi_lua_pushcfunction # define lua_newuserdata xmi_lua_newuserdata # define lua_getuservalue xmi_lua_getuservalue # define lua_setuservalue xmi_lua_setuservalue +// stack functions +# define lua_absindex xmi_lua_absindex +# define lua_gettop xmi_lua_gettop +# define lua_settop xmi_lua_settop +# define lua_pushvalue xmi_lua_pushvalue +# define lua_rotate xmi_lua_rotate +# define lua_copy xmi_lua_copy +# define lua_checkstack xmi_lua_checkstack +# define lua_xmove xmi_lua_xmove + // luaL macros # define luaL_setfuncs xmi_luaL_setfuncs # define luaL_error xmi_luaL_error @@ -287,7 +309,6 @@ typedef struct xmi_luaL_Reg_ { }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { - int (*_lua_gettop)(lua_State* lua); int (*_lua_type)(lua_State* lua, int idx); // get functions @@ -321,6 +342,16 @@ typedef struct xmi_lua_ops_t_ { void (*_lua_pushlightuserdata)(lua_State* lua, void* p); int (*_lua_pushthread)(lua_State* lua); + // stack functions + int (*_lua_absindex)(lua_State* lua, int idx); + int (*_lua_gettop)(lua_State* lua); + void (*_lua_settop)(lua_State* lua, int idx); + void (*_lua_pushvalue)(lua_State* lua, int idx); + void (*_lua_rotate)(lua_State* lua, int idx, int n); + void (*_lua_copy)(lua_State* lua, int fromidx, int toidx); + int (*_lua_checkstack)(lua_State* lua, int n); + void (*_lua_xmove)(lua_State* from, lua_State* to, int n); + // luaL functions void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); int (*_luaL_error)(lua_State* lua, const char* fmt, ...); -- cgit v1.3.1 From 764c5c30bf78bfb0e151d93ea3c0b7cf500df5fe Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:49:48 +0800 Subject: add set functions --- core/src/xmake/package/loadxmi.c | 11 +++++++++++ xmake/scripts/module/xmi.h | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 736dcf9cf..457ed4198 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -100,6 +100,17 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_getmetatable = &lua_getmetatable; s_luaops._lua_getiuservalue = &lua_getiuservalue; + // set functions + s_luaops._lua_setglobal = &lua_setglobal; + s_luaops._lua_settable = &lua_settable; + s_luaops._lua_setfield = &lua_setfield; + s_luaops._lua_seti = &lua_seti; + s_luaops._lua_rawset = &lua_rawset; + s_luaops._lua_rawseti = &lua_rawseti; + s_luaops._lua_rawsetp = &lua_rawsetp; + s_luaops._lua_setmetatable = &lua_setmetatable; + s_luaops._lua_setiuservalue = &lua_setiuservalue; + // to functions s_luaops._lua_tointegerx = &lua_tointegerx; s_luaops._lua_toboolean = &lua_toboolean; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index cda96bdff..4b60b4459 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -81,6 +81,17 @@ #define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) #define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) +// set macros +#define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) +#define xmi_lua_settable(lua, idx) (g_lua_ops)->_lua_settable(lua, idx) +#define xmi_lua_setfield(lua, idx, k) (g_lua_ops)->_lua_setfield(lua, idx, k) +#define xmi_lua_seti(lua, idx, n) (g_lua_ops)->_lua_seti(lua, idx, n) +#define xmi_lua_rawset(lua, idx) (g_lua_ops)->_lua_rawset(lua, idx) +#define xmi_lua_rawseti(lua, idx, n) (g_lua_ops)->_lua_rawseti(lua, idx, n) +#define xmi_lua_rawsetp(lua, idx, p) (g_lua_ops)->_lua_rawsetp(lua, idx, p) +#define xmi_lua_setmetatable(lua, objidx) (g_lua_ops)->_lua_setmetatable(lua, objidx) +#define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) + // to macros #define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) #define xmi_lua_tointeger(lua, i) xmi_lua_tointegerx(lua, (i), NULL) @@ -182,7 +193,18 @@ # define lua_getmetatable xmi_lua_getmetatable # define lua_getiuservalue xmi_lua_getiuservalue -// access macros +// set macros +# define lua_setglobal xmi_lua_setglobal +# define lua_settable xmi_lua_settable +# define lua_setfield xmi_lua_setfield +# define lua_seti xmi_lua_seti +# define lua_rawset xmi_lua_rawset +# define lua_rawseti xmi_lua_rawseti +# define lua_rawsetp xmi_lua_rawsetp +# define lua_setmetatable xmi_lua_setmetatable +# define lua_setiuservalue xmi_lua_setiuservalue + +// to macros # define lua_tointeger xmi_lua_tointeger # define lua_tointegerx xmi_lua_tointegerx # define lua_toboolean xmi_lua_toboolean @@ -324,6 +346,17 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_getmetatable)(lua_State* lua, int objindex); int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); + // set functions + void (*_lua_setglobal)(lua_State* lua, const char* name); + void (*_lua_settable)(lua_State* lua, int idx); + void (*_lua_setfield)(lua_State* lua, int idx, const char* k); + void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); + void (*_lua_rawset)(lua_State* lua, int idx); + void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); + void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); + int (*_lua_setmetatable)(lua_State* lua, int objindex); + int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); + // to functions lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); int (*_lua_toboolean)(lua_State* lua, int idx); -- cgit v1.3.1 From 4b91348f700a9a108a1634601e969d822328282c Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:52:57 +0800 Subject: add more access functions --- core/src/xmake/package/loadxmi.c | 17 +++- xmake/scripts/module/xmi.h | 165 ++++++++++++++++++++++++--------------- 2 files changed, 116 insertions(+), 66 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 457ed4198..ac1cd5a97 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -85,7 +85,6 @@ tb_int_t xm_package_loadxmi(lua_State* lua) static tb_bool_t s_luaops_inited = tb_false; if (!s_luaops_inited) { - s_luaops._lua_type = &lua_type; // get functions s_luaops._lua_getglobal = &lua_getglobal; @@ -111,10 +110,24 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_setmetatable = &lua_setmetatable; s_luaops._lua_setiuservalue = &lua_setiuservalue; - // to functions + // access functions + s_luaops._lua_isnumber = &lua_isnumber; + s_luaops._lua_isstring = &lua_isstring; + s_luaops._lua_iscfunction = &lua_iscfunction; + s_luaops._lua_isinteger = &lua_isinteger; + s_luaops._lua_isuserdata = &lua_isuserdata; + s_luaops._lua_type = &lua_type; + s_luaops._lua_typename = &lua_typename; + + s_luaops._lua_tonumberx = &lua_tonumberx; s_luaops._lua_tointegerx = &lua_tointegerx; s_luaops._lua_toboolean = &lua_toboolean; + s_luaops._lua_tolstring = &lua_tolstring; + s_luaops._lua_rawlen = &lua_rawlen; + s_luaops._lua_tocfunction = &lua_tocfunction; s_luaops._lua_touserdata = &lua_touserdata; + s_luaops._lua_tothread = &lua_tothread; + s_luaops._lua_topointer = &lua_topointer; // push functions s_luaops._lua_pushnil = &lua_pushnil; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 4b60b4459..c68e34094 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -65,7 +65,6 @@ // lua macros #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) -#define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) #define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) // get macros @@ -92,13 +91,15 @@ #define xmi_lua_setmetatable(lua, objidx) (g_lua_ops)->_lua_setmetatable(lua, objidx) #define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) -// to macros -#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) -#define xmi_lua_tointeger(lua, i) xmi_lua_tointegerx(lua, (i), NULL) -#define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) -#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) - // access macros +#define xmi_lua_isnumber(lua, idx) (g_lua_ops)->_lua_isnumber(lua, idx) +#define xmi_lua_isstring(lua, idx) (g_lua_ops)->_lua_isstring(lua, idx) +#define xmi_lua_iscfunction(lua, idx) (g_lua_ops)->_lua_iscfunction(lua, idx) +#define xmi_lua_isinteger(lua, idx) (g_lua_ops)->_lua_isinteger(lua, idx) +#define xmi_lua_isuserdata(lua, idx) (g_lua_ops)->_lua_isuserdata(lua, idx) +#define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) +#define xmi_lua_typename(lua, idx) (g_lua_ops)->_lua_typename(lua, idx) + #define xmi_lua_isfunction(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TFUNCTION) #define xmi_lua_istable(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTABLE) #define xmi_lua_islightuserdata(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TLIGHTUSERDATA) @@ -108,6 +109,16 @@ #define xmi_lua_isnone(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TNONE) #define xmi_lua_isnoneornil(lua, n) (xmi_lua_type(lua, (n)) <= 0) +#define xmi_lua_tonumberx(lua, idx, isnum) (g_lua_ops)->_lua_tonumberx(lua, idx, isnum) +#define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) +#define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) +#define xmi_lua_tolstring(lua, idx, len) (g_lua_ops)->_lua_tolstring(lua, idx, len) +#define xmi_lua_rawlen(lua, idx) (g_lua_ops)->_lua_rawlen(lua, idx) +#define xmi_lua_tocfunction(lua, idx) (g_lua_ops)->_lua_tocfunction(lua, idx) +#define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) +#define xmi_lua_tothread(lua, idx) (g_lua_ops)->_lua_tothread(lua, idx) +#define xmi_lua_topointer(lua, idx) (g_lua_ops)->_lua_topointer(lua, idx) + // push macros #define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) #define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) @@ -176,7 +187,6 @@ */ #ifndef XM_PREFIX_H # define lua_upvalueindex xmi_lua_upvalueindex -# define lua_type xmi_lua_type # define lua_newtable xmi_lua_newtable # define lua_pop xmi_lua_pop @@ -204,13 +214,15 @@ # define lua_setmetatable xmi_lua_setmetatable # define lua_setiuservalue xmi_lua_setiuservalue -// to macros -# define lua_tointeger xmi_lua_tointeger -# define lua_tointegerx xmi_lua_tointegerx -# define lua_toboolean xmi_lua_toboolean -# define lua_touserdata xmi_lua_touserdata - // access macros +# define lua_isnumber xmi_lua_isnumber +# define lua_isstring xmi_lua_isstring +# define lua_iscfunction xmi_lua_iscfunction +# define lua_isinteger xmi_lua_isinteger +# define lua_isuserdata xmi_lua_isuserdata +# define lua_type xmi_lua_type +# define lua_typename xmi_lua_typename + # define lua_isfunction xmi_lua_isfunction # define lua_istable xmi_lua_istable # define lua_islightuserdata xmi_lua_islightuserdata @@ -220,6 +232,18 @@ # define lua_isnone xmi_lua_isnone # define lua_isnoneornil xmi_lua_isnoneornil +# define lua_tonumberx xmi_lua_tonumberx +# define lua_tointeger xmi_lua_tointeger +# define lua_tointegerx xmi_lua_tointegerx +# define lua_toboolean xmi_lua_toboolean + +# define lua_tolstring xmi_lua_tolstring +# define lua_rawlen xmi_lua_rawlen +# define lua_tocfunction xmi_lua_tocfunction +# define lua_touserdata xmi_lua_touserdata +# define lua_tothread xmi_lua_tothread +# define lua_topointer xmi_lua_topointer + // push macros # define lua_pushnil xmi_lua_pushnil # define lua_pushinteger xmi_lua_pushinteger @@ -331,66 +355,79 @@ typedef struct xmi_luaL_Reg_ { }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { - int (*_lua_type)(lua_State* lua, int idx); // get functions - int (*_lua_getglobal)(lua_State* lua, const char *name); - int (*_lua_gettable)(lua_State* lua, int idx); - int (*_lua_getfield)(lua_State* lua, int idx, const char* k); - int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); - int (*_lua_rawget)(lua_State* lua, int idx); - int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); - int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); - void (*_lua_createtable)(lua_State* lua, int narr, int nrec); - void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); - int (*_lua_getmetatable)(lua_State* lua, int objindex); - int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); + int (*_lua_getglobal)(lua_State* lua, const char *name); + int (*_lua_gettable)(lua_State* lua, int idx); + int (*_lua_getfield)(lua_State* lua, int idx, const char* k); + int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawget)(lua_State* lua, int idx); + int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); + void (*_lua_createtable)(lua_State* lua, int narr, int nrec); + void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); + int (*_lua_getmetatable)(lua_State* lua, int objindex); + int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); // set functions - void (*_lua_setglobal)(lua_State* lua, const char* name); - void (*_lua_settable)(lua_State* lua, int idx); - void (*_lua_setfield)(lua_State* lua, int idx, const char* k); - void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); - void (*_lua_rawset)(lua_State* lua, int idx); - void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); - void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); - int (*_lua_setmetatable)(lua_State* lua, int objindex); - int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); - - // to functions - lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); - int (*_lua_toboolean)(lua_State* lua, int idx); - void* (*_lua_touserdata)(lua_State* lua, int idx); + void (*_lua_setglobal)(lua_State* lua, const char* name); + void (*_lua_settable)(lua_State* lua, int idx); + void (*_lua_setfield)(lua_State* lua, int idx, const char* k); + void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); + void (*_lua_rawset)(lua_State* lua, int idx); + void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); + void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); + int (*_lua_setmetatable)(lua_State* lua, int objindex); + int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); + + // access functions + int (*_lua_isnumber)(lua_State* lua, int idx); + int (*_lua_isstring)(lua_State* lua, int idx); + int (*_lua_iscfunction)(lua_State* lua, int idx); + int (*_lua_isinteger)(lua_State* lua, int idx); + int (*_lua_isuserdata)(lua_State* lua, int idx); + int (*_lua_type)(lua_State* lua, int idx); + const char* (*_lua_typename)(lua_State* lua, int tp); + + lua_Number (*_lua_tonumberx)(lua_State* lua, int idx, int* isnum); + lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); + int (*_lua_toboolean)(lua_State* lua, int idx); + const char* (*_lua_tolstring)(lua_State* lua, int idx, size_t* len); + lua_Unsigned (*_lua_rawlen)(lua_State* lua, int idx); + lua_CFunction (*_lua_tocfunction)(lua_State* lua, int idx); + void* (*_lua_touserdata)(lua_State* lua, int idx); + lua_State* (*_lua_tothread)(lua_State* lua, int idx); + const void* (*_lua_topointer)(lua_State* lua, int idx); // push functions - void (*_lua_pushnil)(lua_State* lua); - void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); - void (*_lua_pushboolean)(lua_State* lua, int b); - void (*_lua_pushnumber)(lua_State* lua, lua_Number n); - const char* (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); - const char* (*_lua_pushstring)(lua_State* lua, const char* s); - const char* (*_lua_pushvfstring)(lua_State* lua, const char* fmt, va_list argp); - const char* (*_lua_pushfstring)(lua_State* lua, const char* fmt, ...); - void (*_lua_pushcclosure)(lua_State* lua, lua_CFunction fn, int n); - void (*_lua_pushlightuserdata)(lua_State* lua, void* p); - int (*_lua_pushthread)(lua_State* lua); + void (*_lua_pushnil)(lua_State* lua); + void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); + void (*_lua_pushboolean)(lua_State* lua, int b); + void (*_lua_pushnumber)(lua_State* lua, lua_Number n); + const char* (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); + const char* (*_lua_pushstring)(lua_State* lua, const char* s); + const char* (*_lua_pushvfstring)(lua_State* lua, const char* fmt, va_list argp); + const char* (*_lua_pushfstring)(lua_State* lua, const char* fmt, ...); + void (*_lua_pushcclosure)(lua_State* lua, lua_CFunction fn, int n); + void (*_lua_pushlightuserdata)(lua_State* lua, void* p); + int (*_lua_pushthread)(lua_State* lua); // stack functions - int (*_lua_absindex)(lua_State* lua, int idx); - int (*_lua_gettop)(lua_State* lua); - void (*_lua_settop)(lua_State* lua, int idx); - void (*_lua_pushvalue)(lua_State* lua, int idx); - void (*_lua_rotate)(lua_State* lua, int idx, int n); - void (*_lua_copy)(lua_State* lua, int fromidx, int toidx); - int (*_lua_checkstack)(lua_State* lua, int n); - void (*_lua_xmove)(lua_State* from, lua_State* to, int n); + int (*_lua_absindex)(lua_State* lua, int idx); + int (*_lua_gettop)(lua_State* lua); + void (*_lua_settop)(lua_State* lua, int idx); + void (*_lua_pushvalue)(lua_State* lua, int idx); + void (*_lua_rotate)(lua_State* lua, int idx, int n); + void (*_lua_copy)(lua_State* lua, int fromidx, int toidx); + int (*_lua_checkstack)(lua_State* lua, int n); + void (*_lua_xmove)(lua_State* from, lua_State* to, int n); // luaL functions - void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); - int (*_luaL_error)(lua_State* lua, const char* fmt, ...); - int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); - lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); - int (*_luaL_checkoption)(lua_State* lua, int arg, const char *def, const char *const lst[]); + void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); + int (*_luaL_error)(lua_State* lua, const char* fmt, ...); + int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); + lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); + int (*_luaL_checkoption)(lua_State* lua, int arg, const char *def, const char *const lst[]); }xmi_lua_ops_t; -- cgit v1.3.1 From 2bd085d6428a90b955409268ddacdf6d7d6e7a30 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 00:56:11 +0800 Subject: add miscellaneous functions --- core/src/xmake/package/loadxmi.c | 11 ++++++++ xmake/scripts/module/xmi.h | 61 ++++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 12 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index ac1cd5a97..29794887f 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -152,6 +152,17 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_checkstack = &lua_checkstack; s_luaops._lua_xmove = &lua_xmove; + // miscellaneous functions + s_luaops._lua_error = &lua_error; + s_luaops._lua_next = &lua_next; + s_luaops._lua_concat = &lua_concat; + s_luaops._lua_len = &lua_len; + s_luaops._lua_stringtonumber = &lua_stringtonumber; + s_luaops._lua_getallocf = &lua_getallocf; + s_luaops._lua_setallocf = &lua_setallocf; + s_luaops._lua_toclose = &lua_toclose; + s_luaops._lua_closeslot = &lua_closeslot; + // luaL functions s_luaops._luaL_setfuncs = &luaL_setfuncs; s_luaops._luaL_error = &luaL_error; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index c68e34094..8de81be44 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -63,10 +63,6 @@ # define xmi_lua_upvalueindex(i) (XMI_LUA_REGISTRYINDEX - (i)) #endif -// lua macros -#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) -#define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) - // get macros #define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) #define xmi_lua_gettable(lua, idx) (g_lua_ops)->_lua_gettable(lua, idx) @@ -79,6 +75,8 @@ #define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) #define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) #define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) +#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) +#define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) // set macros #define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) @@ -118,6 +116,9 @@ #define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) #define xmi_lua_tothread(lua, idx) (g_lua_ops)->_lua_tothread(lua, idx) #define xmi_lua_topointer(lua, idx) (g_lua_ops)->_lua_topointer(lua, idx) +#define xmi_lua_tonumber(lua, idx) xmi_lua_tonumberx(lua, (idx), NULL) +#define xmi_lua_tostring(lua, idx) xmi_lua_tolstring(lua, (idx), NULL) +#define xmi_lua_tointeger(lua, idx) xmi_lua_tointegerx(lua, (idx), NULL) // push macros #define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) @@ -136,6 +137,7 @@ #define xmi_lua_pushlightuserdata(lua, p) (g_lua_ops)->_lua_pushlightuserdata(lua, p) #define xmi_lua_pushthread(lua) (g_lua_ops)->_lua_pushthread(lua) #define xmi_lua_pushcfunction(lua, f) xmi_lua_pushcclosure(lua, (f), 0) +#define xmi_lua_pushliteral(lua, s) xmi_lua_pushstring(lua, "" s) // stack functions #define xmi_lua_absindex(lua, idx) (g_lua_ops)->_lua_absindex(lua, idx) @@ -147,10 +149,21 @@ #define xmi_lua_checkstack(lua, n) (g_lua_ops)->_lua_checkstack(lua, n) #define xmi_lua_xmove(from, to, n) (g_lua_ops)->_lua_xmove(from, to, n) +// miscellaneous functions +#define xmi_lua_error(lua) (g_lua_ops)->_lua_error(lua) +#define xmi_lua_next(lua, idx) (g_lua_ops)->_lua_next(lua, idx) +#define xmi_lua_concat(lua, n) (g_lua_ops)->_lua_concat(lua, n) +#define xmi_lua_len(lua, idx) (g_lua_ops)->_lua_len(lua, idx) +#define xmi_lua_stringtonumber(lua, s) (g_lua_ops)->_lua_stringtonumber(lua, s) +#define xmi_lua_getallocf(lua, ud) (g_lua_ops)->_lua_getallocf(lua, ud) +#define xmi_lua_setallocf(lua, f, ud) (g_lua_ops)->_lua_setallocf(lua, f, ud) +#define xmi_lua_toclose(lua, idx) (g_lua_ops)->_lua_toclose(lua, idx) +#define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) + // compatibility macros -#define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) -#define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) -#define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) +#define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) +#define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) +#define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) // luaL macros #define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) @@ -186,9 +199,6 @@ * because original lua.h has been included */ #ifndef XM_PREFIX_H -# define lua_upvalueindex xmi_lua_upvalueindex -# define lua_newtable xmi_lua_newtable -# define lua_pop xmi_lua_pop // get macros # define lua_getglobal xmi_lua_getglobal @@ -202,6 +212,9 @@ # define lua_newuserdatauv xmi_lua_newuserdatauv # define lua_getmetatable xmi_lua_getmetatable # define lua_getiuservalue xmi_lua_getiuservalue +# define lua_upvalueindex xmi_lua_upvalueindex +# define lua_newtable xmi_lua_newtable +# define lua_pop xmi_lua_pop // set macros # define lua_setglobal xmi_lua_setglobal @@ -233,16 +246,17 @@ # define lua_isnoneornil xmi_lua_isnoneornil # define lua_tonumberx xmi_lua_tonumberx -# define lua_tointeger xmi_lua_tointeger # define lua_tointegerx xmi_lua_tointegerx # define lua_toboolean xmi_lua_toboolean - # define lua_tolstring xmi_lua_tolstring # define lua_rawlen xmi_lua_rawlen # define lua_tocfunction xmi_lua_tocfunction # define lua_touserdata xmi_lua_touserdata # define lua_tothread xmi_lua_tothread # define lua_topointer xmi_lua_topointer +# define lua_tostring xmi_lua_tostring +# define lua_tonumber xmi_lua_tonumber +# define lua_tointeger xmi_lua_tointeger // push macros # define lua_pushnil xmi_lua_pushnil @@ -257,6 +271,7 @@ # define lua_pushlightuserdata xmi_lua_pushlightuserdata # define lua_pushthread xmi_lua_pushthread # define lua_pushcfunction xmi_lua_pushcfunction +# define lua_pushliteral xmi_lua_pushliteral # define lua_newuserdata xmi_lua_newuserdata # define lua_getuservalue xmi_lua_getuservalue @@ -272,6 +287,17 @@ # define lua_checkstack xmi_lua_checkstack # define lua_xmove xmi_lua_xmove +// miscellaneous functions +# define lua_error xmi_lua_error +# define lua_next xmi_lua_next +# define lua_concat xmi_lua_concat +# define lua_len xmi_lua_len +# define lua_stringtonumber xmi_lua_stringtonumber +# define lua_getallocf xmi_lua_getallocf +# define lua_setallocf xmi_lua_setallocf +# define lua_toclose xmi_lua_toclose +# define lua_closeslot xmi_lua_closeslot + // luaL macros # define luaL_setfuncs xmi_luaL_setfuncs # define luaL_error xmi_luaL_error @@ -422,6 +448,17 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_checkstack)(lua_State* lua, int n); void (*_lua_xmove)(lua_State* from, lua_State* to, int n); + // miscellaneous functions + int (*_lua_error)(lua_State* lua); + int (*_lua_next)(lua_State* lua, int idx); + void (*_lua_concat)(lua_State* lua, int n); + void (*_lua_len)(lua_State* lua, int idx); + size_t (*_lua_stringtonumber)(lua_State* lua, const char* s); + lua_Alloc (*_lua_getallocf)(lua_State* lua, void** ud); + void (*_lua_setallocf)(lua_State* lua, lua_Alloc f, void* ud); + void (*_lua_toclose)(lua_State* lua, int idx); + void (*_lua_closeslot)(lua_State* lua, int idx); + // luaL functions void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); int (*_luaL_error)(lua_State* lua, const char* fmt, ...); -- cgit v1.3.1 From 1aeccb994e65492f9b24125e1930af19de284017 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 21:03:32 +0800 Subject: add more luaL functions --- core/src/xmake/package/loadxmi.c | 23 ++++++++++-- xmake/scripts/module/xmi.h | 77 ++++++++++++++++++++++++++++++++++------ 2 files changed, 88 insertions(+), 12 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 29794887f..78fba0c76 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -164,11 +164,30 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_closeslot = &lua_closeslot; // luaL functions - s_luaops._luaL_setfuncs = &luaL_setfuncs; - s_luaops._luaL_error = &luaL_error; + s_luaops._luaL_getmetafield = &luaL_getmetafield; + s_luaops._luaL_callmeta = &luaL_callmeta; + s_luaops._luaL_tolstring = &luaL_tolstring; s_luaops._luaL_argerror = &luaL_argerror; + s_luaops._luaL_typeerror = &luaL_typeerror; + s_luaops._luaL_checklstring = &luaL_checklstring; + s_luaops._luaL_optlstring = &luaL_optlstring; + s_luaops._luaL_checknumber = &luaL_checknumber; + s_luaops._luaL_optnumber = &luaL_optnumber; s_luaops._luaL_checkinteger = &luaL_checkinteger; + s_luaops._luaL_optinteger = &luaL_optinteger; + s_luaops._luaL_checkstack = &luaL_checkstack; + s_luaops._luaL_checktype = &luaL_checktype; + s_luaops._luaL_checkany = &luaL_checkany; + s_luaops._luaL_newmetatable = &luaL_newmetatable; + s_luaops._luaL_testudata = &luaL_testudata; + s_luaops._luaL_checkudata = &luaL_checkudata; + s_luaops._luaL_where = &luaL_where; + s_luaops._luaL_error = &luaL_error; s_luaops._luaL_checkoption = &luaL_checkoption; + s_luaops._luaL_fileresult = &luaL_fileresult; + s_luaops._luaL_execresult = &luaL_execresult; + s_luaops._luaL_setfuncs = &luaL_setfuncs; + s_luaops_inited = tb_true; } xmisetup_func(&s_luaops); diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index c8057c51e..1398bdc51 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -124,7 +124,7 @@ #define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) #define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) #define xmi_lua_pushboolean(lua, b) (g_lua_ops)->_lua_pushboolean(lua, b) -#define xmi_lua_pushnumber(lua, b) (g_lua_ops)->_lua_pushnumber(lua, n) +#define xmi_lua_pushnumber(lua, n) (g_lua_ops)->_lua_pushnumber(lua, n) #define xmi_lua_pushlstring(lua, s, len) (g_lua_ops)->_lua_pushlstring(lua, s, len) #define xmi_lua_pushstring(lua, s) (g_lua_ops)->_lua_pushstring(lua, s) #define xmi_lua_pushvfstring(lua, fmt, argp) (g_lua_ops)->_lua_pushvfstring(lua, fmt, argp) @@ -166,15 +166,34 @@ #define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) // luaL macros -#define xmi_luaL_setfuncs(lua, narr, nrec) (g_lua_ops)->_luaL_setfuncs(lua, narr, nrec) +#define xmi_luaL_getmetafield(lua, obj, e) (g_lua_ops)->_luaL_getmetafield(lua, obj, e) +#define xmi_luaL_callmeta(lua, obj, e) (g_lua_ops)->_luaL_callmeta(lua, obj, e) +#define xmi_luaL_tolstring(lua, idx, len) (g_lua_ops)->_luaL_tolstring(lua, idx, len) +#define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) +#define xmi_luaL_typeerror(lua, arg, tname) (g_lua_ops)->_luaL_typeerror(lua, arg, tname) +#define xmi_luaL_checklstring(lua, arg, l) (g_lua_ops)->_luaL_checklstring(lua, arg, l) +#define xmi_luaL_optlstring(lua, arg, def, l) (g_lua_ops)->_luaL_optlstring(lua, arg, def, l) +#define xmi_luaL_checknumber(lua, arg) (g_lua_ops)->_luaL_checknumber(lua, arg) +#define xmi_luaL_optnumber(lua, arg, def) (g_lua_ops)->_luaL_optnumber(lua, arg, def) +#define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) +#define xmi_luaL_optinteger(lua, arg, def) (g_lua_ops)->_luaL_optinteger(lua, arg, def) +#define xmi_luaL_checkstack(lua, sz, msg) (g_lua_ops)->_luaL_checkstack(lua, sz, msg) +#define xmi_luaL_checktype(lua, arg, t) (g_lua_ops)->_luaL_checktype(lua, arg, t) +#define xmi_luaL_checkany(lua, arg) (g_lua_ops)->_luaL_checkany(lua, arg) +#define xmi_luaL_newmetatable(lua, tname) (g_lua_ops)->_luaL_newmetatable(lua, tname) +#define xmi_luaL_setmetatable(lua, tname) (g_lua_ops)->_luaL_setmetatable(lua, tname) +#define xmi_luaL_testudata(lua, tname) (g_lua_ops)->_luaL_testudata(lua, tname) +#define xmi_luaL_checkudata(lua, tname) (g_lua_ops)->_luaL_checkudata(lua, tname) +#define xmi_luaL_where(lua, lvl) (g_lua_ops)->_luaL_where(lua, lvl) #if defined(_MSC_VER) # define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) #else # define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) #endif -#define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) -#define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) #define xmi_luaL_checkoption(lua, arg, def, lst) (g_lua_ops)->_luaL_checkoption(lua, arg, def, lst) +#define xmi_luaL_fileresult(lua, stat, fname) (g_lua_ops)->_luaL_fileresult(lua, stat, fname) +#define xmi_luaL_execresult(lua, stat) (g_lua_ops)->_luaL_execresult(lua, stat) +#define xmi_luaL_setfuncs(lua, l, nup) (g_lua_ops)->_luaL_setfuncs(lua, l, nup) #define xmi_luaL_newlibtable(lua, l) xml_lua_createtable(lua, 0, sizeof(l)/sizeof((l)[0]) - 1) #define xmi_luaL_newlib(lua, l) \ @@ -312,11 +331,30 @@ # define lua_closeslot xmi_lua_closeslot // luaL macros -# define luaL_setfuncs xmi_luaL_setfuncs -# define luaL_error xmi_luaL_error +# define luaL_getmetafield xmi_luaL_getmetafield +# define luaL_callmeta xmi_luaL_callmeta +# define luaL_tolstring xmi_luaL_tolstring # define luaL_argerror xmi_luaL_argerror +# define luaL_typeerror xmi_luaL_typeerror +# define luaL_checklstring xmi_luaL_checklstring +# define luaL_optlstring xmi_luaL_optlstring +# define luaL_checknumber xmi_luaL_checknumber +# define luaL_optnumber xmi_luaL_optnumber # define luaL_checkinteger xmi_luaL_checkinteger +# define luaL_optinteger xmi_luaL_optinteger +# define luaL_checkstack xmi_luaL_checkstack +# define luaL_checktype xmi_luaL_checktype +# define luaL_checkany xmi_luaL_checkany +# define luaL_newmetatable xmi_luaL_newmetatable +# define luaL_setmetatable xmi_luaL_setmetatable +# define luaL_testudata xmi_luaL_testudata +# define luaL_checkudata xmi_luaL_checkudata +# define luaL_where xmi_luaL_where +# define luaL_error xmi_luaL_error # define luaL_checkoption xmi_luaL_checkoption +# define luaL_fileresult xmi_luaL_fileresult +# define luaL_execresult xmi_luaL_execresult +# define luaL_setfuncs xmi_luaL_setfuncs # define luaL_newlibtable xmi_luaL_newlibtable # define luaL_newlib xmi_luaL_newlib @@ -396,7 +434,7 @@ typedef struct xmi_luaL_Reg_ { typedef struct xmi_lua_ops_t_ { // get functions - int (*_lua_getglobal)(lua_State* lua, const char *name); + int (*_lua_getglobal)(lua_State* lua, const char* name); int (*_lua_gettable)(lua_State* lua, int idx); int (*_lua_getfield)(lua_State* lua, int idx, const char* k); int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); @@ -473,11 +511,30 @@ typedef struct xmi_lua_ops_t_ { void (*_lua_closeslot)(lua_State* lua, int idx); // luaL functions - void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); - int (*_luaL_error)(lua_State* lua, const char* fmt, ...); + int (*_luaL_getmetafield)(lua_State* lua, int obj, const char* e); + int (*_luaL_callmeta)(lua_State* lua, int obj, const char* e); + const char* (*_luaL_tolstring)(lua_State* lua, int idx, size_t* len); int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); + int (*_luaL_typeerror)(lua_State* lua, int arg, const char* tname); + const char* (*_luaL_checklstring)(lua_State* lua, int arg, size_t* l); + const char* (*_luaL_optlstring)(lua_State* lua, int arg, const char* def, size_t* l); + lua_Number (*_luaL_checknumber)(lua_State* lua, int arg); + lua_Number (*_luaL_optnumber)(lua_State* lua, int arg, lua_Number def); lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); - int (*_luaL_checkoption)(lua_State* lua, int arg, const char *def, const char *const lst[]); + lua_Integer (*_luaL_optinteger)(lua_State* lua, int arg, lua_Integer def); + void (*_luaL_checkstack)(lua_State* lua, int sz, const char* msg); + void (*_luaL_checktype)(lua_State* lua, int arg, int t); + void (*_luaL_checkany)(lua_State* lua, int arg); + int (*_luaL_newmetatable)(lua_State* lua, const char* tname); + void (*_luaL_setmetatable)(lua_State* lua, const char* tname); + void* (*_luaL_testudata)(lua_State* lua, int ud, const char* tname); + void* (*_luaL_checkudata)(lua_State* lua, int ud, const char* tname); + void (*_luaL_where)(lua_State* lua, int lvl); + int (*_luaL_error)(lua_State* lua, const char* fmt, ...); + int (*_luaL_checkoption)(lua_State* lua, int arg, const char* def, const char* const lst[]); + int (*_luaL_fileresult)(lua_State* lua, int stat, const char* fname); + int (*_luaL_execresult)(lua_State* lua, int stat); + void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); }xmi_lua_ops_t; -- cgit v1.3.1 From 05f7602a1d195308e8c220faee6f18cbf65e6781 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 21:05:07 +0800 Subject: add call functions --- core/src/xmake/package/loadxmi.c | 6 ++++++ xmake/scripts/module/xmi.h | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 78fba0c76..b9572d58d 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -163,6 +163,12 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_toclose = &lua_toclose; s_luaops._lua_closeslot = &lua_closeslot; + // 'load' and 'call' functions + s_luaops._lua_callk = &lua_callk; + s_luaops._lua_pcallk = &lua_pcallk; + s_luaops._lua_load = &lua_load; + s_luaops._lua_dump = &lua_dump; + // luaL functions s_luaops._luaL_getmetafield = &luaL_getmetafield; s_luaops._luaL_callmeta = &luaL_callmeta; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 1398bdc51..c07058487 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -160,6 +160,12 @@ #define xmi_lua_toclose(lua, idx) (g_lua_ops)->_lua_toclose(lua, idx) #define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) +// 'load' and 'call' functions +#define xmi_lua_callk(lua, nargs, nr, ctx, k) (g_lua_ops)->_lua_callk(lua, nargs, nr, ctx, k) +#define xmi_lua_pcallk(lua, nargs, nr, ef, ctx, k) (g_lua_ops)->_lua_pcallk(lua, nargs, nr, ef, ctx, k) +#define xmi_lua_load(lua, r, dt, ch, mode) (g_lua_ops)->_lua_load(lua, r, dt, ch, mode) +#define xmi_lua_dump(lua, w, d, strip) (g_lua_ops)->_lua_dump(lua, r, d, strip) + // compatibility macros #define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) #define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) @@ -330,6 +336,12 @@ # define lua_toclose xmi_lua_toclose # define lua_closeslot xmi_lua_closeslot +// 'load' and 'call' functions +# define lua_callk xmi_lua_callk +# define lua_pcallk xmi_lua_pcallk +# define lua_load xmi_lua_load +# define lua_dump xmi_lua_dump + // luaL macros # define luaL_getmetafield xmi_luaL_getmetafield # define luaL_callmeta xmi_luaL_callmeta @@ -510,6 +522,12 @@ typedef struct xmi_lua_ops_t_ { void (*_lua_toclose)(lua_State* lua, int idx); void (*_lua_closeslot)(lua_State* lua, int idx); + // 'load' and 'call' functions + void (*_lua_callk)(lua_State* lua, int nargs, int nresults, lua_KContext ctx, lua_KFunction k); + int (*_lua_pcallk)(lua_State* lua, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k); + int (*_lua_load)(lua_State* lua, lua_Reader reader, void* dt, const char* chunkname, const char* mode); + int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data, int strip); + // luaL functions int (*_luaL_getmetafield)(lua_State* lua, int obj, const char* e); int (*_luaL_callmeta)(lua_State* lua, int obj, const char* e); -- cgit v1.3.1 From 448b9bb740e803c88faffb1cf15c5f46a8eb979b Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 22:55:43 +0800 Subject: modify funcstion for luajit --- core/src/xmake/package/loadxmi.c | 25 +++++++++---- xmake/scripts/module/xmi.h | 76 +++++++++++++++++++++++++++++----------- 2 files changed, 75 insertions(+), 26 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index b9572d58d..9dfbbf608 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -87,26 +87,30 @@ tb_int_t xm_package_loadxmi(lua_State* lua) { // get functions +#ifndef XMI_USE_LUAJIT s_luaops._lua_getglobal = &lua_getglobal; + s_luaops._lua_geti = &lua_geti; + s_luaops._lua_rawgetp = &lua_rawgetp; +#endif s_luaops._lua_gettable = &lua_gettable; s_luaops._lua_getfield = &lua_getfield; - s_luaops._lua_geti = &lua_geti; s_luaops._lua_rawget = &lua_rawget; s_luaops._lua_rawgeti = &lua_rawgeti; - s_luaops._lua_rawgetp = &lua_rawgetp; s_luaops._lua_createtable = &lua_createtable; s_luaops._lua_newuserdatauv = &lua_newuserdatauv; s_luaops._lua_getmetatable = &lua_getmetatable; s_luaops._lua_getiuservalue = &lua_getiuservalue; // set functions +#ifndef XMI_USE_LUAJIT s_luaops._lua_setglobal = &lua_setglobal; + s_luaops._lua_seti = &lua_seti; + s_luaops._lua_rawsetp = &lua_rawsetp; +#endif s_luaops._lua_settable = &lua_settable; s_luaops._lua_setfield = &lua_setfield; - s_luaops._lua_seti = &lua_seti; s_luaops._lua_rawset = &lua_rawset; s_luaops._lua_rawseti = &lua_rawseti; - s_luaops._lua_rawsetp = &lua_rawsetp; s_luaops._lua_setmetatable = &lua_setmetatable; s_luaops._lua_setiuservalue = &lua_setiuservalue; @@ -114,20 +118,24 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_isnumber = &lua_isnumber; s_luaops._lua_isstring = &lua_isstring; s_luaops._lua_iscfunction = &lua_iscfunction; - s_luaops._lua_isinteger = &lua_isinteger; s_luaops._lua_isuserdata = &lua_isuserdata; s_luaops._lua_type = &lua_type; s_luaops._lua_typename = &lua_typename; +#ifndef XMI_USE_LUAJIT + s_luaops._lua_isinteger = &lua_isinteger; +#endif s_luaops._lua_tonumberx = &lua_tonumberx; s_luaops._lua_tointegerx = &lua_tointegerx; s_luaops._lua_toboolean = &lua_toboolean; s_luaops._lua_tolstring = &lua_tolstring; - s_luaops._lua_rawlen = &lua_rawlen; s_luaops._lua_tocfunction = &lua_tocfunction; s_luaops._lua_touserdata = &lua_touserdata; s_luaops._lua_tothread = &lua_tothread; s_luaops._lua_topointer = &lua_topointer; +#ifndef XMI_USE_LUAJIT + s_luaops._lua_rawlen = &lua_rawlen; +#endif // push functions s_luaops._lua_pushnil = &lua_pushnil; @@ -164,8 +172,13 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_closeslot = &lua_closeslot; // 'load' and 'call' functions +#ifdef XMI_USE_LUAJIT + s_luaops._lua_call = &lua_call; + s_luaops._lua_pcall = &lua_pcall; +#else s_luaops._lua_callk = &lua_callk; s_luaops._lua_pcallk = &lua_pcallk; +#endif s_luaops._lua_load = &lua_load; s_luaops._lua_dump = &lua_dump; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index c9688e9fa..5d30398cd 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -72,13 +72,17 @@ #endif // get macros -#define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) +#ifdef XMI_USE_LUAJIT +# define xmi_lua_getglobal(lua, s) xmi_lua_getfield(lua, LUA_GLOBALSINDEX, (s)) +#else +# define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) +# define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) +# define xmi_lua_rawgetp(lua, idx, p) (g_lua_ops)->_lua_rawgetp(lua, idx, p) +#endif #define xmi_lua_gettable(lua, idx) (g_lua_ops)->_lua_gettable(lua, idx) #define xmi_lua_getfield(lua, idx, k) (g_lua_ops)->_lua_getfield(lua, idx, k) -#define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) #define xmi_lua_rawget(lua, idx) (g_lua_ops)->_lua_rawget(lua, idx) #define xmi_lua_rawgeti(lua, idx, n) (g_lua_ops)->_lua_rawgeti(lua, idx, n) -#define xmi_lua_rawgetp(lua, idx, p) (g_lua_ops)->_lua_rawgetp(lua, idx, p) #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) #define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) @@ -87,13 +91,17 @@ #define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) // set macros -#define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) +#ifdef XMI_USE_LUAJIT +# define xmi_lua_setglobal(lua, s) xmi_lua_setfield(lua, LUA_GLOBALSINDEX, (s)) +#else +# define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) +# define xmi_lua_seti(lua, idx, n) (g_lua_ops)->_lua_seti(lua, idx, n) +# define xmi_lua_rawsetp(lua, idx, p) (g_lua_ops)->_lua_rawsetp(lua, idx, p) +#endif #define xmi_lua_settable(lua, idx) (g_lua_ops)->_lua_settable(lua, idx) #define xmi_lua_setfield(lua, idx, k) (g_lua_ops)->_lua_setfield(lua, idx, k) -#define xmi_lua_seti(lua, idx, n) (g_lua_ops)->_lua_seti(lua, idx, n) #define xmi_lua_rawset(lua, idx) (g_lua_ops)->_lua_rawset(lua, idx) #define xmi_lua_rawseti(lua, idx, n) (g_lua_ops)->_lua_rawseti(lua, idx, n) -#define xmi_lua_rawsetp(lua, idx, p) (g_lua_ops)->_lua_rawsetp(lua, idx, p) #define xmi_lua_setmetatable(lua, objidx) (g_lua_ops)->_lua_setmetatable(lua, objidx) #define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) @@ -101,10 +109,12 @@ #define xmi_lua_isnumber(lua, idx) (g_lua_ops)->_lua_isnumber(lua, idx) #define xmi_lua_isstring(lua, idx) (g_lua_ops)->_lua_isstring(lua, idx) #define xmi_lua_iscfunction(lua, idx) (g_lua_ops)->_lua_iscfunction(lua, idx) -#define xmi_lua_isinteger(lua, idx) (g_lua_ops)->_lua_isinteger(lua, idx) #define xmi_lua_isuserdata(lua, idx) (g_lua_ops)->_lua_isuserdata(lua, idx) #define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) #define xmi_lua_typename(lua, idx) (g_lua_ops)->_lua_typename(lua, idx) +#ifndef XMI_USE_LUAJIT +# define xmi_lua_isinteger(lua, idx) (g_lua_ops)->_lua_isinteger(lua, idx) +#endif #define xmi_lua_isfunction(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TFUNCTION) #define xmi_lua_istable(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTABLE) @@ -172,12 +182,17 @@ #define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) // 'load' and 'call' functions -#define xmi_lua_callk(lua, nargs, nr, ctx, k) (g_lua_ops)->_lua_callk(lua, nargs, nr, ctx, k) -#define xmi_lua_pcallk(lua, nargs, nr, ef, ctx, k) (g_lua_ops)->_lua_pcallk(lua, nargs, nr, ef, ctx, k) +#ifdef XMI_USE_LUAJIT +# define xmi_lua_call(lua, n, nr) (g_lua_ops)->_lua_call(lua, n, nr) +# define xmi_lua_pcall(lua, n, nr, ef) (g_lua_ops)->_lua_pcall(lua, n, nr, ef) +#else +# define xmi_lua_callk(lua, n, nr, ctx, k) (g_lua_ops)->_lua_callk(lua, n, nr, ctx, k) +# define xmi_lua_pcallk(lua, n, nr, ef, ctx, k) (g_lua_ops)->_lua_pcallk(lua, n, nr, ef, ctx, k) +# define xmi_lua_call(lua, n, r) xmi_lua_callk(lua, (n), (r), 0, NULL) +# define xmi_lua_pcall(lua, n, r, f) xmi_lua_pcallk(lua, (n), (r), (f), 0, NULL) +#endif #define xmi_lua_load(lua, r, dt, ch, mode) (g_lua_ops)->_lua_load(lua, r, dt, ch, mode) #define xmi_lua_dump(lua, w, d, strip) (g_lua_ops)->_lua_dump(lua, r, d, strip) -#define xmi_lua_call(lua, n, r) xmi_lua_callk(lua, (n), (r), 0, NULL) -#define xmi_lua_pcall(lua, n, r, f) xmi_lua_pcallk(lua, (n), (r), (f), 0, NULL) // compatibility macros #define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) @@ -290,10 +305,12 @@ # define lua_isnumber xmi_lua_isnumber # define lua_isstring xmi_lua_isstring # define lua_iscfunction xmi_lua_iscfunction -# define lua_isinteger xmi_lua_isinteger # define lua_isuserdata xmi_lua_isuserdata # define lua_type xmi_lua_type # define lua_typename xmi_lua_typename +# ifndef XMI_USE_LUAJIT +# define lua_isinteger xmi_lua_isinteger +# endif # define lua_isfunction xmi_lua_isfunction # define lua_istable xmi_lua_istable @@ -361,12 +378,14 @@ # define lua_closeslot xmi_lua_closeslot // 'load' and 'call' functions +# ifndef XMI_USE_LUAJIT # define lua_callk xmi_lua_callk # define lua_pcallk xmi_lua_pcallk -# define lua_load xmi_lua_load -# define lua_dump xmi_lua_dump +# endif # define lua_call xmi_lua_call # define lua_pcall xmi_lua_pcall +# define lua_load xmi_lua_load +# define lua_dump xmi_lua_dump // luaL macros # define luaL_getmetafield xmi_luaL_getmetafield @@ -450,15 +469,19 @@ int xmiopen_##name(lua) */ typedef LUA_NUMBER xmi_lua_Number; typedef LUA_INTEGER xmi_lua_Integer; +#ifndef XMI_USE_LUAJIT typedef LUA_UNSIGNED xmi_lua_Unsigned; typedef LUA_KCONTEXT xmi_lua_KContext; +#endif typedef struct xmi_lua_State_ { int dummy; }xmi_lua_State; typedef int (*xmi_lua_CFunction)(lua_State* lua); +#ifndef XMI_USE_LUAJIT typedef int (*xmi_lua_KFunction)(lua_State* lua, int status, lua_KContext ctx); +#endif typedef const char* (*xmi_lua_Reader)(lua_State* lua, void* ud, size_t* sz); typedef int (*xmi_lua_Writer)(lua_State* lua, const void* p, size_t sz, void* ud); typedef void* (*xmi_lua_Alloc)(void* ud, void* ptr, size_t osize, size_t nsize); @@ -472,26 +495,30 @@ typedef struct xmi_luaL_Reg_ { typedef struct xmi_lua_ops_t_ { // get functions +#ifndef XMI_USE_LUAJIT int (*_lua_getglobal)(lua_State* lua, const char* name); + int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); + int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); +#endif int (*_lua_gettable)(lua_State* lua, int idx); int (*_lua_getfield)(lua_State* lua, int idx, const char* k); - int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); int (*_lua_rawget)(lua_State* lua, int idx); int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); - int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); void (*_lua_createtable)(lua_State* lua, int narr, int nrec); void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); int (*_lua_getmetatable)(lua_State* lua, int objindex); int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); // set functions +#ifndef XMI_USE_LUAJIT void (*_lua_setglobal)(lua_State* lua, const char* name); + void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); + void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); +#endif void (*_lua_settable)(lua_State* lua, int idx); void (*_lua_setfield)(lua_State* lua, int idx, const char* k); - void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); void (*_lua_rawset)(lua_State* lua, int idx); void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); - void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); int (*_lua_setmetatable)(lua_State* lua, int objindex); int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); @@ -499,20 +526,24 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_isnumber)(lua_State* lua, int idx); int (*_lua_isstring)(lua_State* lua, int idx); int (*_lua_iscfunction)(lua_State* lua, int idx); - int (*_lua_isinteger)(lua_State* lua, int idx); int (*_lua_isuserdata)(lua_State* lua, int idx); int (*_lua_type)(lua_State* lua, int idx); const char* (*_lua_typename)(lua_State* lua, int tp); +#ifndef XMI_USE_LUAJIT + int (*_lua_isinteger)(lua_State* lua, int idx); +#endif lua_Number (*_lua_tonumberx)(lua_State* lua, int idx, int* isnum); lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); int (*_lua_toboolean)(lua_State* lua, int idx); const char* (*_lua_tolstring)(lua_State* lua, int idx, size_t* len); - lua_Unsigned (*_lua_rawlen)(lua_State* lua, int idx); lua_CFunction (*_lua_tocfunction)(lua_State* lua, int idx); void* (*_lua_touserdata)(lua_State* lua, int idx); lua_State* (*_lua_tothread)(lua_State* lua, int idx); const void* (*_lua_topointer)(lua_State* lua, int idx); +#ifndef XMI_USE_LUAJIT + lua_Unsigned (*_lua_rawlen)(lua_State* lua, int idx); +#endif // push functions void (*_lua_pushnil)(lua_State* lua); @@ -549,8 +580,13 @@ typedef struct xmi_lua_ops_t_ { void (*_lua_closeslot)(lua_State* lua, int idx); // 'load' and 'call' functions +#ifdef XMI_USE_LUAJIT + void (*_lua_call)(lua_State* lua, int nargs, int nresults); + int (*_lua_pcall)(lua_State* lua, int nargs, int nresults, int errfunc); +#else void (*_lua_callk)(lua_State* lua, int nargs, int nresults, lua_KContext ctx, lua_KFunction k); int (*_lua_pcallk)(lua_State* lua, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k); +#endif int (*_lua_load)(lua_State* lua, lua_Reader reader, void* dt, const char* chunkname, const char* mode); int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data, int strip); -- cgit v1.3.1 From aec0f76dd46273b48619dc4aa5a8aad22f2b3aad Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 22:56:55 +0800 Subject: update xmi.h --- core/src/xmake/package/loadxmi.c | 6 +++--- xmake/scripts/module/xmi.h | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 9dfbbf608..83c4294cc 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -91,28 +91,28 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_getglobal = &lua_getglobal; s_luaops._lua_geti = &lua_geti; s_luaops._lua_rawgetp = &lua_rawgetp; + s_luaops._lua_getiuservalue = &lua_getiuservalue; + s_luaops._lua_newuserdatauv = &lua_newuserdatauv; #endif s_luaops._lua_gettable = &lua_gettable; s_luaops._lua_getfield = &lua_getfield; s_luaops._lua_rawget = &lua_rawget; s_luaops._lua_rawgeti = &lua_rawgeti; s_luaops._lua_createtable = &lua_createtable; - s_luaops._lua_newuserdatauv = &lua_newuserdatauv; s_luaops._lua_getmetatable = &lua_getmetatable; - s_luaops._lua_getiuservalue = &lua_getiuservalue; // set functions #ifndef XMI_USE_LUAJIT s_luaops._lua_setglobal = &lua_setglobal; s_luaops._lua_seti = &lua_seti; s_luaops._lua_rawsetp = &lua_rawsetp; + s_luaops._lua_setiuservalue = &lua_setiuservalue; #endif s_luaops._lua_settable = &lua_settable; s_luaops._lua_setfield = &lua_setfield; s_luaops._lua_rawset = &lua_rawset; s_luaops._lua_rawseti = &lua_rawseti; s_luaops._lua_setmetatable = &lua_setmetatable; - s_luaops._lua_setiuservalue = &lua_setiuservalue; // access functions s_luaops._lua_isnumber = &lua_isnumber; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 5d30398cd..819c5af58 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -78,17 +78,19 @@ # define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) # define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) # define xmi_lua_rawgetp(lua, idx, p) (g_lua_ops)->_lua_rawgetp(lua, idx, p) +# define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) +# define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) +# define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) #endif #define xmi_lua_gettable(lua, idx) (g_lua_ops)->_lua_gettable(lua, idx) #define xmi_lua_getfield(lua, idx, k) (g_lua_ops)->_lua_getfield(lua, idx, k) #define xmi_lua_rawget(lua, idx) (g_lua_ops)->_lua_rawget(lua, idx) #define xmi_lua_rawgeti(lua, idx, n) (g_lua_ops)->_lua_rawgeti(lua, idx, n) #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) -#define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) #define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) -#define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) #define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) +#define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) // set macros #ifdef XMI_USE_LUAJIT @@ -97,13 +99,14 @@ # define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) # define xmi_lua_seti(lua, idx, n) (g_lua_ops)->_lua_seti(lua, idx, n) # define xmi_lua_rawsetp(lua, idx, p) (g_lua_ops)->_lua_rawsetp(lua, idx, p) +# define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) #endif #define xmi_lua_settable(lua, idx) (g_lua_ops)->_lua_settable(lua, idx) #define xmi_lua_setfield(lua, idx, k) (g_lua_ops)->_lua_setfield(lua, idx, k) #define xmi_lua_rawset(lua, idx) (g_lua_ops)->_lua_rawset(lua, idx) #define xmi_lua_rawseti(lua, idx, n) (g_lua_ops)->_lua_rawseti(lua, idx, n) #define xmi_lua_setmetatable(lua, objidx) (g_lua_ops)->_lua_setmetatable(lua, objidx) -#define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) +#define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) // access macros #define xmi_lua_isnumber(lua, idx) (g_lua_ops)->_lua_isnumber(lua, idx) @@ -194,11 +197,6 @@ #define xmi_lua_load(lua, r, dt, ch, mode) (g_lua_ops)->_lua_load(lua, r, dt, ch, mode) #define xmi_lua_dump(lua, w, d, strip) (g_lua_ops)->_lua_dump(lua, r, d, strip) -// compatibility macros -#define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) -#define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) -#define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) - // luaL macros #define xmi_luaL_getmetafield(lua, obj, e) (g_lua_ops)->_luaL_getmetafield(lua, obj, e) #define xmi_luaL_callmeta(lua, obj, e) (g_lua_ops)->_luaL_callmeta(lua, obj, e) @@ -289,6 +287,8 @@ # define lua_upvalueindex xmi_lua_upvalueindex # define lua_newtable xmi_lua_newtable # define lua_pop xmi_lua_pop +# define lua_newuserdata xmi_lua_newuserdata +# define lua_getuservalue xmi_lua_getuservalue // set macros # define lua_setglobal xmi_lua_setglobal @@ -300,6 +300,7 @@ # define lua_rawsetp xmi_lua_rawsetp # define lua_setmetatable xmi_lua_setmetatable # define lua_setiuservalue xmi_lua_setiuservalue +# define lua_setuservalue xmi_lua_setuservalue // access macros # define lua_isnumber xmi_lua_isnumber @@ -349,10 +350,6 @@ # define lua_pushcfunction xmi_lua_pushcfunction # define lua_pushliteral xmi_lua_pushliteral -# define lua_newuserdata xmi_lua_newuserdata -# define lua_getuservalue xmi_lua_getuservalue -# define lua_setuservalue xmi_lua_setuservalue - // stack functions # define lua_absindex xmi_lua_absindex # define lua_gettop xmi_lua_gettop @@ -499,28 +496,28 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_getglobal)(lua_State* lua, const char* name); int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); + int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); + void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); #endif int (*_lua_gettable)(lua_State* lua, int idx); int (*_lua_getfield)(lua_State* lua, int idx, const char* k); int (*_lua_rawget)(lua_State* lua, int idx); int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); void (*_lua_createtable)(lua_State* lua, int narr, int nrec); - void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); int (*_lua_getmetatable)(lua_State* lua, int objindex); - int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); // set functions #ifndef XMI_USE_LUAJIT void (*_lua_setglobal)(lua_State* lua, const char* name); void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); + int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); #endif void (*_lua_settable)(lua_State* lua, int idx); void (*_lua_setfield)(lua_State* lua, int idx, const char* k); void (*_lua_rawset)(lua_State* lua, int idx); void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); int (*_lua_setmetatable)(lua_State* lua, int objindex); - int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); // access functions int (*_lua_isnumber)(lua_State* lua, int idx); -- cgit v1.3.1 From bcce486dd75ee32d83cb536c3ea58c406944a3cf Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 23:08:00 +0800 Subject: support for luajit native module --- core/src/xmake/package/loadxmi.c | 24 ++++++++++++----- xmake/scripts/module/xmi.h | 57 ++++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 23 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 83c4294cc..c9d3bb80d 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -87,7 +87,9 @@ tb_int_t xm_package_loadxmi(lua_State* lua) { // get functions -#ifndef XMI_USE_LUAJIT +#ifdef XMI_USE_LUAJIT + s_luaops._lua_newuserdata = &lua_newuserdata; +#else s_luaops._lua_getglobal = &lua_getglobal; s_luaops._lua_geti = &lua_geti; s_luaops._lua_rawgetp = &lua_rawgetp; @@ -151,11 +153,17 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_pushthread = &lua_pushthread; // stack functions +#ifdef XMI_USE_LUAJIT + s_luaops._lua_insert = &lua_insert; + s_luaops._lua_remove = &lua_remove; + s_luaops._lua_replace = &lua_replace; +#else s_luaops._lua_absindex = &lua_absindex; + s_luaops._lua_rotate = &lua_rotate; +#endif s_luaops._lua_gettop = &lua_gettop; s_luaops._lua_settop = &lua_settop; s_luaops._lua_pushvalue = &lua_pushvalue; - s_luaops._lua_rotate = &lua_rotate; s_luaops._lua_copy = &lua_copy; s_luaops._lua_checkstack = &lua_checkstack; s_luaops._lua_xmove = &lua_xmove; @@ -164,12 +172,14 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_error = &lua_error; s_luaops._lua_next = &lua_next; s_luaops._lua_concat = &lua_concat; - s_luaops._lua_len = &lua_len; - s_luaops._lua_stringtonumber = &lua_stringtonumber; s_luaops._lua_getallocf = &lua_getallocf; s_luaops._lua_setallocf = &lua_setallocf; +#ifndef XMI_USE_LUAJIT + s_luaops._lua_len = &lua_len; s_luaops._lua_toclose = &lua_toclose; s_luaops._lua_closeslot = &lua_closeslot; + s_luaops._lua_stringtonumber = &lua_stringtonumber; +#endif // 'load' and 'call' functions #ifdef XMI_USE_LUAJIT @@ -183,11 +193,13 @@ tb_int_t xm_package_loadxmi(lua_State* lua) s_luaops._lua_dump = &lua_dump; // luaL functions +#ifndef XMI_USE_LUAJIT + s_luaops._luaL_tolstring = &luaL_tolstring; + s_luaops._luaL_typeerror = &luaL_typeerror; +#endif s_luaops._luaL_getmetafield = &luaL_getmetafield; s_luaops._luaL_callmeta = &luaL_callmeta; - s_luaops._luaL_tolstring = &luaL_tolstring; s_luaops._luaL_argerror = &luaL_argerror; - s_luaops._luaL_typeerror = &luaL_typeerror; s_luaops._luaL_checklstring = &luaL_checklstring; s_luaops._luaL_optlstring = &luaL_optlstring; s_luaops._luaL_checknumber = &luaL_checknumber; diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h index 819c5af58..da5e16906 100644 --- a/xmake/scripts/module/xmi.h +++ b/xmake/scripts/module/xmi.h @@ -74,6 +74,7 @@ // get macros #ifdef XMI_USE_LUAJIT # define xmi_lua_getglobal(lua, s) xmi_lua_getfield(lua, LUA_GLOBALSINDEX, (s)) +# define xmi_lua_newuserdata(lua, s) (g_lua_ops)->_lua_newuserdata(lua, s) #else # define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) # define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) @@ -161,28 +162,36 @@ #define xmi_lua_pushliteral(lua, s) xmi_lua_pushstring(lua, "" s) // stack functions -#define xmi_lua_absindex(lua, idx) (g_lua_ops)->_lua_absindex(lua, idx) +#ifdef XMI_USE_LUAJIT +# define xmi_lua_insert(lua, idx) (g_lua_ops)->_lua_insert(lua, idx) +# define xmi_lua_remove(lua, idx) (g_lua_ops)->_lua_remove(lua, idx) +# define xmi_lua_replace(lua, idx) (g_lua_ops)->_lua_replace(lua, idx) +#else +# define xmi_lua_absindex(lua, idx) (g_lua_ops)->_lua_absindex(lua, idx) +# define xmi_lua_rotate(lua, idx, n) (g_lua_ops)->_lua_rotate(lua, idx, n) +# define xmi_lua_insert(lua, idx) xmi_lua_rotate(lua, (idx), 1) +# define xmi_lua_remove(lua, idx) (xmi_lua_rotate(lua, (idx), -1), xmi_lua_pop(lua, 1)) +# define xmi_lua_replace(lua, idx) (xmi_lua_copy(lua, -1, (idx)), xmi_lua_pop(lua, 1)) +#endif #define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) #define xmi_lua_settop(lua, idx) (g_lua_ops)->_lua_settop(lua, idx) #define xmi_lua_pushvalue(lua, idx) (g_lua_ops)->_lua_pushvalue(lua, idx) -#define xmi_lua_rotate(lua, idx, n) (g_lua_ops)->_lua_rotate(lua, idx, n) #define xmi_lua_copy(lua, fromidx, toidx) (g_lua_ops)->_lua_copy(lua, fromidx, toidx) #define xmi_lua_checkstack(lua, n) (g_lua_ops)->_lua_checkstack(lua, n) #define xmi_lua_xmove(from, to, n) (g_lua_ops)->_lua_xmove(from, to, n) -#define xmi_lua_insert(lua, idx) xmi_lua_rotate(lua, (idx), 1) -#define xmi_lua_remove(lua, idx) (xmi_lua_rotate(lua, (idx), -1), xmi_lua_pop(lua, 1)) -#define xmi_lua_replace(lua, idx) (xmi_lua_copy(lua, -1, (idx)), xmi_lua_pop(lua, 1)) // miscellaneous functions #define xmi_lua_error(lua) (g_lua_ops)->_lua_error(lua) #define xmi_lua_next(lua, idx) (g_lua_ops)->_lua_next(lua, idx) #define xmi_lua_concat(lua, n) (g_lua_ops)->_lua_concat(lua, n) -#define xmi_lua_len(lua, idx) (g_lua_ops)->_lua_len(lua, idx) -#define xmi_lua_stringtonumber(lua, s) (g_lua_ops)->_lua_stringtonumber(lua, s) #define xmi_lua_getallocf(lua, ud) (g_lua_ops)->_lua_getallocf(lua, ud) #define xmi_lua_setallocf(lua, f, ud) (g_lua_ops)->_lua_setallocf(lua, f, ud) -#define xmi_lua_toclose(lua, idx) (g_lua_ops)->_lua_toclose(lua, idx) -#define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) +#ifndef XMI_USE_LUAJIT +# define xmi_lua_len(lua, idx) (g_lua_ops)->_lua_len(lua, idx) +# define xmi_lua_toclose(lua, idx) (g_lua_ops)->_lua_toclose(lua, idx) +# define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) +# define xmi_lua_stringtonumber(lua, s) (g_lua_ops)->_lua_stringtonumber(lua, s) +#endif // 'load' and 'call' functions #ifdef XMI_USE_LUAJIT @@ -198,11 +207,13 @@ #define xmi_lua_dump(lua, w, d, strip) (g_lua_ops)->_lua_dump(lua, r, d, strip) // luaL macros +#ifndef XMI_USE_LUAJIT +# define xmi_luaL_tolstring(lua, idx, len) (g_lua_ops)->_luaL_tolstring(lua, idx, len) +# define xmi_luaL_typeerror(lua, arg, tname) (g_lua_ops)->_luaL_typeerror(lua, arg, tname) +#endif #define xmi_luaL_getmetafield(lua, obj, e) (g_lua_ops)->_luaL_getmetafield(lua, obj, e) #define xmi_luaL_callmeta(lua, obj, e) (g_lua_ops)->_luaL_callmeta(lua, obj, e) -#define xmi_luaL_tolstring(lua, idx, len) (g_lua_ops)->_luaL_tolstring(lua, idx, len) #define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) -#define xmi_luaL_typeerror(lua, arg, tname) (g_lua_ops)->_luaL_typeerror(lua, arg, tname) #define xmi_luaL_checklstring(lua, arg, l) (g_lua_ops)->_luaL_checklstring(lua, arg, l) #define xmi_luaL_optlstring(lua, arg, def, l) (g_lua_ops)->_luaL_optlstring(lua, arg, def, l) #define xmi_luaL_checknumber(lua, arg) (g_lua_ops)->_luaL_checknumber(lua, arg) @@ -492,7 +503,9 @@ typedef struct xmi_luaL_Reg_ { typedef struct xmi_lua_ops_t_ { // get functions -#ifndef XMI_USE_LUAJIT +#ifdef XMI_USE_LUAJIT + void* (*_lua_newuserdata)(lua_State* lua, size_t sz); +#else int (*_lua_getglobal)(lua_State* lua, const char* name); int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); @@ -556,11 +569,17 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_pushthread)(lua_State* lua); // stack functions +#ifdef XMI_USE_LUAJIT + void (*_lua_insert)(lua_State* lua, int idx); + void (*_lua_remove)(lua_State* lua, int idx); + void (*_lua_replace)(lua_State* lua, int idx); +#else int (*_lua_absindex)(lua_State* lua, int idx); + void (*_lua_rotate)(lua_State* lua, int idx, int n); +#endif int (*_lua_gettop)(lua_State* lua); void (*_lua_settop)(lua_State* lua, int idx); void (*_lua_pushvalue)(lua_State* lua, int idx); - void (*_lua_rotate)(lua_State* lua, int idx, int n); void (*_lua_copy)(lua_State* lua, int fromidx, int toidx); int (*_lua_checkstack)(lua_State* lua, int n); void (*_lua_xmove)(lua_State* from, lua_State* to, int n); @@ -569,12 +588,14 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_error)(lua_State* lua); int (*_lua_next)(lua_State* lua, int idx); void (*_lua_concat)(lua_State* lua, int n); - void (*_lua_len)(lua_State* lua, int idx); - size_t (*_lua_stringtonumber)(lua_State* lua, const char* s); lua_Alloc (*_lua_getallocf)(lua_State* lua, void** ud); void (*_lua_setallocf)(lua_State* lua, lua_Alloc f, void* ud); +#ifndef XMI_USE_LUAJIT + void (*_lua_len)(lua_State* lua, int idx); void (*_lua_toclose)(lua_State* lua, int idx); void (*_lua_closeslot)(lua_State* lua, int idx); + size_t (*_lua_stringtonumber)(lua_State* lua, const char* s); +#endif // 'load' and 'call' functions #ifdef XMI_USE_LUAJIT @@ -588,11 +609,13 @@ typedef struct xmi_lua_ops_t_ { int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data, int strip); // luaL functions +#ifdef XMI_USE_LUAJIT + const char* (*_luaL_tolstring)(lua_State* lua, int idx, size_t* len); + int (*_luaL_typeerror)(lua_State* lua, int arg, const char* tname); +#endif int (*_luaL_getmetafield)(lua_State* lua, int obj, const char* e); int (*_luaL_callmeta)(lua_State* lua, int obj, const char* e); - const char* (*_luaL_tolstring)(lua_State* lua, int idx, size_t* len); int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); - int (*_luaL_typeerror)(lua_State* lua, int arg, const char* tname); const char* (*_luaL_checklstring)(lua_State* lua, int arg, size_t* l); const char* (*_luaL_optlstring)(lua_State* lua, int arg, const char* def, size_t* l); lua_Number (*_luaL_checknumber)(lua_State* lua, int arg); -- cgit v1.3.1 From df7a9c2c209b1aa33e7999a309c621e6787f5ae5 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Apr 2024 23:08:43 +0800 Subject: format code --- core/src/xmake/package/loadxmi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'core/src') diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index c9d3bb80d..43915aff3 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -85,7 +85,6 @@ tb_int_t xm_package_loadxmi(lua_State* lua) static tb_bool_t s_luaops_inited = tb_false; if (!s_luaops_inited) { - // get functions #ifdef XMI_USE_LUAJIT s_luaops._lua_newuserdata = &lua_newuserdata; -- cgit v1.3.1