Enhance how Lua file is called
This commit is contained in:
parent
aa5249a0f8
commit
f4aaaf6107
22
test/lua.c
22
test/lua.c
@ -10,10 +10,22 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
lua_State *L = luaL_newstate();
|
lua_State *L = luaL_newstate();
|
||||||
assert(L != NULL);
|
assert(L != NULL);
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
luaopen_unigi(L); // Load the wrapped module
|
luaopen_unigi(L); // Load the wrapped module
|
||||||
luaL_loadfile(L, "mods/main/script/main.lua");
|
|
||||||
lua_pcall(L, 0, 0, 0);
|
for (int i = 0; i < argc; i++) {
|
||||||
|
lua_pushstring(L, argv[i]);
|
||||||
|
lua_rawseti(L, -2, i + 1);
|
||||||
|
}
|
||||||
|
lua_setglobal(L, "arg");
|
||||||
|
|
||||||
|
if (luaL_dostring(L,
|
||||||
|
"main_path = (arg[1]:match(\"(.*[/\\\\])\") or \"./\"):sub(1,-2)\n"
|
||||||
|
"dofile(main_path .. \"/mods/main/script/main.lua\")"
|
||||||
|
) != 0) {
|
||||||
|
fprintf(stderr, "Error running Lua code: %s\n", lua_tostring(L, -1));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user