GC_UNLOAD build time define and replaced with flag to change it at runtime.
This commit is contained in:
6
API.md
6
API.md
@@ -4128,6 +4128,12 @@ Check if Lua garbage collection is set to unload object data
|
||||
|
||||
---
|
||||
|
||||
> RL.SetGCUnload( bool enabled )
|
||||
|
||||
Set Lua garbage collection to unload object data
|
||||
|
||||
---
|
||||
|
||||
## Core - Files management functions
|
||||
|
||||
---
|
||||
|
||||
@@ -8,17 +8,12 @@ set( CMAKE_C_STANDARD 99 ) # Requires C99 standard
|
||||
|
||||
option( SHARED "Build using dynamic libraries." off )
|
||||
option( LUAJIT "Use LuaJIT." off )
|
||||
option( GC_UNLOAD "Lua garbage collector unloads objects. If off, object unloading should be handled manually." on )
|
||||
|
||||
if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
|
||||
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE )
|
||||
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
|
||||
endif()
|
||||
|
||||
if( GC_UNLOAD )
|
||||
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGC_UNLOAD" )
|
||||
endif()
|
||||
|
||||
file( GLOB SOURCES src/*.c )
|
||||
|
||||
include_directories( include )
|
||||
|
||||
@@ -1680,6 +1680,11 @@ function RL.OpenURL( url ) end
|
||||
---@return any enabled
|
||||
function RL.IsGCUnloadEnabled() end
|
||||
|
||||
---Set Lua garbage collection to unload object data
|
||||
---@param enabled boolean
|
||||
---@return any RL.SetGCUnload
|
||||
function RL.SetGCUnload( enabled ) end
|
||||
|
||||
-- Core - Files management functions
|
||||
|
||||
---Return game directory (where main.lua is located)
|
||||
|
||||
@@ -18,6 +18,7 @@ KEY CHANGES:
|
||||
- ADDED: Global variable descriptions for API.
|
||||
- CHANGED: Organized functions by putting them in the same order as in Raylib.
|
||||
- ADDED: Matrix library.
|
||||
- Removed: GC_UNLOAD build time define and replaced with flag to change it at runtime.
|
||||
|
||||
DETAILED CHANGES:
|
||||
- CHANGED: GenImageColor now takes Vector2 as size.
|
||||
|
||||
@@ -294,5 +294,4 @@ function RL.draw()
|
||||
RL.EndTextureMode()
|
||||
|
||||
RL.DrawTexturePro( RL.GetRenderTextureTexture( framebuffer ), { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
|
||||
-- RL.glBlitFramebuffer( framebuffer, -1, res, winSize, RL.GL_COLOR_BUFFER_BIT, RL.GL_NEAREST )
|
||||
end
|
||||
|
||||
@@ -94,6 +94,7 @@ int lcoreSetLogLevelInvalid( lua_State *L );
|
||||
int lcoreGetLogLevelInvalid( lua_State *L );
|
||||
int lcoreOpenURL( lua_State *L );
|
||||
int lcoreIsGCUnloadEnabled( lua_State *L );
|
||||
int lcoreSetGCUnload( lua_State *L );
|
||||
/* Files management functions. */
|
||||
int lcoreGetBasePath( lua_State *L );
|
||||
int lcoreFileExists( lua_State *L );
|
||||
|
||||
11
src/core.c
11
src/core.c
@@ -1253,6 +1253,17 @@ int lcoreIsGCUnloadEnabled( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> RL.SetGCUnload( bool enabled )
|
||||
|
||||
Set Lua garbage collection to unload object data
|
||||
*/
|
||||
int lcoreSetGCUnload( lua_State *L ) {
|
||||
state->gcUnload = uluaGetBoolean( L, 1 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
## Core - Files management functions
|
||||
*/
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
/* Buffer. */
|
||||
static int gcBuffer( lua_State *L ) {
|
||||
if ( state->gcUnload ) {
|
||||
Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
|
||||
|
||||
unloadBuffer( buffer );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineBuffer() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -29,18 +30,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Image *image = luaL_checkudata( L, 1, "Image" );
|
||||
|
||||
UnloadImage( *image );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineImage() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -48,18 +48,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Texture *texture = luaL_checkudata( L, 1, "Texture" );
|
||||
|
||||
UnloadTexture( *texture );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineTexture() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -67,18 +66,18 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
|
||||
|
||||
UnloadRenderTexture( *renderTexture );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineRenderTexture() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -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,10 +109,11 @@ static void defineCamera3D() {
|
||||
|
||||
/* Shader. */
|
||||
static int gcShader( lua_State *L ) {
|
||||
if ( state->gcUnload ) {
|
||||
Shader *shader = luaL_checkudata( L, 1, "Shader" );
|
||||
|
||||
UnloadShader( *shader );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineShader() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -123,18 +121,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Font *font = luaL_checkudata( L, 1, "Font" );
|
||||
|
||||
UnloadFont( *font );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineFont() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -142,18 +139,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Wave *wave = luaL_checkudata( L, 1, "Wave" );
|
||||
|
||||
UnloadWave( *wave );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineWave() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -161,18 +157,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Sound *sound = luaL_checkudata( L, 1, "Sound" );
|
||||
|
||||
UnloadSound( *sound );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineSound() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -180,18 +175,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Music *music = luaL_checkudata( L, 1, "Music" );
|
||||
|
||||
UnloadMusicStream( *music );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineMusic() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Material *material = luaL_checkudata( L, 1, "Material" );
|
||||
|
||||
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
|
||||
unloadMaterial( material );
|
||||
|
||||
// UnloadMaterial( *material );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineMaterial() {
|
||||
@@ -230,18 +221,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
|
||||
|
||||
UnloadMesh( *mesh );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineMesh() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -249,19 +239,18 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
Model *model = luaL_checkudata( L, 1, "Model" );
|
||||
|
||||
UnloadModel( *model );
|
||||
// UnloadModelKeepMeshes( *model );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineModel() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -269,18 +258,17 @@ 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 ) {
|
||||
if ( state->gcUnload ) {
|
||||
ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
|
||||
|
||||
UnloadModelAnimation( *modelAnimation );
|
||||
}
|
||||
}
|
||||
|
||||
static void defineModelAnimation() {
|
||||
lua_State *L = state->luaState;
|
||||
@@ -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 );
|
||||
|
||||
@@ -1471,7 +1471,6 @@ int lmodelsCreateMaterial( lua_State *L ) {
|
||||
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
Texture *texture = uluaGetTexture( L, lua_gettop( L ) );
|
||||
material.maps[map].texture = *texture;
|
||||
printf( "Material Create material.maps[map].texture.id = %d\n", material.maps[map].texture.id );
|
||||
}
|
||||
else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
material.maps[map].color = uluaGetColor( L, lua_gettop( L ) );
|
||||
|
||||
@@ -17,12 +17,7 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
|
||||
state->resolution = (Vector2){ 800, 600 };
|
||||
state->luaState = NULL;
|
||||
state->logLevelInvalid = LOG_ERROR;
|
||||
|
||||
#ifdef GC_UNLOAD
|
||||
state->gcUnload = true;
|
||||
#else
|
||||
state->gcUnload = false;
|
||||
#endif
|
||||
|
||||
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user