summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2025-06-11 17:00:25 +0300
committerjussi2025-06-11 17:00:25 +0300
commita38e76873b5ca3080c8046ae4759866d8cccc4e5 (patch)
treeca3b5b8d0ec66b3d9c64f46b6b7d5db4e481658a
parent5b8af05e96b33f2d032cc31a329b89e1231d5502 (diff)
downloadreilua-enhanced-a38e76873b5ca3080c8046ae4759866d8cccc4e5.tar.gz
reilua-enhanced-a38e76873b5ca3080c8046ae4759866d8cccc4e5.tar.bz2
reilua-enhanced-a38e76873b5ca3080c8046ae4759866d8cccc4e5.zip
uluaGet* pops lua stack correctly when userdata given in table.
-rw-r--r--API.md2
-rw-r--r--ReiLua_API.lua2
-rw-r--r--changelog1
-rw-r--r--examples/instancing/main.lua6
-rw-r--r--examples/lightmap/main.lua10
-rw-r--r--src/lua_core.c220
6 files changed, 177 insertions, 64 deletions
diff --git a/API.md b/API.md
index a2ef74a..7c68141 100644
--- a/API.md
+++ b/API.md
@@ -3682,7 +3682,7 @@ Default projection matrix near cull distance
---
-> RL_CULL_DISTANCE_FAR = 1000.0
+> RL_CULL_DISTANCE_FAR = 1000
Default projection matrix far cull distance
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index dec0d17..93c3cf4 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -1167,7 +1167,7 @@ RL.RL_MAX_SHADER_LOCATIONS=32
---Default projection matrix near cull distance
RL.RL_CULL_DISTANCE_NEAR=0.01
---Default projection matrix far cull distance
-RL.RL_CULL_DISTANCE_FAR=1000.0
+RL.RL_CULL_DISTANCE_FAR=1000
-- Defines - RLGL Texture parameters
diff --git a/changelog b/changelog
index 7689b94..208ecea 100644
--- a/changelog
+++ b/changelog
@@ -52,6 +52,7 @@ DETAILED CHANGES:
- ADDED: RL.load and RL.unload functions for memory leak debugging.
- ADDED: SoundAlias garbage collection.
- ADDED: Frustum math from raylib extras.
+ - FIXED: uluaGet* pops lua stack correctly when userdata given in table.
------------------------------------------------------------------------
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
diff --git a/examples/instancing/main.lua b/examples/instancing/main.lua
index a20c6a3..1966479 100644
--- a/examples/instancing/main.lua
+++ b/examples/instancing/main.lua
@@ -29,6 +29,7 @@ function RL.init()
RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL.SetWindowTitle( "Instancing" )
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
+ RL.SetGCUnload( false )
-- Define the camera to look into our 3d world
camera = RL.CreateCamera3D()
@@ -108,3 +109,8 @@ function RL.draw()
RL.DrawFPS( { 10, 10 } )
end
+
+function RL.exit()
+ RL.UnloadMaterial( matInstances, true )
+ RL.UnloadMesh( cube )
+end
diff --git a/examples/lightmap/main.lua b/examples/lightmap/main.lua
index 20a2729..d7b576d 100644
--- a/examples/lightmap/main.lua
+++ b/examples/lightmap/main.lua
@@ -25,6 +25,7 @@ function RL.init()
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
+ RL.SetGCUnload( false )
camera = Cam3D:new()
camera:setPosition( { 0, 8, 16 } )
@@ -48,9 +49,9 @@ function RL.init()
tileTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/tile.png" )
RL.GenTextureMipmaps( tileTexture )
- RL.SetTextureFilter( tileTexture, RL.TEXTURE_FILTER_TRILINEAR )
+ RL.SetTextureFilter( tileTexture, RL.TEXTURE_FILTER_BILINEAR )
lightmap = RL.LoadTexture( RL.GetBasePath().."../resources/images/lightmap.png" )
- RL.SetTextureFilter( lightmap, RL.TEXTURE_FILTER_TRILINEAR )
+ RL.SetTextureFilter( lightmap, RL.TEXTURE_FILTER_BILINEAR )
shader = RL.LoadShader( RL.GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/lightmap.vs",
RL.GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/lightmap.fs" )
@@ -99,3 +100,8 @@ function RL.draw()
RL.DrawMesh( mesh, material, matrix )
camera:endMode3D()
end
+
+function RL.exit()
+ RL.UnloadMaterial( material, true )
+ RL.UnloadMesh( mesh )
+end
diff --git a/src/lua_core.c b/src/lua_core.c
index 253d9e5..d039208 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -3348,15 +3348,20 @@ Buffer* uluaGetBuffer( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "buffer", lua_tostring( L, -2 ) ) ) {
+ Buffer* buffer = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Buffer*)lua_touserdata( L, lua_gettop( L ) );
+ buffer = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Buffer" );
+ buffer = luaL_checkudata( L, lua_gettop( L ), "Buffer" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return buffer;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3373,15 +3378,20 @@ Image* uluaGetImage( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "image", lua_tostring( L, -2 ) ) ) {
+ Image* image = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Image*)lua_touserdata( L, lua_gettop( L ) );
+ image = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Image" );
+ image = luaL_checkudata( L, lua_gettop( L ), "Image" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return image;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3398,15 +3408,20 @@ Texture* uluaGetTexture( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "texture", lua_tostring( L, -2 ) ) ) {
+ Texture* texture = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Texture*)lua_touserdata( L, lua_gettop( L ) );
+ texture = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Texture" );
+ texture = luaL_checkudata( L, lua_gettop( L ), "Texture" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return texture;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3423,15 +3438,20 @@ RenderTexture* uluaGetRenderTexture( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "renderTexture", lua_tostring( L, -2 ) ) ) {
+ RenderTexture* renderTexture = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (RenderTexture*)lua_touserdata( L, lua_gettop( L ) );
+ renderTexture = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "RenderTexture" );
+ renderTexture = luaL_checkudata( L, lua_gettop( L ), "RenderTexture" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return renderTexture;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3448,15 +3468,20 @@ Shader* uluaGetShader( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "shader", lua_tostring( L, -2 ) ) ) {
+ Shader* shader = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Shader*)lua_touserdata( L, lua_gettop( L ) );
+ shader = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Shader" );
+ shader = luaL_checkudata( L, lua_gettop( L ), "Shader" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return shader;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3473,15 +3498,20 @@ Mesh* uluaGetMesh( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "mesh", lua_tostring( L, -2 ) ) ) {
+ Mesh* mesh = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Mesh*)lua_touserdata( L, lua_gettop( L ) );
+ mesh = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Mesh" );
+ mesh = luaL_checkudata( L, lua_gettop( L ), "Mesh" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return mesh;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3498,15 +3528,20 @@ Camera2D* uluaGetCamera2D( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "camera2D", lua_tostring( L, -2 ) ) ) {
+ Camera2D* camera = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Camera2D*)lua_touserdata( L, lua_gettop( L ) );
+ camera = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Camera2D" );
+ camera = luaL_checkudata( L, lua_gettop( L ), "Camera2D" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return camera;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3523,15 +3558,20 @@ Camera3D* uluaGetCamera3D( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "camera3D", lua_tostring( L, -2 ) ) ) {
+ Camera3D* camera = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Camera3D*)lua_touserdata( L, lua_gettop( L ) );
+ camera = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Camera3D" );
+ camera = luaL_checkudata( L, lua_gettop( L ), "Camera3D" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return camera;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3548,15 +3588,20 @@ Font* uluaGetFont( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "font", lua_tostring( L, -2 ) ) ) {
+ Font* font = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Font*)lua_touserdata( L, lua_gettop( L ) );
+ font = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Font" );
+ font = luaL_checkudata( L, lua_gettop( L ), "Font" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return font;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3573,15 +3618,20 @@ GlyphInfo* uluaGetGlyphInfo( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "glyphInfo", lua_tostring( L, -2 ) ) ) {
+ GlyphInfo* glyph = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (GlyphInfo*)lua_touserdata( L, lua_gettop( L ) );
+ glyph = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "GlyphInfo" );
+ glyph = luaL_checkudata( L, lua_gettop( L ), "GlyphInfo" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return glyph;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3598,15 +3648,20 @@ Wave* uluaGetWave( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "wave", lua_tostring( L, -2 ) ) ) {
+ Wave* wave = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Wave*)lua_touserdata( L, lua_gettop( L ) );
+ wave = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Wave" );
+ wave = luaL_checkudata( L, lua_gettop( L ), "Wave" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return wave;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3623,15 +3678,20 @@ Sound* uluaGetSound( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "sound", lua_tostring( L, -2 ) ) ) {
+ Sound* sound = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Sound*)lua_touserdata( L, lua_gettop( L ) );
+ sound = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Sound" );
+ sound = luaL_checkudata( L, lua_gettop( L ), "Sound" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return sound;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3654,15 +3714,20 @@ Music* uluaGetMusic( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "music", lua_tostring( L, -2 ) ) ) {
+ Music* music = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Music*)lua_touserdata( L, lua_gettop( L ) );
+ music = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Music" );
+ music = luaL_checkudata( L, lua_gettop( L ), "Music" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return music;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3679,15 +3744,20 @@ Light* uluaGetLight( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "light", lua_tostring( L, -2 ) ) ) {
+ Light* light = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Light*)lua_touserdata( L, lua_gettop( L ) );
+ light = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Light" );
+ light = luaL_checkudata( L, lua_gettop( L ), "Light" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return light;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3704,15 +3774,20 @@ Material* uluaGetMaterial( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "material", lua_tostring( L, -2 ) ) ) {
+ Material* material = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Material*)lua_touserdata( L, lua_gettop( L ) );
+ material = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Material" );
+ material = luaL_checkudata( L, lua_gettop( L ), "Material" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return material;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3729,15 +3804,20 @@ Model* uluaGetModel( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "model", lua_tostring( L, -2 ) ) ) {
+ Model* model = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (Model*)lua_touserdata( L, lua_gettop( L ) );
+ model = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "Model" );
+ model = luaL_checkudata( L, lua_gettop( L ), "Model" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return model;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3754,15 +3834,20 @@ ModelAnimation* uluaGetModelAnimation( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "modelAnimation", lua_tostring( L, -2 ) ) ) {
+ ModelAnimation* animation = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (ModelAnimation*)lua_touserdata( L, lua_gettop( L ) );
+ animation = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "ModelAnimation" );
+ animation = luaL_checkudata( L, lua_gettop( L ), "ModelAnimation" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return animation;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3779,15 +3864,20 @@ rlRenderBatch* uluaGetRLRenderBatch( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "rlRenderBatch", lua_tostring( L, -2 ) ) ) {
+ rlRenderBatch* batch = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (rlRenderBatch*)lua_touserdata( L, lua_gettop( L ) );
+ batch = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "rlRenderBatch" );
+ batch = luaL_checkudata( L, lua_gettop( L ), "rlRenderBatch" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return batch;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3804,15 +3894,20 @@ AutomationEvent* uluaGetAutomationEvent( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "automationEvent", lua_tostring( L, -2 ) ) ) {
+ AutomationEvent* event = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (AutomationEvent*)lua_touserdata( L, lua_gettop( L ) );
+ event = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "AutomationEvent" );
+ event = luaL_checkudata( L, lua_gettop( L ), "AutomationEvent" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return event;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default:
@@ -3829,15 +3924,20 @@ AutomationEventList* uluaGetAutomationEventList( lua_State* L, int index ) {
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( TextIsEqual( "automationEventList", lua_tostring( L, -2 ) ) ) {
+ AutomationEventList* list = NULL;
if ( lua_islightuserdata( L, lua_gettop( L ) ) ) {
- return (AutomationEventList*)lua_touserdata( L, lua_gettop( L ) );
+ list = lua_touserdata( L, lua_gettop( L ) );
}
else {
- return luaL_checkudata( L, lua_gettop( L ), "AutomationEventList" );
+ list = luaL_checkudata( L, lua_gettop( L ), "AutomationEventList" );
}
+ lua_pop( L, 2 ); /* Pops also the string. */
+ return list;
+ }
+ else {
+ lua_pop( L, 1 );
}
i++;
- lua_pop( L, 1 );
}
/* Don't brake here, we want to get error from default if not found. */
default: