summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2023-10-30 22:40:20 +0200
committerjussi2023-10-30 22:40:20 +0200
commitc3295e014d979c0213b3fb7e4837b5356bc8fdb4 (patch)
tree66ee22c7140761a17bf174d71fecfb94c1378b1d /src
parent6e0d577d63b221797cdc7f392718dd1c4fb384b4 (diff)
downloadreilua-enhanced-c3295e014d979c0213b3fb7e4837b5356bc8fdb4.tar.gz
reilua-enhanced-c3295e014d979c0213b3fb7e4837b5356bc8fdb4.tar.bz2
reilua-enhanced-c3295e014d979c0213b3fb7e4837b5356bc8fdb4.zip
Reintroducing Unload functions. Is*Ready functions. GC_UNLOAD setting and check function.
Diffstat (limited to 'src')
-rw-r--r--src/audio.c84
-rw-r--r--src/core.c77
-rw-r--r--src/lua_core.c111
-rw-r--r--src/models.c91
-rw-r--r--src/state.c8
-rw-r--r--src/text.c37
-rw-r--r--src/textures.c69
7 files changed, 428 insertions, 49 deletions
diff --git a/src/audio.c b/src/audio.c
index 6a2164d..f1ef460 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -65,6 +65,21 @@ int laudioLoadWave( lua_State *L ) {
}
/*
+> isReady = RL.IsWaveReady( Wave wave )
+
+Checks if wave data is ready
+
+- Success return bool
+*/
+int laudioIsWaveReady( lua_State *L ) {
+ Wave *wave = uluaGetWave( L, 1 );
+
+ lua_pushboolean( L, IsWaveReady( *wave ) );
+
+ return 1;
+}
+
+/*
> sound = RL.LoadSoundFromWave( Wave wave )
Load sound from wave data
@@ -80,6 +95,47 @@ int laudioLoadSoundFromWave( lua_State *L ) {
}
/*
+> isReady = RL.IsSoundReady( Sound sound )
+
+Checks if a sound is ready
+
+- Success return bool
+*/
+int laudioIsSoundReady( lua_State *L ) {
+ Sound *sound = uluaGetSound( L, 1 );
+
+ lua_pushboolean( L, IsSoundReady( *sound ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadWave( Wave wave )
+
+Unload wave data
+*/
+int laudioUnloadWave( lua_State *L ) {
+ Wave *wave = uluaGetWave( L, 1 );
+
+ UnloadWave( *wave );
+
+ return 0;
+}
+
+/*
+> RL.UnloadSound( Sound sound )
+
+Unload sound
+*/
+int laudioUnloadSound( lua_State *L ) {
+ Sound *sound = uluaGetSound( L, 1 );
+
+ UnloadSound( *sound );
+
+ return 0;
+}
+
+/*
> success = RL.ExportWave( Wave wave, string fileName )
Export wave data to file, returns true on success
@@ -292,6 +348,34 @@ int laudioLoadMusicStream( lua_State *L ) {
}
/*
+> isReady = RL.IsMusicReady( Music music )
+
+Checks if a music stream is ready
+
+- Success return bool
+*/
+int laudioIsMusicReady( lua_State *L ) {
+ Music *music = uluaGetMusic( L, 1 );
+
+ lua_pushboolean( L, IsMusicReady( *music ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadMusicStream( Music music )
+
+Unload music stream
+*/
+int laudioUnloadMusicStream( lua_State *L ) {
+ Music *music = uluaGetMusic( L, 1 );
+
+ UnloadMusicStream( *music );
+
+ return 0;
+}
+
+/*
> RL.PlayMusicStream( Music music )
Start music playing
diff --git a/src/core.c b/src/core.c
index 5304b23..92eb5bd 100644
--- a/src/core.c
+++ b/src/core.c
@@ -552,33 +552,34 @@ int lcoreLoadBuffer( lua_State *L ) {
luaL_checktype( L, 1, LUA_TTABLE );
int type = luaL_checkinteger( L, 2 );
- Buffer *buffer = lua_newuserdata( L, sizeof( Buffer ) );
+ Buffer buffer = { 0 };
+ // Buffer *buffer = lua_newuserdata( L, sizeof( Buffer ) );
int len = uluaGetTableLenIndex( L, 1 );
switch ( type ) {
case BUFFER_UNSIGNED_CHAR:
- buffer->size = len * sizeof( unsigned char );
+ buffer.size = len * sizeof( unsigned char );
break;
case BUFFER_UNSIGNED_SHORT:
- buffer->size = len * sizeof( unsigned short );
+ buffer.size = len * sizeof( unsigned short );
break;
case BUFFER_UNSIGNED_INT:
- buffer->size = len * sizeof( unsigned int );
+ buffer.size = len * sizeof( unsigned int );
break;
case BUFFER_FLOAT:
- buffer->size = len * sizeof( float );
+ buffer.size = len * sizeof( float );
break;
default:
break;
}
- buffer->data = malloc( buffer->size );
+ buffer.data = malloc( buffer.size );
int t = 1;
int i = 0;
- unsigned char *up = buffer->data;
- unsigned short *sp = buffer->data;
- unsigned int *ip = buffer->data;
- float *fp = buffer->data;
+ unsigned char *up = buffer.data;
+ unsigned short *sp = buffer.data;
+ unsigned int *ip = buffer.data;
+ float *fp = buffer.data;
lua_pushnil( L );
@@ -606,7 +607,33 @@ int lcoreLoadBuffer( lua_State *L ) {
lua_pop( L, 1 );
i++;
}
- luaL_setmetatable( L, "Buffer" );
+ uluaPushBuffer( L, buffer );
+
+ return 1;
+}
+
+/*
+> RL.UnloadBuffer( Buffer buffer )
+
+Unload buffer data
+*/
+int lcoreUnloadBuffer( lua_State *L ) {
+ Buffer *buffer = uluaGetBuffer( L, 1 );
+
+ free( buffer->data );
+
+ return 0;
+}
+
+/*
+> enabled = RL.IsGCUnloadEnabled()
+
+Check if Lua garbage collection is set to unload object data
+
+- Success return bool
+*/
+int lcoreIsGCUnloadEnabled( lua_State *L ) {
+ lua_pushboolean( L, state->gcUnload );
return 1;
}
@@ -862,6 +889,21 @@ int lcoreLoadShaderFromMemory( lua_State *L ) {
}
/*
+> isReady = RL.IsShaderReady( Shader shader )
+
+Check if a shader is ready
+
+- Success return bool
+*/
+int lcoreIsShaderReady( lua_State *L ) {
+ Shader *shader = uluaGetShader( L, 1 );
+
+ lua_pushboolean( L, IsShaderReady( *shader ) );
+
+ return 1;
+}
+
+/*
> RL.BeginShaderMode( Shader shader )
Begin custom shader drawing
@@ -1062,6 +1104,19 @@ int lcoreSetShaderValueV( lua_State *L ) {
}
/*
+> RL.UnloadShader( Shader shader )
+
+Unload shader from GPU memory (VRAM)
+*/
+int lcoreUnloadShader( lua_State *L ) {
+ Shader *shader = uluaGetShader( L, 1 );
+
+ UnloadShader( *shader );
+
+ return 0;
+}
+
+/*
## Core - Input-related Keyboard
*/
diff --git a/src/lua_core.c b/src/lua_core.c
index a2b3303..10f48b8 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -18,7 +18,8 @@
/* Buffer. */
static int gcBuffer( lua_State *L ) {
- Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
+ Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
+
free( buffer->data );
}
@@ -28,13 +29,15 @@ 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" );
+ Image *image = luaL_checkudata( L, 1, "Image" );
UnloadImage( *image );
}
@@ -45,13 +48,15 @@ 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" );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
UnloadTexture( *texture );
}
@@ -62,13 +67,15 @@ 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" );
+ RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
UnloadRenderTexture( *renderTexture );
}
@@ -79,8 +86,10 @@ 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. */
@@ -103,7 +112,7 @@ static void defineCamera3D() {
/* Shader. */
static int gcShader( lua_State *L ) {
- Shader *shader = luaL_checkudata ( L, 1, "Shader" );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
UnloadShader( *shader );
}
@@ -114,13 +123,15 @@ 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" );
+ Font *font = luaL_checkudata( L, 1, "Font" );
UnloadFont( *font );
}
@@ -131,13 +142,15 @@ 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" );
+ Wave *wave = luaL_checkudata( L, 1, "Wave" );
UnloadWave( *wave );
}
@@ -148,13 +161,15 @@ 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" );
+ Sound *sound = luaL_checkudata( L, 1, "Sound" );
UnloadSound( *sound );
}
@@ -165,13 +180,15 @@ 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" );
+ Music *music = luaL_checkudata( L, 1, "Music" );
UnloadMusicStream( *music );
}
@@ -182,8 +199,10 @@ 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. */
@@ -197,22 +216,12 @@ static void defineLight() {
/* Material. */
static int gcMaterial( lua_State *L ) {
- Material *material = luaL_checkudata ( L, 1, "Material" );
-
- // int MAX_MATERIAL_MAPS = 12;
-
- // Unload loaded texture maps (avoid unloading default texture, managed by raylib)
- // if ( material->maps != NULL ) {
- // for ( int i = 0; i < MAX_MATERIAL_MAPS; i++ ) {
- // if ( material->maps[i].texture.id != rlGetTextureIdDefault() ) {
- // printf( "gcMaterial material->maps[i].texture.id = %d\n", material->maps[i].texture.id );
- // rlUnloadTexture( material->maps[i].texture.id );
- // }
- // }
- // }
+ Material *material = luaL_checkudata( L, 1, "Material" );
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
- RL_FREE( material->maps );
+ RL_FREE( material->maps );
+
+ // UnloadMaterial( *material );
}
static void defineMaterial() {
@@ -221,13 +230,15 @@ 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" );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
UnloadMesh( *mesh );
}
@@ -238,13 +249,15 @@ 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" );
+ Model *model = luaL_checkudata( L, 1, "Model" );
UnloadModel( *model );
// UnloadModelKeepMeshes( *model );
@@ -256,13 +269,15 @@ 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" );
+ ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
UnloadModelAnimation( *modelAnimation );
}
@@ -273,8 +288,10 @@ 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. */
@@ -316,12 +333,6 @@ static void defineGlobals() {
lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" );
- uluaPushFont( L, GetFontDefault() );
- lua_setfield( L, -2, "defaultFont" );
-
- uluaPushMaterial( L, LoadMaterialDefault() );
- lua_setfield( L, -2, "defaultMaterial" );
-
/*DOC_START*/
/* ConfigFlags */
assignGlobalInt( FLAG_VSYNC_HINT, "FLAG_VSYNC_HINT" );
@@ -1527,6 +1538,8 @@ void luaRegister() {
assingGlobalFunction( "GetLogLevelInvalid", lcoreGetLogLevelInvalid );
assingGlobalFunction( "OpenURL", lcoreOpenURL );
assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer );
+ assingGlobalFunction( "UnloadBuffer", lcoreUnloadBuffer );
+ assingGlobalFunction( "IsGCUnloadEnabled", lcoreIsGCUnloadEnabled );
/* Cursor. */
assingGlobalFunction( "ShowCursor", lcoreShowCursor );
assingGlobalFunction( "HideCursor", lcoreHideCursor );
@@ -1545,6 +1558,7 @@ void luaRegister() {
/* Shader. */
assingGlobalFunction( "LoadShader", lcoreLoadShader );
assingGlobalFunction( "LoadShaderFromMemory", lcoreLoadShaderFromMemory );
+ assingGlobalFunction( "IsShaderReady", lcoreIsShaderReady );
assingGlobalFunction( "BeginShaderMode", lcoreBeginShaderMode );
assingGlobalFunction( "EndShaderMode", lcoreEndShaderMode );
assingGlobalFunction( "GetShaderLocation", lcoreGetShaderLocation );
@@ -1555,6 +1569,7 @@ void luaRegister() {
assingGlobalFunction( "SetShaderValueTexture", lcoreSetShaderValueTexture );
assingGlobalFunction( "SetShaderValue", lcoreSetShaderValue );
assingGlobalFunction( "SetShaderValueV", lcoreSetShaderValueV );
+ assingGlobalFunction( "UnloadShader", lcoreUnloadShader );
/* File. */
assingGlobalFunction( "GetBasePath", lcoreGetBasePath );
assingGlobalFunction( "FileExists", lcoreFileExists );
@@ -1717,6 +1732,8 @@ void luaRegister() {
assingGlobalFunction( "LoadImage", ltexturesLoadImage );
assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture );
assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen );
+ assingGlobalFunction( "IsImageReady", ltextureIsImageReady );
+ assingGlobalFunction( "UnloadImage", ltextureUnloadImage );
assingGlobalFunction( "ExportImage", ltexturesExportImage );
assingGlobalFunction( "ExportImageAsCode", ltexturesExportImageAsCode );
/* Image Generation. */
@@ -1782,6 +1799,9 @@ void luaRegister() {
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
assingGlobalFunction( "LoadRenderTextureFromData", ltexturesLoadRenderTextureFromData );
assingGlobalFunction( "IsTextureReady", ltexturesIsTextureReady );
+ assingGlobalFunction( "UnloadTexture", ltextureUnloadTexture );
+ assingGlobalFunction( "IsRenderTextureReady", ltexturesIsRenderTextureReady );
+ assingGlobalFunction( "UnloadRenderTexture", ltextureUnloadRenderTexture );
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
/* Texture Drawing. */
@@ -1852,6 +1872,7 @@ void luaRegister() {
assingGlobalFunction( "GenMeshHeightmap", lmodelsGenMeshHeightmap );
assingGlobalFunction( "GenMeshCustom", lmodelsGenMeshCustom );
assingGlobalFunction( "UpdateMesh", lmodelsUpdateMesh );
+ assingGlobalFunction( "UnloadMesh", lmodelsUnloadMesh );
assingGlobalFunction( "DrawMesh", lmodelsDrawMesh );
assingGlobalFunction( "DrawMeshInstanced", lmodelsDrawMeshInstanced );
assingGlobalFunction( "SetMeshColor", lmodelsSetMeshColor );
@@ -1859,8 +1880,11 @@ void luaRegister() {
assingGlobalFunction( "GetMeshBoundingBox", lmodelsGetMeshBoundingBox );
assingGlobalFunction( "GenMeshTangents", lmodelsGenMeshTangents );
/* Material. */
+ assingGlobalFunction( "GetMaterialDefault", lmodelsGetMaterialDefault );
assingGlobalFunction( "LoadMaterialDefault", lmodelsLoadMaterialDefault );
assingGlobalFunction( "CreateMaterial", lmodelsCreateMaterial );
+ assingGlobalFunction( "IsMaterialReady", lmodelsIsMaterialReady );
+ assingGlobalFunction( "UnloadMaterial", lmodelsUnloadMaterial );
assingGlobalFunction( "SetMaterialTexture", lmodelsSetMaterialTexture );
assingGlobalFunction( "SetMaterialColor", lmodelsSetMaterialColor );
assingGlobalFunction( "SetMaterialValue", lmodelsSetMaterialValue );
@@ -1874,6 +1898,8 @@ void luaRegister() {
/* Model. */
assingGlobalFunction( "LoadModel", lmodelsLoadModel );
assingGlobalFunction( "LoadModelFromMesh", lmodelsLoadModelFromMesh );
+ assingGlobalFunction( "IsModelReady", lmodelsIsModelReady );
+ assingGlobalFunction( "UnloadModel", lmodelsUnloadModel );
assingGlobalFunction( "DrawModel", lmodelsDrawModel );
assingGlobalFunction( "DrawModelEx", lmodelsDrawModelEx );
assingGlobalFunction( "SetModelMaterial", lmodelsSetModelMaterial );
@@ -1905,6 +1931,8 @@ void luaRegister() {
assingGlobalFunction( "LoadFont", ltextLoadFont );
assingGlobalFunction( "LoadFontEx", ltextLoadFontEx );
assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage );
+ assingGlobalFunction( "IsFontReady", ltextIsFontReady );
+ assingGlobalFunction( "UnloadFont", ltextUnloadFont );
/* Drawing. */
assingGlobalFunction( "DrawFPS", ltextDrawFPS );
assingGlobalFunction( "DrawText", ltextDrawText );
@@ -1922,7 +1950,11 @@ void luaRegister() {
/* Wave/Sound Loading. */
assingGlobalFunction( "LoadSound", laudioLoadSound );
assingGlobalFunction( "LoadWave", laudioLoadWave );
+ assingGlobalFunction( "IsWaveReady", laudioIsWaveReady );
assingGlobalFunction( "LoadSoundFromWave", laudioLoadSoundFromWave );
+ assingGlobalFunction( "IsSoundReady", laudioIsSoundReady );
+ assingGlobalFunction( "UnloadWave", laudioUnloadWave );
+ assingGlobalFunction( "UnloadSound", laudioUnloadSound );
assingGlobalFunction( "ExportWave", laudioExportWave );
assingGlobalFunction( "ExportWaveAsCode", laudioExportWaveAsCode );
/* Wave/Sound management */
@@ -1939,6 +1971,8 @@ void luaRegister() {
assingGlobalFunction( "WaveCrop", laudioWaveCrop );
/* Music management. */
assingGlobalFunction( "LoadMusicStream", laudioLoadMusicStream );
+ assingGlobalFunction( "IsMusicReady", laudioIsMusicReady );
+ assingGlobalFunction( "UnloadMusicStream", laudioUnloadMusicStream );
assingGlobalFunction( "PlayMusicStream", laudioPlayMusicStream );
assingGlobalFunction( "IsMusicStreamPlaying", laudioIsMusicStreamPlaying );
assingGlobalFunction( "UpdateMusicStream", laudioUpdateMusicStream );
@@ -2788,6 +2822,13 @@ NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
return npatch;
}
+Buffer* uluaGetBuffer( lua_State *L, int index ) {
+ if ( lua_islightuserdata( L, index ) ) {
+ return (Buffer*)lua_touserdata( L, index );
+ }
+ return luaL_checkudata( L, index, "Buffer" );
+}
+
Image* uluaGetImage( lua_State *L, int index ) {
if ( lua_islightuserdata( L, index ) ) {
return (Image*)lua_touserdata( L, index );
@@ -3065,6 +3106,12 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_rawseti( L, -2, 2 );
}
+void uluaPushBuffer( lua_State *L, Buffer buffer ) {
+ Buffer *bufferP = lua_newuserdata( L, sizeof( Buffer ) );
+ *bufferP = buffer;
+ luaL_setmetatable( L, "Buffer" );
+}
+
void uluaPushImage( lua_State *L, Image image ) {
Image *imageP = lua_newuserdata( L, sizeof( Image ) );
*imageP = image;
diff --git a/src/models.c b/src/models.c
index 75f07fd..330346f 100644
--- a/src/models.c
+++ b/src/models.c
@@ -924,6 +924,19 @@ int lmodelsUpdateMesh( lua_State *L ) {
}
/*
+> RL.UnloadMesh( Mesh mesh )
+
+Unload mesh data from CPU and GPU
+*/
+int lmodelsUnloadMesh( lua_State *L ) {
+ Mesh *mesh = uluaGetMesh( L, 1 );
+
+ UnloadMesh( *mesh );
+
+ return 0;
+}
+
+/*
> RL.DrawMesh( Mesh mesh, Material material, Matrix transform )
Draw a 3d mesh with material and transform
@@ -1047,9 +1060,22 @@ int lmodelsGenMeshTangents( lua_State *L ) {
*/
/*
+> material = RL.GetMaterialDefault()
+
+Default material for reference. Return as lightuserdata
+
+- Success return Material
+*/
+int lmodelsGetMaterialDefault( lua_State *L ) {
+ lua_pushlightuserdata( L, &state->defaultMaterial );
+
+ return 1;
+}
+
+/*
> material = RL.LoadMaterialDefault()
-Load default material
+Load default material as new object
- Success return Material
*/
@@ -1145,6 +1171,37 @@ int lmodelsCreateMaterial( lua_State *L ) {
}
/*
+> isReady = RL.IsMaterialReady( Material material )
+
+Check if a material is ready
+
+- Success return bool
+*/
+int lmodelsIsMaterialReady( lua_State *L ) {
+ Material *material = uluaGetMaterial( L, 1 );
+
+ lua_pushboolean( L, IsMaterialReady( *material ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadMaterial( Material material )
+
+Unload material from GPU memory (VRAM)
+*/
+int lmodelsUnloadMaterial( lua_State *L ) {
+ Material *material = uluaGetMaterial( L, 1 );
+
+ /* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
+ RL_FREE( material->maps );
+
+ // UnloadMaterial( *material );
+
+ return 0;
+}
+
+/*
> RL.SetMaterialTexture( Material material, int mapType, Texture texture )
Set texture for a material map type (MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS...)
@@ -1286,7 +1343,7 @@ int lmodelsGetMaterialValue( lua_State *L ) {
Get material shader
-- Success return Shader. Returns as lightuserdata
+- Success return Shader. Return as lightuserdata
*/
int lmodelsGetMaterialShader( lua_State *L ) {
Material *material = uluaGetMaterial( L, 1 );
@@ -1357,6 +1414,34 @@ int lmodelsLoadModelFromMesh( lua_State *L ) {
}
/*
+> isReady = RL.IsModelReady( Model model )
+
+Check if a model is ready
+
+- Success return bool
+*/
+int lmodelsIsModelReady( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+
+ lua_pushboolean( L, IsModelReady( *model ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadModel( Model model )
+
+Unload model (including meshes) from memory (RAM and/or VRAM)
+*/
+int lmodelsUnloadModel( lua_State *L ) {
+ Model *model = uluaGetModel( L, 1 );
+
+ UnloadModel( *model );
+
+ return 0;
+}
+
+/*
> RL.DrawModel( Model model, Vector3 position, float scale, Color tint )
Draw a model (With texture if set)
@@ -1400,6 +1485,8 @@ int lmodelsSetModelMaterial( lua_State *L ) {
int modelMaterialId = luaL_checkinteger( L, 2 );
Material *material = uluaGetMaterial( L, 3 );
+ //TODO Could maybe return old shader and textures for storage or get garbage collected?
+
/* Copy material data instead of using pointer. Pointer would result in double free error. */
model->materials[ modelMaterialId ].shader = material->shader;
model->materials[ modelMaterialId ].maps[ MATERIAL_MAP_ALBEDO ] = material->maps[ MATERIAL_MAP_ALBEDO ];
diff --git a/src/state.c b/src/state.c
index 6102a2d..b96b557 100644
--- a/src/state.c
+++ b/src/state.c
@@ -18,6 +18,12 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
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" );
if ( !IsWindowReady() ) {
@@ -28,6 +34,8 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
InitAudioDevice();
state->run = luaInit( argn, argc );
}
+ state->defaultFont = GetFontDefault();
+ state->defaultMaterial = LoadMaterialDefault();
return state->run;
}
diff --git a/src/text.c b/src/text.c
index 1a8f0fd..e2135d1 100644
--- a/src/text.c
+++ b/src/text.c
@@ -11,10 +11,10 @@
/*
> RL.GetFontDefault()
-Get the default Font
+Get the default Font. Return as lightuserdata
*/
int ltextGetFontDefault( lua_State *L ) {
- uluaPushFont( L, GetFontDefault() );
+ lua_pushlightuserdata( L, &state->defaultFont );
return 1;
}
@@ -97,6 +97,34 @@ int ltextLoadFontFromImage( lua_State *L ) {
}
/*
+> isReady = RL.IsFontReady( Font font )
+
+Check if a font is ready
+
+- Success return bool
+*/
+int ltextIsFontReady( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+
+ lua_pushboolean( L, IsFontReady( *font ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadFont( Font font )
+
+Unload font from GPU memory (VRAM)
+*/
+int ltextUnloadFont( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+
+ UnloadFont( *font );
+
+ return 0;
+}
+
+/*
## Text - Draw
*/
@@ -218,14 +246,15 @@ int ltextGetFontGlyphPadding( lua_State *L ) {
/*
> texture = RL.GetFontTexture( Font font )
-Get font texture atlas containing the glyphs.
+Get font texture atlas containing the glyphs. Returns as lightuserdata
- Success return Texture
*/
int ltextGetFontTexture( lua_State *L ) {
Font *font = uluaGetFont( L, 1 );
- uluaPushTexture( L, font->texture );
+ // uluaPushTexture( L, font->texture );
+ lua_pushlightuserdata( L, &font->texture );
return 1;
}
diff --git a/src/textures.c b/src/textures.c
index abfdf01..9f65ab5 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -55,6 +55,34 @@ int ltexturesLoadImageFromScreen( lua_State *L ) {
}
/*
+> isReady = RL.IsImageReady( Image image )
+
+Check if an image is ready
+
+- Success return bool
+*/
+int ltextureIsImageReady( lua_State *L ) {
+ Image *image = uluaGetImage( L, 1 );
+
+ lua_pushboolean( L, IsImageReady( *image ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadImage( Image image )
+
+Unload image from CPU memory (RAM)
+*/
+int ltextureUnloadImage( lua_State *L ) {
+ Image *image = uluaGetImage( L, 1 );
+
+ UnloadImage( *image );
+
+ return 0;
+}
+
+/*
> success = RL.ExportImage( Image image, string fileName )
Export image data to file, returns true on success
@@ -1042,6 +1070,47 @@ int ltexturesIsTextureReady( lua_State *L ) {
}
/*
+> RL.UnloadTexture( Texture texture )
+
+Unload texture from GPU memory (VRAM)
+*/
+int ltextureUnloadTexture( lua_State *L ) {
+ Texture *texture = uluaGetTexture( L, 1 );
+
+ UnloadTexture( *texture );
+
+ return 0;
+}
+
+/*
+> isReady = RL.IsRenderTextureReady( RenderTexture target )
+
+Check if a render texture is ready
+
+- Success return bool
+*/
+int ltexturesIsRenderTextureReady( lua_State *L ) {
+ RenderTexture *target = uluaGetRenderTexture( L, 1 );
+
+ lua_pushboolean( L, IsRenderTextureReady( *target ) );
+
+ return 1;
+}
+
+/*
+> RL.UnloadRenderTexture( RenderTexture target )
+
+Unload render texture from GPU memory (VRAM)
+*/
+int ltextureUnloadRenderTexture( lua_State *L ) {
+ RenderTexture *target = uluaGetRenderTexture( L, 1 );
+
+ UnloadRenderTexture( *target );
+
+ return 0;
+}
+
+/*
> RL.UpdateTexture( Texture texture, int{} pixels )
Update GPU texture with new data