summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md6
-rw-r--r--changelog2
-rw-r--r--examples/n-patches/main.lua25
-rw-r--r--examples/resources/images/n-patch.pngbin0 -> 6021 bytes
-rw-r--r--include/lua_core.h1
-rw-r--r--src/lua_core.c96
-rw-r--r--src/main.c1
-rw-r--r--src/textures.c1
8 files changed, 92 insertions, 40 deletions
diff --git a/API.md b/API.md
index c30e84a..94b9d65 100644
--- a/API.md
+++ b/API.md
@@ -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
FLAG_VSYNC_HINT
diff --git a/changelog b/changelog
index 92caf06..db08e35 100644
--- a/changelog
+++ b/changelog
@@ -5,6 +5,8 @@ KEY CHANGES:
- ADDED: This changelog.
- ADDED: Lua interpreter mode.
- 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:
ADDED: Help argument.
diff --git a/examples/n-patches/main.lua b/examples/n-patches/main.lua
new file mode 100644
index 0000000..045bb84
--- /dev/null
+++ b/examples/n-patches/main.lua
@@ -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
diff --git a/examples/resources/images/n-patch.png b/examples/resources/images/n-patch.png
new file mode 100644
index 0000000..c6e738b
--- /dev/null
+++ b/examples/resources/images/n-patch.png
Binary files differ
diff --git a/include/lua_core.h b/include/lua_core.h
index 58b84d2..228c4c0 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -5,6 +5,7 @@ int luaTraceback( lua_State *L );
bool luaCallMain();
void luaCallProcess();
void luaCallDraw();
+void luaCallExit();
void luaRegister();
/* Lua Util functions */
Color uluaGetColor( lua_State *L );
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 );