diff options
| author | jussi | 2023-10-15 22:31:17 +0300 |
|---|---|---|
| committer | jussi | 2023-10-15 22:31:17 +0300 |
| commit | 95be0403e69b3047a0375cf965dedca0ad876409 (patch) | |
| tree | ebfc72f0e5ad7c193e679a0744443b367902c09a /src | |
| parent | 7af7e7003131e182efb30bac8c1ff06ac1d667d6 (diff) | |
| download | reilua-enhanced-95be0403e69b3047a0375cf965dedca0ad876409.tar.gz reilua-enhanced-95be0403e69b3047a0375cf965dedca0ad876409.tar.bz2 reilua-enhanced-95be0403e69b3047a0375cf965dedca0ad876409.zip | |
Argumets stored in RL.arg array.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua_core.c | 20 | ||||
| -rw-r--r-- | src/main.c | 4 | ||||
| -rw-r--r-- | src/state.c | 8 |
3 files changed, 23 insertions, 9 deletions
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; } @@ -48,7 +48,7 @@ int main( int argn, const char **argc ) { } if ( interpret_mode ) { - stateInitInterpret(); + stateInitInterpret( argn, argc ); lua_State *L = state->luaState; lua_pushcfunction( L, luaTraceback ); @@ -63,7 +63,7 @@ int main( int argn, const char **argc ) { } else { printVersion(); - stateInit( exePath ); + stateInit( argn, argc, exePath ); luaRegister(); state->run = luaCallMain(); diff --git a/src/state.c b/src/state.c index 2e1a50f..d1a3329 100644 --- a/src/state.c +++ b/src/state.c @@ -6,7 +6,7 @@ State *state; -bool stateInit( const char *exePath ) { +bool stateInit( int argn, const char **argc, const char *exePath ) { state = malloc( sizeof( State ) ); state->exePath = malloc( STRING_LEN * sizeof( char ) ); @@ -107,15 +107,15 @@ bool stateInit( const char *exePath ) { } if ( state->run ) { InitAudioDevice(); - state->run = luaInit(); + state->run = luaInit( argn, argc ); } return state->run; } -void stateInitInterpret() { +void stateInitInterpret( int argn, const char **argc ) { state = malloc( sizeof( State ) ); - luaInit(); + luaInit( argn, argc ); } void stateFree() { |
