Exit function and N-Patch fix.

This commit is contained in:
jussi
2022-11-27 14:08:58 +02:00
parent c327a1ed55
commit deda5fb917
8 changed files with 92 additions and 40 deletions

6
API.md
View File

@@ -31,6 +31,12 @@ This function can be used for custom log message handling.
--- ---
> function exit()
This function will be called on program close. Cleanup could be done here.
---
## Globals - ConfigFlags ## Globals - ConfigFlags
FLAG_VSYNC_HINT FLAG_VSYNC_HINT

View File

@@ -5,6 +5,8 @@ KEY CHANGES:
- ADDED: This changelog. - ADDED: This changelog.
- ADDED: Lua interpreter mode. - ADDED: Lua interpreter mode.
- ADDED: Easings extra module. - ADDED: Easings extra module.
- ADDED: exit function.
- FIX: uluaGetNPatchInfo fix for RL_DrawTextureNPatch. Guess this was never tested and did not work at all >:E.
Detailed changes: Detailed changes:
ADDED: Help argument. ADDED: Help argument.

View File

@@ -0,0 +1,25 @@
local dstRec = { 160.0, 160.0, 8.0, 8.0 };
local origin = { 0.0, 0.0 }
-- local ninePatchInfo = { { 0.0, 0.0, 24.0, 24.0 }, 8, 8, 8, 8, NPATCH_NINE_PATCH }
local ninePatchInfo = { source = { 0, 0, 24.0, 24.0 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }
local nPatchTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/n-patch.png" )
function init()
RL_SetWindowTitle( "N-Patches" )
RL_SetWindowState( FLAG_VSYNC_HINT )
end
function process( delta )
local mousePosition = RL_GetMousePosition();
-- Resize the n-patch based on mouse position
dstRec[3] = mousePosition[1] - dstRec[1];
dstRec[4] = mousePosition[2] - dstRec[2];
end
function draw()
RL_ClearBackground( RAYWHITE )
RL_DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, WHITE )
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@@ -5,6 +5,7 @@ int luaTraceback( lua_State *L );
bool luaCallMain(); bool luaCallMain();
void luaCallProcess(); void luaCallProcess();
void luaCallDraw(); void luaCallDraw();
void luaCallExit();
void luaRegister(); void luaRegister();
/* Lua Util functions */ /* Lua Util functions */
Color uluaGetColor( lua_State *L ); Color uluaGetColor( lua_State *L );

View File

@@ -645,6 +645,23 @@ void luaCallDraw() {
lua_pop( L, -1 ); 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() { void luaRegister() {
lua_State *L = state->luaState; lua_State *L = state->luaState;
@@ -1730,54 +1747,53 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
lua_pushnil( L ); lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) { while ( lua_next( L, t ) != 0 ) {
if ( lua_isnumber( L, -1 ) ) { /* Do not check type since there should be table and ints. */
if ( lua_isnumber( L, -2 ) ) { if ( lua_isnumber( L, -2 ) ) {
switch ( i ) { switch ( i ) {
case 0: 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 ) {
npatch.source = uluaGetRectangle( L ); npatch.source = uluaGetRectangle( L );
} break;
else if ( strcmp( "left", (char*)lua_tostring( L, -2 ) ) == 0 ) { case 1:
npatch.left = lua_tointeger( L, -1 ); npatch.left = lua_tointeger( L, -1 );
} break;
else if ( strcmp( "top", (char*)lua_tostring( L, -2 ) ) == 0 ) { case 2:
npatch.top = lua_tointeger( L, -1 ); npatch.top = lua_tointeger( L, -1 );
} break;
else if ( strcmp( "right", (char*)lua_tostring( L, -2 ) ) == 0 ) { case 3:
npatch.right = lua_tointeger( L, -1 ); npatch.right = lua_tointeger( L, -1 );
} break;
else if ( strcmp( "bottom", (char*)lua_tostring( L, -2 ) ) == 0 ) { case 4:
npatch.bottom = lua_tointeger( L, -1 ); npatch.bottom = lua_tointeger( L, -1 );
} break;
else if ( strcmp( "layout", (char*)lua_tostring( L, -2 ) ) == 0 ) { case 5:
npatch.layout = lua_tointeger( L, -1 ); npatch.layout = lua_tointeger( L, -1 );
} break;
default:
break;
} }
i++;
lua_pop( L, 1 );
} }
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 );
} }
return npatch; return npatch;
} }

View File

@@ -71,6 +71,7 @@ int main( int argn, const char **argc ) {
luaCallProcess(); luaCallProcess();
luaCallDraw(); luaCallDraw();
} }
luaCallExit();
} }
stateFree(); stateFree();

View File

@@ -2099,6 +2099,7 @@ int ltexturesDrawTextureNPatch( lua_State *L ) {
Rectangle dest = uluaGetRectangle( L ); Rectangle dest = uluaGetRectangle( L );
lua_pop( L, 1 ); lua_pop( L, 1 );
NPatchInfo nPatchInfo = uluaGetNPatchInfo( L ); NPatchInfo nPatchInfo = uluaGetNPatchInfo( L );
lua_pop( L, 1 ); lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 ); size_t texId = lua_tointeger( L, -1 );