summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.c366
-rw-r--r--src/gl.c2
-rw-r--r--src/lua_core.c188
-rw-r--r--src/models.c40
-rw-r--r--src/shapes.c2
-rw-r--r--src/textures.c48
6 files changed, 279 insertions, 367 deletions
diff --git a/src/core.c b/src/core.c
index 3a4756d..313fd88 100644
--- a/src/core.c
+++ b/src/core.c
@@ -49,26 +49,6 @@ static void checkShaderRealloc( int i ) {
}
}
-bool validCamera2D( size_t id ) {
- if ( id < 0 || state->camera2DCount < id || state->camera2Ds[ id ] == NULL ) {
- TraceLog( LOG_WARNING, "%s %d", "Invalid camera2D", id );
- return false;
- }
- else {
- return true;
- }
-}
-
-bool validCamera3D( size_t id ) {
- if ( id < 0 || state->camera3DCount < id || state->camera3Ds[ id ] == NULL ) {
- TraceLog( LOG_WARNING, "%s %d", "Invalid camera3D", id );
- return false;
- }
- else {
- return true;
- }
-}
-
bool validShader( size_t id ) {
if ( id < 0 || state->shaderCount < id || state->shaders[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid shader", id );
@@ -1238,7 +1218,7 @@ Set shader uniform value for texture ( sampler2d )
- Success return true
*/
int lcoreSetShaderValueTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3 ) ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetShaderValueTexture( Shader shader, int locIndex, Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2523,7 +2503,7 @@ int lcoreCreateCamera2D( lua_State *L ) {
}
/*
-> success = RL.UnloadCamera2D( int Camera2D )
+> success = RL.UnloadCamera2D( camera2D camera )
Unload Camera2D
@@ -2531,18 +2511,13 @@ Unload Camera2D
- Success return true
*/
int lcoreUnloadCamera2D( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UnloadCamera2D( int Camera2D )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
free( state->camera2Ds[ cameraId ] );
state->camera2Ds[ cameraId ] = NULL;
lua_pushboolean( L, true );
@@ -2559,19 +2534,14 @@ Begin 2D mode with custom camera ( 2D )
- Success return true
*/
int lcoreBeginMode2D( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.BeginMode2D( camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera2D camera = uluaGetCamera2D( L, 1 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
- BeginMode2D( *state->camera2Ds[ cameraId ] );
+ BeginMode2D( camera );
lua_pushboolean( L, true );
return 1;
@@ -2597,7 +2567,7 @@ Set camera target ( rotation and zoom origin )
- Success return true
*/
int lcoreSetCamera2DTarget( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera2DTarget( camera2D camera, Vector2 target )" );
lua_pushboolean( L, false );
return 1;
@@ -2605,11 +2575,6 @@ int lcoreSetCamera2DTarget( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
Vector2 target = uluaGetVector2Index( L, 2 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera2Ds[ cameraId ]->target = target;
lua_pushboolean( L, true );
@@ -2625,7 +2590,7 @@ Set camera offset ( displacement from target )
- Success return true
*/
int lcoreSetCamera2DOffset( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera2DOffset( camera2D camera, Vector2 offset )" );
lua_pushboolean( L, false );
return 1;
@@ -2633,11 +2598,6 @@ int lcoreSetCamera2DOffset( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
Vector2 offset = uluaGetVector2Index( L, 2 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera2Ds[ cameraId ]->offset = offset;
lua_pushboolean( L, true );
@@ -2653,7 +2613,7 @@ Set camera rotation in degrees
- Success return true
*/
int lcoreSetCamera2DRotation( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera2DRotation( camera2D camera, float rotation )" );
lua_pushboolean( L, false );
return 1;
@@ -2661,11 +2621,6 @@ int lcoreSetCamera2DRotation( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
float rotation = lua_tonumber( L, 2 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera2Ds[ cameraId ]->rotation = rotation;
lua_pushboolean( L, true );
@@ -2681,7 +2636,7 @@ Set camera zoom ( scaling ), should be 1.0f by default
- Success return true
*/
int lcoreSetCamera2DZoom( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera2DZoom( camera2D camera, float zoom )" );
lua_pushboolean( L, false );
return 1;
@@ -2689,11 +2644,6 @@ int lcoreSetCamera2DZoom( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
float zoom = lua_tonumber( L, 2 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera2Ds[ cameraId ]->zoom = zoom;
lua_pushboolean( L, true );
@@ -2709,18 +2659,12 @@ Get camera2D target
- Success return Vector2
*/
int lcoreGetCamera2DTarget( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera2DTarget( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
-
- if ( !validCamera2D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
uluaPushVector2( L, state->camera2Ds[ cameraId ]->target );
return 1;
@@ -2735,18 +2679,12 @@ Get camera2D offset
- Success return Vector2
*/
int lcoreGetCamera2DOffset( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera2DOffset( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
-
- if ( !validCamera2D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
uluaPushVector2( L, state->camera2Ds[ cameraId ]->offset );
return 1;
@@ -2761,17 +2699,12 @@ Get camera2D rotation
- Success return float
*/
int lcoreGetCamera2DRotation( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera2DRotation( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
-
- if ( !validCamera2D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
lua_pushnumber( L, state->camera2Ds[ cameraId ]->rotation );
return 1;
@@ -2786,17 +2719,12 @@ Get camera2D zoom
- Success return float
*/
int lcoreGetCamera2DZoom( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera2DZoom( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
-
- if ( !validCamera2D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
lua_pushnumber( L, state->camera2Ds[ cameraId ]->zoom );
return 1;
@@ -2843,18 +2771,13 @@ Unload Camera3D
- Success return true
*/
int lcoreUnloadCamera3D( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UnloadCamera3D( int Camera3D )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
free( state->camera3Ds[ cameraId ] );
state->camera3Ds[ cameraId ] = NULL;
lua_pushboolean( L, true );
@@ -2871,19 +2794,14 @@ Begin 3D mode with custom camera ( 3D )
- Success return true
*/
int lcoreBeginMode3D( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.BeginMode3D( camera3D camera )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
- BeginMode3D( *state->camera3Ds[ cameraId ] );
+ BeginMode3D( camera );
lua_pushboolean( L, true );
return 1;
@@ -2909,7 +2827,7 @@ Set camera position ( Remember to call "RL.UpdateCamera3D()" to apply changes )
- Success return true
*/
int lcoreSetCamera3DPosition( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera3DPosition( camera3D camera, Vector3 position )" );
lua_pushboolean( L, false );
return 1;
@@ -2917,11 +2835,6 @@ int lcoreSetCamera3DPosition( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
Vector3 pos = uluaGetVector3Index( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera3Ds[ cameraId ]->position = pos;
lua_pushboolean( L, true );
@@ -2937,7 +2850,7 @@ Set camera target it looks-at
- Success return true
*/
int lcoreSetCamera3DTarget( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera3DTarget( camera3D camera, Vector3 target )" );
lua_pushboolean( L, false );
return 1;
@@ -2945,11 +2858,6 @@ int lcoreSetCamera3DTarget( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
Vector3 target = uluaGetVector3Index( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera3Ds[ cameraId ]->target = target;
lua_pushboolean( L, true );
@@ -2965,7 +2873,7 @@ Set camera up vector ( Rotation over it's axis )
- Success return true
*/
int lcoreSetCamera3DUp( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera3DUp( camera3D camera, Vector3 up )" );
lua_pushboolean( L, false );
return 1;
@@ -2973,11 +2881,6 @@ int lcoreSetCamera3DUp( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
Vector3 up = uluaGetVector3Index( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera3Ds[ cameraId ]->up = up;
lua_pushboolean( L, true );
@@ -2993,7 +2896,7 @@ Set camera field-of-view apperture in Y ( degrees ) in perspective, used as near
- Success return true
*/
int lcoreSetCamera3DFovy( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera3DFovy( camera3D camera, float fovy )" );
lua_pushboolean( L, false );
return 1;
@@ -3001,11 +2904,6 @@ int lcoreSetCamera3DFovy( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
float fovy = lua_tonumber( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera3Ds[ cameraId ]->fovy = fovy;
lua_pushboolean( L, true );
@@ -3021,7 +2919,7 @@ Set camera projection mode ( CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC )
- Success return true
*/
int lcoreSetCamera3DProjection( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetCamera3DProjection( camera3D camera, int projection )" );
lua_pushboolean( L, false );
return 1;
@@ -3029,11 +2927,6 @@ int lcoreSetCamera3DProjection( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
int projection = lua_tointeger( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
state->camera3Ds[ cameraId ]->projection = projection;
lua_pushboolean( L, true );
@@ -3049,18 +2942,13 @@ Get camera position
- Success return Vector3
*/
int lcoreGetCamera3DPosition( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DPosition( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
uluaPushVector3( L, state->camera3Ds[ cameraId ]->position );
return 1;
@@ -3075,18 +2963,13 @@ Get camera target it looks-at
- Success return Vector3
*/
int lcoreGetCamera3DTarget( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DTarget( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
uluaPushVector3( L, state->camera3Ds[ cameraId ]->target );
return 1;
@@ -3101,18 +2984,13 @@ Get camera up vector ( Rotation over it's axis )
- Success return Vector3
*/
int lcoreGetCamera3DUp( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DUp( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
uluaPushVector3( L, state->camera3Ds[ cameraId ]->up );
return 1;
@@ -3127,18 +3005,13 @@ Get camera field-of-view apperture in Y ( degrees ) in perspective, used as near
- Success return float
*/
int lcoreGetCamera3DFovy( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DFovy( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
lua_pushnumber( L, state->camera3Ds[ cameraId ]->fovy );
return 1;
@@ -3153,18 +3026,13 @@ Get camera projection mode
- Success return int
*/
int lcoreGetCamera3DProjection( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DProjection( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
-
lua_pushinteger( L, state->camera3Ds[ cameraId ]->projection );
return 1;
@@ -3179,18 +3047,14 @@ Returns the cameras forward vector ( normalized )
- Success return Vector3
*/
int lcoreGetCamera3DForward( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DForward( camera3D camera )" );
lua_pushnil( L );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
- uluaPushVector3( L, GetCameraForward( state->camera3Ds[ cameraId ] ) );
+ uluaPushVector3( L, GetCameraForward( &camera ) );
return 1;
}
@@ -3205,24 +3069,20 @@ Note: The up vector might not be perpendicular to the forward vector
- Success return Vector3
*/
int lcoreGetCamera3DUpNormalized( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DUpNormalized( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
uluaPushVector3( L, GetCameraUp( state->camera3Ds[ cameraId ] ) );
return 1;
}
/*
-> forward = RL.GetCamera3DRight( camera3D camera )
+> right = RL.GetCamera3DRight( camera3D camera )
Returns the cameras right vector ( normalized )
@@ -3230,17 +3090,13 @@ Returns the cameras right vector ( normalized )
- Success return Vector3
*/
int lcoreGetCamera3DRight( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DRight( camera3D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushnil( L );
- return 1;
- }
uluaPushVector3( L, GetCameraRight( state->camera3Ds[ cameraId ] ) );
return 1;
@@ -3255,7 +3111,7 @@ Moves the camera in it's forward direction
- Success return true
*/
int lcoreCamera3DMoveForward( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DRight( camera3D camera )" );
lua_pushboolean( L, false );
return 1;
@@ -3264,11 +3120,6 @@ int lcoreCamera3DMoveForward( lua_State *L ) {
float distance = lua_tonumber( L, 2 );
bool moveInWorldPlane = lua_toboolean( L, 3 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraMoveForward( state->camera3Ds[ cameraId ], distance, moveInWorldPlane );
lua_pushboolean( L, true );
@@ -3284,7 +3135,7 @@ Moves the camera in it's up direction
- Success return true
*/
int lcoreCamera3DMoveUp( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DMoveUp( camera3D camera, float distance )" );
lua_pushboolean( L, false );
return 1;
@@ -3292,11 +3143,6 @@ int lcoreCamera3DMoveUp( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
float distance = lua_tonumber( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraMoveUp( state->camera3Ds[ cameraId ], distance );
lua_pushboolean( L, true );
@@ -3312,7 +3158,7 @@ Moves the camera target in it's current right direction
- Success return true
*/
int lcoreCamera3DMoveRight( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DMoveRight( camera3D camera, float distance, bool moveInWorldPlane )" );
lua_pushboolean( L, false );
return 1;
@@ -3321,11 +3167,6 @@ int lcoreCamera3DMoveRight( lua_State *L ) {
float distance = lua_tonumber( L, 2 );
bool moveInWorldPlane = lua_toboolean( L, 3 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraMoveRight( state->camera3Ds[ cameraId ], distance, moveInWorldPlane );
lua_pushboolean( L, true );
@@ -3341,7 +3182,7 @@ Moves the camera position closer/farther to/from the camera target
- Success return true
*/
int lcoreCamera3DMoveToTarget( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DMoveToTarget( camera3D camera, float delta )" );
lua_pushboolean( L, false );
return 1;
@@ -3349,11 +3190,6 @@ int lcoreCamera3DMoveToTarget( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
float delta = lua_tonumber( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraMoveToTarget( state->camera3Ds[ cameraId ], delta );
lua_pushboolean( L, true );
@@ -3372,7 +3208,7 @@ Note: angle must be provided in radians
- Success return true
*/
int lcoreCamera3DYaw( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )" );
lua_pushboolean( L, false );
return 1;
@@ -3381,11 +3217,6 @@ int lcoreCamera3DYaw( lua_State *L ) {
float delta = lua_tonumber( L, 2 );
bool rotateAroundTarget = lua_toboolean( L, 3 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraYaw( state->camera3Ds[ cameraId ], delta, rotateAroundTarget );
lua_pushboolean( L, true );
@@ -3405,7 +3236,7 @@ NOTE: angle must be provided in radians
- Success return true
*/
int lcoreCamera3DPitch( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 )
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 )
|| !lua_isboolean( L, 4 ) || !lua_isboolean( L, 5 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )" );
lua_pushboolean( L, false );
@@ -3417,11 +3248,6 @@ int lcoreCamera3DPitch( lua_State *L ) {
bool rotateAroundTarget = lua_toboolean( L, 4 );
bool rotateUp = lua_toboolean( L, 5 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraPitch( state->camera3Ds[ cameraId ], delta, lockView, rotateAroundTarget, rotateUp );
lua_pushboolean( L, true );
@@ -3439,7 +3265,7 @@ Note: angle must be provided in radians
- Success return true
*/
int lcoreCamera3DRoll( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DRoll( camera3D camera, float angle )" );
lua_pushboolean( L, false );
return 1;
@@ -3447,11 +3273,6 @@ int lcoreCamera3DRoll( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
float angle = lua_tonumber( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
CameraRoll( state->camera3Ds[ cameraId ], angle );
lua_pushboolean( L, true );
@@ -3467,18 +3288,14 @@ Returns the camera view matrix
- Success return Matrix
*/
int lcoreGetCamera3DViewMatrix( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DViewMatrix( camera3D camera )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushMatrix( L, GetCameraViewMatrix( state->camera3Ds[ cameraId ] ) );
+ uluaPushMatrix( L, GetCameraViewMatrix( &camera ) );
return 1;
}
@@ -3492,19 +3309,15 @@ Returns the camera projection matrix
- Success return Matrix
*/
int lcoreGetCamera3DProjectionMatrix( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DProjectionMatrix( camera3D camera, float aspect )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
float aspect = lua_tonumber( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushMatrix( L, GetCameraProjectionMatrix( state->camera3Ds[ cameraId ], aspect ) );
+ uluaPushMatrix( L, GetCameraProjectionMatrix( &camera, aspect ) );
return 1;
}
@@ -3518,7 +3331,7 @@ Update camera position for selected mode
- Success return true
*/
int lcoreUpdateCamera3D( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateCamera3D( camera3D camera, int mode )" );
lua_pushboolean( L, false );
return 1;
@@ -3526,11 +3339,6 @@ int lcoreUpdateCamera3D( lua_State *L ) {
size_t cameraId = lua_tointeger( L, 1 );
int mode = lua_tointeger( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
UpdateCamera( state->camera3Ds[ cameraId ], mode );
lua_pushboolean( L, true );
@@ -3546,7 +3354,7 @@ Update camera movement, movement/rotation values should be provided by user
- Success return true
*/
int lcoreUpdateCamera3DPro( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) {
+ if ( !isValidCamera3D( L, 1, false ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateCamera3DPro( camera3D camera, Vector3 movement, Vector3 rotation, float zoom )" );
lua_pushboolean( L, false );
return 1;
@@ -3556,11 +3364,6 @@ int lcoreUpdateCamera3DPro( lua_State *L ) {
Vector3 rotation = uluaGetVector3Index( L, 3 );
float zoom = lua_tointeger( L, 4 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
UpdateCameraPro( state->camera3Ds[ cameraId ], movement, rotation, zoom );
lua_pushboolean( L, true );
@@ -3580,19 +3383,15 @@ Get a ray trace from mouse position
- Success return Ray
*/
int lcoreGetMouseRay( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !lua_istable( L, 1 ) || !isValidCamera3D( L, 2, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMouseRay( Vector2 mousePosition, Camera3D camera )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 mousePosition = uluaGetVector2Index( L, 1 );
- size_t cameraId = lua_tointeger( L, 2 );
+ Camera3D camera = uluaGetCamera3D( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushRay( L, GetMouseRay( mousePosition, *state->camera3Ds[ cameraId ] ) );
+ uluaPushRay( L, GetMouseRay( mousePosition, camera ) );
return 1;
}
@@ -3606,18 +3405,14 @@ Get camera transform matrix ( view matrix )
- Success return Matrix
*/
int lcoreGetCameraMatrix( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera3D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCameraMatrix( Camera3D camera )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushMatrix( L, GetCameraMatrix( *state->camera3Ds[ cameraId ] ) );
+ uluaPushMatrix( L, GetCameraMatrix( camera ) );
return 1;
}
@@ -3631,18 +3426,13 @@ Get camera 2d transform matrix
- Success return Matrix
*/
int lcoreGetCameraMatrix2D( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
+ if ( !isValidCamera2D( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCameraMatrix2D( Camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
-
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushMatrix( L, GetCameraMatrix2D( *state->camera2Ds[ cameraId ] ) );
+ Camera2D camera = uluaGetCamera2D( L, 1 );
+ uluaPushMatrix( L, GetCameraMatrix2D( camera ) );
return 1;
}
@@ -3656,19 +3446,15 @@ Get the screen space position for a 3d world space position
- Success return Vector2
*/
int lcoreGetWorldToScreen( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !lua_istable( L, 1 ) || !isValidCamera3D( L, 2, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetWorldToScreen( Vector3 position, Camera3D camera )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 position = uluaGetVector3Index( L, 1 );
- size_t cameraId = lua_tointeger( L, 2 );
+ Camera3D camera = uluaGetCamera3D( L, 2 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushVector2( L, GetWorldToScreen( position, *state->camera3Ds[ cameraId ] ) );
+ uluaPushVector2( L, GetWorldToScreen( position, camera ) );
return 1;
}
@@ -3682,20 +3468,16 @@ Get size position for a 3d world space position
- Success return Vector2
*/
int lcoreGetWorldToScreenEx( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
+ if ( !lua_istable( L, 1 ) || !isValidCamera3D( L, 2, true ) || !lua_istable( L, 3 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 position = uluaGetVector3Index( L, 1 );
- size_t cameraId = lua_tointeger( L, 2 );
+ Camera3D camera = uluaGetCamera3D( L, 2 );
Vector2 size = uluaGetVector2Index( L, 3 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushVector2( L, GetWorldToScreenEx( position, *state->camera3Ds[ cameraId ], size.x, size.y ) );
+ uluaPushVector2( L, GetWorldToScreenEx( position, camera, size.x, size.y ) );
return 1;
}
@@ -3709,19 +3491,15 @@ Get the screen space position for a 2d camera world space position
- Success return Vector2
*/
int lcoreGetWorldToScreen2D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !lua_istable( L, 1 ) || !isValidCamera2D( L, 2, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetWorldToScreen2D( Vector2 position, Camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 position = uluaGetVector2Index( L, 1 );
- size_t cameraId = lua_tointeger( L, 2 );
+ Camera2D camera = uluaGetCamera2D( L, 1 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushVector2( L, GetWorldToScreen2D( position, *state->camera2Ds[ cameraId ] ) );
+ uluaPushVector2( L, GetWorldToScreen2D( position, camera ) );
return 1;
}
@@ -3735,19 +3513,15 @@ Get the world space position for a 2d camera screen space position
- Success return Vector2
*/
int lcoreGetScreenToWorld2D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !lua_istable( L, 1 ) || !isValidCamera2D( L, 2, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetScreenToWorld2D( Vector2 position, Camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 position = uluaGetVector2Index( L, 1 );
- size_t cameraId = lua_tointeger( L, 2 );
+ Camera2D camera = uluaGetCamera2D( L, 1 );
- if ( !validCamera2D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushVector2( L, GetScreenToWorld2D( position, *state->camera2Ds[ cameraId ] ) );
+ uluaPushVector2( L, GetScreenToWorld2D( position, camera ) );
return 1;
}
diff --git a/src/gl.c b/src/gl.c
index 57f5376..ceb9ff8 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -18,7 +18,7 @@ Use -1 RenderTexture for window framebuffer.
- Success return true
*/
int lglBlitFramebuffer( lua_State *L ) {
- if ( !isValidRenderTexture( L, 1) || !isValidRenderTexture( L, 2 ) || !lua_istable( L, 3 )
+ 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( LOG_WARNING, "%s", "Bad call of function. RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )" );
lua_pushboolean( L, false );
diff --git a/src/lua_core.c b/src/lua_core.c
index 14bb73e..fbdcbfd 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1446,22 +1446,82 @@ void luaRegister() {
/* Type validators. */
-bool isValidTexture( lua_State *L, int index ) {
- if ( lua_isnumber( L, index ) || lua_istable( L, index ) ) {
+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 {
+ return false;
+ }
+ }
+ else if ( allowTable && lua_istable( L, index ) ) {
return true;
+ }
+ else {
+ TraceLog( LOG_WARNING, "%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 ) ) {
+ return true;
+ }
+ else {
+ return false;
+ }
}
+ else if ( allowTable && lua_istable( L, index ) ) {
+ return true;
+ }
else {
- TraceLog( LOG_WARNING, "%s", "Error. Invalid texture." );
+ TraceLog( LOG_WARNING, "%s", "Error. Invalid RenderTexture." );
return false;
}
}
-bool isValidRenderTexture( lua_State *L, int index ) {
- if ( lua_isnumber( L, index ) || lua_istable( L, index ) ) {
+bool isValidCamera2D( lua_State *L, int index, bool allowTable ) {
+ if ( lua_isnumber( L, index ) ) {
+ int id = lua_tointeger( L, index );
+
+ if ( ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) ) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ else if ( allowTable && lua_istable( L, index ) ) {
return true;
+ }
+ else {
+ TraceLog( LOG_WARNING, "%s", "Error. Invalid Camera2D." );
+ return false;
+ }
+}
+
+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 {
+ return false;
+ }
}
+ else if ( allowTable && lua_istable( L, index ) ) {
+ return true;
+ }
else {
- TraceLog( LOG_WARNING, "%s", "Error. Invalid renderTexture." );
+ TraceLog( LOG_WARNING, "%s", "Error. Invalid Camera3D." );
return false;
}
}
@@ -1979,9 +2039,7 @@ Texture uluaGetTexture( lua_State *L, int index ) {
Texture texture = { 0 };
if ( lua_isnumber( L, index ) ) {
- if ( 0 <= lua_tointeger( L, index ) ) {
- texture = *texturesGetSourceTexture( lua_tointeger( L, index ) );
- }
+ texture = *texturesGetSourceTexture( lua_tointeger( L, index ) );
}
else if ( lua_istable( L, index ) ) {
int t = index, i = 0;
@@ -2038,9 +2096,7 @@ RenderTexture uluaGetRenderTexture( lua_State *L, int index ) {
RenderTexture renderTexture = { 0 };
if ( lua_isnumber( L, index ) ) {
- if ( 0 <= lua_tointeger( L, index ) ) {
- renderTexture = state->textures[ lua_tointeger( L, index ) ]->renderTexture;
- }
+ renderTexture = state->textures[ lua_tointeger( L, index ) ]->renderTexture;
}
else if ( lua_istable( L, index ) ) {
int t = index, i = 0;
@@ -2081,6 +2137,114 @@ RenderTexture uluaGetRenderTexture( lua_State *L, int index ) {
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 ) {
diff --git a/src/models.c b/src/models.c
index dbedb07..97e930c 100644
--- a/src/models.c
+++ b/src/models.c
@@ -708,7 +708,7 @@ Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
- Success return true
*/
int lmodelDrawQuad3DTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )" );
lua_pushboolean( L, false );
return 1;
@@ -1743,7 +1743,7 @@ Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNES
- Success return true
*/
int lmodelsSetMaterialTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3 ) ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2263,7 +2263,7 @@ int lmodelsSetModelMeshMaterial( lua_State *L ) {
}
/*
-> success = RL.DrawBillboard( Camera camera, Texture2D texture, Vector3 position, float size, Color tint )
+> success = RL.DrawBillboard( Camera3D camera, Texture2D texture, Vector3 position, float size, Color tint )
Draw a billboard texture
@@ -2271,30 +2271,26 @@ Draw a billboard texture
- Success return true
*/
int lmodelsDrawBillboard( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !isValidTexture( L, 2 ) || !lua_istable( L, 3 )
+ if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|| !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawBillboard( Camera camera, Texture2D texture, Vector3 position, float size, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
Texture texture = uluaGetTexture( L, 2 );
Vector3 position = uluaGetVector3Index( L, 3 );
float size = lua_tonumber( L, 4 );
Color tint = uluaGetColorIndex( L, 5 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- DrawBillboard( *state->camera3Ds[ cameraId ], texture, position, size, tint );
+ DrawBillboard( camera, texture, position, size, tint );
lua_pushboolean( L, true );
return 1;
}
/*
-> success = RL.DrawBillboardRec( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
+> success = RL.DrawBillboardRec( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
Draw a billboard texture defined by source
@@ -2302,32 +2298,28 @@ Draw a billboard texture defined by source
- Success return true
*/
int lmodelsDrawBillboardRec( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !isValidTexture( L, 2 ) || !lua_istable( L, 3 )
+ 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( LOG_WARNING, "%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;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
Texture texture = uluaGetTexture( L, 2 );
Rectangle source = uluaGetRectangleIndex( L, 3 );
Vector3 position = uluaGetVector3Index( L, 4 );
Vector2 size = uluaGetVector2Index( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
// DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint );
- DrawBillboardRecNoRatio( *state->camera3Ds[ cameraId ], texture, source, position, size, tint );
+ DrawBillboardRecNoRatio( camera, texture, source, position, size, tint );
lua_pushboolean( L, true );
return 1;
}
/*
-> success = RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
+> success = RL.DrawBillboardPro( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
Draw a billboard texture defined by source and rotation
@@ -2335,14 +2327,14 @@ Draw a billboard texture defined by source and rotation
- Success return true
*/
int lmodelsDrawBillboardPro( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !isValidTexture( L, 2 ) || !lua_istable( L, 3 )
+ 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( LOG_WARNING, "%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;
}
- size_t cameraId = lua_tointeger( L, 1 );
+ Camera3D camera = uluaGetCamera3D( L, 1 );
Texture texture = uluaGetTexture( L, 2 );
Rectangle source = uluaGetRectangleIndex( L, 3 );
Vector3 position = uluaGetVector3Index( L, 4 );
@@ -2352,12 +2344,8 @@ int lmodelsDrawBillboardPro( lua_State *L ) {
float rotation = lua_tonumber( L, 8 );
Color tint = uluaGetColorIndex( L, 9 );
- if ( !validCamera3D( cameraId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
// DrawBillboardPro( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint );
- DrawBillboardProNoRatio( *state->camera3Ds[ cameraId ], texture, source, position, up, size, origin, rotation, tint );
+ DrawBillboardProNoRatio( camera, texture, source, position, up, size, origin, rotation, tint );
lua_pushboolean( L, true );
return 1;
diff --git a/src/shapes.c b/src/shapes.c
index 36ac646..a3be51b 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -18,7 +18,7 @@ defining a font char white rectangle would allow drawing everything in a single
- Success return true
*/
int lshapesSetShapesTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetShapesTexture( Texture2D texture, Rectangle source )" );
lua_pushboolean( L, false );
return 1;
diff --git a/src/textures.c b/src/textures.c
index b8c67ed..6e4578c 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -44,20 +44,6 @@ bool validImage( size_t id ) {
}
}
-// bool validTexture( size_t id, int type ) {
-// if ( id < 0 || state->textureCount < id || state->textures[ id ] == NULL ) {
-// TraceLog( LOG_WARNING, "%s %d", "Invalid texture", id );
-// return false;
-// }
-// else if ( type != TEXTURE_TYPE_ALL && type != state->textures[ id ]->type ) {
-// TraceLog( LOG_WARNING, "%s %d", "Wrong texture type", type );
-// return false;
-// }
-// else {
-// return true;
-// }
-// }
-
static int newImage() {
int i = 0;
@@ -154,7 +140,7 @@ Load image from GPU texture data
- Success return int
*/
int ltexturesLoadImageFromTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.LoadImageFromTexture( Texture2D texture )" );
lua_pushinteger( L, -1 );
return 1;
@@ -1754,7 +1740,7 @@ Check if a texture is ready
- Success return true
*/
int ltexturesIsTextureReady( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.IsTextureReady( Texture2D texture )" );
lua_pushnil( L );
return 1;
@@ -1776,7 +1762,7 @@ NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 25
- Success return true
*/
int ltexturesUpdateTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateTexture( Texture2D texture, int{} pixels )" );
lua_pushboolean( L, false );
return 1;
@@ -1824,7 +1810,7 @@ NOTE! Should be TEXTURE_TYPE_TEXTURE. Pixel should be in format { { 255, 255, 25
- Success return true
*/
int ltexturesUpdateTextureRec( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateTextureRec( Texture2D texture, Rectangle rec, int{} pixels )" );
lua_pushboolean( L, false );
return 1;
@@ -1879,7 +1865,7 @@ Draw a Texture2D
- Success return true
*/
int ltexturesDrawTexture( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawTexture( Texture2D texture, Vector2 position, Color tint )" );
lua_pushboolean( L, false );
return 1;
@@ -1903,7 +1889,7 @@ Draw a part of a texture defined by a rectangle
- Success return true
*/
int ltexturesDrawTextureRec( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawTextureRec( Texture2D texture, Rectangle source, Vector2 position, Color tint )" );
lua_pushboolean( L, false );
return 1;
@@ -1928,7 +1914,7 @@ Draw a part of a texture defined by a rectangle with "pro" parameters
- Success return true
*/
int ltexturesDrawTexturePro( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
+ 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( LOG_WARNING, "%s", "Bad call of function. RL.DrawTexturePro( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )" );
lua_pushboolean( L, false );
@@ -1956,7 +1942,7 @@ Draws a texture ( or part of it ) that stretches or shrinks nicely
- Success return true
*/
int ltexturesDrawTextureNPatch( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
+ 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( LOG_WARNING, "%s", "Bad call of function. RL.DrawTextureNPatch( Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )" );
lua_pushboolean( L, false );
@@ -1984,7 +1970,7 @@ Begin drawing to render texture
- Success return true
*/
int ltexturesBeginTextureMode( lua_State *L ) {
- if ( !isValidRenderTexture( L, 1 ) ) {
+ if ( !isValidRenderTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.BeginTextureMode( RenderTexture2D target )" );
lua_pushboolean( L, false );
return 1;
@@ -2042,7 +2028,7 @@ Generate GPU mipmaps for a texture
- Success return true
*/
int ltexturesGenTextureMipmaps( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GenTextureMipmaps( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2064,7 +2050,7 @@ Set texture scaling filter mode ( TEXTURE_FILTER_POINT, TEXTURE_FILTER_BILINEAR.
- Success return true
*/
int ltexturesSetTextureFilter( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetTextureFilter( Texture2D texture, int filter )" );
lua_pushboolean( L, false );
return 1;
@@ -2087,7 +2073,7 @@ Set texture wrapping mode ( TEXTURE_WRAP_REPEAT, TEXTURE_WRAP_CLAMP... )
- Success return true
*/
int ltexturesSetTextureWrap( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetTextureWrap( Texture2D texture, int wrap )" );
lua_pushboolean( L, false );
return 1;
@@ -2110,7 +2096,7 @@ Get texture OpenGL id
- Success return int
*/
int ltexturesGetTextureId( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureId( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2130,7 +2116,7 @@ Get texture size
- Success return Vector2
*/
int ltexturesGetTextureSize( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureSize( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2150,7 +2136,7 @@ Get texture mipmaps. Mipmap levels, 1 by default
- Success return int
*/
int ltexturesGetTextureMipmaps( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureMipmaps( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2170,7 +2156,7 @@ Get texture mipmaps. Mipmap levels, 1 by default
- Success return int
*/
int ltexturesGetTextureFormat( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) ) {
+ if ( !isValidTexture( L, 1, true ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetTextureFormat( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
@@ -2455,7 +2441,7 @@ Get pixel color from source texture
- Success return Color
*/
int ltexturesGetPixelColor( lua_State *L ) {
- if ( !isValidTexture( L, 1 ) || !lua_istable( L, 2 ) ) {
+ if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetPixelColor( Texture2D texture, Vector2 position )" );
lua_pushboolean( L, false );
return 1;