summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2023-10-27 01:16:03 +0300
committerjussi2023-10-27 01:16:03 +0300
commit6be8d71fac6dfdc3a4a55e342c61435b8906c8b9 (patch)
tree3cf7848ec47636b383a452e413ff78e91be4e59c /src
parent56c365c8cc88455d69df42e7842c986e760c776e (diff)
downloadreilua-enhanced-6be8d71fac6dfdc3a4a55e342c61435b8906c8b9.tar.gz
reilua-enhanced-6be8d71fac6dfdc3a4a55e342c61435b8906c8b9.tar.bz2
reilua-enhanced-6be8d71fac6dfdc3a4a55e342c61435b8906c8b9.zip
Release v0.5.
Diffstat (limited to 'src')
-rw-r--r--src/core.c1
-rw-r--r--src/lua_core.c61
-rw-r--r--src/rlgl.c23
-rw-r--r--src/state.c7
-rw-r--r--src/textures.c11
5 files changed, 80 insertions, 23 deletions
diff --git a/src/core.c b/src/core.c
index e49c84d..953dd1a 100644
--- a/src/core.c
+++ b/src/core.c
@@ -981,7 +981,6 @@ int lcoreLoadShader( lua_State *L ) {
lua_pushinteger( L, -1 );
return 1;
}
-
char *vsFileName = NULL;
char *fsFileName = NULL;
diff --git a/src/lua_core.c b/src/lua_core.c
index 1d6372b..5d2bab3 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -641,21 +641,39 @@ static void defineGlobals() {
lua_pop( L, -1 );
}
-static int freeBuffer( lua_State *L ) {
+static int gcBuffer( lua_State *L ) {
Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
free( buffer->data );
}
-static void defineCBuffer() {
+static void defineBuffer() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Buffer" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
- lua_pushcfunction( L, freeBuffer );
+ lua_pushcfunction( L, gcBuffer );
lua_setfield( L, -2, "__gc" );
}
+// static int gcTexture( lua_State *L ) {
+// Texture *texture = luaL_checkudata ( L, 1, "Texture" );
+// printf( "gcTexture\n" );
+// printf( "\ttexture->id = %d\n", texture->id );
+
+// UnloadTexture( *texture );
+// }
+
+// static void defineTexture() {
+// lua_State *L = state->luaState;
+
+// luaL_newmetatable( L, "Texture" );
+// lua_pushvalue( L, -1 );
+// lua_setfield( L, -2, "__index" );
+// lua_pushcfunction( L, gcTexture );
+// lua_setfield( L, -2, "__gc" );
+// }
+
// Custom logging funtion.
static void logCustom( int logLevel, const char *text, va_list args ) {
char string[ STRING_LEN ] = {'\0'};
@@ -678,24 +696,27 @@ static void logCustom( int logLevel, const char *text, va_list args ) {
/* Call Lua log function if exists. */
lua_State *L = state->luaState;
- lua_pushcfunction( L, luaTraceback );
- int tracebackidx = lua_gettop( L );
+ /* Prevent calling lua log function when lua is already shutdown. */
+ if ( L != NULL ) {
+ lua_pushcfunction( L, luaTraceback );
+ int tracebackidx = lua_gettop( L );
- lua_getglobal( L, "RL" );
- lua_getfield( L, -1, "log" );
+ lua_getglobal( L, "RL" );
+ lua_getfield( L, -1, "log" );
- if ( lua_isfunction( L, -1 ) ) {
- lua_pushinteger( L, logLevel );
- lua_pushstring( L, msg );
+ if ( lua_isfunction( L, -1 ) ) {
+ lua_pushinteger( L, logLevel );
+ lua_pushstring( L, msg );
- if ( lua_pcall( L, 2, 0, tracebackidx ) != 0 ) {
- TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
- state->run = false;
- lua_pop( L, -1 );
- return;
- }
- }
- lua_pop( L, -1 );
+ if ( lua_pcall( L, 2, 0, tracebackidx ) != 0 ) {
+ TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
+ state->run = false;
+ lua_pop( L, -1 );
+ return;
+ }
+ }
+ lua_pop( L, -1 );
+ }
}
/* Window events. */
@@ -1039,7 +1060,8 @@ bool luaInit( int argn, const char **argc ) {
return false;
}
defineGlobals();
- defineCBuffer();
+ defineBuffer();
+ // defineTexture();
/* Set arguments. */
lua_getglobal( L, "RL" );
@@ -2166,6 +2188,7 @@ Vector2 uluaGetVector2( lua_State *L ) {
}
Vector2 uluaGetVector2Index( lua_State *L, int index ) {
+ // luaL_checktype( L, index, LUA_TTABLE );
Vector2 vector = { 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
diff --git a/src/rlgl.c b/src/rlgl.c
index 6f5ece1..d13defe 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -1733,6 +1733,29 @@ int lrlglUnloadFramebuffer( lua_State *L ) {
}
/*
+## RLGL - Shaders management
+*/
+
+/*
+> success = RL.rlLoadShaderCode( string vsCode, string fsCode )
+
+Load shader from code strings
+
+- Failure return nil
+- Success return int
+*/
+// int lrlglUnloadFramebuffer( lua_State *L ) {
+// if ( !lua_isstring( L, 1 ) || !lua_isstring( L, 2 ) ) {
+// TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadShaderCode( string vsCode, string fsCode )" );
+// lua_pushnil( L );
+// return 1;
+// }
+// lua_pushinteger( L, rlLoadShaderCode( luaL_checkstring( L, 1 ), luaL_checkstring( L, 2 ) ) );
+
+// return 1;
+// }
+
+/*
## RLGL - Matrix state management
*/
diff --git a/src/state.c b/src/state.c
index d1a3329..b2b8aa0 100644
--- a/src/state.c
+++ b/src/state.c
@@ -211,11 +211,12 @@ void stateFree() {
if ( IsAudioDeviceReady() ) {
CloseAudioDevice();
}
- if ( state->hasWindow ) {
- CloseWindow();
- }
if ( state->luaState != NULL ) {
lua_close( state->luaState );
+ state->luaState = NULL;
+ }
+ if ( state->hasWindow ) {
+ CloseWindow();
}
free( state->images );
free( state->textures );
diff --git a/src/textures.c b/src/textures.c
index 061e1b2..b5677ee 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1673,6 +1673,12 @@ int ltexturesLoadTexture( lua_State *L ) {
int i = newTexture( TEXTURE_TYPE_TEXTURE );
state->textures[i]->texture = LoadTexture( lua_tostring( L, 1 ) );
lua_pushinteger( L, i );
+
+ // Texture loadedTex = LoadTexture( lua_tostring( L, 1 ) );
+ // Texture *texture = lua_newuserdata( L, sizeof( Texture ) );
+ // *texture = loadedTex;
+ // luaL_setmetatable( L, "Texture" );
+
return 1;
}
else {
@@ -1921,10 +1927,12 @@ int ltexturesDrawTexture( lua_State *L ) {
return 1;
}
Texture texture = uluaGetTexture( L, 1 );
+ // Texture *texture = luaL_checkudata( L, 1, "Texture" );
Vector2 pos = uluaGetVector2Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
DrawTexture( texture, pos.x, pos.y, color );
+ // DrawTexture( *texture, pos.x, pos.y, color );
lua_pushboolean( L, true );
return 1;
@@ -2174,6 +2182,9 @@ int ltexturesGetTextureSize( lua_State *L ) {
Texture texture = uluaGetTexture( L, 1 );
uluaPushVector2( L, (Vector2){ texture.width, texture.height } );
+ // Texture *texture = luaL_checkudata( L, 1, "Texture" );
+ // uluaPushVector2( L, (Vector2){ texture->width, texture->height } );
+
return 1;
}