diff options
| author | jussi | 2024-11-21 23:25:28 +0200 |
|---|---|---|
| committer | jussi | 2024-11-21 23:25:28 +0200 |
| commit | c9ebe23d6282e96b410dc7687e0be1c4f3ba1b4d (patch) | |
| tree | dfd26a87fb2b2f702f77728b98a1e6c193684631 /src/lua_core.c | |
| parent | d96e33bb1772c28f630de32e09201c0cdea6f896 (diff) | |
| download | reilua-enhanced-c9ebe23d6282e96b410dc7687e0be1c4f3ba1b4d.tar.gz reilua-enhanced-c9ebe23d6282e96b410dc7687e0be1c4f3ba1b4d.tar.bz2 reilua-enhanced-c9ebe23d6282e96b410dc7687e0be1c4f3ba1b4d.zip | |
RL.config and InitWindow.
Diffstat (limited to 'src/lua_core.c')
| -rw-r--r-- | src/lua_core.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/lua_core.c b/src/lua_core.c index 7150d6d..3dbd199 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1149,7 +1149,7 @@ int luaTraceback( lua_State* L ) { return 1; } -bool luaCallMain() { +void luaCallMain() { lua_State* L = state->luaState; char path[ STRING_LEN ] = { '\0' }; @@ -1168,6 +1168,11 @@ bool luaCallMain() { snprintf( path, STRING_LEN, "%smain", state->basePath ); } #endif + if ( !FileExists( path ) ) { + TraceLog( LOG_ERROR, "Cannot find file: %s\n", path ); + state->run = false; + return; + } luaL_dofile( L, path ); /* Check errors in main.lua */ @@ -1181,26 +1186,48 @@ bool luaCallMain() { SetTraceLogCallback( logCustom ); lua_getglobal( L, "RL" ); - lua_getfield( L, -1, "init" ); + lua_getfield( L, -1, "config" ); if ( lua_isfunction( L, -1 ) ) { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); - return false; + state->run = false; + return; } } - //TODO Should this be removed? + lua_pop( L, -1 ); + /* If InitWindow is not called in RL.config, call it here. */ + if ( !IsWindowReady() ) { + InitWindow( 800, 600, "ReiLua" ); + } + /* Set shader locs after we have window. */ + if ( IsWindowReady() ) { + stateContextInit(); + } else { - TraceLog( LOG_ERROR, "%s", "No Lua init found!" ); - return false; + state->run = false; } - lua_pop( L, -1 ); +} + +void luaCallInit() { + lua_State* L = state->luaState; + lua_pushcfunction( L, luaTraceback ); + int tracebackidx = lua_gettop(L); + + lua_getglobal( L, "RL" ); + lua_getfield( L, -1, "init" ); - return state->run; + if ( lua_isfunction( L, -1 ) ) { + if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { + TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); + state->run = false; + } + } + lua_pop( L, -1 ); } -void luaCallUpdate() { +void luaCallUpdate() { #if defined PLATFORM_DESKTOP_SDL && defined LUA_EVENTS platformSendEvents(); #endif @@ -1218,8 +1245,6 @@ void luaCallUpdate() { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); state->run = false; - lua_pop( L, -1 ); - return; } } lua_pop( L, -1 ); @@ -1239,7 +1264,6 @@ void luaCallDraw() { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); state->run = false; - return; } EndDrawing(); } @@ -1258,7 +1282,6 @@ void luaCallExit() { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); state->run = false; - return; } } lua_pop( L, -1 ); @@ -1270,6 +1293,7 @@ void luaRegister() { /* Core. */ /* Window-related functions. */ + assingGlobalFunction( "InitWindow", lcoreInitWindow ); assingGlobalFunction( "CloseWindow", lcoreCloseWindow ); assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady ); assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen ); |
