summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2023-10-27 22:53:56 +0300
committerjussi2023-10-27 22:53:56 +0300
commit7ef87c8e2f7824a8abfe715aef23b4a6d2e4db78 (patch)
treea1a669e8af511c79657cbad1de69419c86212127 /src
parent4cb4edcaf0d8b08d888a60d1a5d36f6e3690a4df (diff)
downloadreilua-enhanced-7ef87c8e2f7824a8abfe715aef23b4a6d2e4db78.tar.gz
reilua-enhanced-7ef87c8e2f7824a8abfe715aef23b4a6d2e4db78.tar.bz2
reilua-enhanced-7ef87c8e2f7824a8abfe715aef23b4a6d2e4db78.zip
New object types for Image, Texture, RenderTexture, Camera2D, Camera3D and Shader.
Diffstat (limited to 'src')
-rw-r--r--src/core.c1081
-rw-r--r--src/gl.c26
-rw-r--r--src/lights.c33
-rw-r--r--src/lua_core.c497
-rw-r--r--src/models.c223
-rw-r--r--src/shapes.c17
-rw-r--r--src/state.c58
-rw-r--r--src/text.c14
-rw-r--r--src/textures.c1806
9 files changed, 915 insertions, 2840 deletions
diff --git a/src/core.c b/src/core.c
index 953dd1a..82e9879 100644
--- a/src/core.c
+++ b/src/core.c
@@ -4,61 +4,6 @@
#include "textures.h"
#include "lua_core.h"
-static void checkCamera2DRealloc( int i ) {
- if ( i == state->camera2DCount ) {
- state->camera2DCount++;
- }
-
- if ( state->camera2DCount == state->camera2DAlloc ) {
- state->camera2DAlloc += ALLOC_PAGE_SIZE;
- state->camera2Ds = realloc( state->camera2Ds, state->camera2DAlloc * sizeof( Camera2D* ) );
-
- for ( i = state->camera2DCount; i < state->camera2DAlloc; i++ ) {
- state->camera2Ds[i] = NULL;
- }
- }
-}
-
-static void checkCamera3DRealloc( int i ) {
- if ( i == state->camera3DCount ) {
- state->camera3DCount++;
- }
-
- if ( state->camera3DCount == state->camera3DAlloc ) {
- state->camera3DAlloc += ALLOC_PAGE_SIZE;
- state->camera3Ds = realloc( state->camera3Ds, state->camera3DAlloc * sizeof( Camera3D* ) );
-
- for ( i = state->camera3DCount; i < state->camera3DAlloc; i++ ) {
- state->camera3Ds[i] = NULL;
- }
- }
-}
-
-static void checkShaderRealloc( int i ) {
- if ( i == state->shaderCount ) {
- state->shaderCount++;
- }
-
- if ( state->shaderCount == state->shaderAlloc ) {
- state->shaderAlloc += ALLOC_PAGE_SIZE;
- state->shaders = realloc( state->shaders, state->shaderAlloc * sizeof( Shader* ) );
-
- for ( i = state->shaderCount; i < state->shaderAlloc; i++ ) {
- state->shaders[i] = NULL;
- }
- }
-}
-
-bool validShader( size_t id ) {
- if ( id < 0 || state->shaderCount < id || state->shaders[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid shader", id );
- return false;
- }
- else {
- return true;
- }
-}
-
/*
## Core - Window
*/
@@ -375,30 +320,16 @@ int lcoreIsWindowResized( lua_State *L ) {
}
/*
-> success = RL.SetWindowIcon( Image image )
+> RL.SetWindowIcon( Image image )
Set icon for window ( Only PLATFORM_DESKTOP )
-
-- Failure return false
-- Success return true
*/
int lcoreSetWindowIcon( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetWindowIcon( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
-
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
+ Image *image = luaL_checkudata( L, 1, "Image" );
- SetWindowIcon( *state->images[ imageId ] );
- lua_pushboolean( L, true );
+ SetWindowIcon( *image );
- return 1;
+ return 0;
}
/*
@@ -855,7 +786,7 @@ int lcoreIsCursorOnScreen( lua_State *L ) {
/*
> success = RL.ClearBackground( Color color )
-Set background color ( framebuffer clear color )
+Set background color (framebuffer clear color)
- Failure return false
- Success return true
@@ -972,13 +903,13 @@ int lcoreEndScissorMode( lua_State *L ) {
Load shader from files and bind default locations.
NOTE: Set nil if no shader
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Shader
*/
int lcoreLoadShader( lua_State *L ) {
if ( !( lua_isstring( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isstring( L, 2 ) || lua_isnil( L, 2 ) ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadShader( string vsFileName, string fsFileName )" );
- lua_pushinteger( L, -1 );
+ lua_pushnil( L );
return 1;
}
char *vsFileName = NULL;
@@ -996,18 +927,7 @@ int lcoreLoadShader( lua_State *L ) {
strcpy( fsFileName, lua_tostring( L, 2 ) );
}
}
-
- int i = 0;
-
- for ( i = 0; i < state->shaderCount; i++ ) {
- if ( state->shaders[i] == NULL ) {
- break;
- }
- }
- state->shaders[i] = malloc( sizeof( Shader ) );
- *state->shaders[i] = LoadShader( vsFileName, fsFileName );
- lua_pushinteger( L, i );
- checkShaderRealloc( i );
+ uluaPushShader( L, LoadShader( vsFileName, fsFileName ) );
if ( vsFileName != NULL ) {
free( vsFileName );
@@ -1025,14 +945,14 @@ int lcoreLoadShader( lua_State *L ) {
Load shader from code strings and bind default locations
NOTE: Set nil if no shader
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Shader
*/
int lcoreLoadShaderFromMemory( lua_State *L ) {
if ( !( lua_isstring( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isstring( L, 2 ) || lua_isnil( L, 2 ) ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadShaderFromMemory( string vsCode, string fsCode )" );
- lua_pushinteger( L, -1 );
+ lua_pushnil( L );
return 1;
}
char *vs = NULL;
@@ -1050,18 +970,7 @@ int lcoreLoadShaderFromMemory( lua_State *L ) {
fs = malloc( fsLen * sizeof( char ) );
strcpy( fs, lua_tostring( L, 2 ) );
}
-
- int i = 0;
-
- for ( i = 0; i < state->shaderCount; i++ ) {
- if ( state->shaders[i] == NULL ) {
- break;
- }
- }
- state->shaders[i] = malloc( sizeof( Shader ) );
- *state->shaders[i] = LoadShaderFromMemory( vs, fs );
- lua_pushinteger( L, i );
- checkShaderRealloc( i );
+ uluaPushShader( L, LoadShaderFromMemory( vs, fs ) );
if ( vs != NULL ) {
free( vs );
@@ -1074,40 +983,27 @@ int lcoreLoadShaderFromMemory( lua_State *L ) {
}
/*
-> success = RL.BeginShaderMode( Shader shader )
+> RL.BeginShaderMode( Shader shader )
Begin custom shader drawing
-
-- Failure return false
-- Success return true
*/
int lcoreBeginShaderMode( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.BeginShaderMode( Shader shader )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
-
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- BeginShaderMode( *state->shaders[ shaderId ] );
- lua_pushboolean( L, true );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
- return 1;
+ BeginShaderMode( *shader );
+
+ return 0;
}
/*
> RL.EndShaderMode()
-End custom shader drawing ( use default shader )
+End custom shader drawing (use default shader)
*/
int lcoreEndShaderMode( lua_State *L ) {
EndShaderMode();
- return 1;
+ return 0;
}
/*
@@ -1115,22 +1011,12 @@ int lcoreEndShaderMode( lua_State *L ) {
Get shader uniform location
-- Failure return -1
- Success return int
*/
int lcoreGetShaderLocation( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetShaderLocation( Shader shader, string uniformName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
- if ( !validShader( shaderId ) ) {
- lua_pushinteger( L, -1 );
- return 1;
- }
- lua_pushinteger( L, GetShaderLocation( *state->shaders[ shaderId ], lua_tostring( L, 2 ) ) );
+ lua_pushinteger( L, GetShaderLocation( *shader, luaL_checkstring( L, 2 ) ) );
return 1;
}
@@ -1140,52 +1026,29 @@ int lcoreGetShaderLocation( lua_State *L ) {
Get shader attribute location
-- Failure return -1
- Success return int
*/
int lcoreGetShaderLocationAttrib( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetShaderLocationAttrib( Shader shader, string attribName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
- if ( !validShader( shaderId ) ) {
- lua_pushinteger( L, -1 );
- return 1;
- }
- lua_pushinteger( L, GetShaderLocationAttrib( *state->shaders[ shaderId ], lua_tostring( L, 2 ) ) );
+ lua_pushinteger( L, GetShaderLocationAttrib( *shader, luaL_checkstring( L, 2 ) ) );
return 1;
}
/*
-> success = RL.SetShaderLocationIndex( Shader shader, int shaderLocationIndex, int location )
+> RL.SetShaderLocationIndex( Shader shader, int shaderLocationIndex, int location )
Set shader location index
-
-- Failure return false
-- Success return true
*/
int lcoreSetShaderLocationIndex( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShaderLocationIndex( Shader shader, int shaderLocationIndex, int location )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
- int shaderLocationIndex = lua_tointeger( L, 2 );
- int location = lua_tointeger( L, 3 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
+ int shaderLocationIndex = luaL_checkinteger( L, 2 );
+ int location = luaL_checkinteger( L, 3 );
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- state->shaders[ shaderId ]->locs[ shaderLocationIndex ] = location;
- lua_pushboolean( L, true );
+ shader->locs[ shaderLocationIndex ] = location;
- return 1;
+ return 0;
}
/*
@@ -1193,102 +1056,58 @@ int lcoreSetShaderLocationIndex( lua_State *L ) {
Get shader location index
-- Failure return false
- Success return int
*/
int lcoreGetShaderLocationIndex( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetShaderLocationIndex( Shader shader, int shaderLocationIndex )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
- int shaderLocationIndex = lua_tointeger( L, 2 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
+ int shaderLocationIndex = luaL_checkinteger( L, 2 );
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->shaders[ shaderId ]->locs[ shaderLocationIndex ] );
+ lua_pushinteger( L, shader->locs[ shaderLocationIndex ] );
return 1;
}
/*
-> success = RL.SetShaderValueMatrix( Shader shader, int locIndex, Matrix mat )
+> RL.SetShaderValueMatrix( Shader shader, int locIndex, Matrix mat )
-Set shader uniform value ( matrix 4x4 )
-
-- Failure return false
-- Success return true
+Set shader uniform value (matrix 4x4)
*/
int lcoreSetShaderValueMatrix( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShaderValueMatrix( Shader shader, int locIndex, Matrix mat )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
- int locIndex = lua_tointeger( L, 2 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
+ int locIndex = luaL_checkinteger( L, 2 );
Matrix mat = uluaGetMatrixIndex( L, 3 );
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- SetShaderValueMatrix( *state->shaders[ shaderId ], locIndex, mat );
- lua_pushboolean( L, true );
+ SetShaderValueMatrix( *shader, locIndex, mat );
- return 1;
+ return 0;
}
/*
-> success = RL.SetShaderValueTexture( Shader shader, int locIndex, Texture2D texture )
-
-Set shader uniform value for texture ( sampler2d )
+> RL.SetShaderValueTexture( Shader shader, int locIndex, Texture texture )
-- Failure return false
-- Success return true
+Set shader uniform value for texture (sampler2d)
*/
int lcoreSetShaderValueTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShaderValueTexture( Shader shader, int locIndex, Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
- int locIndex = lua_tointeger( L, 2 );
- Texture texture = uluaGetTexture( L, 3 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
+ int locIndex = luaL_checkinteger( L, 2 );
+ Texture *texture = luaL_checkudata( L, 3, "Texture" );
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- SetShaderValueTexture( *state->shaders[ shaderId ], locIndex, texture );
- lua_pushboolean( L, true );
+ SetShaderValueTexture( *shader, locIndex, *texture );
- return 1;
+ return 0;
}
/*
-> success = RL.SetShaderValue( Shader shader, int locIndex, number{} values, int uniformType )
+> RL.SetShaderValue( Shader shader, int locIndex, number{} values, int uniformType )
Set shader uniform value
NOTE: Even one value should be in table
-
-- Failure return false
-- Success return true
*/
int lcoreSetShaderValue( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShaderValue( Shader shader, int locIndex, number{} values, int uniformType )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
- int locIndex = lua_tointeger( L, 2 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
+ int locIndex = luaL_checkinteger( L, 2 );
size_t valueCount = uluaGetTableLenIndex( L, 3 );
- int uniformType = lua_tointeger( L, 4 );
+ int uniformType = luaL_checkinteger( L, 4 );
/* Read values. */
float floats[ valueCount ];
@@ -1309,45 +1128,29 @@ int lcoreSetShaderValue( lua_State *L ) {
lua_pop( L, 1 );
/* Read values end. */
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
if ( uniformType == SHADER_UNIFORM_FLOAT || uniformType == SHADER_UNIFORM_VEC2
|| uniformType == SHADER_UNIFORM_VEC3 || uniformType == SHADER_UNIFORM_VEC4 ) {
- SetShaderValue( *state->shaders[ shaderId ], locIndex, floats, uniformType );
+ SetShaderValue( *shader, locIndex, floats, uniformType );
}
else {
- SetShaderValue( *state->shaders[ shaderId ], locIndex, ints, uniformType );
+ SetShaderValue( *shader, locIndex, ints, uniformType );
}
- lua_pushboolean( L, true );
-
- return 1;
+ return 0;
}
/*
-> success = RL.SetShaderValueV( Shader shader, int locIndex, number{} values, int uniformType, int count )
+> RL.SetShaderValueV( Shader shader, int locIndex, number{} values, int uniformType, int count )
Set shader uniform value vector
NOTE: Even one value should be in table
-
-- Failure return false
-- Success return true
*/
int lcoreSetShaderValueV( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShaderValueV( Shader shader, int locIndex, number{} values, int uniformType, int count )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
- int locIndex = lua_tointeger( L, 2 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
+ int locIndex = luaL_checkinteger( L, 2 );
size_t valueCount = uluaGetTableLenIndex( L, 3 );
- int uniformType = lua_tointeger( L, 4 );
- int count = lua_tointeger( L, 5 );
+ int uniformType = luaL_checkinteger( L, 4 );
+ int count = luaL_checkinteger( L, 5 );
/* Read values. */
float floats[ valueCount * count ];
@@ -1368,48 +1171,15 @@ int lcoreSetShaderValueV( lua_State *L ) {
lua_pop( L, 1 );
/* Read values end. */
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
if ( uniformType == SHADER_UNIFORM_FLOAT || uniformType == SHADER_UNIFORM_VEC2
|| uniformType == SHADER_UNIFORM_VEC3 || uniformType == SHADER_UNIFORM_VEC4 ) {
- SetShaderValueV( *state->shaders[ shaderId ], locIndex, floats, uniformType, count );
+ SetShaderValueV( *shader, locIndex, floats, uniformType, count );
}
else {
- SetShaderValueV( *state->shaders[ shaderId ], locIndex, ints, uniformType, count );
+ SetShaderValueV( *shader, locIndex, ints, uniformType, count );
}
- lua_pushboolean( L, true );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadShader( Shader shader )
-
-Unload shader from GPU memory ( VRAM )
-- Failure return false
-- Success return true
-*/
-int lcoreUnloadShader( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadShader( Shader shader )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validShader( id ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadShader( *state->shaders[ id ] );
- state->shaders[ id ] = NULL;
- lua_pushboolean( L, true );
-
- return 1;
+ return 0;
}
/*
@@ -2510,73 +2280,34 @@ int lcoreGetFileModTime( lua_State *L ) {
/*
> camera2D = RL.CreateCamera2D()
-Return camera2D id set to default configuration
+Return camera2D set to default configuration
-- Success return int
+- Success return Camera2D
*/
int lcoreCreateCamera2D( lua_State *L ) {
- int i = 0;
-
- for ( i = 0; i < state->camera2DCount; i++ ) {
- if ( state->camera2Ds[i] == NULL ) {
- break;
- }
- }
- state->camera2Ds[i] = malloc( sizeof( Camera2D ) );
- state->camera2Ds[i]->offset = (Vector2){ 0.0, 0.0 };
- state->camera2Ds[i]->target = (Vector2){ 0.0, 0.0 };
- state->camera2Ds[i]->rotation = 0.0;
- state->camera2Ds[i]->zoom = 1.0;
-
- lua_pushinteger( L, i );
- checkCamera2DRealloc(i);
-
- return 1;
-}
-
-/*
-> success = RL.UnloadCamera2D( camera2D camera )
-
-Unload Camera2D
-
-- Failure return false
-- Success return true
-*/
-int lcoreUnloadCamera2D( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadCamera2D( int Camera2D )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera2D camera = { 0 };
+
+ camera.offset = (Vector2){ 0.0, 0.0 };
+ camera.target = (Vector2){ 0.0, 0.0 };
+ camera.rotation = 0.0;
+ camera.zoom = 1.0;
- free( state->camera2Ds[ cameraId ] );
- state->camera2Ds[ cameraId ] = NULL;
- lua_pushboolean( L, true );
+ uluaPushCamera2D( L, camera );
return 1;
}
/*
-> success = RL.BeginMode2D( camera2D camera )
+> RL.BeginMode2D( camera2D camera )
-Begin 2D mode with custom camera ( 2D )
-
-- Failure return false
-- Success return true
+Begin 2D mode with custom camera (2D)
*/
int lcoreBeginMode2D( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.BeginMode2D( camera2D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera2D camera = uluaGetCamera2D( L, 1 );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
- BeginMode2D( camera );
- lua_pushboolean( L, true );
+ BeginMode2D( *camera );
- return 1;
+ return 0;
}
/*
@@ -2587,99 +2318,63 @@ Ends 2D mode with custom camera
int lcoreEndMode2D( lua_State *L ) {
EndMode2D();
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera2DTarget( camera2D camera, Vector2 target )
-
-Set camera target ( rotation and zoom origin )
+> RL.SetCamera2DTarget( camera2D camera, Vector2 target )
-- Failure return false
-- Success return true
+Set camera target (rotation and zoom origin)
*/
int lcoreSetCamera2DTarget( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera2DTarget( camera2D camera, Vector2 target )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
Vector2 target = uluaGetVector2Index( L, 2 );
- state->camera2Ds[ cameraId ]->target = target;
- lua_pushboolean( L, true );
+ camera->target = target;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera2DOffset( camera2D camera, Vector2 offset )
-
-Set camera offset ( displacement from target )
+> RL.SetCamera2DOffset( camera2D camera, Vector2 offset )
-- Failure return false
-- Success return true
+Set camera offset (displacement from target)
*/
int lcoreSetCamera2DOffset( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera2DOffset( camera2D camera, Vector2 offset )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
Vector2 offset = uluaGetVector2Index( L, 2 );
- state->camera2Ds[ cameraId ]->offset = offset;
- lua_pushboolean( L, true );
+ camera->offset = offset;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera2DRotation( camera2D camera, float rotation )
+> RL.SetCamera2DRotation( camera2D camera, float rotation )
Set camera rotation in degrees
-
-- Failure return false
-- Success return true
*/
int lcoreSetCamera2DRotation( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera2DRotation( camera2D camera, float rotation )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float rotation = lua_tonumber( L, 2 );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+ float rotation = luaL_checknumber( L, 2 );
- state->camera2Ds[ cameraId ]->rotation = rotation;
- lua_pushboolean( L, true );
+ camera->rotation = rotation;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera2DZoom( camera2D camera, float zoom )
-
-Set camera zoom ( scaling ), should be 1.0f by default
+> RL.SetCamera2DZoom( camera2D camera, float zoom )
-- Failure return false
-- Success return true
+Set camera zoom (scaling), should be 1.0f by default
*/
int lcoreSetCamera2DZoom( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera2DZoom( camera2D camera, float zoom )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float zoom = lua_tonumber( L, 2 );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+ float zoom = luaL_checknumber( L, 2 );
- state->camera2Ds[ cameraId ]->zoom = zoom;
- lua_pushboolean( L, true );
+ camera->zoom = zoom;
- return 1;
+ return 0;
}
/*
@@ -2687,17 +2382,12 @@ int lcoreSetCamera2DZoom( lua_State *L ) {
Get camera2D target
-- Failure return nil
- Success return Vector2
*/
int lcoreGetCamera2DTarget( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera2DTarget( camera2D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- uluaPushVector2( L, state->camera2Ds[ cameraId ]->target );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+
+ uluaPushVector2( L, camera->target );
return 1;
}
@@ -2707,17 +2397,11 @@ int lcoreGetCamera2DTarget( lua_State *L ) {
Get camera2D offset
-- Failure return nil
- Success return Vector2
*/
int lcoreGetCamera2DOffset( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera2DOffset( camera2D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- uluaPushVector2( L, state->camera2Ds[ cameraId ]->offset );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+ uluaPushVector2( L, camera->offset );
return 1;
}
@@ -2727,17 +2411,11 @@ int lcoreGetCamera2DOffset( lua_State *L ) {
Get camera2D rotation
-- Failure return nil
- Success return float
*/
int lcoreGetCamera2DRotation( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera2DRotation( camera2D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- lua_pushnumber( L, state->camera2Ds[ cameraId ]->rotation );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+ lua_pushnumber( L, camera->rotation );
return 1;
}
@@ -2747,17 +2425,11 @@ int lcoreGetCamera2DRotation( lua_State *L ) {
Get camera2D zoom
-- Failure return nil
- Success return float
*/
int lcoreGetCamera2DZoom( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera2DZoom( camera2D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- lua_pushnumber( L, state->camera2Ds[ cameraId ]->zoom );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+ lua_pushnumber( L, camera->zoom );
return 1;
}
@@ -2774,69 +2446,30 @@ Return camera3D id set to default configuration
- Success return int
*/
int lcoreCreateCamera3D( lua_State *L ) {
- int i = 0;
+ Camera3D camera = { 0 };
- for ( i = 0; i < state->camera3DCount; i++ ) {
- if ( state->camera3Ds[i] == NULL ) {
- break;
- }
- }
- state->camera3Ds[i] = malloc( sizeof( Camera3D ) );
- state->camera3Ds[i]->position = (Vector3){ 0.0, 0.0, 0.0 };
- state->camera3Ds[i]->target = (Vector3){ 0.0, 0.0, 0.0 };
- state->camera3Ds[i]->up = (Vector3){ 0.0, 0.0, 0.0 };
- state->camera3Ds[i]->fovy = 45.0f;
- state->camera3Ds[i]->projection = CAMERA_PERSPECTIVE;
+ camera.position = (Vector3){ 0.0, 0.0, 0.0 };
+ camera.target = (Vector3){ 0.0, 0.0, 0.0 };
+ camera.up = (Vector3){ 0.0, 0.0, 0.0 };
+ camera.fovy = 45.0f;
+ camera.projection = CAMERA_PERSPECTIVE;
- lua_pushinteger( L, i );
- checkCamera3DRealloc(i);
+ uluaPushCamera3D( L, camera );
return 1;
}
/*
-> success = RL.UnloadCamera3D( int Camera3D )
+> RL.BeginMode3D( camera3D camera )
-Unload Camera3D
-
-- Failure return false
-- Success return true
-*/
-int lcoreUnloadCamera3D( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadCamera3D( int Camera3D )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
-
- free( state->camera3Ds[ cameraId ] );
- state->camera3Ds[ cameraId ] = NULL;
- lua_pushboolean( L, true );
-
- return 1;
-}
-
-/*
-> success = RL.BeginMode3D( camera3D camera )
-
-Begin 3D mode with custom camera ( 3D )
-
-- Failure return false
-- Success return true
+Begin 3D mode with custom camera (3D)
*/
int lcoreBeginMode3D( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.BeginMode3D( camera3D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- BeginMode3D( camera );
- lua_pushboolean( L, true );
+ BeginMode3D( *camera );
- return 1;
+ return 0;
}
/*
@@ -2847,122 +2480,77 @@ Ends 3D mode and returns to default 2D orthographic mode
int lcoreEndMode3D( lua_State *L ) {
EndMode3D();
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera3DPosition( camera3D camera, Vector3 position )
+> RL.SetCamera3DPosition( camera3D camera, Vector3 position )
-Set camera position ( Remember to call "RL.UpdateCamera3D()" to apply changes )
-
-- Failure return false
-- Success return true
+Set camera position (Remember to call "RL.UpdateCamera3D()" to apply changes)
*/
int lcoreSetCamera3DPosition( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera3DPosition( camera3D camera, Vector3 position )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Vector3 pos = uluaGetVector3Index( L, 2 );
- state->camera3Ds[ cameraId ]->position = pos;
- lua_pushboolean( L, true );
+ camera->position = pos;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera3DTarget( camera3D camera, Vector3 target )
+> RL.SetCamera3DTarget( camera3D camera, Vector3 target )
Set camera target it looks-at
-
-- Failure return false
-- Success return true
*/
int lcoreSetCamera3DTarget( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera3DTarget( camera3D camera, Vector3 target )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Vector3 target = uluaGetVector3Index( L, 2 );
- state->camera3Ds[ cameraId ]->target = target;
- lua_pushboolean( L, true );
+ camera->target = target;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera3DUp( camera3D camera, Vector3 up )
-
-Set camera up vector ( Rotation over it's axis )
+> RL.SetCamera3DUp( camera3D camera, Vector3 up )
-- Failure return false
-- Success return true
+Set camera up vector (Rotation over it's axis)
*/
int lcoreSetCamera3DUp( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera3DUp( camera3D camera, Vector3 up )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Vector3 up = uluaGetVector3Index( L, 2 );
- state->camera3Ds[ cameraId ]->up = up;
- lua_pushboolean( L, true );
+ camera->up = up;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera3DFovy( camera3D camera, float fovy )
+> RL.SetCamera3DFovy( camera3D camera, float fovy )
-Set camera field-of-view apperture in Y ( degrees ) in perspective, used as near plane width in orthographic
-
-- Failure return false
-- Success return true
+Set camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
*/
int lcoreSetCamera3DFovy( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera3DFovy( camera3D camera, float fovy )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float fovy = lua_tonumber( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float fovy = luaL_checknumber( L, 2 );
- state->camera3Ds[ cameraId ]->fovy = fovy;
- lua_pushboolean( L, true );
+ camera->fovy = fovy;
- return 1;
+ return 0;
}
/*
-> success = RL.SetCamera3DProjection( camera3D camera, int projection )
-
-Set camera projection mode ( CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC )
+> RL.SetCamera3DProjection( camera3D camera, int projection )
-- Failure return false
-- Success return true
+Set camera projection mode (CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC)
*/
int lcoreSetCamera3DProjection( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetCamera3DProjection( camera3D camera, int projection )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- int projection = lua_tointeger( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ int projection = luaL_checkinteger( L, 2 );
- state->camera3Ds[ cameraId ]->projection = projection;
- lua_pushboolean( L, true );
+ camera->projection = projection;
- return 1;
+ return 0;
}
/*
@@ -2970,18 +2558,12 @@ int lcoreSetCamera3DProjection( lua_State *L ) {
Get camera position
-- Failure return nil
- Success return Vector3
*/
int lcoreGetCamera3DPosition( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DPosition( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushVector3( L, state->camera3Ds[ cameraId ]->position );
+ uluaPushVector3( L, camera->position );
return 1;
}
@@ -2991,18 +2573,12 @@ int lcoreGetCamera3DPosition( lua_State *L ) {
Get camera target it looks-at
-- Failure return nil
- Success return Vector3
*/
int lcoreGetCamera3DTarget( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DTarget( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushVector3( L, state->camera3Ds[ cameraId ]->target );
+ uluaPushVector3( L, camera->target );
return 1;
}
@@ -3010,20 +2586,14 @@ int lcoreGetCamera3DTarget( lua_State *L ) {
/*
> up = RL.GetCamera3DUp( camera3D camera )
-Get camera up vector ( Rotation over it's axis )
+Get camera up vector (Rotation over it's axis)
-- Failure return nil
- Success return Vector3
*/
int lcoreGetCamera3DUp( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DUp( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushVector3( L, state->camera3Ds[ cameraId ]->up );
+ uluaPushVector3( L, camera->up );
return 1;
}
@@ -3031,20 +2601,14 @@ int lcoreGetCamera3DUp( lua_State *L ) {
/*
> fovy = RL.GetCamera3DFovy( camera3D camera )
-Get camera field-of-view apperture in Y ( degrees ) in perspective, used as near plane width in orthographic
+Get camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
-- Failure return nil
- Success return float
*/
int lcoreGetCamera3DFovy( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DFovy( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- lua_pushnumber( L, state->camera3Ds[ cameraId ]->fovy );
+ lua_pushnumber( L, camera->fovy );
return 1;
}
@@ -3054,18 +2618,12 @@ int lcoreGetCamera3DFovy( lua_State *L ) {
Get camera projection mode
-- Failure return nil
- Success return int
*/
int lcoreGetCamera3DProjection( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DProjection( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- lua_pushinteger( L, state->camera3Ds[ cameraId ]->projection );
+ lua_pushinteger( L, camera->projection );
return 1;
}
@@ -3073,20 +2631,14 @@ int lcoreGetCamera3DProjection( lua_State *L ) {
/*
> forward = RL.GetCamera3DForward( camera3D camera )
-Returns the cameras forward vector ( normalized )
+Returns the cameras forward vector (normalized)
-- Failure return nil
- Success return Vector3
*/
int lcoreGetCamera3DForward( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DForward( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushVector3( L, GetCameraForward( &camera ) );
+ uluaPushVector3( L, GetCameraForward( camera ) );
return 1;
}
@@ -3094,21 +2646,15 @@ int lcoreGetCamera3DForward( lua_State *L ) {
/*
> up = RL.GetCamera3DUpNormalized( camera3D camera )
-Returns the cameras up vector ( normalized )
+Returns the cameras up vector (normalized)
Note: The up vector might not be perpendicular to the forward vector
-- Failure return nil
- Success return Vector3
*/
int lcoreGetCamera3DUpNormalized( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DUpNormalized( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushVector3( L, GetCameraUp( state->camera3Ds[ cameraId ] ) );
+ uluaPushVector3( L, GetCameraUp( camera ) );
return 1;
}
@@ -3116,199 +2662,129 @@ int lcoreGetCamera3DUpNormalized( lua_State *L ) {
/*
> right = RL.GetCamera3DRight( camera3D camera )
-Returns the cameras right vector ( normalized )
+Returns the cameras right vector (normalized)
-- Failure return nil
- Success return Vector3
*/
int lcoreGetCamera3DRight( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DRight( camera3D camera )" );
- lua_pushnil( L );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushVector3( L, GetCameraRight( state->camera3Ds[ cameraId ] ) );
+ uluaPushVector3( L, GetCameraRight( camera ) );
return 1;
}
/*
-> success = RL.Camera3DMoveForward( camera3D camera, float distance, bool moveInWorldPlane )
+> RL.Camera3DMoveForward( camera3D camera, float distance, bool moveInWorldPlane )
Moves the camera in it's forward direction
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DMoveForward( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DRight( camera3D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float distance = lua_tonumber( L, 2 );
- bool moveInWorldPlane = lua_toboolean( L, 3 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float distance = luaL_checknumber( L, 2 );
+ bool moveInWorldPlane = uluaGetBoolean( L, 3 );
- CameraMoveForward( state->camera3Ds[ cameraId ], distance, moveInWorldPlane );
- lua_pushboolean( L, true );
+ CameraMoveForward( camera, distance, moveInWorldPlane );
- return 1;
+ return 0;
}
/*
-> success = RL.Camera3DMoveUp( camera3D camera, float distance )
+> RL.Camera3DMoveUp( camera3D camera, float distance )
Moves the camera in it's up direction
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DMoveUp( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Camera3DMoveUp( camera3D camera, float distance )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float distance = lua_tonumber( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float distance = luaL_checknumber( L, 2 );
- CameraMoveUp( state->camera3Ds[ cameraId ], distance );
- lua_pushboolean( L, true );
+ CameraMoveUp( camera, distance );
- return 1;
+ return 0;
}
/*
-> success = RL.Camera3DMoveRight( camera3D camera, float distance, bool moveInWorldPlane )
+> RL.Camera3DMoveRight( camera3D camera, float distance, bool moveInWorldPlane )
Moves the camera target in it's current right direction
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DMoveRight( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Camera3DMoveRight( camera3D camera, float distance, bool moveInWorldPlane )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float distance = lua_tonumber( L, 2 );
- bool moveInWorldPlane = lua_toboolean( L, 3 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float distance = luaL_checknumber( L, 2 );
+ bool moveInWorldPlane = uluaGetBoolean( L, 3 );
- CameraMoveRight( state->camera3Ds[ cameraId ], distance, moveInWorldPlane );
- lua_pushboolean( L, true );
+ CameraMoveRight( camera, distance, moveInWorldPlane );
- return 1;
+ return 0;
}
/*
-> success = RL.Camera3DMoveToTarget( camera3D camera, float delta )
+> RL.Camera3DMoveToTarget( camera3D camera, float delta )
Moves the camera position closer/farther to/from the camera target
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DMoveToTarget( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Camera3DMoveToTarget( camera3D camera, float delta )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float delta = lua_tonumber( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float delta = luaL_checknumber( L, 2 );
- CameraMoveToTarget( state->camera3Ds[ cameraId ], delta );
- lua_pushboolean( L, true );
+ CameraMoveToTarget( camera, delta );
- return 1;
+ return 0;
}
/*
-> success = RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )
+> RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )
Rotates the camera around it's up vector
Yaw is "looking left and right"
If rotateAroundTarget is false, the camera rotates around it's position
Note: angle must be provided in radians
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DYaw( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float delta = lua_tonumber( L, 2 );
- bool rotateAroundTarget = lua_toboolean( L, 3 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float delta = luaL_checknumber( L, 2 );
+ bool rotateAroundTarget = uluaGetBoolean( L, 3 );
- CameraYaw( state->camera3Ds[ cameraId ], delta, rotateAroundTarget );
- lua_pushboolean( L, true );
+ CameraYaw( camera, delta, rotateAroundTarget );
- return 1;
+ return 0;
}
/*
-> success = RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp )
+> RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp )
Rotates the camera around it's right vector, pitch is "looking up and down"
- lockView prevents camera overrotation (aka "somersaults")
- rotateAroundTarget defines if rotation is around target or around it's position
- rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
NOTE: angle must be provided in radians
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DPitch( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 )
- || !lua_isboolean( L, 4 ) || !lua_isboolean( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float delta = lua_tonumber( L, 2 );
- bool lockView = lua_toboolean( L, 3 );
- bool rotateAroundTarget = lua_toboolean( L, 4 );
- bool rotateUp = lua_toboolean( L, 5 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float delta = luaL_checknumber( L, 2 );
+ bool lockView = uluaGetBoolean( L, 3 );
+ bool rotateAroundTarget = uluaGetBoolean( L, 4 );
+ bool rotateUp = uluaGetBoolean( L, 5 );
- CameraPitch( state->camera3Ds[ cameraId ], delta, lockView, rotateAroundTarget, rotateUp );
- lua_pushboolean( L, true );
+ CameraPitch( camera, delta, lockView, rotateAroundTarget, rotateUp );
- return 1;
+ return 0;
}
/*
-> success = RL.Camera3DRoll( camera3D camera, float angle )
+> RL.Camera3DRoll( camera3D camera, float angle )
Rotates the camera around it's forward vector
Roll is "turning your head sideways to the left or right"
Note: angle must be provided in radians
-
-- Failure return false
-- Success return true
*/
int lcoreCamera3DRoll( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Camera3DRoll( camera3D camera, float angle )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- float angle = lua_tonumber( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float angle = luaL_checknumber( L, 2 );
- CameraRoll( state->camera3Ds[ cameraId ], angle );
- lua_pushboolean( L, true );
+ CameraRoll( camera, angle );
- return 1;
+ return 0;
}
/*
@@ -3316,18 +2792,12 @@ int lcoreCamera3DRoll( lua_State *L ) {
Returns the camera view matrix
-- Failure return false
- Success return Matrix
*/
int lcoreGetCamera3DViewMatrix( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DViewMatrix( camera3D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushMatrix( L, GetCameraViewMatrix( &camera ) );
+ uluaPushMatrix( L, GetCameraViewMatrix( camera ) );
return 1;
}
@@ -3337,69 +2807,45 @@ int lcoreGetCamera3DViewMatrix( lua_State *L ) {
Returns the camera projection matrix
-- Failure return false
- Success return Matrix
*/
int lcoreGetCamera3DProjectionMatrix( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCamera3DProjectionMatrix( camera3D camera, float aspect )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
- float aspect = lua_tonumber( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ float aspect = luaL_checknumber( L, 2 );
- uluaPushMatrix( L, GetCameraProjectionMatrix( &camera, aspect ) );
+ uluaPushMatrix( L, GetCameraProjectionMatrix( camera, aspect ) );
return 1;
}
/*
-> success = RL.UpdateCamera3D( camera3D camera, int mode )
+> RL.UpdateCamera3D( camera3D camera, int mode )
Update camera position for selected mode
-
-- Failure return false
-- Success return true
*/
int lcoreUpdateCamera3D( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateCamera3D( camera3D camera, int mode )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
- int mode = lua_tointeger( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ int mode = luaL_checkinteger( L, 2 );
- UpdateCamera( state->camera3Ds[ cameraId ], mode );
- lua_pushboolean( L, true );
+ UpdateCamera( camera, mode );
- return 1;
+ return 0;
}
/*
-> success = RL.UpdateCamera3DPro( camera3D camera, Vector3 movement, Vector3 rotation, float zoom )
+> RL.UpdateCamera3DPro( camera3D camera, Vector3 movement, Vector3 rotation, float zoom )
Update camera movement, movement/rotation values should be provided by user
-
-- Failure return false
-- Success return true
*/
int lcoreUpdateCamera3DPro( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateCamera3DPro( camera3D camera, Vector3 movement, Vector3 rotation, float zoom )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
Vector3 movement = uluaGetVector3Index( L, 2 );
Vector3 rotation = uluaGetVector3Index( L, 3 );
- float zoom = lua_tointeger( L, 4 );
+ float zoom = luaL_checknumber( L, 4 );
- UpdateCameraPro( state->camera3Ds[ cameraId ], movement, rotation, zoom );
- lua_pushboolean( L, true );
+ UpdateCameraPro( camera, movement, rotation, zoom );
- return 1;
+ return 0;
}
/*
@@ -3411,19 +2857,13 @@ int lcoreUpdateCamera3DPro( lua_State *L ) {
Get a ray trace from mouse position
-- Failure return false
- Success return Ray
*/
int lcoreGetMouseRay( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !isValidCamera3D( L, 2, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMouseRay( Vector2 mousePosition, Camera3D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector2 mousePosition = uluaGetVector2Index( L, 1 );
- Camera3D camera = uluaGetCamera3D( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 2, "Camera3D" );
- uluaPushRay( L, GetMouseRay( mousePosition, camera ) );
+ uluaPushRay( L, GetMouseRay( mousePosition, *camera ) );
return 1;
}
@@ -3431,20 +2871,14 @@ int lcoreGetMouseRay( lua_State *L ) {
/*
> matrix = RL.GetCameraMatrix( Camera3D camera )
-Get camera transform matrix ( view matrix )
+Get camera transform matrix (view matrix)
-- Failure return false
- Success return Matrix
*/
int lcoreGetCameraMatrix( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCameraMatrix( Camera3D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
- uluaPushMatrix( L, GetCameraMatrix( camera ) );
+ uluaPushMatrix( L, GetCameraMatrix( *camera ) );
return 1;
}
@@ -3454,17 +2888,12 @@ int lcoreGetCameraMatrix( lua_State *L ) {
Get camera 2d transform matrix
-- Failure return false
- Success return Matrix
*/
int lcoreGetCameraMatrix2D( lua_State *L ) {
- if ( !isValidCamera2D( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCameraMatrix2D( Camera2D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera2D camera = uluaGetCamera2D( L, 1 );
- uluaPushMatrix( L, GetCameraMatrix2D( camera ) );
+ Camera2D *camera = luaL_checkudata( L, 1, "Camera2D" );
+
+ uluaPushMatrix( L, GetCameraMatrix2D( *camera ) );
return 1;
}
@@ -3474,19 +2903,13 @@ int lcoreGetCameraMatrix2D( lua_State *L ) {
Get the screen space position for a 3d world space position
-- Failure return false
- Success return Vector2
*/
int lcoreGetWorldToScreen( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !isValidCamera3D( L, 2, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetWorldToScreen( Vector3 position, Camera3D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 position = uluaGetVector3Index( L, 1 );
- Camera3D camera = uluaGetCamera3D( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 2, "Camera3D" );
- uluaPushVector2( L, GetWorldToScreen( position, camera ) );
+ uluaPushVector2( L, GetWorldToScreen( position, *camera ) );
return 1;
}
@@ -3496,20 +2919,14 @@ int lcoreGetWorldToScreen( lua_State *L ) {
Get size position for a 3d world space position
-- Failure return false
- Success return Vector2
*/
int lcoreGetWorldToScreenEx( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !isValidCamera3D( L, 2, true ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 position = uluaGetVector3Index( L, 1 );
- Camera3D camera = uluaGetCamera3D( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 2, "Camera3D" );
Vector2 size = uluaGetVector2Index( L, 3 );
- uluaPushVector2( L, GetWorldToScreenEx( position, camera, size.x, size.y ) );
+ uluaPushVector2( L, GetWorldToScreenEx( position, *camera, size.x, size.y ) );
return 1;
}
@@ -3519,19 +2936,13 @@ int lcoreGetWorldToScreenEx( lua_State *L ) {
Get the screen space position for a 2d camera world space position
-- Failure return false
- Success return Vector2
*/
int lcoreGetWorldToScreen2D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !isValidCamera2D( L, 2, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetWorldToScreen2D( Vector2 position, Camera2D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector2 position = uluaGetVector2Index( L, 1 );
- Camera2D camera = uluaGetCamera2D( L, 1 );
+ Camera2D *camera = luaL_checkudata( L, 2, "Camera2D" );
- uluaPushVector2( L, GetWorldToScreen2D( position, camera ) );
+ uluaPushVector2( L, GetWorldToScreen2D( position, *camera ) );
return 1;
}
@@ -3541,19 +2952,13 @@ int lcoreGetWorldToScreen2D( lua_State *L ) {
Get the world space position for a 2d camera screen space position
-- Failure return false
- Success return Vector2
*/
int lcoreGetScreenToWorld2D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !isValidCamera2D( L, 2, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetScreenToWorld2D( Vector2 position, Camera2D camera )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector2 position = uluaGetVector2Index( L, 1 );
- Camera2D camera = uluaGetCamera2D( L, 1 );
+ Camera2D *camera = luaL_checkudata( L, 2, "Camera2D" );
- uluaPushVector2( L, GetScreenToWorld2D( position, camera ) );
+ uluaPushVector2( L, GetScreenToWorld2D( position, *camera ) );
return 1;
}
@@ -3563,16 +2968,12 @@ int lcoreGetScreenToWorld2D( lua_State *L ) {
Creates buffer as userdata. Type should be one of the Buffer types
-- Failure return false
- Success return Buffer
*/
int lcoreLoadBuffer( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadBuffer( data{} buffer, int type )" );
- lua_pushboolean( L, false );
- return 1;
- }
- int type = lua_tointeger( L, 2 );
+ luaL_checktype( L, 1, LUA_TTABLE );
+ int type = luaL_checkinteger( L, 2 );
+
Buffer *buffer = lua_newuserdata( L, sizeof( Buffer ) );
int len = uluaGetTableLenIndex( L, 1 );
diff --git a/src/gl.c b/src/gl.c
index 36a0637..513caf9 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -9,40 +9,32 @@
*/
/*
-> success = RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
+> RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
Copy a block of pixels from one framebuffer object to another.
Use -1 RenderTexture for window framebuffer.
-
-- Failure return false
-- Success return true
*/
int lglBlitFramebuffer( lua_State *L ) {
- if ( !isValidRenderTexture( L, 1, true ) || !isValidRenderTexture( L, 2, true ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )" );
- lua_pushboolean( L, false );
- return 1;
- }
- RenderTexture2D srcTex = uluaGetRenderTexture( L, 1 );
- RenderTexture2D dstTex = uluaGetRenderTexture( L, 2 );
+ // TOCO Currently doesn't support setting window render target because of luaL_checkudata.
+ RenderTexture *srcTex = luaL_checkudata( L, 1, "RenderTexture" );
+ RenderTexture *dstTex = luaL_checkudata( L, 2, "RenderTexture" );
Rectangle srcRect = uluaGetRectangleIndex( L, 3 );
Rectangle dstRect = uluaGetRectangleIndex( L, 4 );
- int mask = lua_tointeger( L, 5 );
- int filter = lua_tointeger( L, 6 );
+ int mask = luaL_checkinteger( L, 5 );
+ int filter = luaL_checkinteger( L, 6 );
if ( lua_tointeger( L, 1 ) == -1 ) {
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
}
else {
- glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex.id );
+ glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex->id );
}
if ( lua_tointeger( L, 2 ) == -1 ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
}
else {
- glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex.id );
+ glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex->id );
}
glBlitFramebuffer(
@@ -55,7 +47,5 @@ int lglBlitFramebuffer( lua_State *L ) {
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
- lua_pushboolean( L, true );
-
return 1;
}
diff --git a/src/lights.c b/src/lights.c
index a7caf2c..1a7e0c7 100644
--- a/src/lights.c
+++ b/src/lights.c
@@ -59,54 +59,35 @@ Create a light and get shader locations
- Success return int
*/
int llightsCreateLight( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CreateLight( int type, Vector3 position, Vector3 target, Color color, Shader shader )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- int type = lua_tointeger( L, 1 );
+ int type = luaL_checkinteger( L, 1 );
Vector3 position = uluaGetVector3Index( L, 2 );
Vector3 target = uluaGetVector3Index( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
- size_t shaderId = lua_tointeger( L, 5 );
+ Shader *shader = luaL_checkudata( L, 5, "Shader" );
int i = newLight();
- *state->lights[i] = CreateLight( type, position, target, color, *state->shaders[ shaderId ] );
+ *state->lights[i] = CreateLight( type, position, target, color, *shader );
lua_pushinteger( L, i );
return 1;
}
/*
-> success = RL.UpdateLightValues( Shader shader, Light light )
+> RL.UpdateLightValues( Shader shader, Light light )
Send light properties to shader
-
-- Failure return false
-- Success return true
*/
int llightsUpdateLightValues( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateLightValues( Shader shader, Light light )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t shaderId = lua_tointeger( L, 1 );
+ Shader *shader = luaL_checkudata( L, 1, "Shader" );
size_t lightId = lua_tointeger( L, 2 );
if ( !validLight( lightId ) ) {
lua_pushboolean( L, false );
return 1;
}
- if ( !validShader( shaderId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UpdateLightValues( *state->shaders[ shaderId ], *state->lights[ lightId ] );
- lua_pushboolean( L, true );
+ UpdateLightValues( *shader, *state->lights[ lightId ] );
- return 1;
+ return 0;
}
/*
diff --git a/src/lua_core.c b/src/lua_core.c
index 5d2bab3..d388c88 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -14,6 +14,116 @@
#include "lgl.h"
#include "reasings.h"
+/* Define types. */
+
+/* Buffer. */
+static int gcBuffer( lua_State *L ) {
+ Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
+ free( buffer->data );
+}
+
+static void defineBuffer() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Buffer" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcBuffer );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* Image */
+static int gcImage( lua_State *L ) {
+ Image *image = luaL_checkudata ( L, 1, "Image" );
+ printf( "gcImage\n" );
+
+ UnloadImage( *image );
+}
+
+static void defineImage() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Image" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcImage );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* Texture */
+static int gcTexture( lua_State *L ) {
+ Texture *texture = luaL_checkudata ( L, 1, "Texture" );
+ printf( "gcTexture\n" );
+
+ 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" );
+}
+
+/* RenderRexture. */
+static int gcRenderTexture( lua_State *L ) {
+ RenderTexture *renderTexture = luaL_checkudata ( L, 1, "RenderTexture" );
+ printf( "gcRenderTexture\n" );
+
+ UnloadRenderTexture( *renderTexture );
+}
+
+static void defineRenderTexture() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "RenderTexture" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcRenderTexture );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* Camera2D. */
+static void defineCamera2D() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Camera2D" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+}
+
+/* Camera3D. */
+static void defineCamera3D() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Camera3D" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+}
+
+/* Shader. */
+static int gcShader( lua_State *L ) {
+ Shader *shader = luaL_checkudata ( L, 1, "Shader" );
+ printf( "gcShader\n" );
+
+ UnloadShader( *shader );
+}
+
+static void defineShader() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Shader" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcShader );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* Assing globals. */
+
static void assignGlobalInt( int value, const char *name ) {
lua_State *L = state->luaState;
lua_pushinteger( L, value );
@@ -371,9 +481,6 @@ static void defineGlobals() {
assignGlobalInt( NPATCH_NINE_PATCH, "NPATCH_NINE_PATCH" );
assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" );
assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" );
- /* TextureTypes */
- assignGlobalInt( TEXTURE_TYPE_TEXTURE, "TEXTURE_TYPE_TEXTURE" );
- assignGlobalInt( TEXTURE_TYPE_RENDER_TEXTURE, "TEXTURE_TYPE_RENDER_TEXTURE" );
/* Colors */
assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" );
assignGlobalColor( GRAY, "GRAY" );
@@ -641,39 +748,6 @@ static void defineGlobals() {
lua_pop( L, -1 );
}
-static int gcBuffer( lua_State *L ) {
- Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
- free( buffer->data );
-}
-
-static void defineBuffer() {
- lua_State *L = state->luaState;
-
- luaL_newmetatable( L, "Buffer" );
- lua_pushvalue( L, -1 );
- lua_setfield( L, -2, "__index" );
- 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'};
@@ -1060,8 +1134,14 @@ bool luaInit( int argn, const char **argc ) {
return false;
}
defineGlobals();
+ /* Define object types. */
defineBuffer();
- // defineTexture();
+ defineImage();
+ defineTexture();
+ defineRenderTexture();
+ defineCamera2D();
+ defineCamera3D();
+ defineShader();
/* Set arguments. */
lua_getglobal( L, "RL" );
@@ -1124,7 +1204,6 @@ bool luaCallMain() {
if ( lua_tostring( state->luaState, -1 ) ) {
TraceLog( LOG_ERROR, "Lua error: %s\n", lua_tostring( state->luaState, -1 ) );
}
-
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
@@ -1235,7 +1314,6 @@ void luaRegister() {
/* Core. */
/* Window. */
-
assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady );
assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen );
assingGlobalFunction( "IsWindowHidden", lcoreIsWindowHidden );
@@ -1307,7 +1385,6 @@ void luaRegister() {
assingGlobalFunction( "SetShaderValueTexture", lcoreSetShaderValueTexture );
assingGlobalFunction( "SetShaderValue", lcoreSetShaderValue );
assingGlobalFunction( "SetShaderValueV", lcoreSetShaderValueV );
- assingGlobalFunction( "UnloadShader", lcoreUnloadShader );
/* File. */
assingGlobalFunction( "GetBasePath", lcoreGetBasePath );
assingGlobalFunction( "FileExists", lcoreFileExists );
@@ -1329,7 +1406,6 @@ void luaRegister() {
assingGlobalFunction( "GetFileModTime", lcoreGetFileModTime );
/* Camera2D. */
assingGlobalFunction( "CreateCamera2D", lcoreCreateCamera2D );
- assingGlobalFunction( "UnloadCamera2D", lcoreUnloadCamera2D );
assingGlobalFunction( "BeginMode2D", lcoreBeginMode2D );
assingGlobalFunction( "EndMode2D", lcoreEndMode2D );
assingGlobalFunction( "SetCamera2DTarget", lcoreSetCamera2DTarget );
@@ -1342,7 +1418,6 @@ void luaRegister() {
assingGlobalFunction( "GetCamera2DZoom", lcoreGetCamera2DZoom );
/* Camera3D. */
assingGlobalFunction( "CreateCamera3D", lcoreCreateCamera3D );
- assingGlobalFunction( "UnloadCamera3D", lcoreUnloadCamera3D );
assingGlobalFunction( "BeginMode3D", lcoreBeginMode3D );
assingGlobalFunction( "EndMode3D", lcoreEndMode3D );
assingGlobalFunction( "SetCamera3DPosition", lcoreSetCamera3DPosition );
@@ -1472,7 +1547,6 @@ void luaRegister() {
assingGlobalFunction( "LoadImage", ltexturesLoadImage );
assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture );
assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen );
- assingGlobalFunction( "UnloadImage", ltexturesUnloadImage );
assingGlobalFunction( "ExportImage", ltexturesExportImage );
assingGlobalFunction( "ExportImageAsCode", ltexturesExportImageAsCode );
/* Image Generation. */
@@ -1535,7 +1609,6 @@ void luaRegister() {
assingGlobalFunction( "LoadTextureFromImage", ltexturesLoadTextureFromImage );
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
- assingGlobalFunction( "UnloadTexture", ltexturesUnloadTexture );
assingGlobalFunction( "IsTextureReady", ltexturesIsTextureReady );
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
@@ -1546,7 +1619,6 @@ void luaRegister() {
assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch );
assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode );
assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode );
- assingGlobalFunction( "GetTextureType", ltexturesGetTextureType );
/* Texture Configuration. */
assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps );
assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter );
@@ -1555,6 +1627,10 @@ void luaRegister() {
assingGlobalFunction( "GetTextureSize", ltexturesGetTextureSize );
assingGlobalFunction( "GetTextureMipmaps", ltexturesGetTextureMipmaps );
assingGlobalFunction( "GetTextureFormat", ltexturesGetTextureFormat );
+ /* RenderTexture Configuration. */
+ assingGlobalFunction( "GetRenderTextureId", ltexturesGetRenderTextureId );
+ assingGlobalFunction( "GetRenderTextureTexture", ltexturesGetRenderTextureTexture );
+ assingGlobalFunction( "GetRenderTextureDepthTexture", ltexturesGetRenderTextureDepthTexture );
/* Color/pixel */
assingGlobalFunction( "Fade", ltexturesFade );
assingGlobalFunction( "ColorToInt", ltexturesColorToInt );
@@ -2063,76 +2139,20 @@ void luaRegister() {
lua_pop( L, -1 );
}
-/* Type validators. */
-
-bool isValidTexture( lua_State *L, int index, bool allowTable ) {
- if ( lua_isnumber( L, index ) ) {
- int id = lua_tointeger( L, index );
-
- if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) {
- return true;
- }
- }
- else if ( allowTable && lua_istable( L, index ) ) {
- return true;
- }
- TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Texture." );
- return false;
-}
-
-bool isValidRenderTexture( lua_State *L, int index, bool allowTable ) {
- if ( lua_isnumber( L, index ) ) {
- int id = lua_tointeger( L, index );
-
- if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL
- && state->textures[ id ]->type == TEXTURE_TYPE_RENDER_TEXTURE ) {
- return true;
- }
- }
- else if ( allowTable && lua_istable( L, index ) ) {
- return true;
- }
- TraceLog( state->logLevelInvalid, "%s", "Error. Invalid RenderTexture." );
- return false;
-}
+/* Lua util functions. */
-bool isValidCamera2D( lua_State *L, int index, bool allowTable ) {
- if ( lua_isnumber( L, index ) ) {
- int id = lua_tointeger( L, index );
+bool uluaGetBoolean( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TBOOLEAN );
- if ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) {
- return true;
- }
- }
- else if ( allowTable && lua_istable( L, index ) ) {
- return true;
- }
- TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera2D." );
- return false;
+ return lua_toboolean( L, index );
}
-bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
- if ( lua_isnumber( L, index ) ) {
- int id = lua_tointeger( L, index );
-
- if ( ( 0 <= id && id < state->camera3DCount && state->camera3Ds[ id ] != NULL ) ) {
- return true;
- }
- }
- else if ( allowTable && lua_istable( L, index ) ) {
- return true;
- }
- TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera3D." );
- return false;
-}
-
-/* Lua util functions. */
-
Color uluaGetColor( lua_State *L ) {
return uluaGetColorIndex( L, lua_gettop( L ) );
}
Color uluaGetColorIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Color color = { 0, 0, 0, 255 };
if ( !lua_istable( L, index ) ) {
@@ -2188,7 +2208,7 @@ Vector2 uluaGetVector2( lua_State *L ) {
}
Vector2 uluaGetVector2Index( lua_State *L, int index ) {
- // luaL_checktype( L, index, LUA_TTABLE );
+ luaL_checktype( L, index, LUA_TTABLE );
Vector2 vector = { 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2232,6 +2252,7 @@ Vector3 uluaGetVector3( lua_State *L ) {
}
Vector3 uluaGetVector3Index( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Vector3 vector = { 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2281,6 +2302,7 @@ Vector4 uluaGetVector4( lua_State *L ) {
}
Vector4 uluaGetVector4Index( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Vector4 vector = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2336,6 +2358,7 @@ Rectangle uluaGetRectangle( lua_State *L ) {
}
Rectangle uluaGetRectangleIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Rectangle rect = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2392,6 +2415,7 @@ Quaternion uluaGetQuaternion( lua_State *L ) {
}
Quaternion uluaGetQuaternionIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Quaternion quaternion = { 0.0f, 0.0f, 0.0f, 0.0f };
if ( !lua_istable( L, index ) ) {
@@ -2447,6 +2471,7 @@ Matrix uluaGetMatrix( lua_State *L ) {
}
Matrix uluaGetMatrixIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Matrix matrix = { 0.0f };
float m[4][4];
@@ -2486,6 +2511,7 @@ BoundingBox uluaGetBoundingBox( lua_State *L ) {
}
BoundingBox uluaGetBoundingBoxIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
BoundingBox box = { .min = { 0.0, 0.0, 0.0 }, .max = { 0.0, 0.0, 0.0 } };
if ( !lua_istable( L, index ) ) {
@@ -2530,6 +2556,7 @@ Ray uluaGetRay( lua_State *L ) {
}
Ray uluaGetRayIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
Ray ray = { .position = { 0.0, 0.0, 0.0 }, .direction = { 0.0, 0.0, 0.0 } };
if ( !lua_istable( L, index ) ) {
@@ -2574,6 +2601,7 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
}
NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
NPatchInfo npatch = { .source = { 0.0, 0.0, 0.0, 0.0 }, .left = 0, .top = 0, .right = 0, .bottom = 0, .layout = NPATCH_NINE_PATCH };
if ( !lua_istable( L, index ) ) {
@@ -2635,216 +2663,6 @@ NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
return npatch;
}
-Texture uluaGetTexture( lua_State *L, int index ) {
- Texture texture = { 0 };
-
- if ( lua_isnumber( L, index ) ) {
- texture = *texturesGetSourceTexture( lua_tointeger( L, index ) );
- }
- else if ( lua_istable( L, index ) ) {
- int t = index, i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- if ( lua_isnumber( L, -2 ) ) {
- switch ( i ) {
- case 0:
- texture.id = lua_tointeger( L, -1 );
- break;
- case 1:
- texture.width = lua_tointeger( L, -1 );
- break;
- case 2:
- texture.height = lua_tointeger( L, -1 );
- break;
- case 3:
- texture.mipmaps = lua_tointeger( L, -1 );
- break;
- case 4:
- texture.format = lua_tointeger( L, -1 );
- break;
- default:
- break;
- }
- }
- else if ( lua_isstring( L, -2 ) ) {
- if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- texture.id = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "width", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- texture.width = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "height", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- texture.height = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "mipmaps", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- texture.mipmaps = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "format", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- texture.format = lua_tointeger( L, -1 );
- }
- }
- i++;
- lua_pop( L, 1 );
- }
- }
-
- return texture;
-}
-
-RenderTexture uluaGetRenderTexture( lua_State *L, int index ) {
- RenderTexture renderTexture = { 0 };
-
- if ( lua_isnumber( L, index ) ) {
- renderTexture = state->textures[ lua_tointeger( L, index ) ]->renderTexture;
- }
- else if ( lua_istable( L, index ) ) {
- int t = index, i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- if ( lua_isnumber( L, -2 ) ) {
- switch ( i ) {
- case 0:
- renderTexture.id = lua_tointeger( L, -1 );
- break;
- case 1:
- renderTexture.texture = uluaGetTexture( L, lua_gettop( L ) );
- break;
- case 2:
- renderTexture.depth = uluaGetTexture( L, lua_gettop( L ) );
- break;
- default:
- break;
- }
- }
- else if ( lua_isstring( L, -2 ) ) {
- if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- renderTexture.id = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- renderTexture.texture = uluaGetTexture( L, lua_gettop( L ) );
- }
- else if ( strcmp( "depth", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- renderTexture.depth = uluaGetTexture( L, lua_gettop( L ) );
- }
- }
- i++;
- lua_pop( L, 1 );
- }
- }
-
- return renderTexture;
-}
-
-Camera2D uluaGetCamera2D( lua_State *L, int index ) {
- Camera2D camera = { 0 };
-
- if ( lua_isnumber( L, index ) ) {
- camera = *state->camera2Ds[ lua_tointeger( L, index ) ];
- }
- else if ( lua_istable( L, index ) ) {
- int t = index, i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- if ( lua_isnumber( L, -2 ) ) {
- switch ( i ) {
- case 0:
- camera.offset = uluaGetVector2Index( L, lua_gettop( L ) );
- break;
- case 1:
- camera.target = uluaGetVector2Index( L, lua_gettop( L ) );
- break;
- case 2:
- camera.rotation = lua_tonumber( L, -1 );
- break;
- case 3:
- camera.zoom = lua_tonumber( L, -1 );
- break;
- default:
- break;
- }
- }
- else if ( lua_isstring( L, -2 ) ) {
- if ( strcmp( "offset", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.offset = uluaGetVector2Index( L, lua_gettop( L ) );
- }
- else if ( strcmp( "target", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.target = uluaGetVector2Index( L, lua_gettop( L ) );
- }
- else if ( strcmp( "rotation", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.rotation = lua_tonumber( L, -1 );
- }
- else if ( strcmp( "zoom", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.zoom = lua_tonumber( L, -1 );
- }
- }
- i++;
- lua_pop( L, 1 );
- }
- }
-
- return camera;
-}
-
-Camera3D uluaGetCamera3D( lua_State *L, int index ) {
- Camera3D camera = { 0 };
-
- if ( lua_isnumber( L, index ) ) {
- camera = *state->camera3Ds[ lua_tointeger( L, index ) ];
- }
- else if ( lua_istable( L, index ) ) {
- int t = index, i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- if ( lua_isnumber( L, -2 ) ) {
- switch ( i ) {
- case 0:
- camera.position = uluaGetVector3Index( L, lua_gettop( L ) );
- break;
- case 1:
- camera.target = uluaGetVector3Index( L, lua_gettop( L ) );
- break;
- case 2:
- camera.up = uluaGetVector3Index( L, lua_gettop( L ) );
- break;
- case 3:
- camera.fovy = lua_tonumber( L, -1 );
- break;
- case 4:
- camera.projection = lua_tointeger( L, -1 );
- break;
- default:
- break;
- }
- }
- else if ( lua_isstring( L, -2 ) ) {
- if ( strcmp( "position", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.position = uluaGetVector3Index( L, lua_gettop( L ) );
- }
- else if ( strcmp( "target", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.target = uluaGetVector3Index( L, lua_gettop( L ) );
- }
- else if ( strcmp( "up", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.up = uluaGetVector3Index( L, lua_gettop( L ) );
- }
- else if ( strcmp( "fovy", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.fovy = lua_tonumber( L, -1 );
- }
- else if ( strcmp( "projection", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- camera.projection = lua_tointeger( L, -1 );
- }
- }
- i++;
- lua_pop( L, 1 );
- }
- }
-
- return camera;
-}
-
/* Push types. */
void uluaPushColor( lua_State *L, Color color ) {
@@ -3017,18 +2835,40 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_rawseti( L, -2, 2 );
}
+void uluaPushImage( lua_State *L, Image image ) {
+ Image *imageP = lua_newuserdata( L, sizeof( Image ) );
+ *imageP = image;
+ luaL_setmetatable( L, "Image" );
+}
+
void uluaPushTexture( lua_State *L, Texture texture ) {
- lua_createtable( L, 5, 0 );
- lua_pushinteger( L, texture.id );
- lua_setfield( L, -2, "id" );
- lua_pushinteger( L, texture.width );
- lua_setfield( L, -2, "width" );
- lua_pushinteger( L, texture.height );
- lua_setfield( L, -2, "height" );
- lua_pushinteger( L, texture.mipmaps );
- lua_setfield( L, -2, "mipmaps" );
- lua_pushinteger( L, texture.format );
- lua_setfield( L, -2, "format" );
+ Texture *textureP = lua_newuserdata( L, sizeof( Texture ) );
+ *textureP = texture;
+ luaL_setmetatable( L, "Texture" );
+}
+
+void uluaPushRenderTexture( lua_State *L, RenderTexture renderTexture ) {
+ RenderTexture *renderTextureP = lua_newuserdata( L, sizeof( RenderTexture ) );
+ *renderTextureP = renderTexture;
+ luaL_setmetatable( L, "RenderTexture" );
+}
+
+void uluaPushCamera2D( lua_State *L, Camera2D camera ) {
+ Camera2D *cameraP = lua_newuserdata( L, sizeof( Camera2D ) );
+ *cameraP = camera;
+ luaL_setmetatable( L, "Camera2D" );
+}
+
+void uluaPushCamera3D( lua_State *L, Camera3D camera ) {
+ Camera3D *cameraP = lua_newuserdata( L, sizeof( Camera3D ) );
+ *cameraP = camera;
+ luaL_setmetatable( L, "Camera3D" );
+}
+
+void uluaPushShader( lua_State *L, Shader shader ) {
+ Shader *shaderP = lua_newuserdata( L, sizeof( Shader ) );
+ *shaderP = shader;
+ luaL_setmetatable( L, "Shader" );
}
int uluaGetTableLen( lua_State *L ) {
@@ -3036,6 +2876,7 @@ int uluaGetTableLen( lua_State *L ) {
}
int uluaGetTableLenIndex( lua_State *L, int index ) {
+ luaL_checktype( L, index, LUA_TTABLE );
int t = index, i = 0;
lua_pushnil( L );
diff --git a/src/models.c b/src/models.c
index 89ea810..77e900c 100644
--- a/src/models.c
+++ b/src/models.c
@@ -700,21 +700,12 @@ int lmodelsDrawPlane( lua_State *L ) {
}
/*
-> success = RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
+> RL.DrawQuad3DTexture( Texture texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
-
-- Failure return false
-- Success return true
*/
int lmodelDrawQuad3DTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )" );
- lua_pushboolean( L, false );
- return 1;
- }
- /* Texture. */
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
/* Vertices. */
Vector3 vertices[4] = { 0 };
@@ -762,7 +753,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
/* Draw. */
rlCheckRenderBatchLimit( 4 );
- rlSetTexture( texture.id );
+ rlSetTexture( texture->id );
rlBegin( RL_QUADS );
for ( i = 0; i < 4; ++i ) {
@@ -773,9 +764,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
rlEnd();
rlSetTexture( 0 );
- lua_pushboolean( L, true );
-
- return 1;
+ return 0;
}
/*
@@ -1053,19 +1042,9 @@ Generate heightmap mesh from image data
- Success return int
*/
int lmodelsGenMeshHeightmap( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshHeightmap( Image heightmap, Vector3 size )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *heightmap = luaL_checkudata( L, 1, "Image" );
Vector3 size = uluaGetVector3Index( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- Image *heightmap = state->images[ imageId ];
int i = newMesh();
*state->meshes[i] = GenMeshHeightmap( *heightmap, size );
@@ -1661,14 +1640,15 @@ int lmodelsCreateMaterial( lua_State *L ) {
lua_pushnil( L );
while ( lua_next( L, t4 ) != 0 ) {
- if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 && isValidTexture( L, lua_gettop( L ), true ) ) {
- state->materials[i]->maps[map].texture = uluaGetTexture( L, lua_gettop( L ) );
+ if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ Texture *texture = luaL_checkudata( L, lua_gettop( L ), "Texture" );
+ state->materials[i]->maps[map].texture = *texture;
}
- else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 && lua_istable( L, -1 ) ) {
- state->materials[i]->maps[map].color = uluaGetColor( L );
+ else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ state->materials[i]->maps[map].color = uluaGetColorIndex( L, lua_gettop( L ) );
}
- else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
- state->materials[i]->maps[map].value = lua_tonumber( L, -1 );
+ else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ state->materials[i]->maps[map].value = luaL_checkinteger( L, -1 );
}
lua_pop( L, 1 );
}
@@ -1697,7 +1677,8 @@ int lmodelsCreateMaterial( lua_State *L ) {
}
}
else if ( strcmp( "shader", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
- state->materials[i]->shader = *state->shaders[ lua_tointeger( L, -1 ) ];
+ Shader *shader = luaL_checkudata( L, lua_gettop( L ), "Shader" );
+ state->materials[i]->shader = *shader;
}
lua_pop( L, 1 );
}
@@ -1735,27 +1716,18 @@ int lmodelsUnloadMaterial( lua_State *L ) {
}
/*
-> success = RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
+> RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
-
-- Failure return false
-- Success return true
*/
int lmodelsSetMaterialTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
size_t materialId = lua_tointeger( L, 1 );
int mapType = lua_tointeger( L, 2 );
- Texture texture = uluaGetTexture( L, 3 );
+ Texture *texture = luaL_checkudata( L, 3, "Texture" );
- SetMaterialTexture( state->materials[ materialId ], mapType, texture );
- lua_pushboolean( L, true );
+ SetMaterialTexture( state->materials[ materialId ], mapType, *texture );
- return 1;
+ return 0;
}
/*
@@ -1815,30 +1787,17 @@ int lmodelsSetMaterialValue( lua_State *L ) {
}
/*
-> success = RL.SetMaterialShader( Material material, Shader shader )
+> RL.SetMaterialShader( Material material, Shader shader )
Set shader for material
-
-- Failure return false
-- Success return true
*/
int lmodelsSetMaterialShader( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialShader( Material material, Shader shader )" );
- lua_pushboolean( L, false );
- return 1;
- }
size_t materialId = lua_tointeger( L, 1 );
- size_t shaderId = lua_tointeger( L, 2 );
+ Shader *shader = luaL_checkudata( L, 2, "Shader" );
- if ( !validMaterial( materialId || !validShader( shaderId ) ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- state->materials[ materialId ]->shader = *state->shaders[ shaderId ];
- lua_pushboolean( L, true );
+ state->materials[ materialId ]->shader = *shader;
- return 1;
+ return 0;
}
/*
@@ -1892,32 +1851,32 @@ Get texture from material map type. Returns -1 if no texture.
- Success return int
*/
int lmodelsGetMaterialTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
- int mapType = lua_tointeger( L, 2 );
-
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- /* Check what ReiLua texture has same openGL texture and return that. */
- for ( int i = 0; i < state->textureCount; i++ ) {
- if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
- && state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
- lua_pushinteger( L, i );
- return 1;
- }
- else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
- && state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
- lua_pushinteger( L, i );
- return 1;
- }
- }
- lua_pushinteger( L, -1 );
+ // if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ // TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
+ // lua_pushboolean( L, false );
+ // return 1;
+ // }
+ // size_t materialId = lua_tointeger( L, 1 );
+ // int mapType = lua_tointeger( L, 2 );
+
+ // if ( !validMaterial( materialId ) ) {
+ // lua_pushboolean( L, false );
+ // return 1;
+ // }
+ // /* Check what ReiLua texture has same openGL texture and return that. */
+ // for ( int i = 0; i < state->textureCount; i++ ) {
+ // if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
+ // && state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
+ // lua_pushinteger( L, i );
+ // return 1;
+ // }
+ // else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
+ // && state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
+ // lua_pushinteger( L, i );
+ // return 1;
+ // }
+ // }
+ // lua_pushinteger( L, -1 );
return 1;
}
@@ -1980,7 +1939,7 @@ int lmodelsGetMaterialValue( lua_State *L ) {
Get material shader. Returns -1 if no shader.
- Failure return false
-- Success return int
+- Success return Shader
*/
int lmodelsGetMaterialShader( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
@@ -1994,14 +1953,17 @@ int lmodelsGetMaterialShader( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
+
+ uluaPushShader( L, state->materials[ materialId ]->shader );
+
/* Look for shader that has same shader program id. */
- for ( int i = 0; i < state->shaderCount; i++ ) {
- if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
- lua_pushinteger( L, i );
- return 1;
- }
- }
- lua_pushinteger( L, -1 );
+ // for ( int i = 0; i < state->shaderCount; i++ ) {
+ // if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
+ // lua_pushinteger( L, i );
+ // return 1;
+ // }
+ // }
+ // lua_pushinteger( L, -1 );
return 1;
}
@@ -2263,92 +2225,59 @@ int lmodelsSetModelMeshMaterial( lua_State *L ) {
}
/*
-> success = RL.DrawBillboard( Camera3D camera, Texture2D texture, Vector3 position, float size, Color tint )
+> RL.DrawBillboard( Camera3D camera, Texture texture, Vector3 position, float size, Color tint )
Draw a billboard texture
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawBillboard( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboard( Camera camera, Texture2D texture, Vector3 position, float size, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
- Texture texture = uluaGetTexture( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ Texture *texture = luaL_checkudata( L, 2, "Texture" );
Vector3 position = uluaGetVector3Index( L, 3 );
- float size = lua_tonumber( L, 4 );
+ float size = luaL_checknumber( L, 4 );
Color tint = uluaGetColorIndex( L, 5 );
- DrawBillboard( camera, texture, position, size, tint );
- lua_pushboolean( L, true );
+ DrawBillboard( *camera, *texture, position, size, tint );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawBillboardRec( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
+> RL.DrawBillboardRec( Camera3D camera, Texture texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
Draw a billboard texture defined by source
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawBillboardRec( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboardRec( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
- Texture texture = uluaGetTexture( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ Texture *texture = luaL_checkudata( L, 2, "Texture" );
Rectangle source = uluaGetRectangleIndex( L, 3 );
Vector3 position = uluaGetVector3Index( L, 4 );
Vector2 size = uluaGetVector2Index( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- // DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint );
- DrawBillboardRecNoRatio( camera, texture, source, position, size, tint );
- lua_pushboolean( L, true );
+ DrawBillboardRecNoRatio( *camera, *texture, source, position, size, tint );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawBillboardPro( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
+> RL.DrawBillboardPro( Camera3D camera, Texture texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
Draw a billboard texture defined by source and rotation
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawBillboardPro( lua_State *L ) {
- if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 )
- || !lua_istable( L, 7 ) || !lua_isnumber( L, 8 ) || !lua_istable( L, 9 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Camera3D camera = uluaGetCamera3D( L, 1 );
- Texture texture = uluaGetTexture( L, 2 );
+ Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
+ Texture *texture = luaL_checkudata( L, 2, "Texture" );
Rectangle source = uluaGetRectangleIndex( L, 3 );
Vector3 position = uluaGetVector3Index( L, 4 );
Vector3 up = uluaGetVector3Index( L, 5 );
Vector2 size = uluaGetVector2Index( L, 6 );
Vector2 origin = uluaGetVector2Index( L, 7 );
- float rotation = lua_tonumber( L, 8 );
+ float rotation = luaL_checknumber( L, 8 );
Color tint = uluaGetColorIndex( L, 9 );
- // DrawBillboardPro( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint );
- DrawBillboardProNoRatio( camera, texture, source, position, up, size, origin, rotation, tint );
- lua_pushboolean( L, true );
+ DrawBillboardProNoRatio( *camera, *texture, source, position, up, size, origin, rotation, tint );
- return 1;
+ return 0;
}
/*
diff --git a/src/shapes.c b/src/shapes.c
index b384271..876520a 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -9,28 +9,19 @@
*/
/*
-> success = RL.SetShapesTexture( Texture2D texture, Rectangle source )
+> RL.SetShapesTexture( Texture texture, Rectangle source )
Set texture and rectangle to be used on shapes drawing
NOTE: It can be useful when using basic shapes and one single font,
defining a font char white rectangle would allow drawing everything in a single draw call
-
-- Failure return false
-- Success return true
*/
int lshapesSetShapesTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShapesTexture( Texture2D texture, Rectangle source )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
Rectangle source = uluaGetRectangleIndex( L, 2 );
- SetShapesTexture( texture, source );
- lua_pushboolean( L, true );
+ SetShapesTexture( *texture, source );
- return 1;
+ return 0;
}
/*
diff --git a/src/state.c b/src/state.c
index b2b8aa0..da065a5 100644
--- a/src/state.c
+++ b/src/state.c
@@ -18,14 +18,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->luaState = NULL;
state->guiFont = 0;
state->logLevelInvalid = LOG_ERROR;
- /* Images. */
- state->imageAlloc = ALLOC_PAGE_SIZE;
- state->imageCount = 0;
- state->images = malloc( state->imageAlloc * sizeof( Image* ) );
- /* Textures. */
- state->textureAlloc = ALLOC_PAGE_SIZE;
- state->textureCount = 0;
- state->textures = malloc( state->textureAlloc * sizeof( ReiTexture* ) );
/* Fonts. */
state->fontAlloc = ALLOC_PAGE_SIZE;
state->fontCount = 1;
@@ -42,14 +34,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->musicAlloc = ALLOC_PAGE_SIZE;
state->musicCount = 0;
state->musics = malloc( state->musicAlloc * sizeof( Music* ) );
- /* Camera2D's. */
- state->camera2DAlloc = ALLOC_PAGE_SIZE;
- state->camera2DCount = 0;
- state->camera2Ds = malloc( state->camera2DAlloc * sizeof( Camera2D* ) );
- /* Camera3D's. */
- state->camera3DAlloc = ALLOC_PAGE_SIZE;
- state->camera3DCount = 0;
- state->camera3Ds = malloc( state->camera3DAlloc * sizeof( Camera3D* ) );
/* Meshes. */
state->meshAlloc = ALLOC_PAGE_SIZE;
state->meshCount = 0;
@@ -66,26 +50,17 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->animationAlloc = ALLOC_PAGE_SIZE;
state->animationCount = 0;
state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) );
- /* Shaders. */
- state->shaderAlloc = ALLOC_PAGE_SIZE;
- state->shaderCount = 0;
- state->shaders = malloc( state->shaderAlloc * sizeof( Shader* ) );
/* Lights. */
state->lightAlloc = ALLOC_PAGE_SIZE;
state->lightCount = 0;
state->lights = malloc( state->lightAlloc * sizeof( Light* ) );
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
- state->images[i] = NULL;
- state->textures[i] = NULL;
state->waves[i] = NULL;
state->sounds[i] = NULL;
- state->camera2Ds[i] = NULL;
- state->camera3Ds[i] = NULL;
state->meshes[i] = NULL;
state->models[i] = NULL;
state->animations[i] = NULL;
- state->shaders[i] = NULL;
state->lights[i] = NULL;
/* The ones we want to save the first. */
@@ -119,18 +94,6 @@ void stateInitInterpret( int argn, const char **argc ) {
}
void stateFree() {
- for ( int i = 0; i < state->imageCount; ++i ) {
- if ( state->images[i] != NULL ) {
- UnloadImage( *state->images[i] );
- free( state->images[i] );
- }
- }
- for ( int i = 0; i < state->textureCount; ++i ) {
- if ( state->textures[i] != NULL ) {
- texturesFreeTexture(i);
- free( state->textures[i] );
- }
- }
for ( int i = 0; i < state->fontCount; ++i ) {
if ( state->fonts[i] != NULL ) {
UnloadFont( *state->fonts[i] );
@@ -155,16 +118,6 @@ void stateFree() {
free( state->musics[i] );
}
}
- for ( int i = 0; i < state->camera2DCount; ++i ) {
- if ( state->camera2Ds[i] != NULL ) {
- free( state->camera2Ds[i] );
- }
- }
- for ( int i = 0; i < state->camera3DCount; ++i ) {
- if ( state->camera3Ds[i] != NULL ) {
- free( state->camera3Ds[i] );
- }
- }
for ( int i = 0; i < state->modelCount; ++i ) {
if ( state->models[i] != NULL ) {
//TODO Test if UnloadModel causes segfaults on exit.
@@ -194,12 +147,6 @@ void stateFree() {
free( state->animations[i] );
}
}
- for ( int i = 0; i < state->shaderCount; ++i ) {
- if ( state->shaders[i] != NULL ) {
- UnloadShader( *state->shaders[i] );
- free( state->shaders[i] );
- }
- }
#if !defined( PLATFORM_RPI ) || !defined( PLATFORM_DRM )
for ( int i = 0; i < state->lightCount; ++i ) {
@@ -218,19 +165,14 @@ void stateFree() {
if ( state->hasWindow ) {
CloseWindow();
}
- free( state->images );
- free( state->textures );
free( state->fonts );
free( state->waves );
free( state->sounds );
free( state->musics );
- free( state->camera2Ds );
- free( state->camera3Ds );
free( state->meshes );
free( state->materials );
free( state->models );
free( state->animations );
- free( state->shaders );
free( state->lights );
free( state->exePath );
free( state );
diff --git a/src/text.c b/src/text.c
index 0339aa6..1d6b464 100644
--- a/src/text.c
+++ b/src/text.c
@@ -114,22 +114,12 @@ Load font from Image ( XNA style )
- Success return int
*/
int ltextLoadFontFromImage( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFontFromImage( Image image, Color key, int firstChar )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color key = uluaGetColorIndex( L, 2 );
int firstChar = lua_tointeger( L, 3 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
int i = newFont();
- *state->fonts[i] = LoadFontFromImage( *state->images[ imageId ], key, firstChar );
+ *state->fonts[i] = LoadFontFromImage( *image, key, firstChar );
lua_pushinteger( L, i );
return 1;
diff --git a/src/textures.c b/src/textures.c
index b5677ee..28cb1cb 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -4,105 +4,6 @@
#include "text.h"
#include "lua_core.h"
-static void checkImageRealloc( int i ) {
- if ( i == state->imageCount ) {
- state->imageCount++;
- }
-
- if ( state->imageCount == state->imageAlloc ) {
- state->imageAlloc += ALLOC_PAGE_SIZE;
- state->images = realloc( state->images, state->imageAlloc * sizeof( Image* ) );
-
- for ( i = state->imageCount; i < state->imageAlloc; i++ ) {
- state->images[i] = NULL;
- }
- }
-}
-
-static void checkTextureRealloc( int i ) {
- if ( i == state->textureCount ) {
- state->textureCount++;
- }
-
- if ( state->textureCount == state->textureAlloc ) {
- state->textureAlloc += ALLOC_PAGE_SIZE;
- state->textures = realloc( state->textures, state->textureAlloc * sizeof( ReiTexture* ) );
-
- for ( i = state->textureCount; i < state->textureAlloc; i++ ) {
- state->textures[i] = NULL;
- }
- }
-}
-
-bool validImage( size_t id ) {
- if ( id < 0 || state->imageCount < id || state->images[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid image", id );
- return false;
- }
- else {
- return true;
- }
-}
-
-static int newImage() {
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
- checkImageRealloc( i );
-
- return i;
-}
-
-static int newTexture( int type ) {
- int i = 0;
-
- for ( i = 0; i < state->textureCount; i++ ) {
- if ( state->textures[i] == NULL ) {
- break;
- }
- }
- state->textures[i] = malloc( sizeof( ReiTexture ) );
- state->textures[i]->type = type;
-
- checkTextureRealloc( i );
-
- return i;
-}
-
-Texture2D* texturesGetSourceTexture( size_t id ) {
- if ( state->textures[id] != NULL ) {
- switch ( state->textures[id]->type ) {
- case TEXTURE_TYPE_TEXTURE:
- return &state->textures[id]->texture;
- break;
- case TEXTURE_TYPE_RENDER_TEXTURE:
- return &state->textures[id]->renderTexture.texture;
- break;
- }
- }
-
- return &state->textures[id]->texture;
-}
-
-void texturesFreeTexture( size_t id ) {
- if ( state->textures[id] != NULL ) {
- switch ( state->textures[id]->type ) {
- case TEXTURE_TYPE_TEXTURE:
- UnloadTexture( state->textures[id]->texture );
- break;
- case TEXTURE_TYPE_RENDER_TEXTURE:
- UnloadRenderTexture( state->textures[id]->renderTexture );
- break;
- }
- state->textures[id] = NULL;
- }
-}
-
/*
## Textures - Image Loading
*/
@@ -110,28 +11,20 @@ void texturesFreeTexture( size_t id ) {
/*
> image = RL.LoadImage( string fileName )
-Load image from file into CPU memory ( RAM )
+Load image from file into CPU memory (RAM)
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesLoadImage( lua_State *L ) {
- if ( !lua_isstring( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadImage( string fileName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
+ if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
+ uluaPushImage( L, LoadImage( luaL_checkstring( L, 1 ) ) );
- if ( FileExists( lua_tostring( L, 1 ) ) ) {
- int i = newImage();
- *state->images[i] = LoadImage( lua_tostring( L, 1 ) );
- lua_pushinteger( L, i );
- return 1;
- }
- else {
- lua_pushinteger( L, -1 );
return 1;
}
+ TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
+ lua_pushnil( L );
+
+ return 1;
}
/*
@@ -139,20 +32,11 @@ int ltexturesLoadImage( lua_State *L ) {
Load image from GPU texture data
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesLoadImageFromTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadImageFromTexture( Texture2D texture )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
-
- int i = newImage();
- *state->images[i] = LoadImageFromTexture( texture );
- lua_pushinteger( L, i );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+ uluaPushImage( L, LoadImageFromTexture( *texture ) );
return 1;
}
@@ -160,41 +44,12 @@ int ltexturesLoadImageFromTexture( lua_State *L ) {
/*
> image = RL.LoadImageFromScreen()
-Load image from screen buffer and ( screenshot )
+Load image from screen buffer and (screenshot)
-- Success return int
+- Success return Image
*/
int ltexturesLoadImageFromScreen( lua_State *L ) {
- int i = newImage();
- *state->images[i] = LoadImageFromScreen();
- lua_pushinteger( L, i );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadImage( Image image )
-
-Unload image from CPU memory ( RAM )
-
-- Failure return false
-- Success return true
-*/
-int ltexturesUnloadImage( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadImage( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validImage( id ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadImage( *state->images[ id ] );
- state->images[ id ] = NULL;
- lua_pushboolean( L, true );
+ uluaPushImage( L, LoadImageFromScreen() );
return 1;
}
@@ -204,22 +59,11 @@ int ltexturesUnloadImage( lua_State *L ) {
Export image data to file, returns true on success
-- Failure return nil
- Success return bool
*/
int ltexturesExportImage( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ExportImage( Image image, string fileName )" );
- lua_pushnil( L );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validImage( id ) ) {
- lua_pushnil( L );
- return 1;
- }
- lua_pushboolean( L, ExportImage( *state->images[ id ], lua_tostring( L, 2 ) ) );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ lua_pushboolean( L, ExportImage( *image, luaL_checkstring( L, 2 ) ) );
return 1;
}
@@ -229,22 +73,11 @@ int ltexturesExportImage( lua_State *L ) {
Export image as code file defining an array of bytes, returns true on success
-- Failure return nil
- Success return bool
*/
int ltexturesExportImageAsCode( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ExportImageAsCode( Image image, string fileName )" );
- lua_pushnil( L );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validImage( id ) ) {
- lua_pushnil( L );
- return 1;
- }
- lua_pushboolean( L, ExportImageAsCode( *state->images[ id ], lua_tostring( L, 2 ) ) );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ lua_pushboolean( L, ExportImageAsCode( *image, luaL_checkstring( L, 2 ) ) );
return 1;
}
@@ -254,26 +87,17 @@ int ltexturesExportImageAsCode( lua_State *L ) {
*/
/*
-> image = RL.GenImageColor( int width, int height, Color color )
+> image = RL.GenImageColor( Vector2 size, Color color )
Generate image: plain color
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageColor( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageColor( int width, int height, Color color )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- int width = lua_tointeger( L, 1 );
- int height = lua_tointeger( L, 2 );
- Color color = uluaGetColorIndex( L, 3 );
+ Vector2 size = uluaGetVector2Index( L, 1 );
+ Color color = uluaGetColorIndex( L, 1 );
- int i = newImage();
- *state->images[i] = GenImageColor( width, height, color );
- lua_pushinteger( L, i );
+ uluaPushImage( L, GenImageColor( size.x, size.y, color ) );
return 1;
}
@@ -283,22 +107,14 @@ int ltexturesGenImageColor( lua_State *L ) {
Generate image: vertical gradient
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageGradientV( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageGradientV( Vector2 size, Color top, Color bottom )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
Color top = uluaGetColorIndex( L, 2 );
Color bottom = uluaGetColorIndex( L, 3 );
-
- int i = newImage();
- *state->images[i] = GenImageGradientV( (int)size.x, (int)size.y, top, bottom );
- lua_pushinteger( L, i );
+
+ uluaPushImage( L, GenImageGradientV( (int)size.x, (int)size.y, top, bottom ) );
return 1;
}
@@ -308,22 +124,14 @@ int ltexturesGenImageGradientV( lua_State *L ) {
Generate image: horizontal gradient
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageGradientH( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageGradientH( Vector2 size, Color left, Color right )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
Color left = uluaGetColorIndex( L, 2 );
Color right = uluaGetColorIndex( L, 3 );
-
- int i = newImage();
- *state->images[i] = GenImageGradientH( (int)size.x, (int)size.y, left, right );
- lua_pushinteger( L, i );
+
+ uluaPushImage( L, GenImageGradientH( (int)size.x, (int)size.y, left, right ) );
return 1;
}
@@ -333,23 +141,15 @@ int ltexturesGenImageGradientH( lua_State *L ) {
Generate image: radial gradient
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageGradientRadial( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageGradientRadial( Vector2 size, float density, Color inner, Color outer )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
- float density = lua_tonumber( L, 2 );
+ float density = luaL_checknumber( L, 2 );
Color inner = uluaGetColorIndex( L, 3 );
Color outer = uluaGetColorIndex( L, 4 );
-
- int i = newImage();
- *state->images[i] = GenImageGradientRadial( (int)size.x, (int)size.y, density, inner, outer );
- lua_pushinteger( L, i );
+
+ uluaPushImage( L, GenImageGradientRadial( (int)size.x, (int)size.y, density, inner, outer ) );
return 1;
}
@@ -359,23 +159,15 @@ int ltexturesGenImageGradientRadial( lua_State *L ) {
Generate image: checked
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageChecked( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageChecked( Vector2 size, Vector2 checks, Color col1, Color col2 )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
Vector2 checks = uluaGetVector2Index( L, 2 );
Color col1 = uluaGetColorIndex( L, 3 );
Color col2 = uluaGetColorIndex( L, 4 );
-
- int i = newImage();
- *state->images[i] = GenImageChecked( (int)size.x, (int)size.y, (int)checks.x, (int)checks.y, col1, col2 );
- lua_pushinteger( L, i );
+
+ uluaPushImage( L, GenImageChecked( (int)size.x, (int)size.y, (int)checks.x, (int)checks.y, col1, col2 ) );
return 1;
}
@@ -385,21 +177,13 @@ int ltexturesGenImageChecked( lua_State *L ) {
Generate image: white noise
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageWhiteNoise( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageWhiteNoise( Vector2 size, float factor )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
- float factor = lua_tonumber( L, 2 );
-
- int i = newImage();
- *state->images[i] = GenImageWhiteNoise( (int)size.x, (int)size.y, factor );
- lua_pushinteger( L, i );
+ float factor = luaL_checknumber( L, 2 );
+
+ uluaPushImage( L, GenImageWhiteNoise( (int)size.x, (int)size.y, factor ) );
return 1;
}
@@ -409,21 +193,14 @@ int ltexturesGenImageWhiteNoise( lua_State *L ) {
Generate image: perlin noise
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImagePerlinNoise( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImagePerlinNoise( Vector2 size, Vector2 offset, float factor )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
Vector2 offset = uluaGetVector2Index( L, 2 );
-
- int i = newImage();
- *state->images[i] = GenImagePerlinNoise( (int)size.x, (int)size.y, (int)offset.x, (int)offset.y, lua_tonumber( L, 3 ) );
- lua_pushinteger( L, i );
+ float factor = luaL_checknumber( L, 3 );
+
+ uluaPushImage( L, GenImagePerlinNoise( (int)size.x, (int)size.y, (int)offset.x, (int)offset.y, factor ) );
return 1;
}
@@ -433,21 +210,13 @@ int ltexturesGenImagePerlinNoise( lua_State *L ) {
Generate image: cellular algorithm. Bigger tileSize means bigger cells
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageCellular( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageCellular( Vector2 size, int tileSize )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
- int tileSize = lua_tointeger( L, 2 );
-
- int i = newImage();
- *state->images[i] = GenImageCellular( (int)size.x, (int)size.y, tileSize );
- lua_pushinteger( L, i );
+ int tileSize = luaL_checkinteger( L, 2 );
+
+ uluaPushImage( L, GenImageCellular( (int)size.x, (int)size.y, tileSize ) );
return 1;
}
@@ -457,20 +226,12 @@ int ltexturesGenImageCellular( lua_State *L ) {
Generate image: grayscale image from text data
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesGenImageText( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenImageText( Vector2 size, string text )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
- int i = newImage();
- *state->images[i] = GenImageText( (int)size.x, (int)size.y, lua_tostring( L, 2 ) );
- lua_pushinteger( L, i );
+ uluaPushImage( L, GenImageText( (int)size.x, (int)size.y, luaL_checkstring( L, 2 ) ) );
return 1;
}
@@ -482,26 +243,14 @@ int ltexturesGenImageText( lua_State *L ) {
/*
> image = RL.ImageCopy( Image image )
-Create an image duplicate ( useful for transformations )
+Create an image duplicate (useful for transformations)
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesImageCopy( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageCopy( Image image )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushinteger( L, -1 );
- return 1;
- }
- int i = newImage();
- *state->images[i] = ImageCopy( *state->images[ imageId ] );
- lua_pushinteger( L, i );
+ uluaPushImage( L, ImageCopy( *image ) );
return 1;
}
@@ -511,25 +260,13 @@ int ltexturesImageCopy( lua_State *L ) {
Create an image from another image piece
-- Failure return -1
-- Success return int
+- Success return Image
*/
int ltexturesImageFromImage( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageFromImage( Image image, Rectangle rec )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Rectangle rec = uluaGetRectangleIndex( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushinteger( L, -1 );
- return 1;
- }
- int i = newImage();
- *state->images[i] = ImageFromImage( *state->images[ imageId ], rec );
- lua_pushinteger( L, i );
+ uluaPushImage( L, ImageFromImage( *image, rec ) );
return 1;
}
@@ -537,674 +274,364 @@ int ltexturesImageFromImage( lua_State *L ) {
/*
> image = RL.ImageText( Font font, string text, float fontSize, float spacing, Color tint )
-Create an image from text ( custom sprite font )
+Create an image from text (custom sprite font)
- Failure return -1
- Success return int
*/
int ltexturesImageText( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageText( Font font, string text, float fontSize, float spacing, Color tint )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
- float fontSize = lua_tonumber( L, 3 );
- float spacing = lua_tonumber( L, 4 );
- Color tint = uluaGetColorIndex( L, 5 );
+ // if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 )
+ // || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
+ // TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageText( Font font, string text, float fontSize, float spacing, Color tint )" );
+ // lua_pushinteger( L, -1 );
+ // return 1;
+ // }
+ // size_t fontId = lua_tointeger( L, 1 );
+ // float fontSize = lua_tonumber( L, 3 );
+ // float spacing = lua_tonumber( L, 4 );
+ // Color tint = uluaGetColorIndex( L, 5 );
- if ( !validFont( fontId ) ) {
- lua_pushinteger( L, -1 );
- return 1;
- }
- int i = newImage();
- *state->images[i] = ImageTextEx( *state->fonts[ fontId ], lua_tostring( L, 2 ), fontSize, spacing, tint );
- lua_pushinteger( L, i );
+ // if ( !validFont( fontId ) ) {
+ // lua_pushinteger( L, -1 );
+ // return 1;
+ // }
+ // int i = newImage();
+ // *state->images[i] = ImageTextEx( *state->fonts[ fontId ], lua_tostring( L, 2 ), fontSize, spacing, tint );
+ // lua_pushinteger( L, i );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageFormat( Image image, int newFormat )
+> RL.ImageFormat( Image image, int newFormat )
Convert image data to desired format
-
-- Failure return false
-- Success return true
*/
int ltexturesImageFormat( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageFormat( Image image, int newFormat )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- int newFormat = lua_tointeger( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ int newFormat = luaL_checkinteger( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageFormat( state->images[ imageId ], newFormat );
- lua_pushboolean( L, true );
+ ImageFormat( image, newFormat );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageToPOT( Image image, Color fill )
+> RL.ImageToPOT( Image image, Color fill )
-Convert image to POT ( power-of-two )
-
-- Failure return false
-- Success return true
+Convert image to POT (power-of-two)
*/
int ltexturesImageToPOT( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageToPOT( Image image, Color fill )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color fill = uluaGetColorIndex( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageToPOT( state->images[ imageId ], fill );
- lua_pushboolean( L, true );
+ ImageToPOT( image, fill );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageCrop( Image image, Rectangle crop )
+> RL.ImageCrop( Image image, Rectangle crop )
Crop an image to a defined rectangle
-
-- Failure return false
-- Success return true
*/
int ltexturesImageCrop( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageCrop( Image image, Rectangle crop )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Rectangle crop = uluaGetRectangleIndex( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageCrop( state->images[ imageId ], crop );
- lua_pushboolean( L, true );
+ ImageCrop( image, crop );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageAlphaCrop( Image image, float threshold )
+> RL.ImageAlphaCrop( Image image, float threshold )
Crop image depending on alpha value
-
-- Failure return false
-- Success return true
*/
int ltexturesImageAlphaCrop( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageAlphaCrop( Image image, float threshold )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
float threshold = lua_tonumber( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageAlphaCrop( state->images[ imageId ], threshold );
- lua_pushboolean( L, true );
+ ImageAlphaCrop( image, threshold );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageAlphaClear( Image image, Color color, float threshold )
+> RL.ImageAlphaClear( Image image, Color color, float threshold )
Clear alpha channel to desired color
-
-- Failure return false
-- Success return true
*/
int ltexturesImageAlphaClear( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageAlphaClear( Image image, Color color, float threshold )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color color = uluaGetColorIndex( L, 2 );
float threshold = lua_tonumber( L, 3 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageAlphaClear( state->images[ imageId ], color, threshold );
- lua_pushboolean( L, true );
+ ImageAlphaClear( image, color, threshold );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageAlphaMask( Image image, Image alphaMask )
+> RL.ImageAlphaMask( Image image, Image alphaMask )
Apply alpha mask to image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageAlphaMask( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageAlphaMask( Image image, Image alphaMask )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- size_t alphaMaskId = lua_tonumber( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ Image *alphaMask = luaL_checkudata( L, 2, "Image" );
- if ( !validImage( imageId ) || !validImage( alphaMaskId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageAlphaMask( state->images[ imageId ], *state->images[ alphaMaskId ] );
- lua_pushboolean( L, true );
+ ImageAlphaMask( image, *alphaMask );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageAlphaPremultiply( Image image )
+> RL.ImageAlphaPremultiply( Image image )
Premultiply alpha channel
-
-- Failure return false
-- Success return true
*/
int ltexturesImageAlphaPremultiply( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageAlphaPremultiply( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageAlphaPremultiply( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageAlphaPremultiply( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageBlurGaussian( Image image, int blurSize )
+> RL.ImageBlurGaussian( Image image, int blurSize )
Apply Gaussian blur using a box blur approximation
-
-- Failure return false
-- Success return true
*/
int ltexturesImageBlurGaussian( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageBlurGaussian( Image image, int blurSize )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- int blurSize = lua_tointeger( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ int blurSize = luaL_checkinteger( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageBlurGaussian( state->images[ imageId ], blurSize );
- lua_pushboolean( L, true );
+ ImageBlurGaussian( image, blurSize );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageResize( Image image, Vector2 size )
+> RL.ImageResize( Image image, Vector2 size )
-Resize image ( Bicubic scaling algorithm )
-
-- Failure return false
-- Success return true
+Resize image (Bicubic scaling algorithm)
*/
int ltexturesImageResize( lua_State *L ) {
- if ( !lua_isnumber( L, 1) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageResize( Image image, Vector2 size )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 size = uluaGetVector2Index( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageResize( state->images[ imageId ], size.x, size.y );
- lua_pushboolean( L, true );
+ ImageResize( image, (int)size.x, (int)size.y );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageResizeNN( Image image, Vector2 size )
-
-Resize image ( Nearest-Neighbor scaling algorithm )
+> RL.ImageResizeNN( Image image, Vector2 size )
-- Failure return false
-- Success return true
+Resize image (Nearest-Neighbor scaling algorithm)
*/
int ltexturesImageResizeNN( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageResizeNN( Image image, Vector2 size )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 size = uluaGetVector2Index( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageResizeNN( state->images[ imageId ], size.x, size.y );
- lua_pushboolean( L, true );
+ ImageResizeNN( image, (int)size.x, (int)size.y );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageResizeCanvas( Image image, Vector2 size, Vector2 offset, Color fill )
+> RL.ImageResizeCanvas( Image image, Vector2 size, Vector2 offset, Color fill )
Resize canvas and fill with color
-
-- Failure return false
-- Success return true
*/
int ltexturesImageResizeCanvas( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageResizeCanvas( Image image, Vector2 size, Vector2 offset, Color fill )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 size = uluaGetVector2Index( L, 2 );
Vector2 offset = uluaGetVector2Index( L, 3 );
Color fill = uluaGetColorIndex( L, 4 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageResizeCanvas( state->images[ imageId ], size.x, size.y, offset.x, offset.y, fill );
- lua_pushboolean( L, true );
+ ImageResizeCanvas( image, (int)size.x, (int)size.y, (int)offset.x, (int)offset.y, fill );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageMipmaps( Image image )
+> RL.ImageMipmaps( Image image )
Generate all mipmap levels for a provided image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageMipmaps( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageMipmaps( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageMipmaps( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageMipmaps( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDither( Image image, Color bpp )
+> RL.ImageDither( Image image, Color bpp )
-Dither image data to 16bpp or lower ( Floyd-Steinberg dithering )
-
-- Failure return false
-- Success return true
+Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
*/
int ltexturesImageDither( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDither( Image image, Color bpp )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color bpp = uluaGetColorIndex( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDither( state->images[ imageId ], bpp.r, bpp.g, bpp.b, bpp.a );
- lua_pushboolean( L, true );
+ ImageDither( image, bpp.r, bpp.g, bpp.b, bpp.a );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageFlipVertical( Image image )
+> RL.ImageFlipVertical( Image image )
Flip image vertically
-
-- Failure return false
-- Success return true
*/
int ltexturesImageFlipVertical( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageFlipVertical( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageFlipVertical( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageFlipVertical( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageFlipHorizontal( Image image )
+> RL.ImageFlipHorizontal( Image image )
Flip image horizontally
-
-- Failure return false
-- Success return true
*/
int ltexturesImageFlipHorizontal( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageFlipHorizontal( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageFlipHorizontal( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageFlipHorizontal( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageRotateCW( Image image )
+> RL.ImageRotateCW( Image image )
Rotate image clockwise 90deg
-
-- Failure return false
-- Success return true
*/
int ltexturesImageRotateCW( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageRotateCW( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageRotateCW( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageRotateCW( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageRotateCCW( Image image )
+> RL.ImageRotateCCW( Image image )
Rotate image counter-clockwise 90deg
-
-- Failure return false
-- Success return true
*/
int ltexturesImageRotateCCW( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageRotateCCW( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageRotateCCW( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageRotateCCW( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageColorTint( Image image, Color color )
+> RL.ImageColorTint( Image image, Color color )
Modify image color: tint
-
-- Failure return false
-- Success return true
*/
int ltexturesImageColorTint( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageColorTint( Image image, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color color = uluaGetColorIndex( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageColorTint( state->images[ imageId ], color );
- lua_pushboolean( L, true );
+ ImageColorTint( image, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageColorInvert( Image image )
+> RL.ImageColorInvert( Image image )
Modify image color: invert
-
-- Failure return false
-- Success return true
*/
int ltexturesImageColorInvert( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageColorInvert( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageColorInvert( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageColorInvert( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageColorGrayscale( Image image )
+> RL.ImageColorGrayscale( Image image )
Modify image color: grayscale
-
-- Failure return false
-- Success return true
*/
int ltexturesImageColorGrayscale( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageColorGrayscale( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageColorGrayscale( state->images[ imageId ] );
- lua_pushboolean( L, true );
+ ImageColorGrayscale( image );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageColorContrast( Image image, float contrast )
-
-Modify image color: contrast ( -100 to 100 )
+> RL.ImageColorContrast( Image image, float contrast )
-- Failure return false
-- Success return true
+Modify image color: contrast (-100 to 100)
*/
int ltexturesImageColorContrast( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageColorContrast( Image image, float contrast )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- float contrast = lua_tonumber( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ float contrast = luaL_checkinteger( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageColorContrast( state->images[ imageId ], contrast );
- lua_pushboolean( L, true );
+ ImageColorContrast( image, contrast );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageColorBrightness( Image image, int brightness )
-
-Modify image color: brightness ( -255 to 255 )
+> RL.ImageColorBrightness( Image image, int brightness )
-- Failure return false
-- Success return true
+Modify image color: brightness (-255 to 255)
*/
int ltexturesImageColorBrightness( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageColorBrightness( Image image, int brightness )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- int brightness = lua_tointeger( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ int brightness = luaL_checkinteger( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageColorBrightness( state->images[ imageId ], brightness );
- lua_pushboolean( L, true );
+ ImageColorBrightness( image, brightness );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageColorReplace( Image image, Color color, Color replace )
+> RL.ImageColorReplace( Image image, Color color, Color replace )
Modify image color: replace color
-
-- Failure return false
-- Success return true
*/
int ltexturesImageColorReplace( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageColorReplace( Image image, Color color, Color replace )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color color = uluaGetColorIndex( L, 2 );
Color replace = uluaGetColorIndex( L, 3 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageColorReplace( state->images[ imageId ], color, replace );
- lua_pushboolean( L, true );
+ ImageColorReplace( image, color, replace );
- return 1;
+ return 0;
}
/*
> colors = RL.LoadImageColors( Image image )
-Load color data from image as a Color array ( RGBA - 32bit )
+Load color data from image as a Color array (RGBA - 32bit)
-- Failure return false
- Success return Color{}
*/
int ltexturesLoadImageColors( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadImageColors( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
-
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- int colorCount = state->images[ imageId ]->width * state->images[ imageId ]->height;
+ Image *image = luaL_checkudata( L, 1, "Image" );
- Color *colors = LoadImageColors( *state->images[ imageId ] );
+ int colorCount = image->width * image->height;
+ Color *colors = LoadImageColors( *image );
lua_createtable( L, colorCount, 0 );
@@ -1220,27 +647,16 @@ int ltexturesLoadImageColors( lua_State *L ) {
/*
> colors = RL.LoadImagePalette( Image image, int maxPaletteSize )
-Load colors palette from image as a Color array ( RGBA - 32bit )
+Load colors palette from image as a Color array (RGBA - 32bit)
-- Failure return false
- Success return Color{}
*/
int ltexturesLoadImagePalette( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadImagePalette( Image image, int maxPaletteSize )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- int maxPaletteSize = lua_tointeger( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ int maxPaletteSize = luaL_checkinteger( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
int colorCount = 0;
-
- Color *colors = LoadImagePalette( *state->images[ imageId ], maxPaletteSize, &colorCount );
+ Color *colors = LoadImagePalette( *image, maxPaletteSize, &colorCount );
lua_createtable( L, colorCount, 0 );
@@ -1258,23 +674,13 @@ int ltexturesLoadImagePalette( lua_State *L ) {
Get image alpha border rectangle
-- Failure return false
- Success return Rectangle
*/
int ltexturesGetImageAlphaBorder( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetImageAlphaBorder( Image image, float threshold )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- float threshold = lua_tonumber( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ float threshold = luaL_checknumber( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushRectangle( L, GetImageAlphaBorder( *state->images[ imageId ], threshold ) );
+ uluaPushRectangle( L, GetImageAlphaBorder( *image, threshold ) );
return 1;
}
@@ -1282,25 +688,15 @@ int ltexturesGetImageAlphaBorder( lua_State *L ) {
/*
> color = RL.GetImageColor( Image image, Vector2 pixelPos )
-Get image pixel color at ( x, y ) position
+Get image pixel color at (x, y) position
-- Failure return false
- Success return Color
*/
int ltexturesGetImageColor( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetImageColor( Image image, Vector2 pixelPos )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 pixelPos = uluaGetVector2Index( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushColor( L, GetImageColor( *state->images[ imageId ], pixelPos.x, pixelPos.y ) );
+ uluaPushColor( L, GetImageColor( *image, pixelPos.x, pixelPos.y ) );
return 1;
}
@@ -1310,233 +706,128 @@ int ltexturesGetImageColor( lua_State *L ) {
*/
/*
-> success = RL.ImageClearBackground( Image dst, Color color )
+> RL.ImageClearBackground( Image dst, Color color )
Clear image background with given color
-
-- Failure return false
-- Success return true
*/
int ltexturesImageClearBackground( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageClearBackground( Image dst, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Color color = uluaGetColorIndex( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageClearBackground( state->images[ imageId ], color );
- lua_pushboolean( L, true );
+ ImageClearBackground( image, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDrawPixel( Image dst, Vector2 position, Color color )
+> RL.ImageDrawPixel( Image dst, Vector2 position, Color color )
Draw pixel within an image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageDrawPixel( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawPixel( Image dst, Vector2 position, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 position = uluaGetVector2Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawPixelV( state->images[ imageId ], position, color );
- lua_pushboolean( L, true );
+ ImageDrawPixelV( image, position, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDrawLine( Image dst, Vector2 a, Vector2 b, Color color )
+> RL.ImageDrawLine( Image dst, Vector2 a, Vector2 b, Color color )
Draw line within an image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageDrawLine( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawLine( Image dst, Vector2 a, Vector2 b, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 start = uluaGetVector2Index( L, 2 );
Vector2 end = uluaGetVector2Index( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawLineV( state->images[ imageId ], start, end, color );
- lua_pushboolean( L, true );
+ ImageDrawLineV( image, start, end, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDrawCircle( Image dst, Vector2 center, int radius, Color color )
+> RL.ImageDrawCircle( Image dst, Vector2 center, int radius, Color color )
Draw circle within an image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageDrawCircle( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawCircle( Image dst, Vector2 center, int radius, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 center = uluaGetVector2Index( L, 2 );
- int radius = lua_tointeger( L, 3 );
+ int radius = luaL_checkinteger( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawCircleV( state->images[ imageId ], center, radius, color );
- lua_pushboolean( L, true );
+ ImageDrawCircleV( image, center, radius, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )
+> RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )
Draw circle outline within an image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageDrawCircleLines( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawCircleLines( Image dst, Vector2 center, int radius, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Vector2 center = uluaGetVector2Index( L, 2 );
- int radius = lua_tointeger( L, 3 );
+ int radius = luaL_checkinteger( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawCircleLinesV( state->images[ imageId ], center, radius, color );
- lua_pushboolean( L, true );
+ ImageDrawCircleLinesV( image, center, radius, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDrawRectangle( Image dst, Rectangle rec, Color color )
+> RL.ImageDrawRectangle( Image dst, Rectangle rec, Color color )
Draw rectangle within an image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageDrawRectangle( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawRectangle( Image dst, Rectangle rec, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Rectangle rec = uluaGetRectangleIndex( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawRectangleRec( state->images[ imageId ], rec, color );
- lua_pushboolean( L, true );
+ ImageDrawRectangleRec( image, rec, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDrawRectangleLines( Image dst, Rectangle rec, int thick, Color color )
+> RL.ImageDrawRectangleLines( Image dst, Rectangle rec, int thick, Color color )
Draw rectangle lines within an image
-
-- Failure return false
-- Success return true
*/
int ltexturesImageDrawRectangleLines( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawRectangleLines( Image dst, Rectangle rec, int thick, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
Rectangle rec = uluaGetRectangleIndex( L, 2 );
- int thick = lua_tointeger( L, 3 );
+ int thick = luaL_checkinteger( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawRectangleLines( state->images[ imageId ], rec, thick, color );
- lua_pushboolean( L, true );
+ ImageDrawRectangleLines( image, rec, thick, color );
- return 1;
+ return 0;
}
/*
-> success = RL.ImageDraw( Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint )
-
-Draw a source image within a destination image ( Tint applied to source )
+> RL.ImageDraw( Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint )
-- Failure return false
-- Success return true
+Draw a source image within a destination image (Tint applied to source)
*/
int ltexturesImageDraw( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDraw( Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageDstId = lua_tointeger( L, 1 );
- size_t imageSrcId = lua_tointeger( L, 2 );
+ Image *imageDstId = luaL_checkudata( L, 1, "Image" );
+ Image *imageSrcId = luaL_checkudata( L, 2, "Image" );
Rectangle srcRec = uluaGetRectangleIndex( L, 3 );
Rectangle dstRec = uluaGetRectangleIndex( L, 4 );
Color tint = uluaGetColorIndex( L, 5 );
- if ( !validImage( imageDstId ) || !validImage( imageSrcId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDraw( state->images[ imageDstId ], *state->images[ imageSrcId ], srcRec, dstRec, tint );
- lua_pushboolean( L, true );
+ ImageDraw( imageDstId, *imageSrcId, srcRec, dstRec, tint );
- return 1;
+ return 0;
}
/*
@@ -1548,25 +839,25 @@ Draw text ( Custom sprite font ) within an image ( Destination )
- Success return true
*/
int ltexturesImageDrawTextEx( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isstring( L, 3 ) || !lua_istable( L, 4 )
- || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_istable( L, 7 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- size_t fontId = lua_tointeger( L, 2 );
- Vector2 position = uluaGetVector2Index( L, 4 );
- float fontSize = lua_tonumber( L, 5 );
- float spacing = lua_tonumber( L, 6 );
- Color tint = uluaGetColorIndex( L, 7 );
-
- if ( !validImage( imageId ) || !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- ImageDrawTextEx( state->images[ imageId ], *state->fonts[ fontId ], lua_tostring( L, 3 ), position, fontSize, spacing, tint );
- lua_pushboolean( L, true );
+ // if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isstring( L, 3 ) || !lua_istable( L, 4 )
+ // || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_istable( L, 7 ) ) {
+ // TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
+ // lua_pushboolean( L, false );
+ // return 1;
+ // }
+ // size_t imageId = lua_tointeger( L, 1 );
+ // size_t fontId = lua_tointeger( L, 2 );
+ // Vector2 position = uluaGetVector2Index( L, 4 );
+ // float fontSize = lua_tonumber( L, 5 );
+ // float spacing = lua_tonumber( L, 6 );
+ // Color tint = uluaGetColorIndex( L, 7 );
+
+ // if ( !validImage( imageId ) || !validFont( fontId ) ) {
+ // lua_pushboolean( L, false );
+ // return 1;
+ // }
+ // ImageDrawTextEx( state->images[ imageId ], *state->fonts[ fontId ], lua_tostring( L, 3 ), position, fontSize, spacing, tint );
+ // lua_pushboolean( L, true );
return 1;
}
@@ -1580,22 +871,11 @@ int ltexturesImageDrawTextEx( lua_State *L ) {
Get image size
-- Failure return nil
- Success return Vector2
*/
int ltexturesGetImageSize( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetImageSize( Image image )" );
- lua_pushnil( L );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushnil( L );
- return 1;
- }
- Image *image = state->images[ imageId ];
uluaPushVector2( L, (Vector2){ image->width, image->height } );
return 1;
@@ -1606,22 +886,12 @@ int ltexturesGetImageSize( lua_State *L ) {
Get image mipmaps. Mipmap levels, 1 by default
-- Failure return false
- Success return int
*/
int ltexturesGetImageMipmaps( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetImageMipmaps( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->images[ imageId ]->mipmaps );
+ lua_pushinteger( L, image->mipmaps );
return 1;
}
@@ -1629,24 +899,14 @@ int ltexturesGetImageMipmaps( lua_State *L ) {
/*
> format = RL.GetImageFormat( Image image )
-Get image data format ( PixelFormat type )
+Get image data format (PixelFormat type)
-- Failure return false
- Success return int
*/
int ltexturesGetImageFormat( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetImageFormat( Image image )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->images[ imageId ]->format );
+ lua_pushinteger( L, image->format );
return 1;
}
@@ -1660,31 +920,19 @@ int ltexturesGetImageFormat( lua_State *L ) {
Load texture from file into GPU memory ( VRAM )
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Texture
*/
int ltexturesLoadTexture( lua_State *L ) {
- if ( !lua_isstring( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadTexture( string fileName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
if ( FileExists( lua_tostring( L, 1 ) ) ) {
- 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" );
+ uluaPushTexture( L, LoadTexture( lua_tostring( L, 1 ) ) );
return 1;
}
- else {
- lua_pushinteger( L, -1 );
- return 1;
- }
+ TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
+ lua_pushnil( L );
+
+ return 1;
}
/*
@@ -1692,24 +940,12 @@ int ltexturesLoadTexture( lua_State *L ) {
Load texture from image data
-- Failure return -1
-- Success return int
+- Success return Texture
*/
int ltexturesLoadTextureFromImage( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadTextureFromImage( Image image )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- int i = newTexture( TEXTURE_TYPE_TEXTURE );
- state->textures[i]->texture = LoadTextureFromImage( *state->images[ imageId ] );
- lua_pushinteger( L, i );
+ uluaPushTexture( L, LoadTextureFromImage( *image ) );
return 1;
}
@@ -1719,25 +955,13 @@ int ltexturesLoadTextureFromImage( lua_State *L ) {
Load cubemap from image, multiple image cubemap layouts supported
-- Failure return -1
-- Success return int
+- Success return Texture
*/
int ltexturesLoadTextureCubemap( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadTextureCubemap( Image image, int layout )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t imageId = lua_tointeger( L, 1 );
- int layout = lua_tointeger( L, 2 );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ int layout = luaL_checkinteger( L, 2 );
- if ( !validImage( imageId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- int i = newTexture( TEXTURE_TYPE_TEXTURE );
- state->textures[i]->texture = LoadTextureCubemap( *state->images[ imageId ], layout );
- lua_pushinteger( L, i );
+ uluaPushTexture( L, LoadTextureCubemap( *image, layout ) );
return 1;
}
@@ -1745,87 +969,43 @@ int ltexturesLoadTextureCubemap( lua_State *L ) {
/*
> renderTexture = RL.LoadRenderTexture( Vector2 size )
-Load texture for rendering ( framebuffer )
+Load texture for rendering (framebuffer)
-- Failure return -1
-- Success return int
+- Success return RenderTexture
*/
int ltexturesLoadRenderTexture( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadRenderTexture( Vector2 size )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector2 size = uluaGetVector2Index( L, 1 );
- int i = newTexture( TEXTURE_TYPE_RENDER_TEXTURE );
- state->textures[i]->renderTexture = LoadRenderTexture( (int)size.x, (int)size.y );
- lua_pushinteger( L, i );
+ uluaPushRenderTexture( L, LoadRenderTexture( (int)size.x, (int)size.y ) );
return 1;
}
/*
-> success = RL.UnloadTexture( Texture2D texture )
-
-Unload texture from GPU memory ( VRAM ). NOTE! Must be texture id.
-
-- Failure return false
-- Success return true
-*/
-int ltexturesUnloadTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadTexture( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t texId = lua_tointeger( L, 1 );
-
- texturesFreeTexture( texId );
- lua_pushboolean( L, true );
-
- return 1;
-}
-
-/*
-> isReady = RL.IsTextureReady( Texture2D texture )
+> isReady = RL.IsTextureReady( Texture texture )
Check if a texture is ready
-- Failure return nil
-- Success return true
+- Success return bool
*/
int ltexturesIsTextureReady( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.IsTextureReady( Texture2D texture )" );
- lua_pushnil( L );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
- lua_pushboolean( L, IsTextureReady( texture ) );
+ lua_pushboolean( L, IsTextureReady( *texture ) );
return 1;
}
/*
-> success = RL.UpdateTexture( Texture2D texture, int{} pixels )
+> RL.UpdateTexture( Texture texture, int{} pixels )
Update GPU texture with new data
NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
-
-- Failure return false
-- Success return true
*/
int ltexturesUpdateTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateTexture( Texture2D texture, int{} pixels )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
-
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
size_t len = uluaGetTableLenIndex( L, 2 );
+
unsigned char *pixels = malloc( len * 4 * sizeof( unsigned char ) );
int t = lua_gettop( L );
@@ -1848,32 +1028,23 @@ int ltexturesUpdateTexture( lua_State *L ) {
i++;
lua_pop( L, 1 );
}
- UpdateTexture( texture, pixels );
- lua_pushboolean( L, true );
-
+ UpdateTexture( *texture, pixels );
free( pixels );
- return 1;
+ return 0;
}
/*
-> success = RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )
+> RL.UpdateTextureRec( Texture texture, Rectangle rec, int{} pixels )
Update GPU texture rectangle with new data
NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
-
-- Failure return false
-- Success return true
*/
int ltexturesUpdateTextureRec( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
-
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+ Rectangle rec = uluaGetRectangleIndex( L, 2 );
size_t len = uluaGetTableLenIndex( L, 3 );
+
unsigned char *pixels = malloc( len * 4 * sizeof( unsigned char ) );
int t = lua_gettop( L );
@@ -1898,14 +1069,10 @@ int ltexturesUpdateTextureRec( lua_State *L ) {
}
lua_pop( L, 1 ); /* Pixels arg. */
- Rectangle rec = uluaGetRectangleIndex( L, 2 );
-
- UpdateTextureRec( texture, rec, pixels );
- lua_pushboolean( L, true );
-
+ UpdateTextureRec( *texture, rec, pixels );
free( pixels );
- return 1;
+ return 0;
}
/*
@@ -1913,132 +1080,81 @@ int ltexturesUpdateTextureRec( lua_State *L ) {
*/
/*
-> success = RL.DrawTexture( Texture2D texture, Vector2 position, Color tint )
+> RL.DrawTexture( Texture texture, Vector2 position, Color tint )
Draw a Texture2D
-
-- Failure return false
-- Success return true
*/
int ltexturesDrawTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTexture( Texture2D texture, Vector2 position, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- // Texture *texture = luaL_checkudata( L, 1, "Texture" );
+ 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;
+ DrawTexture( *texture, pos.x, pos.y, color );
+ return 0;
}
/*
-> success = RL.DrawTextureRec( Texture2D texture, Rectangle source, Vector2 position, Color tint )
+> RL.DrawTextureRec( Texture texture, Rectangle source, Vector2 position, Color tint )
Draw a part of a texture defined by a rectangle
-
-- Failure return false
-- Success return true
*/
int ltexturesDrawTextureRec( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTextureRec( Texture2D texture, Rectangle source, Vector2 position, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
Rectangle srcRect = uluaGetRectangleIndex( L, 2 );
Vector2 pos = uluaGetVector2Index( L, 3 );
Color tint = uluaGetColorIndex( L, 4 );
- DrawTextureRec( texture, srcRect, pos, tint );
- lua_pushboolean( L, true );
-
- return 1;
+ DrawTextureRec( *texture, srcRect, pos, tint );
+ return 0;
}
/*
-> success = RL.DrawTexturePro( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )
+> RL.DrawTexturePro( Texture texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )
Draw a part of a texture defined by a rectangle with "pro" parameters
-
-- Failure return false
-- Success return true
*/
int ltexturesDrawTexturePro( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTexturePro( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
Rectangle srcRect = uluaGetRectangleIndex( L, 2 );
Rectangle dstRect = uluaGetRectangleIndex( L, 3 );
Vector2 origin = uluaGetVector2Index( L, 4 );
- float rot = lua_tonumber( L, 5 );
+ float rot = luaL_checknumber( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
- DrawTexturePro( texture, srcRect, dstRect, origin, rot, color );
- lua_pushboolean( L, true );
+ DrawTexturePro( *texture, srcRect, dstRect, origin, rot, color );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawTextureNPatch( Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )
-
-Draws a texture ( or part of it ) that stretches or shrinks nicely
+> RL.DrawTextureNPatch( Texture texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )
-- Failure return false
-- Success return true
+Draws a texture (or part of it) that stretches or shrinks nicely
*/
int ltexturesDrawTextureNPatch( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTextureNPatch( Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
NPatchInfo nPatchInfo = uluaGetNPatchInfoIndex( L, 2 );
Rectangle dest = uluaGetRectangleIndex( L, 3 );
Vector2 origin = uluaGetVector2Index( L, 4 );
- float rotation = lua_tonumber( L, 5 );
+ float rotation = luaL_checknumber( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- DrawTextureNPatch( texture, nPatchInfo, dest, origin, rotation, tint );
- lua_pushboolean( L, true );
+ DrawTextureNPatch( *texture, nPatchInfo, dest, origin, rotation, tint );
- return 1;
+ return 0;
}
/*
-> success = RL.BeginTextureMode( RenderTexture2D target )
+> RL.BeginTextureMode( RenderTexture target )
Begin drawing to render texture
-
-- Failure return false
-- Success return true
*/
int ltexturesBeginTextureMode( lua_State *L ) {
- if ( !isValidRenderTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.BeginTextureMode( RenderTexture2D target )" );
- lua_pushboolean( L, false );
- return 1;
- }
- RenderTexture renderTexture = uluaGetRenderTexture( L, 1 );
+ RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
- BeginTextureMode( renderTexture );
- lua_pushboolean( L, true );
+ BeginTextureMode( *renderTexture );
- return 1;
+ return 0;
}
/*
@@ -2049,28 +1165,7 @@ Ends drawing to render texture
int ltexturesEndTextureMode( lua_State *L ) {
EndTextureMode();
- return 1;
-}
-
-/*
-> type = RL.GetTextureType( Texture2D texture )
-
-Get texture type ( TEXTURE_TYPE_TEXTURE or TEXTURE_TYPE_RENDER_TEXTURE )
-
-- Failure return false
-- Success return int
-*/
-int ltexturesGetTextureType( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetTextureType( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t texId = lua_tointeger( L, 1 );
-
- lua_pushinteger( L, state->textures[ texId ]->type );
-
- return 1;
+ return 0;
}
/*
@@ -2078,152 +1173,151 @@ int ltexturesGetTextureType( lua_State *L ) {
*/
/*
-> success = RL.GenTextureMipmaps( Texture2D texture )
+> RL.GenTextureMipmaps( Texture texture )
Generate GPU mipmaps for a texture
-
-- Failure return false
-- Success return true
*/
int ltexturesGenTextureMipmaps( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenTextureMipmaps( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
- GenTextureMipmaps( &texture );
- lua_pushboolean( L, true );
+ GenTextureMipmaps( texture );
- return 1;
+ return 0;
}
/*
-> success = RL.SetTextureFilter( Texture2D texture, int filter )
-
-Set texture scaling filter mode ( TEXTURE_FILTER_POINT, TEXTURE_FILTER_BILINEAR... )
+> RL.SetTextureFilter( Texture texture, int filter )
-- Failure return false
-- Success return true
+Set texture scaling filter mode (TEXTURE_FILTER_POINT, TEXTURE_FILTER_BILINEAR...)
*/
int ltexturesSetTextureFilter( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetTextureFilter( Texture2D texture, int filter )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- int filter = lua_tointeger( L, 2 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+ int filter = luaL_checkinteger( L, 2 );
- SetTextureFilter( texture, filter );
- lua_pushboolean( L, true );
+ SetTextureFilter( *texture, filter );
- return 1;
+ return 0;
}
/*
-> success = RL.SetTextureWrap( Texture2D texture, int wrap )
+> RL.SetTextureWrap( Texture texture, int wrap )
-Set texture wrapping mode ( TEXTURE_WRAP_REPEAT, TEXTURE_WRAP_CLAMP... )
-
-- Failure return false
-- Success return true
+Set texture wrapping mode (TEXTURE_WRAP_REPEAT, TEXTURE_WRAP_CLAMP...)
*/
int ltexturesSetTextureWrap( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetTextureWrap( Texture2D texture, int wrap )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- int wrap = lua_tointeger( L, 2 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+ int wrap = luaL_checkinteger( L, 2 );
- SetTextureWrap( texture, wrap );
- lua_pushboolean( L, true );
+ SetTextureWrap( *texture, wrap );
- return 1;
+ return 0;
}
/*
-> id = RL.GetTextureId( Texture2D texture )
+> id = RL.GetTextureId( Texture texture )
-Get texture OpenGL id
+Get OpenGL texture id
-- Failure return false
- Success return int
*/
int ltexturesGetTextureId( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetTextureId( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- lua_pushinteger( L, texture.id );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+
+ lua_pushinteger( L, texture->id );
return 1;
}
/*
-> size = RL.GetTextureSize( Texture2D texture )
+> size = RL.GetTextureSize( Texture texture )
Get texture size
-- Failure return false
- Success return Vector2
*/
int ltexturesGetTextureSize( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetTextureSize( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- uluaPushVector2( L, (Vector2){ texture.width, texture.height } );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
- // Texture *texture = luaL_checkudata( L, 1, "Texture" );
- // uluaPushVector2( L, (Vector2){ texture->width, texture->height } );
+ uluaPushVector2( L, (Vector2){ texture->width, texture->height } );
return 1;
}
/*
-> mipmaps = RL.GetTextureMipmaps( Texture2D texture )
+> mipmaps = RL.GetTextureMipmaps( Texture texture )
Get texture mipmaps. Mipmap levels, 1 by default
-- Failure return false
- Success return int
*/
int ltexturesGetTextureMipmaps( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetTextureMipmaps( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- lua_pushinteger( L, texture.mipmaps );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+
+ lua_pushinteger( L, texture->mipmaps );
return 1;
}
/*
-> format = RL.GetTextureFormat( Texture2D texture )
+> format = RL.GetTextureFormat( Texture texture )
-Get texture data format ( PixelFormat type )
+Get texture data format (PixelFormat type)
-- Failure return false
- Success return int
*/
int ltexturesGetTextureFormat( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetTextureFormat( Texture2D texture )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
- lua_pushinteger( L, texture.format );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
+
+ lua_pushinteger( L, texture->format );
+
+ return 1;
+}
+
+/*
+## Textures - RenderTexture Configuration
+*/
+
+/*
+> id = RL.GetRenderTextureId( RenderTexture renderTexture )
+
+Get OpenGL framebuffer object id
+
+- Success return int
+*/
+int ltexturesGetRenderTextureId( lua_State *L ) {
+ RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
+
+ lua_pushinteger( L, renderTexture->id );
+
+ return 1;
+}
+
+/*
+> texture = RL.GetRenderTextureTexture( RenderTexture renderTexture )
+
+Get color buffer attachment texture
+
+- Success return Texture
+*/
+int ltexturesGetRenderTextureTexture( lua_State *L ) {
+ RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
+
+ uluaPushTexture( L, renderTexture->texture );
+
+ return 1;
+}
+
+/*
+> texture = RL.GetRenderTextureDepthTexture( RenderTexture renderTexture )
+
+Get depth buffer attachment texture
+
+- Success return Texture
+*/
+int ltexturesGetRenderTextureDepthTexture( lua_State *L ) {
+ RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
+
+ uluaPushTexture( L, renderTexture->depth );
return 1;
}
@@ -2237,17 +1331,11 @@ int ltexturesGetTextureFormat( lua_State *L ) {
Returns color with alpha applied, alpha goes from 0.0f to 1.0f
-- Failure return false
- Success return Color
*/
int ltexturesFade( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Fade( Color color, float alpha )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
- float alpha = lua_tonumber( L, 2 );
+ float alpha = luaL_checknumber( L, 2 );
uluaPushColor( L, Fade( color, alpha ) );
@@ -2259,15 +1347,9 @@ int ltexturesFade( lua_State *L ) {
Returns hexadecimal value for a Color
-- Failure return false
- Success return int
*/
int ltexturesColorToInt( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorToInt( Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
lua_pushinteger( L, ColorToInt( color ) );
@@ -2280,15 +1362,9 @@ int ltexturesColorToInt( lua_State *L ) {
Returns Color normalized as float [0..1]
-- Failure return false
- Success return Vector4
*/
int ltexturesColorNormalize( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorNormalize( Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
uluaPushVector4( L, ColorNormalize( color ) );
@@ -2301,15 +1377,9 @@ int ltexturesColorNormalize( lua_State *L ) {
Color from normalized values [0..1]
-- Failure return false
- Success return Color
*/
int ltexturesColorFromNormalized( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorFromNormalized( Vector4 normalized )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector4 normalized = uluaGetVector4Index( L, 1 );
uluaPushColor( L, ColorFromNormalized( normalized ) );
@@ -2322,15 +1392,9 @@ int ltexturesColorFromNormalized( lua_State *L ) {
Returns HSV values for a Color, hue [0..360], saturation/value [0..1]
-- Failure return false
- Success return Vector3
*/
int ltexturesColorToHSV( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorToHSV( Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
uluaPushVector3( L, ColorToHSV( color ) );
@@ -2343,18 +1407,12 @@ int ltexturesColorToHSV( lua_State *L ) {
Returns a Color from HSV values, hue [0..360], saturation/value [0..1]
-- Failure return false
- Success return Color
*/
int ltexturesColorFromHSV( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorFromHSV( float hue, float saturation, float value )" );
- lua_pushboolean( L, false );
- return 1;
- }
- float hue = lua_tonumber( L, 1 );
- float saturation = lua_tonumber( L, 2 );
- float value = lua_tonumber( L, 3 );
+ float hue = luaL_checknumber( L, 1 );
+ float saturation = luaL_checknumber( L, 2 );
+ float value = luaL_checknumber( L, 3 );
uluaPushColor( L, ColorFromHSV( hue, saturation, value ) );
@@ -2366,15 +1424,9 @@ int ltexturesColorFromHSV( lua_State *L ) {
Get color multiplied with another color
-- Failure return false
- Success return Color
*/
int ltexturesColorTint( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorTint( Color color, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
Color tint = uluaGetColorIndex( L, 2 );
@@ -2388,17 +1440,11 @@ int ltexturesColorTint( lua_State *L ) {
Get color with brightness correction, brightness factor goes from -1.0f to 1.0f
-- Failure return false
- Success return Color
*/
int ltexturesColorBrightness( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorBrightness( Color color, float factor )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
- float factor = lua_tonumber( L, 2 );
+ float factor = luaL_checknumber( L, 2 );
uluaPushColor( L, ColorBrightness( color, factor ) );
@@ -2410,17 +1456,11 @@ int ltexturesColorBrightness( lua_State *L ) {
Get color with contrast correction, contrast values between -1.0f and 1.0f
-- Failure return false
- Success return Color
*/
int ltexturesColorContrast( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorContrast( Color color, float contrast )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
- float contrast = lua_tonumber( L, 2 );
+ float contrast = luaL_checknumber( L, 2 );
uluaPushColor( L, ColorContrast( color, contrast ) );
@@ -2432,17 +1472,11 @@ int ltexturesColorContrast( lua_State *L ) {
Returns color with alpha applied, alpha goes from 0.0f to 1.0f
-- Failure return false
- Success return Color
*/
int ltexturesColorAlpha( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorAlpha( Color color, float alpha )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color color = uluaGetColorIndex( L, 1 );
- float alpha = lua_tonumber( L, 2 );
+ float alpha = luaL_checknumber( L, 2 );
uluaPushColor( L, ColorAlpha( color, alpha ) );
@@ -2454,15 +1488,9 @@ int ltexturesColorAlpha( lua_State *L ) {
Returns src alpha-blended into dst color with tint
-- Failure return false
- Success return Color
*/
int ltexturesColorAlphaBlend( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ColorAlphaBlend( Color dst, Color src, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
Color dst = uluaGetColorIndex( L, 1 );
Color src = uluaGetColorIndex( L, 2 );
Color tint = uluaGetColorIndex( L, 3 );
@@ -2473,20 +1501,14 @@ int ltexturesColorAlphaBlend( lua_State *L ) {
}
/*
-> color = RL.GetColor( unsigned int hexValue )
+> color = RL.GetColor( int hexValue )
Get Color structure from hexadecimal value
-- Failure return false
- Success return Color
*/
int ltexturesGetColor( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetColor( unsigned int hexValue )" );
- lua_pushboolean( L, false );
- return 1;
- }
- unsigned int hexValue = (unsigned int)lua_tointeger( L, 1 );
+ unsigned int hexValue = (unsigned int)luaL_checkinteger( L, 1 );
uluaPushColor( L, GetColor( hexValue ) );
@@ -2494,22 +1516,16 @@ int ltexturesGetColor( lua_State *L ) {
}
/*
-> color = RL.GetPixelColor( Texture2D texture, Vector2 position )
+> color = RL.GetPixelColor( Texture texture, Vector2 position )
Get pixel color from source texture
-- Failure return false
- Success return Color
*/
int ltexturesGetPixelColor( lua_State *L ) {
- if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetPixelColor( Texture2D texture, Vector2 position )" );
- lua_pushboolean( L, false );
- return 1;
- }
- Texture texture = uluaGetTexture( L, 1 );
+ Texture *texture = luaL_checkudata( L, 1, "Texture" );
Vector2 pos = uluaGetVector2Index( L, 2 );
- Image srcImage = LoadImageFromTexture( texture );
+ Image srcImage = LoadImageFromTexture( *texture );
uluaPushColor( L, GetImageColor( srcImage, pos.x, pos.y ) );
UnloadImage( srcImage );
@@ -2522,18 +1538,12 @@ int ltexturesGetPixelColor( lua_State *L ) {
Get pixel data size in bytes for certain format
-- Failure return false
- Success return int
*/
int ltexturesGetPixelDataSize( lua_State *L ) {
- if ( !lua_isnumber( L, 1) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetPixelDataSize( int width, int height, int format )" );
- lua_pushboolean( L, false );
- return 1;
- }
- int width = lua_tointeger( L, 1 );
- int height = lua_tointeger( L, 2 );
- int format = lua_tointeger( L, 3 );
+ int width = luaL_checkinteger( L, 1 );
+ int height = luaL_checkinteger( L, 2 );
+ int format = luaL_checkinteger( L, 3 );
lua_pushinteger( L, GetPixelDataSize( width, height, format ) );