summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua_core.c96
-rw-r--r--src/main.c1
-rw-r--r--src/textures.c1
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;
}
diff --git a/src/main.c b/src/main.c
index 0f935a1..d1be4a1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 );