diff options
| author | jussi | 2022-11-27 14:08:58 +0200 |
|---|---|---|
| committer | jussi | 2022-11-27 14:08:58 +0200 |
| commit | deda5fb9170295133444809618835e8b9aa61512 (patch) | |
| tree | b00b07e245e2b9899f2c0059706b1f112e6b8c3a /src | |
| parent | c327a1ed55fafc212bf0e3bd5067ab246f1f041c (diff) | |
| download | reilua-enhanced-deda5fb9170295133444809618835e8b9aa61512.tar.gz reilua-enhanced-deda5fb9170295133444809618835e8b9aa61512.tar.bz2 reilua-enhanced-deda5fb9170295133444809618835e8b9aa61512.zip | |
Exit function and N-Patch fix.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua_core.c | 96 | ||||
| -rw-r--r-- | src/main.c | 1 | ||||
| -rw-r--r-- | src/textures.c | 1 |
3 files changed, 58 insertions, 40 deletions
diff --git a/src/lua_core.c b/src/lua_core.c index ac0ba32..1d46440 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -645,6 +645,23 @@ void luaCallDraw() { lua_pop( L, -1 ); } +void luaCallExit() { + lua_State *L = state->luaState; + lua_pushcfunction( L, luaTraceback ); + int tracebackidx = lua_gettop(L); + + lua_getglobal( L, "exit" ); + + 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; + return; + } + } + lua_pop( L, -1 ); +} + void luaRegister() { lua_State *L = state->luaState; @@ -1730,54 +1747,53 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) { lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { - if ( lua_isnumber( L, -1 ) ) { - if ( lua_isnumber( L, -2 ) ) { - switch ( i ) { - case 0: - npatch.source = uluaGetRectangle( L ); - break; - case 1: - npatch.left = lua_tointeger( L, -1 ); - break; - case 2: - npatch.top = lua_tointeger( L, -1 ); - break; - case 3: - npatch.right = lua_tointeger( L, -1 ); - break; - case 4: - npatch.bottom = lua_tointeger( L, -1 ); - break; - case 5: - npatch.layout = lua_tointeger( L, -1 ); - break; - default: - break; - } - } - else if ( lua_isstring( L, -2 ) ) { - if ( strcmp( "source", (char*)lua_tostring( L, -2 ) ) == 0 ) { + /* Do not check type since there should be table and ints. */ + if ( lua_isnumber( L, -2 ) ) { + switch ( i ) { + case 0: npatch.source = uluaGetRectangle( L ); - } - else if ( strcmp( "left", (char*)lua_tostring( L, -2 ) ) == 0 ) { + break; + case 1: npatch.left = lua_tointeger( L, -1 ); - } - else if ( strcmp( "top", (char*)lua_tostring( L, -2 ) ) == 0 ) { + break; + case 2: npatch.top = lua_tointeger( L, -1 ); - } - else if ( strcmp( "right", (char*)lua_tostring( L, -2 ) ) == 0 ) { + break; + case 3: npatch.right = lua_tointeger( L, -1 ); - } - else if ( strcmp( "bottom", (char*)lua_tostring( L, -2 ) ) == 0 ) { + break; + case 4: npatch.bottom = lua_tointeger( L, -1 ); - } - else if ( strcmp( "layout", (char*)lua_tostring( L, -2 ) ) == 0 ) { + break; + case 5: npatch.layout = lua_tointeger( L, -1 ); - } + break; + default: + break; + } + } + else if ( lua_isstring( L, -2 ) ) { + if ( strcmp( "source", (char*)lua_tostring( L, -2 ) ) == 0 ) { + npatch.source = uluaGetRectangle( L ); + } + else if ( strcmp( "left", (char*)lua_tostring( L, -2 ) ) == 0 ) { + npatch.left = lua_tointeger( L, -1 ); + } + else if ( strcmp( "top", (char*)lua_tostring( L, -2 ) ) == 0 ) { + npatch.top = lua_tointeger( L, -1 ); + } + else if ( strcmp( "right", (char*)lua_tostring( L, -2 ) ) == 0 ) { + npatch.right = lua_tointeger( L, -1 ); + } + else if ( strcmp( "bottom", (char*)lua_tostring( L, -2 ) ) == 0 ) { + npatch.bottom = lua_tointeger( L, -1 ); + } + else if ( strcmp( "layout", (char*)lua_tostring( L, -2 ) ) == 0 ) { + npatch.layout = lua_tointeger( L, -1 ); } - i++; - lua_pop( L, 1 ); } + i++; + lua_pop( L, 1 ); } return npatch; } @@ -71,6 +71,7 @@ int main( int argn, const char **argc ) { luaCallProcess(); luaCallDraw(); } + luaCallExit(); } stateFree(); diff --git a/src/textures.c b/src/textures.c index 7cc423a..0b1a198 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2099,6 +2099,7 @@ int ltexturesDrawTextureNPatch( lua_State *L ) { Rectangle dest = uluaGetRectangle( L ); lua_pop( L, 1 ); NPatchInfo nPatchInfo = uluaGetNPatchInfo( L ); + lua_pop( L, 1 ); size_t texId = lua_tointeger( L, -1 ); |
