From 95be0403e69b3047a0375cf965dedca0ad876409 Mon Sep 17 00:00:00 2001 From: jussi Date: Sun, 15 Oct 2023 22:31:17 +0300 Subject: Argumets stored in RL.arg array. --- src/lua_core.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/lua_core.c') diff --git a/src/lua_core.c b/src/lua_core.c index 15dfe70..c254a9d 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1007,18 +1007,32 @@ static void cursorEnterInputEvent( GLFWwindow* window, int enter ) { lua_pop( L, -1 ); } -bool luaInit() { +bool luaInit( int argn, const char **argc ) { state->luaState = luaL_newstate(); + lua_State *L = state->luaState; - luaL_openlibs( state->luaState ); + luaL_openlibs( L ); - if ( state->luaState == NULL ) { + if ( L == NULL ) { TraceLog( LOG_WARNING, "%s", "Failed to init Lua" ); return false; } defineGlobals(); + /* Set arguments. */ + lua_getglobal( L, "RL" ); + lua_newtable( L ); + lua_setfield( L, -2, "arg" ); + lua_getglobal( L, "RL" ); + lua_getfield( L, -1, "arg" ); + + for ( int i = 0; i < argn; i++ ) { + lua_pushstring( L, argc[i] ); + lua_rawseti( L, -2, i + 1 ); + } + lua_pop( L, -1 ); + return true; } -- cgit v1.2.3