diff options
| author | ruki <[email protected]> | 2020-04-22 23:23:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-22 14:21:42 +0800 |
| commit | 9407f3893ca3f71578febcabdf6a022a80dae209 (patch) | |
| tree | ed5e08bf206b406028b840a7f036af4c9a4d96c7 /core/src/xmake/engine.c | |
| parent | 8567065df7d23e7c51880d1e36a9895a13cd4b89 (diff) | |
add lni module
Diffstat (limited to 'core/src/xmake/engine.c')
| -rw-r--r-- | core/src/xmake/engine.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index b7ef783d1..f92729297 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -829,8 +829,13 @@ xm_engine_ref_t xm_engine_init(xm_engine_lua_initializer_cb_t lua_initalizer) lua_newtable(engine->lua); lua_setglobal(engine->lua, "xmake"); - // do lua initializer - if (lua_initalizer) lua_initalizer(engine->lua); + /* do lua initializer and init namespace: _lni + * + * we can get the lni modules for _lni or `import("lib.lni.xxx")` in sandbox + */ + lua_newtable(engine->lua); + if (lua_initalizer) lua_initalizer((xm_engine_ref_t)engine, engine->lua); + lua_setglobal(engine->lua, "_lni"); #ifdef TB_CONFIG_OS_WINDOWS // enable terminal colors output for windows cmd @@ -943,3 +948,15 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv) // get the error code return (tb_int_t)lua_tonumber(engine->lua, -1); } +tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL_Reg const funcs[]) +{ + // check + xm_engine_t* engine = (xm_engine_t*)self; + tb_assert_and_check_return(engine && engine->lua && module && funcs); + + // do register + lua_pushstring(engine->lua, module); + lua_newtable(engine->lua); + luaL_register(engine->lua, tb_null, funcs); + lua_rawset(engine->lua, -3); +} |
