Reintroducing Unload functions. Is*Ready functions. GC_UNLOAD setting and check function.
This commit is contained in:
84
src/audio.c
84
src/audio.c
@@ -64,6 +64,21 @@ int laudioLoadWave( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -79,6 +94,47 @@ int laudioLoadSoundFromWave( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -291,6 +347,34 @@ int laudioLoadMusicStream( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
|
||||
77
src/core.c
77
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;
|
||||
}
|
||||
@@ -861,6 +888,21 @@ int lcoreLoadShaderFromMemory( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -1061,6 +1103,19 @@ int lcoreSetShaderValueV( lua_State *L ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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
|
||||
*/
|
||||
|
||||
111
src/lua_core.c
111
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;
|
||||
|
||||
91
src/models.c
91
src/models.c
@@ -923,6 +923,19 @@ int lmodelsUpdateMesh( lua_State *L ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -1046,10 +1059,23 @@ int lmodelsGenMeshTangents( lua_State *L ) {
|
||||
## Models - Material
|
||||
*/
|
||||
|
||||
/*
|
||||
> 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
|
||||
*/
|
||||
@@ -1144,6 +1170,37 @@ int lmodelsCreateMaterial( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -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 );
|
||||
@@ -1356,6 +1413,34 @@ int lmodelsLoadModelFromMesh( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -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 ];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
37
src/text.c
37
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;
|
||||
}
|
||||
@@ -96,6 +96,34 @@ int ltextLoadFontFromImage( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,34 @@ int ltexturesLoadImageFromScreen( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -1041,6 +1069,47 @@ int ltexturesIsTextureReady( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user