GC_UNLOAD build time define and replaced with flag to change it at runtime.

This commit is contained in:
jussi
2023-11-15 18:34:34 +02:00
parent 7b10306ed5
commit 841aa897f1
10 changed files with 80 additions and 81 deletions

View File

@@ -18,9 +18,10 @@
/* Buffer. */
static int gcBuffer( lua_State *L ) {
Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
unloadBuffer( buffer );
if ( state->gcUnload ) {
Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
unloadBuffer( buffer );
}
}
static void defineBuffer() {
@@ -29,17 +30,16 @@ static void defineBuffer() {
luaL_newmetatable( L, "Buffer" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcBuffer );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Image */
static int gcImage( lua_State *L ) {
Image *image = luaL_checkudata( L, 1, "Image" );
UnloadImage( *image );
if ( state->gcUnload ) {
Image *image = luaL_checkudata( L, 1, "Image" );
UnloadImage( *image );
}
}
static void defineImage() {
@@ -48,17 +48,16 @@ static void defineImage() {
luaL_newmetatable( L, "Image" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcImage );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Texture */
static int gcTexture( lua_State *L ) {
Texture *texture = luaL_checkudata( L, 1, "Texture" );
UnloadTexture( *texture );
if ( state->gcUnload ) {
Texture *texture = luaL_checkudata( L, 1, "Texture" );
UnloadTexture( *texture );
}
}
static void defineTexture() {
@@ -67,17 +66,17 @@ static void defineTexture() {
luaL_newmetatable( L, "Texture" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcTexture );
lua_setfield( L, -2, "__gc" );
#endif
}
/* RenderRexture. */
static int gcRenderTexture( lua_State *L ) {
RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
UnloadRenderTexture( *renderTexture );
if ( state->gcUnload ) {
RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
UnloadRenderTexture( *renderTexture );
}
}
static void defineRenderTexture() {
@@ -86,10 +85,8 @@ static void defineRenderTexture() {
luaL_newmetatable( L, "RenderTexture" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcRenderTexture );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Camera2D. */
@@ -112,9 +109,10 @@ static void defineCamera3D() {
/* Shader. */
static int gcShader( lua_State *L ) {
Shader *shader = luaL_checkudata( L, 1, "Shader" );
UnloadShader( *shader );
if ( state->gcUnload ) {
Shader *shader = luaL_checkudata( L, 1, "Shader" );
UnloadShader( *shader );
}
}
static void defineShader() {
@@ -123,17 +121,16 @@ static void defineShader() {
luaL_newmetatable( L, "Shader" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcShader );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Font. */
static int gcFont( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
UnloadFont( *font );
if ( state->gcUnload ) {
Font *font = luaL_checkudata( L, 1, "Font" );
UnloadFont( *font );
}
}
static void defineFont() {
@@ -142,17 +139,16 @@ static void defineFont() {
luaL_newmetatable( L, "Font" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcFont );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Wave. */
static int gcWave( lua_State *L ) {
Wave *wave = luaL_checkudata( L, 1, "Wave" );
UnloadWave( *wave );
if ( state->gcUnload ) {
Wave *wave = luaL_checkudata( L, 1, "Wave" );
UnloadWave( *wave );
}
}
static void defineWave() {
@@ -161,17 +157,16 @@ static void defineWave() {
luaL_newmetatable( L, "Wave" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcWave );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Sound. */
static int gcSound( lua_State *L ) {
Sound *sound = luaL_checkudata( L, 1, "Sound" );
UnloadSound( *sound );
if ( state->gcUnload ) {
Sound *sound = luaL_checkudata( L, 1, "Sound" );
UnloadSound( *sound );
}
}
static void defineSound() {
@@ -180,17 +175,16 @@ static void defineSound() {
luaL_newmetatable( L, "Sound" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcSound );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Music. */
static int gcMusic( lua_State *L ) {
Music *music = luaL_checkudata( L, 1, "Music" );
UnloadMusicStream( *music );
if ( state->gcUnload ) {
Music *music = luaL_checkudata( L, 1, "Music" );
UnloadMusicStream( *music );
}
}
static void defineMusic() {
@@ -199,10 +193,8 @@ static void defineMusic() {
luaL_newmetatable( L, "Music" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcMusic );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Light. */
@@ -216,12 +208,11 @@ static void defineLight() {
/* Material. */
static int gcMaterial( lua_State *L ) {
Material *material = luaL_checkudata( L, 1, "Material" );
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
unloadMaterial( material );
// UnloadMaterial( *material );
if ( state->gcUnload ) {
Material *material = luaL_checkudata( L, 1, "Material" );
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
unloadMaterial( material );
}
}
static void defineMaterial() {
@@ -230,17 +221,16 @@ static void defineMaterial() {
luaL_newmetatable( L, "Material" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcMaterial );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Mesh. */
static int gcMesh( lua_State *L ) {
Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
UnloadMesh( *mesh );
if ( state->gcUnload ) {
Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
UnloadMesh( *mesh );
}
}
static void defineMesh() {
@@ -249,18 +239,17 @@ static void defineMesh() {
luaL_newmetatable( L, "Mesh" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcMesh );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Model. */
static int gcModel( lua_State *L ) {
Model *model = luaL_checkudata( L, 1, "Model" );
UnloadModel( *model );
// UnloadModelKeepMeshes( *model );
if ( state->gcUnload ) {
Model *model = luaL_checkudata( L, 1, "Model" );
UnloadModel( *model );
// UnloadModelKeepMeshes( *model );
}
}
static void defineModel() {
@@ -269,17 +258,16 @@ static void defineModel() {
luaL_newmetatable( L, "Model" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcModel );
lua_setfield( L, -2, "__gc" );
#endif
}
/* ModelAnimation. */
static int gcModelAnimation( lua_State *L ) {
ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
UnloadModelAnimation( *modelAnimation );
if ( state->gcUnload ) {
ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
UnloadModelAnimation( *modelAnimation );
}
}
static void defineModelAnimation() {
@@ -288,10 +276,8 @@ static void defineModelAnimation() {
luaL_newmetatable( L, "ModelAnimation" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
#ifdef GC_UNLOAD
lua_pushcfunction( L, gcModelAnimation );
lua_setfield( L, -2, "__gc" );
#endif
}
/* Assing globals. */
@@ -1591,6 +1577,7 @@ void luaRegister() {
assingGlobalFunction( "GetLogLevelInvalid", lcoreGetLogLevelInvalid );
assingGlobalFunction( "OpenURL", lcoreOpenURL );
assingGlobalFunction( "IsGCUnloadEnabled", lcoreIsGCUnloadEnabled );
assingGlobalFunction( "SetGCUnload", lcoreSetGCUnload );
/* Files management functions. */
assingGlobalFunction( "GetBasePath", lcoreGetBasePath );
assingGlobalFunction( "FileExists", lcoreFileExists );