diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 2 | ||||
| -rw-r--r-- | src/easings.c | 350 | ||||
| -rw-r--r-- | src/gl.c | 14 | ||||
| -rw-r--r-- | src/lua_core.c | 73 | ||||
| -rw-r--r-- | src/rgui.c | 559 | ||||
| -rw-r--r-- | src/rlgl.c | 979 | ||||
| -rw-r--r-- | src/rmath.c | 777 | ||||
| -rw-r--r-- | src/shapes.c | 588 | ||||
| -rw-r--r-- | src/textures.c | 29 |
9 files changed, 669 insertions, 2702 deletions
@@ -787,7 +787,7 @@ NOTE: Set nil if no 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 )" ); + TraceLog( state->logLevelInvalid, "%s", "Argument needs to be string or nil" ); lua_pushnil( L ); return 1; } diff --git a/src/easings.c b/src/easings.c index f4092f0..cae349c 100644 --- a/src/easings.c +++ b/src/easings.c @@ -13,19 +13,13 @@ Ease linear -- Failure return false - Success return float */ int leasingsEaseLinear( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseLinear( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseLinearNone( t, b, c, d ) ); @@ -41,19 +35,13 @@ int leasingsEaseLinear( lua_State *L ) { Ease sine in -- Failure return false - Success return float */ int leasingsEaseSineIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseSineIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseSineIn( t, b, c, d ) ); @@ -65,19 +53,13 @@ int leasingsEaseSineIn( lua_State *L ) { Ease sine out -- Failure return false - Success return float */ int leasingsEaseSineOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseSineOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseSineOut( t, b, c, d ) ); @@ -89,19 +71,13 @@ int leasingsEaseSineOut( lua_State *L ) { Ease sine in out -- Failure return false - Success return float */ int leasingsEaseSineInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseSineInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseSineInOut( t, b, c, d ) ); @@ -117,19 +93,13 @@ int leasingsEaseSineInOut( lua_State *L ) { Ease circle in -- Failure return false - Success return float */ int leasingsEaseCircIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseCircIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseCircIn( t, b, c, d ) ); @@ -141,19 +111,13 @@ int leasingsEaseCircIn( lua_State *L ) { Ease circle out -- Failure return false - Success return float */ int leasingsEaseCircOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseCircOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseCircOut( t, b, c, d ) ); @@ -165,19 +129,13 @@ int leasingsEaseCircOut( lua_State *L ) { Ease circle in out -- Failure return false - Success return float */ int leasingsEaseCircInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseCircInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseCircInOut( t, b, c, d ) ); @@ -193,19 +151,13 @@ int leasingsEaseCircInOut( lua_State *L ) { Ease cubic in -- Failure return false - Success return float */ int leasingsEaseCubicIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseCubicIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseCubicIn( t, b, c, d ) ); @@ -217,19 +169,13 @@ int leasingsEaseCubicIn( lua_State *L ) { Ease cubic out -- Failure return false - Success return float */ int leasingsEaseCubicOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseCubicOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseCubicOut( t, b, c, d ) ); @@ -241,19 +187,13 @@ int leasingsEaseCubicOut( lua_State *L ) { Ease cubic in out -- Failure return false - Success return float */ int leasingsEaseCubicInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseCubicInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseCubicInOut( t, b, c, d ) ); @@ -269,19 +209,13 @@ int leasingsEaseCubicInOut( lua_State *L ) { Ease quadratic in -- Failure return false - Success return float */ int leasingsEaseQuadIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseQuadIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseQuadIn( t, b, c, d ) ); @@ -293,19 +227,13 @@ int leasingsEaseQuadIn( lua_State *L ) { Ease quadratic out -- Failure return false - Success return float */ int leasingsEaseQuadOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseQuadOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseQuadOut( t, b, c, d ) ); @@ -317,19 +245,13 @@ int leasingsEaseQuadOut( lua_State *L ) { Ease quadratic in out -- Failure return false - Success return float */ int leasingsEaseQuadInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseQuadInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseQuadInOut( t, b, c, d ) ); @@ -345,19 +267,13 @@ int leasingsEaseQuadInOut( lua_State *L ) { Ease exponential in -- Failure return false - Success return float */ int leasingsEaseExpoIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseExpoIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseExpoIn( t, b, c, d ) ); @@ -369,19 +285,13 @@ int leasingsEaseExpoIn( lua_State *L ) { Ease exponential out -- Failure return false - Success return float */ int leasingsEaseExpoOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseExpoOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseExpoOut( t, b, c, d ) ); @@ -393,19 +303,13 @@ int leasingsEaseExpoOut( lua_State *L ) { Ease exponential in out -- Failure return false - Success return float */ int leasingsEaseExpoInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseExpoInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseExpoInOut( t, b, c, d ) ); @@ -421,19 +325,13 @@ int leasingsEaseExpoInOut( lua_State *L ) { Ease back in -- Failure return false - Success return float */ int leasingsEaseBackIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseBackIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseBackIn( t, b, c, d ) ); @@ -445,19 +343,13 @@ int leasingsEaseBackIn( lua_State *L ) { Ease back out -- Failure return false - Success return float */ int leasingsEaseBackOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseBackOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseBackOut( t, b, c, d ) ); @@ -469,19 +361,13 @@ int leasingsEaseBackOut( lua_State *L ) { Ease back in out -- Failure return false - Success return float */ int leasingsEaseBackInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseBackInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseBackInOut( t, b, c, d ) ); @@ -497,19 +383,13 @@ int leasingsEaseBackInOut( lua_State *L ) { Ease bounce in -- Failure return false - Success return float */ int leasingsEaseBounceIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseBounceIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseBounceIn( t, b, c, d ) ); @@ -521,19 +401,13 @@ int leasingsEaseBounceIn( lua_State *L ) { Ease bounce out -- Failure return false - Success return float */ int leasingsEaseBounceOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseBounceOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseBounceOut( t, b, c, d ) ); @@ -545,19 +419,13 @@ int leasingsEaseBounceOut( lua_State *L ) { Ease bounce in out -- Failure return false - Success return float */ int leasingsEaseBounceInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseBounceInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseBounceInOut( t, b, c, d ) ); @@ -573,19 +441,13 @@ int leasingsEaseBounceInOut( lua_State *L ) { Ease elastic in -- Failure return false - Success return float */ int leasingsEaseElasticIn( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseElasticIn( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseElasticIn( t, b, c, d ) ); @@ -597,19 +459,13 @@ int leasingsEaseElasticIn( lua_State *L ) { Ease elastic out -- Failure return false - Success return float */ int leasingsEaseElasticOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseElasticOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseElasticOut( t, b, c, d ) ); @@ -621,19 +477,13 @@ int leasingsEaseElasticOut( lua_State *L ) { Ease elastic in out -- Failure return false - Success return float */ int leasingsEaseElasticInOut( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.EaseElasticInOut( float t, float b, float c, float d )" ); - lua_pushboolean( L, false ); - return 1; - } - float t = lua_tonumber( L, 1 ); - float b = lua_tonumber( L, 2 ); - float c = lua_tonumber( L, 3 ); - float d = lua_tonumber( L, 4 ); + float t = luaL_checknumber( L, 1 ); + float b = luaL_checknumber( L, 2 ); + float c = luaL_checknumber( L, 3 ); + float d = luaL_checknumber( L, 4 ); lua_pushnumber( L, EaseElasticInOut( t, b, c, d ) ); @@ -15,25 +15,29 @@ Copy a block of pixels from one framebuffer object to another. Use -1 RenderTexture for window framebuffer. */ int lglBlitFramebuffer( lua_State *L ) { - // TODO 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" ); + if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) { + TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" ); + lua_pushnil( L ); + return 1; + } Rectangle srcRect = uluaGetRectangleIndex( L, 3 ); Rectangle dstRect = uluaGetRectangleIndex( L, 4 ); int mask = luaL_checkinteger( L, 5 ); int filter = luaL_checkinteger( L, 6 ); - if ( lua_tointeger( L, 1 ) == -1 ) { + if ( lua_isnil( L, 1 ) ) { glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); } else { + RenderTexture *srcTex = luaL_checkudata( L, 1, "RenderTexture" ); glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex->id ); } - if ( lua_tointeger( L, 2 ) == -1 ) { + if ( lua_isnil( L, 2 ) ) { glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); } else { + RenderTexture *dstTex = luaL_checkudata( L, 2, "RenderTexture" ); glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex->id ); } diff --git a/src/lua_core.c b/src/lua_core.c index fa60517..659cf56 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -16,7 +16,7 @@ /* Define types. */ -/* Buffer. */ + /* Buffer. */ static int gcBuffer( lua_State *L ) { Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" ); free( buffer->data ); @@ -32,7 +32,7 @@ static void defineBuffer() { lua_setfield( L, -2, "__gc" ); } -/* Image */ + /* Image */ static int gcImage( lua_State *L ) { Image *image = luaL_checkudata ( L, 1, "Image" ); printf( "gcImage\n" ); @@ -50,7 +50,7 @@ static void defineImage() { lua_setfield( L, -2, "__gc" ); } -/* Texture */ + /* Texture */ static int gcTexture( lua_State *L ) { Texture *texture = luaL_checkudata ( L, 1, "Texture" ); printf( "gcTexture\n" ); @@ -68,7 +68,7 @@ static void defineTexture() { lua_setfield( L, -2, "__gc" ); } -/* RenderRexture. */ + /* RenderRexture. */ static int gcRenderTexture( lua_State *L ) { RenderTexture *renderTexture = luaL_checkudata ( L, 1, "RenderTexture" ); printf( "gcRenderTexture\n" ); @@ -86,7 +86,7 @@ static void defineRenderTexture() { lua_setfield( L, -2, "__gc" ); } -/* Camera2D. */ + /* Camera2D. */ static void defineCamera2D() { lua_State *L = state->luaState; @@ -95,7 +95,7 @@ static void defineCamera2D() { lua_setfield( L, -2, "__index" ); } -/* Camera3D. */ + /* Camera3D. */ static void defineCamera3D() { lua_State *L = state->luaState; @@ -104,7 +104,7 @@ static void defineCamera3D() { lua_setfield( L, -2, "__index" ); } -/* Shader. */ + /* Shader. */ static int gcShader( lua_State *L ) { Shader *shader = luaL_checkudata ( L, 1, "Shader" ); printf( "gcShader\n" ); @@ -122,7 +122,7 @@ static void defineShader() { lua_setfield( L, -2, "__gc" ); } -/* Font. */ + /* Font. */ static int gcFont( lua_State *L ) { Font *font = luaL_checkudata ( L, 1, "Font" ); printf( "gcFont\n" ); @@ -140,7 +140,7 @@ static void defineFont() { lua_setfield( L, -2, "__gc" ); } -/* Wave. */ + /* Wave. */ static int gcWave( lua_State *L ) { Wave *wave = luaL_checkudata ( L, 1, "Wave" ); printf( "gcWave\n" ); @@ -158,7 +158,7 @@ static void defineWave() { lua_setfield( L, -2, "__gc" ); } -/* Sound. */ + /* Sound. */ static int gcSound( lua_State *L ) { Sound *sound = luaL_checkudata ( L, 1, "Sound" ); printf( "gcSound\n" ); @@ -176,7 +176,7 @@ static void defineSound() { lua_setfield( L, -2, "__gc" ); } -/* Music. */ + /* Music. */ static int gcMusic( lua_State *L ) { Music *music = luaL_checkudata ( L, 1, "Music" ); printf( "gcMusic\n" ); @@ -194,7 +194,7 @@ static void defineMusic() { lua_setfield( L, -2, "__gc" ); } -/* Light. */ + /* Light. */ static void defineLight() { lua_State *L = state->luaState; @@ -203,7 +203,7 @@ static void defineLight() { lua_setfield( L, -2, "__index" ); } -/* Material. */ + /* Material. */ static int gcMaterial( lua_State *L ) { Material *material = luaL_checkudata ( L, 1, "Material" ); printf( "gcMaterial\n" ); @@ -235,7 +235,7 @@ static void defineMaterial() { lua_setfield( L, -2, "__gc" ); } -/* Mesh. */ + /* Mesh. */ static int gcMesh( lua_State *L ) { Mesh *mesh = luaL_checkudata ( L, 1, "Mesh" ); printf( "gcMesh\n" ); @@ -253,7 +253,7 @@ static void defineMesh() { lua_setfield( L, -2, "__gc" ); } -/* Model. */ + /* Model. */ static int gcModel( lua_State *L ) { Model *model = luaL_checkudata ( L, 1, "Model" ); printf( "gcModel\n" ); @@ -272,7 +272,7 @@ static void defineModel() { lua_setfield( L, -2, "__gc" ); } -/* ModelAnimation. */ + /* ModelAnimation. */ static int gcModelAnimation( lua_State *L ) { ModelAnimation *modelAnimation = luaL_checkudata ( L, 1, "ModelAnimation" ); printf( "gcModelAnimation\n" ); @@ -2332,10 +2332,6 @@ Color uluaGetColorIndex( lua_State *L, int index ) { luaL_checktype( L, index, LUA_TTABLE ); Color color = { 0, 0, 0, 255 }; - if ( !lua_istable( L, index ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong color value. Returning { 0, 0, 0, 255 }" ); - return color; - } int t = index, i = 0; lua_pushnil( L ); @@ -2388,10 +2384,6 @@ Vector2 uluaGetVector2Index( lua_State *L, int index ) { luaL_checktype( L, index, LUA_TTABLE ); Vector2 vector = { 0.0f, 0.0f }; - if ( !lua_istable( L, index ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong vector2 value. Returning { 0, 0 }" ); - return vector; - } int t = index, i = 0; lua_pushnil( L ); @@ -2432,10 +2424,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong vector3 value. Returning { 0, 0, 0 }" ); - return vector; - } int t = index, i = 0; lua_pushnil( L ); @@ -2482,10 +2470,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong vector4 value. Returning { 0, 0, 0, 0 }" ); - return vector; - } int t = index, i = 0; lua_pushnil( L ); @@ -2538,11 +2522,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong rectangle value. Returning { 0, 0, 0, 0 }" ); - return rect; - } - int t = index, i = 0; lua_pushnil( L ); @@ -2595,10 +2574,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong quaternion value. Returning { 0, 0, 0, 0 }" ); - return quaternion; - } int t = index, i = 0; lua_pushnil( L ); @@ -2652,10 +2627,6 @@ Matrix uluaGetMatrixIndex( lua_State *L, int index ) { Matrix matrix = { 0.0f }; float m[4][4]; - if ( !lua_istable( L, index ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong matrix value. Returning MatrixIdentity." ); - return MatrixIdentity(); - } int t = index, i = 0; lua_pushnil( L ); @@ -2691,10 +2662,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong boundingbox value. Returning { min{ 0, 0, 0 }, max{ 0, 0, 0 } }." ); - return box; - } int t = index, i = 0; lua_pushnil( L ); @@ -2736,10 +2703,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong ray value. Returning { position{ 0, 0, 0 }, direction{ 0, 0, 0 } }." ); - return ray; - } int t = index, i = 0; lua_pushnil( L ); @@ -2781,10 +2744,6 @@ 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 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Error. Wrong ray value. Returning { source = { 0.0, 0.0, 0.0, 0.0 }, left = 0, top = 0, right = 0, bottom = 0, layout = NPATCH_NINE_PATCH }." ); - return npatch; - } int t = index, i = 0; lua_pushnil( L ); @@ -13,7 +13,7 @@ /* > RL.GuiEnable() -Enable gui controls ( global state ) +Enable gui controls (global state) */ int lguiGuiEnable( lua_State *L ) { GuiEnable(); @@ -24,7 +24,7 @@ int lguiGuiEnable( lua_State *L ) { /* > RL.GuiDisable() -Disable gui controls ( global state ) +Disable gui controls (global state) */ int lguiGuiDisable( lua_State *L ) { GuiDisable(); @@ -35,7 +35,7 @@ int lguiGuiDisable( lua_State *L ) { /* > RL.GuiLock() -Lock gui controls ( global state ) +Lock gui controls (global state) */ int lguiGuiLock( lua_State *L ) { GuiLock(); @@ -46,7 +46,7 @@ int lguiGuiLock( lua_State *L ) { /* > RL.GuiUnlock() -Unlock gui controls ( global state ) +Unlock gui controls (global state) */ int lguiGuiUnlock( lua_State *L ) { GuiUnlock(); @@ -57,7 +57,7 @@ int lguiGuiUnlock( lua_State *L ) { /* > locked = RL.GuiIsLocked() -Check if gui is locked ( global state ) +Check if gui is locked (global state) - Success return bool */ @@ -68,53 +68,35 @@ int lguiGuiIsLocked( lua_State *L ) { } /* -> success = RL.GuiFade( float alpha ) +> RL.GuiFade( float alpha ) -Set gui controls alpha ( global state ), alpha goes from 0.0f to 1.0f - -- Failure return false -- Success return true +Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f */ int lguiGuiFade( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiFade( float alpha )" ); - lua_pushboolean( L, false ); - return 1; - } - float alpha = lua_tonumber( L, 1 ); + float alpha = luaL_checknumber( L, 1 ); GuiFade( alpha ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.GuiSetState( int state ) - -Set gui state ( global state ) +> RL.GuiSetState( int state ) -- Failure return false -- Success return true +Set gui state (global state) */ int lguiGuiSetState( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSetState( int state )" ); - lua_pushboolean( L, false ); - return 1; - } - int state = lua_tointeger( L, 1 ); + int state = luaL_checkinteger( L, 1 ); GuiSetState( state ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* > state = RL.GuiGetState() -Get gui state ( global state ) +Get gui state (global state) - Success return int */ @@ -144,9 +126,9 @@ int lguiGuiSetFont( lua_State *L ) { /* > font = RL.GuiGetFont() -Get gui custom font ( global state ) +Get gui custom font (global state) -- Success return int +- Success return Font */ int lguiGuiGetFont( lua_State *L ) { uluaPushFont( L, GuiGetFont() ); @@ -159,27 +141,18 @@ int lguiGuiGetFont( lua_State *L ) { */ /* -> success = RL.GuiSetStyle( int control, int property, int value ) +> RL.GuiSetStyle( int control, int property, int value ) Set one style property - -- Failure return false -- Success return true */ int lguiGuiSetStyle( 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.GuiSetStyle( int control, int property, int value )" ); - lua_pushboolean( L, false ); - return 1; - } - int control = lua_tointeger( L, 1 ); - int property = lua_tointeger( L, 2 ); - int value = lua_tointeger( L, 3 ); + int control = luaL_checkinteger( L, 1 ); + int property = luaL_checkinteger( L, 2 ); + int value = luaL_checkinteger( L, 3 ); GuiSetStyle( control, property, value ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -187,17 +160,11 @@ int lguiGuiSetStyle( lua_State *L ) { Get one style property -- Failure return false - Success return int */ int lguiGuiGetStyle( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiGetStyle( int control, int property )" ); - lua_pushboolean( L, false ); - return 1; - } - int control = lua_tointeger( L, 1 ); - int property = lua_tointeger( L, 2 ); + int control = luaL_checkinteger( L, 1 ); + int property = luaL_checkinteger( L, 2 ); lua_pushinteger( L, GuiGetStyle( control, property ) ); @@ -207,27 +174,20 @@ int lguiGuiGetStyle( lua_State *L ) { /* > success = RL.GuiLoadStyle( string fileName ) -Load style file over global style variable ( .rgs ) +Load style file over global style variable (.rgs) - Failure return false - Success return true */ int lguiGuiLoadStyle( lua_State *L ) { - if ( !lua_isstring( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiLoadStyle( string fileName )" ); - lua_pushboolean( L, false ); - return 1; - } - - if ( FileExists( lua_tostring( L, 1 ) ) ) { + if ( FileExists( luaL_checkstring( L, 1 ) ) ) { GuiLoadStyle( lua_tostring( L, 1 ) ); lua_pushboolean( L, true ); + return 1; } - else { - lua_pushboolean( L, false ); - return 1; - } + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); + lua_pushboolean( L, false ); return 1; } @@ -252,86 +212,53 @@ int lguiGuiLoadStyleDefault( lua_State *L ) { Window Box control, shows a window that can be closed -- Failure return nil - Success return bool */ int lguiGuiWindowBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiWindowBox( Rectangle bounds, string title )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushboolean( L, GuiWindowBox( bounds, lua_tostring( L, 2 ) ) ); + lua_pushboolean( L, GuiWindowBox( bounds, luaL_checkstring( L, 2 ) ) ); return 1; } /* -> success = RL.GuiGroupBox( Rectangle bounds, string text ) +> RL.GuiGroupBox( Rectangle bounds, string text ) Group Box control with text name - -- Failure return false -- Success return true */ int lguiGuiGroupBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiGroupBox( Rectangle bounds, string text )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiGroupBox( bounds, lua_tostring( L, 2 ) ); - lua_pushboolean( L, true ); + GuiGroupBox( bounds, luaL_checkstring( L, 2 ) ); - return 1; + return 0; } /* -> success = RL.GuiLine( Rectangle bounds, string text ) +> RL.GuiLine( Rectangle bounds, string text ) Line separator control, could contain text - -- Failure return false -- Success return true */ int lguiGuiLine( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiLine( Rectangle bounds, string text )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiLine( bounds, lua_tostring( L, 2 ) ); - lua_pushboolean( L, true ); + GuiLine( bounds, luaL_checkstring( L, 2 ) ); - return 1; + return 0; } /* -> success = RL.GuiPanel( Rectangle bounds, string text ) +> RL.GuiPanel( Rectangle bounds, string text ) Panel control, useful to group controls - -- Failure return false -- Success return true */ int lguiGuiPanel( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiPanel( Rectangle bounds, string text )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiPanel( bounds, lua_tostring( L, 2 ) ); - lua_pushboolean( L, true ); + GuiPanel( bounds, luaL_checkstring( L, 2 ) ); - return 1; + return 0; } /* @@ -339,20 +266,14 @@ int lguiGuiPanel( lua_State *L ) { Scroll Panel control -- Failure return false - Success return Rectangle, Vector2 */ int lguiGuiScrollPanel( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiScrollPanel( Rectangle bounds, string text, Rectangle content, Vector2 scroll )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); Rectangle content = uluaGetRectangleIndex( L, 3 ); Vector2 scroll = uluaGetVector2Index( L, 4 ); - uluaPushRectangle( L, GuiScrollPanel( bounds, lua_tostring( L, 2 ), content, &scroll ) ); + uluaPushRectangle( L, GuiScrollPanel( bounds, luaL_checkstring( L, 2 ), content, &scroll ) ); uluaPushVector2( L, scroll ); return 2; @@ -363,25 +284,16 @@ int lguiGuiScrollPanel( lua_State *L ) { */ /* -> success = RL.GuiLabel( Rectangle bounds, string text ) +> RL.GuiLabel( Rectangle bounds, string text ) Label control, shows text - -- Failure return false -- Success return true */ int lguiGuiLabel( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiLabel( Rectangle bounds, string text )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiLabel( bounds, lua_tostring( L, 2 ) ); - lua_pushboolean( L, true ); + GuiLabel( bounds, luaL_checkstring( L, 2 ) ); - return 1; + return 0; } /* @@ -389,18 +301,12 @@ int lguiGuiLabel( lua_State *L ) { Button control, returns true when clicked -- Failure return nil - Success return boolean */ int lguiGuiButton( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiButton( Rectangle bounds, string text )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushboolean( L, GuiButton( bounds, lua_tostring( L, 2 ) ) ); + lua_pushboolean( L, GuiButton( bounds, luaL_checkstring( L, 2 ) ) ); return 1; } @@ -410,18 +316,12 @@ int lguiGuiButton( lua_State *L ) { Label button control, show true when clicked -- Failure return nil - Success return boolean */ int lguiGuiLabelButton( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiLabelButton( Rectangle bounds, string text )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushboolean( L, GuiLabelButton( bounds, lua_tostring( L, 2 ) ) ); + lua_pushboolean( L, GuiLabelButton( bounds, luaL_checkstring( L, 2 ) ) ); return 1; } @@ -431,19 +331,13 @@ int lguiGuiLabelButton( lua_State *L ) { Toggle Button control, returns true when active -- Failure return nil - Success return boolean */ int lguiGuiToggle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isboolean( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiToggle( Rectangle bounds, string text, bool active )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); bool checked = lua_toboolean( L, 3 ); - lua_pushboolean( L, GuiToggle( bounds, lua_tostring( L, 2 ), checked ) ); + lua_pushboolean( L, GuiToggle( bounds, luaL_checkstring( L, 2 ), checked ) ); return 1; } @@ -453,19 +347,13 @@ int lguiGuiToggle( lua_State *L ) { Toggle Group control, returns active toggle index -- Failure return false - Success return int */ int lguiGuiToggleGroup( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiToggleGroup( Rectangle bounds, string text, bool active )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int active = lua_tointeger( L, 3 ); + int active = luaL_checkinteger( L, 3 ); - lua_pushinteger( L, GuiToggleGroup( bounds, lua_tostring( L, 2 ), active ) ); + lua_pushinteger( L, GuiToggleGroup( bounds, luaL_checkstring( L, 2 ), active ) ); return 1; } @@ -475,19 +363,13 @@ int lguiGuiToggleGroup( lua_State *L ) { Check Box control, returns true when active -- Failure return nil - Success return boolean */ int lguiGuiCheckBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isboolean( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiCheckBox( Rectangle bounds, string text, bool checked )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); bool checked = lua_toboolean( L, 3 ); - lua_pushboolean( L, GuiCheckBox( bounds, lua_tostring( L, 2 ), checked ) ); + lua_pushboolean( L, GuiCheckBox( bounds, luaL_checkstring( L, 2 ), checked ) ); return 1; } @@ -497,19 +379,13 @@ int lguiGuiCheckBox( lua_State *L ) { Combo Box control, returns selected item index -- Failure return nil - Success return int */ int lguiGuiComboBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiComboBox( Rectangle bounds, string text, int active )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int active = lua_tointeger( L, 3 ); + int active = luaL_checkinteger( L, 3 ); - lua_pushinteger( L, GuiComboBox( bounds, lua_tostring( L, 2 ), active ) ); + lua_pushinteger( L, GuiComboBox( bounds, luaL_checkstring( L, 2 ), active ) ); return 1; } @@ -519,20 +395,14 @@ int lguiGuiComboBox( lua_State *L ) { Text Box control, updates input text -- Failure return nil - Success return boolean, string */ int lguiGuiTextBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isboolean( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int textSize = lua_tointeger( L, 3 ); + int textSize = luaL_checkinteger( L, 3 ); // char text[ STRING_LEN ] = { '\0' }; char text[ textSize + 1 ]; - strcpy( text, lua_tostring( L, 2 ) ); + strcpy( text, luaL_checkstring( L, 2 ) ); bool editMode = lua_toboolean( L, 4 ); lua_pushboolean( L, GuiTextBox( bounds, text, textSize, editMode ) ); @@ -546,20 +416,14 @@ int lguiGuiTextBox( lua_State *L ) { Text Box control with multiple lines -- Failure return nil - Success return boolean, string */ int lguiGuiTextBoxMulti( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isboolean( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiTextBoxMulti( Rectangle bounds, string text, int textSize, bool editMode )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int textSize = lua_tointeger( L, 3 ); + int textSize = luaL_checkinteger( L, 3 ); // char text[ STRING_LEN ] = { '\0' }; char text[ textSize + 1 ]; - strcpy( text, lua_tostring( L, 2 ) ); + strcpy( text, luaL_checkstring( L, 2 ) ); bool editMode = lua_toboolean( L, 4 ); lua_pushboolean( L, GuiTextBoxMulti( bounds, text, textSize, editMode ) ); @@ -573,23 +437,16 @@ int lguiGuiTextBoxMulti( lua_State *L ) { Spinner control, returns selected value -- Failure return nil - Success return boolean, int */ int lguiGuiSpinner( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isboolean( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int value = lua_tointeger( L, 3 ); - int minValue = lua_tointeger( L, 4 ); - int maxValue = lua_tointeger( L, 5 ); + int value = luaL_checkinteger( L, 3 ); + int minValue = luaL_checkinteger( L, 4 ); + int maxValue = luaL_checkinteger( L, 5 ); bool editMode = lua_toboolean( L, 6 ); - lua_pushboolean( L, GuiSpinner( bounds, lua_tostring( L, 2 ), &value, minValue, maxValue, editMode ) ); + lua_pushboolean( L, GuiSpinner( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode ) ); lua_pushinteger( L, value ); return 2; @@ -600,23 +457,16 @@ int lguiGuiSpinner( lua_State *L ) { Value Box control, updates input text with numbers -- Failure return nil - Success return boolean, int */ int lguiGuiValueBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isboolean( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int value = lua_tointeger( L, 3 ); - int minValue = lua_tointeger( L, 4 ); - int maxValue = lua_tointeger( L, 5 ); + int value = luaL_checkinteger( L, 3 ); + int minValue = luaL_checkinteger( L, 4 ); + int maxValue = luaL_checkinteger( L, 5 ); bool editMode = lua_toboolean( L, 6 ); - lua_pushboolean( L, GuiValueBox( bounds, lua_tostring( L, 2 ), &value, minValue, maxValue, editMode ) ); + lua_pushboolean( L, GuiValueBox( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode ) ); lua_pushinteger( L, value ); return 2; @@ -627,22 +477,15 @@ int lguiGuiValueBox( lua_State *L ) { Slider control, returns selected value -- Failure return nil - Success return float */ int lguiGuiSlider( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - float value = lua_tonumber( L, 4 ); - float minValue = lua_tonumber( L, 5 ); - float maxValue = lua_tonumber( L, 6 ); + float value = luaL_checknumber( L, 4 ); + float minValue = luaL_checknumber( L, 5 ); + float maxValue = luaL_checknumber( L, 6 ); - lua_pushnumber( L, GuiSlider( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), value, minValue, maxValue ) ); + lua_pushnumber( L, GuiSlider( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), value, minValue, maxValue ) ); return 1; } @@ -652,22 +495,15 @@ int lguiGuiSlider( lua_State *L ) { Slider Bar control, returns selected value -- Failure return nil - Success return float */ int lguiGuiSliderBar( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - float value = lua_tonumber( L, 4 ); - float minValue = lua_tonumber( L, 5 ); - float maxValue = lua_tonumber( L, 6 ); + float value = luaL_checknumber( L, 4 ); + float minValue = luaL_checknumber( L, 5 ); + float maxValue = luaL_checknumber( L, 6 ); - lua_pushnumber( L, GuiSliderBar( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), value, minValue, maxValue ) ); + lua_pushnumber( L, GuiSliderBar( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), value, minValue, maxValue ) ); return 1; } @@ -677,22 +513,15 @@ int lguiGuiSliderBar( lua_State *L ) { Progress Bar control, shows current progress value -- Failure return nil - Success return float */ int lguiGuiProgressBar( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - float value = lua_tonumber( L, 4 ); - float minValue = lua_tonumber( L, 5 ); - float maxValue = lua_tonumber( L, 6 ); + float value = luaL_checknumber( L, 4 ); + float minValue = luaL_checknumber( L, 5 ); + float maxValue = luaL_checknumber( L, 6 ); - lua_pushnumber( L, GuiProgressBar( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), value, minValue, maxValue ) ); + lua_pushnumber( L, GuiProgressBar( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), value, minValue, maxValue ) ); return 1; } @@ -702,19 +531,13 @@ int lguiGuiProgressBar( lua_State *L ) { Scroll Bar control -- Failure return nil - Success return int */ int lguiGuiScrollBar( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int value = lua_tointeger( L, 2 ); - int minValue = lua_tointeger( L, 3 ); - int maxValue = lua_tointeger( L, 4 ); + int value = luaL_checkinteger( L, 2 ); + int minValue = luaL_checkinteger( L, 3 ); + int maxValue = luaL_checkinteger( L, 4 ); lua_pushinteger( L, GuiScrollBar( bounds, value, minValue, maxValue ) ); @@ -726,67 +549,43 @@ int lguiGuiScrollBar( lua_State *L ) { Dropdown Box control, returns selected item -- Failure return nil - Success return bool, int */ int lguiGuiDropdownBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isboolean( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiDropdownBox( Rectangle bounds, string text, int active, bool editMode )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int active = lua_tointeger( L, 3 ); + int active = luaL_checkinteger( L, 3 ); bool editMode = lua_toboolean( L, 4 ); - lua_pushboolean( L, GuiDropdownBox( bounds, lua_tostring( L, 2 ), &active, editMode ) ); + lua_pushboolean( L, GuiDropdownBox( bounds, luaL_checkstring( L, 2 ), &active, editMode ) ); lua_pushinteger( L, active ); return 2; } /* -> success = RL.GuiStatusBar( Rectangle bounds, string text ) +> RL.GuiStatusBar( Rectangle bounds, string text ) Status Bar control, shows info text - -- Failure return false -- Success return true */ int lguiGuiStatusBar( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiStatusBar( Rectangle bounds, string text )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiStatusBar( bounds, lua_tostring( L, 2 ) ); - lua_pushboolean( L, true ); + GuiStatusBar( bounds, luaL_checkstring( L, 2 ) ); - return 1; + return 0; } /* -> success = RL.GuiDummyRec( Rectangle bounds, string text ) +> RL.GuiDummyRec( Rectangle bounds, string text ) Dummy control for placeholders - -- Failure return false -- Success return true */ int lguiGuiDummyRec( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiDummyRec( Rectangle bounds, string text )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiDummyRec( bounds, lua_tostring( L, 2 ) ); - lua_pushboolean( L, true ); + GuiDummyRec( bounds, luaL_checkstring( L, 2 ) ); - return 1; + return 0; } /* @@ -794,20 +593,14 @@ int lguiGuiDummyRec( lua_State *L ) { Grid control, returns mouse cell position -- Failure return false - Success return Vector2 */ int lguiGuiGrid( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiGrid( Rectangle bounds, string text, float spacing, int subdivs )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - float spacing = lua_tonumber( L, 3 ); - int subdivs = lua_tointeger( L, 4 ); + float spacing = luaL_checknumber( L, 3 ); + int subdivs = luaL_checkinteger( L, 4 ); - uluaPushVector2( L, GuiGrid( bounds, lua_tostring( L, 2 ), spacing, subdivs ) ); + uluaPushVector2( L, GuiGrid( bounds, luaL_checkstring( L, 2 ), spacing, subdivs ) ); return 1; } @@ -821,20 +614,14 @@ int lguiGuiGrid( lua_State *L ) { List View control, returns selected list item index and scroll index -- Failure return nil - Success return int, int */ int lguiGuiListView( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiListView( Rectangle bounds, string text, int scrollIndex, int active )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int scrollIndex = lua_tointeger( L, 3 ); - int active = lua_tointeger( L, 4 ); + int scrollIndex = luaL_checkinteger( L, 3 ); + int active = luaL_checkinteger( L, 4 ); - lua_pushinteger( L, GuiListView( bounds, lua_tostring( L, 2 ), &scrollIndex, active ) ); + lua_pushinteger( L, GuiListView( bounds, luaL_checkstring( L, 2 ), &scrollIndex, active ) ); lua_pushinteger( L, scrollIndex ); return 2; @@ -845,22 +632,15 @@ int lguiGuiListView( lua_State *L ) { List View with extended parameters, returns selected list item index, scroll index and focus -- Failure return nil - Success return int, int, int */ int lguiGuiListViewEx( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiListViewEx( Rectangle bounds, string text, int focus, int scrollIndex, int active )" ); - lua_pushnil( L ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int focus = lua_tointeger( L, 3 ); - int scrollIndex = lua_tointeger( L, 4 ); - int active = lua_tointeger( L, 5 ); + int focus = luaL_checkinteger( L, 3 ); + int scrollIndex = luaL_checkinteger( L, 4 ); + int active = luaL_checkinteger( L, 5 ); int count = 0; - const char **text = GuiTextSplit( lua_tostring( L, 2 ), &count, NULL ); + const char **text = GuiTextSplit( luaL_checkstring( L, 2 ), &count, NULL ); lua_pushinteger( L, GuiListViewEx( bounds, text, count, &focus, &scrollIndex, active ) ); lua_pushinteger( L, scrollIndex ); @@ -872,20 +652,14 @@ int lguiGuiListViewEx( lua_State *L ) { /* > buttonIndex = RL.GuiMessageBox( Rectangle bounds, string title, string message, string buttons ) -Message Box control, displays a message, returns button index ( 0 is x button ) +Message Box control, displays a message, returns button index (0 is x button) -- Failure return false - Success return int */ int lguiGuiMessageBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) || !lua_isstring( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiMessageBox( Rectangle bounds, string title, string message, string buttons )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushinteger( L, GuiMessageBox( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), lua_tostring( L, 4 ) ) ); + lua_pushinteger( L, GuiMessageBox( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), luaL_checkstring( L, 4 ) ) ); return 1; } @@ -895,23 +669,16 @@ int lguiGuiMessageBox( lua_State *L ) { Text Input Box control, ask for text, supports secret -- Failure return false - Success return int, string, int */ int lguiGuiTextInputBox( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) || !lua_isstring( L, 4 ) - || !lua_isstring( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_isnumber( L, 7 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiTextInputBox( Rectangle bounds, string title, string message, string buttons, string text, int textMaxSize, int secretViewActive )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - int textMaxSize = lua_tointeger( L, 6 ); - int secretViewActive = lua_tointeger( L, 7 ); + int textMaxSize = luaL_checkinteger( L, 6 ); + int secretViewActive = luaL_checkinteger( L, 7 ); char text[ textMaxSize + 1 ]; - strcpy( text, lua_tostring( L, 5 ) ); + strcpy( text, luaL_checkstring( L, 5 ) ); - lua_pushinteger( L, GuiTextInputBox( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), lua_tostring( L, 4 ), text, textMaxSize, &secretViewActive ) ); + lua_pushinteger( L, GuiTextInputBox( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), luaL_checkstring( L, 4 ), text, textMaxSize, &secretViewActive ) ); lua_pushstring( L, text ); lua_pushinteger( L, secretViewActive ); @@ -921,21 +688,15 @@ int lguiGuiTextInputBox( lua_State *L ) { /* > color = RL.GuiColorPicker( Rectangle bounds, string text, Color color ) -Color Picker control ( multiple color controls ) +Color Picker control (multiple color controls) -- Failure return false - Success return Color */ int lguiGuiColorPicker( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiColorPicker( Rectangle bounds, string text, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); Color color = uluaGetColorIndex( L, 3 ); - uluaPushColor( L, GuiColorPicker( bounds, lua_tostring( L, 2 ), color ) ); + uluaPushColor( L, GuiColorPicker( bounds, luaL_checkstring( L, 2 ), color ) ); return 1; } @@ -945,19 +706,13 @@ int lguiGuiColorPicker( lua_State *L ) { Color Panel control -- Failure return false - Success return Color */ int lguiGuiColorPanel( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiColorPanel( Rectangle bounds, string text, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); Color color = uluaGetColorIndex( L, 3 ); - uluaPushColor( L, GuiColorPanel( bounds, lua_tostring( L, 2 ), color ) ); + uluaPushColor( L, GuiColorPanel( bounds, luaL_checkstring( L, 2 ), color ) ); return 1; } @@ -967,19 +722,13 @@ int lguiGuiColorPanel( lua_State *L ) { Color Bar Alpha control -- Failure return false - Success return float */ int lguiGuiColorBarAlpha( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiColorBarAlpha( Rectangle bounds, string text, float alpha )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - float alpha = lua_tonumber( L, 3 ); + float alpha = luaL_checknumber( L, 3 ); - lua_pushnumber( L, GuiColorBarAlpha( bounds, lua_tostring( L, 2 ), alpha ) ); + lua_pushnumber( L, GuiColorBarAlpha( bounds, luaL_checkstring( L, 2 ), alpha ) ); return 1; } @@ -989,19 +738,13 @@ int lguiGuiColorBarAlpha( lua_State *L ) { Color Bar Hue control -- Failure return false - Success return float */ int lguiGuiColorBarHue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiColorBarHue( Rectangle bounds, string text, float value )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - float value = lua_tonumber( L, 3 ); + float value = luaL_checknumber( L, 3 ); - lua_pushnumber( L, GuiColorBarHue( bounds, lua_tostring( L, 2 ), value ) ); + lua_pushnumber( L, GuiColorBarHue( bounds, luaL_checkstring( L, 2 ), value ) ); return 1; } @@ -1013,120 +756,78 @@ int lguiGuiColorBarHue( lua_State *L ) { /* > text = RL.GuiIconText( int iconId, string text ) -Get text with icon id prepended ( if supported ) +Get text with icon id prepended (if supported) -- Failure return false - Success return string */ int lguiGuiIconText( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiIconText( int iconId, string text )" ); - lua_pushboolean( L, false ); - return 1; - } - int iconId = lua_tointeger( L, 1 ); + int iconId = luaL_checkinteger( L, 1 ); - if ( TextIsEqual( lua_tostring( L, 2 ), "" ) ) { + if ( TextIsEqual( luaL_checkstring( L, 2 ), "" ) ) { lua_pushstring( L, GuiIconText( iconId, NULL ) ); } else { - lua_pushstring( L, GuiIconText( iconId, lua_tostring( L, 2 ) ) ); + lua_pushstring( L, GuiIconText( iconId, luaL_checkstring( L, 2 ) ) ); } return 1; } /* -> success = RL.GuiDrawIcon( int iconId, Vector2 pos, int pixelSize, Color color ) +> RL.GuiDrawIcon( int iconId, Vector2 pos, int pixelSize, Color color ) Draw icon - -- Failure return false -- Success return true */ int lguiGuiDrawIcon( 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.GuiDrawIcon( int iconId, Vector2 pos, int pixelSize, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } - int iconId = lua_tointeger( L, 1 ); + int iconId = luaL_checkinteger( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 2 ); - int pixelSize = lua_tointeger( L, 3 ); + int pixelSize = luaL_checkinteger( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); GuiDrawIcon( iconId, pos.x, pos.y, pixelSize, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.GuiSetIconScale( int scale ) +> RL.GuiSetIconScale( int scale ) -Set icon scale ( 1 by default ) - -- Failure return false -- Success return true +Set icon scale (1 by default) */ int lguiGuiSetIconScale( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSetIconScale( int scale )" ); - lua_pushboolean( L, false ); - return 1; - } - unsigned int scale = lua_tointeger( L, 1 ); + unsigned int scale = luaL_checkinteger( L, 1 ); GuiSetIconScale( scale ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.GuiSetIconPixel( int iconId, Vector2 pos ) +> RL.GuiSetIconPixel( int iconId, Vector2 pos ) Set icon pixel value - -- Failure return false -- Success return true */ int lguiGuiSetIconPixel( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSetIconPixel( int iconId, Vector2 pos )" ); - lua_pushboolean( L, false ); - return 1; - } - int iconId = lua_tointeger( L, 1 ); + int iconId = luaL_checkinteger( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 2 ); GuiSetIconPixel( iconId, pos.x, pos.y ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.GuiClearIconPixel( int iconId, Vector2 pos ) +> RL.GuiClearIconPixel( int iconId, Vector2 pos ) Clear icon pixel value - -- Failure return false -- Success return true */ int lguiGuiClearIconPixel( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiClearIconPixel( int iconId, Vector2 pos )" ); - lua_pushboolean( L, false ); - return 1; - } - int iconId = lua_tointeger( L, 1 ); + int iconId = luaL_checkinteger( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 2 ); GuiClearIconPixel( iconId, pos.x, pos.y ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -1134,16 +835,10 @@ int lguiGuiClearIconPixel( lua_State *L ) { Check icon pixel value -- Failure return nil - Success return bool */ int lguiGuiCheckIconPixel( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiCheckIconPixel( int iconId, Vector2 pos )" ); - lua_pushnil( L ); - return 1; - } - int iconId = lua_tointeger( L, 1 ); + int iconId = luaL_checkinteger( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 2 ); lua_pushboolean( L, GuiCheckIconPixel( iconId, pos.x, pos.y ) ); @@ -8,23 +8,14 @@ */ /* -> success = RL.rlMatrixMode( int mode ) +> RL.rlMatrixMode( int mode ) Choose the current matrix to be transformed - -- Failure return false -- Success return true */ int lrlglMatrixMode( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlMatrixMode( int mode )" ); - lua_pushboolean( L, false ); - return 1; - } - rlMatrixMode( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlMatrixMode( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -61,87 +52,53 @@ int lrlglLoadIdentity( lua_State *L ) { } /* -> success = RL.rlTranslatef( Vector3 translation ) +> RL.rlTranslatef( Vector3 translation ) Multiply the current matrix by a translation matrix - -- Failure return false -- Success return true */ int lrlglTranslatef( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlTranslatef( Vector3 translation )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 translation = uluaGetVector3Index( L, 1 ); rlTranslatef( translation.x, translation.y, translation.z ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlRotatef( float angle, Vector3 rotation ) +> RL.rlRotatef( float angle, Vector3 rotation ) Multiply the current matrix by a rotation matrix - -- Failure return false -- Success return true */ int lrlglRotatef( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlRotatef( float angle, Vector3 rotation )" ); - lua_pushboolean( L, false ); - return 1; - } - float angle = lua_tonumber( L, 1 ); + float angle = luaL_checknumber( L, 1 ); Vector3 rotation = uluaGetVector3Index( L, 2 ); rlRotatef( angle, rotation.x, rotation.y, rotation.z ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlScalef( Vector3 scale ) +> RL.rlScalef( Vector3 scale ) Multiply the current matrix by a scaling matrix - -- Failure return false -- Success return true */ int lrlglScalef( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlScalef( Vector3 scale )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 scale = uluaGetVector3Index( L, 1 ); rlScalef( scale.x, scale.y, scale.z ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlMultMatrixf( Matrix matrix ) +> RL.rlMultMatrixf( Matrix matrix ) Multiply the current matrix by another matrix - -- Failure return false -- Success return true */ int lrlglMultMatrixf( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlMultMatrixf( Matrix matrix )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix matrix = uluaGetMatrixIndex( L, 1 ); + float matf[16] = { matrix.m0, matrix.m4, matrix.m8, matrix.m12, matrix.m1, matrix.m5, matrix.m9, matrix.m13, @@ -149,88 +106,58 @@ int lrlglMultMatrixf( lua_State *L ) { matrix.m3, matrix.m7, matrix.m11, matrix.m15 }; rlMultMatrixf( matf ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlFrustum( float left, float right, float bottom, float top, float znear, float zfar ) +> RL.rlFrustum( float left, float right, float bottom, float top, float znear, float zfar ) Multiply the current matrix by a perspective matrix generated by parameters - -- Failure return false -- Success return true */ int lrlglFrustum( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlFrustum( float left, float right, float bottom, float top, float znear, float zfar )" ); - lua_pushboolean( L, false ); - return 1; - } - double left = lua_tonumber( L, 1 ); - double right = lua_tonumber( L, 2 ); - double bottom = lua_tonumber( L, 3 ); - double top = lua_tonumber( L, 4 ); - double znear = lua_tonumber( L, 5 ); - double zfar = lua_tonumber( L, 6 ); + double left = luaL_checknumber( L, 1 ); + double right = luaL_checknumber( L, 2 ); + double bottom = luaL_checknumber( L, 3 ); + double top = luaL_checknumber( L, 4 ); + double znear = luaL_checknumber( L, 5 ); + double zfar = luaL_checknumber( L, 6 ); rlFrustum( left, right, bottom, top, znear, zfar ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlOrtho( float left, float right, float bottom, float top, float znear, float zfar ) +> RL.rlOrtho( float left, float right, float bottom, float top, float znear, float zfar ) Multiply the current matrix by an orthographic matrix generated by parameters - -- Failure return false -- Success return true */ int lrlglOrtho( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlOrtho( float left, float right, float bottom, float top, float znear, float zfar )" ); - lua_pushboolean( L, false ); - return 1; - } - double left = lua_tonumber( L, 1 ); - double right = lua_tonumber( L, 2 ); - double bottom = lua_tonumber( L, 3 ); - double top = lua_tonumber( L, 4 ); - double znear = lua_tonumber( L, 5 ); - double zfar = lua_tonumber( L, 6 ); + double left = luaL_checknumber( L, 1 ); + double right = luaL_checknumber( L, 2 ); + double bottom = luaL_checknumber( L, 3 ); + double top = luaL_checknumber( L, 4 ); + double znear = luaL_checknumber( L, 5 ); + double zfar = luaL_checknumber( L, 6 ); rlOrtho( left, right, bottom, top, znear, zfar ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlViewport( Rectangle viewport ) +> RL.rlViewport( Rectangle viewport ) -Set the viewport area ( transformation from normalized device coordinates to window coordinates ) +Set the viewport area (transformation from normalized device coordinates to window coordinates) NOTE: We store current viewport dimensions - -- Failure return false -- Success return true */ int lrlglViewport( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlViewport( Rectangle viewport )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); rlViewport( rect.x, rect.y, rect.width, rect.height ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -238,23 +165,14 @@ int lrlglViewport( lua_State *L ) { */ /* -> success = RL.rlBegin( int mode ) +> RL.rlBegin( int mode ) -Initialize drawing mode ( how to organize vertex ) - -- Failure return false -- Success return true +Initialize drawing mode (how to organize vertex) */ int lrlglBegin( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlBegin( int mode )" ); - lua_pushboolean( L, false ); - return 1; - } - rlBegin( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlBegin( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -269,157 +187,94 @@ int lrlglEnd( lua_State *L ) { } /* -> success = RL.rlVertex2f( Vector2 position ) - -Define one vertex ( position ) +> RL.rlVertex2f( Vector2 position ) -- Failure return false -- Success return true +Define one vertex (position) */ int lrlglVertex2f( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlVertex2f( Vector2 position )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 position = uluaGetVector2Index( L, 1 ); rlVertex2f( position.x, position.y ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlVertex3f( Vector3 position ) - -Define one vertex ( position ) +> RL.rlVertex3f( Vector3 position ) -- Failure return false -- Success return true +Define one vertex (position) */ int lrlglVertex3f( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlVertex3f( Vector3 position )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 position = uluaGetVector3Index( L, 1 ); rlVertex3f( position.x, position.y, position.z ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlTexCoord2f( Vector2 texCoord ) +> RL.rlTexCoord2f( Vector2 texCoord ) -Define one vertex ( texture coordinate ) - 2 float - -- Failure return false -- Success return true +Define one vertex (texture coordinate) - 2 float */ int lrlglTexCoord2f( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlTexCoord2f( Vector2 texCoord )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 texCoord = uluaGetVector2Index( L, 1 ); rlTexCoord2f( texCoord.x, texCoord.y ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlNormal3f( Vector3 normal ) +> RL.rlNormal3f( Vector3 normal ) -Define one vertex ( normal ) - 3 float - -- Failure return false -- Success return true +Define one vertex (normal) - 3 float */ int lrlglNormal3f( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlNormal3f( Vector3 normal )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 normal = uluaGetVector3Index( L, 1 ); rlNormal3f( normal.x, normal.y, normal.z ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlColor4ub( Color color ) - -Define one vertex ( color ) - 4 byte +> RL.rlColor4ub( Color color ) -- Failure return false -- Success return true +Define one vertex (color) - 4 byte */ int lrlglColor4ub( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlColor4ub( Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Color color = uluaGetColorIndex( L, 1 ); rlColor4ub( color.r, color.g, color.b, color.a ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlColor3f( Vector3 color ) +> RL.rlColor3f( Vector3 color ) -Define one vertex ( color ) - 3 float - -- Failure return false -- Success return true +Define one vertex (color) - 3 float */ int lrlglColor3f( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlColor3f( Vector3 color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 color = uluaGetVector3Index( L, 1 ); rlColor3f( color.x, color.y, color.z ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlColor4f( Vector4 color ) +> RL.rlColor4f( Vector4 color ) -Define one vertex ( color ) - 4 float - -- Failure return false -- Success return true +Define one vertex (color) - 4 float */ int lrlglColor4f( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlColor4f( Vector4 color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector4 color = uluaGetVector4Index( L, 1 ); rlColor4f( color.x, color.y, color.z, color.w ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -429,18 +284,12 @@ int lrlglColor4f( lua_State *L ) { /* > supported = RL.rlEnableVertexArray( int vaoId ) -Enable vertex array ( VAO, if supported ) +Enable vertex array (VAO, if supported) -- Failure return nil - Success return bool */ int lrlglEnableVertexArray( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexArray( int vaoId )" ); - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, rlEnableVertexArray( lua_tointeger( L, 1 ) ) ); + lua_pushboolean( L, rlEnableVertexArray( luaL_checkinteger( L, 1 ) ) ); return 1; } @@ -448,7 +297,7 @@ int lrlglEnableVertexArray( lua_State *L ) { /* > RL.rlDisableVertexArray() -Disable vertex array ( VAO, if supported ) +Disable vertex array (VAO, if supported) */ int lrlglDisableVertexArray( lua_State *L ) { rlDisableVertexArray(); @@ -457,29 +306,23 @@ int lrlglDisableVertexArray( lua_State *L ) { } /* -> success = RL.rlEnableVertexBuffer( int id ) +> RL.rlEnableVertexBuffer( int id ) -Enable vertex buffer ( VBO ) +Enable vertex buffer (VBO) - Failure return false - Success return true */ int lrlglEnableVertexBuffer( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexBuffer( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableVertexBuffer( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableVertexBuffer( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* > RL.rlDisableVertexBuffer() -Disable vertex buffer ( VBO ) +Disable vertex buffer (VBO) */ int lrlglDisableVertexBuffer( lua_State *L ) { rlDisableVertexBuffer(); @@ -488,29 +331,20 @@ int lrlglDisableVertexBuffer( lua_State *L ) { } /* -> success = RL.rlEnableVertexBufferElement( int id ) - -Enable vertex buffer element ( VBO element ) +> RL.rlEnableVertexBufferElement( int id ) -- Failure return false -- Success return true +Enable vertex buffer element (VBO element) */ int lrlglEnableVertexBufferElement( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexBufferElement( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableVertexBufferElement( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableVertexBufferElement( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* > RL.rlDisableVertexBufferElement() -Disable vertex buffer element ( VBO element ) +Disable vertex buffer element (VBO element) */ int lrlglDisableVertexBufferElement( lua_State *L ) { rlDisableVertexBufferElement(); @@ -519,43 +353,25 @@ int lrlglDisableVertexBufferElement( lua_State *L ) { } /* -> success = RL.rlEnableVertexAttribute( int index ) +> RL.rlEnableVertexAttribute( int index ) Enable vertex attribute index - -- Failure return false -- Success return true */ int lrlglEnableVertexAttribute( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableVertexAttribute( int index )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableVertexAttribute( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableVertexAttribute( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* -> success = RL.rlDisableVertexAttribute( int index ) +> RL.rlDisableVertexAttribute( int index ) Disable vertex attribute index - -- Failure return false -- Success return true */ int lrlglDisableVertexAttribute( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDisableVertexAttribute( int index )" ); - lua_pushboolean( L, false ); - return 1; - } - rlDisableVertexAttribute( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlDisableVertexAttribute( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -563,43 +379,25 @@ int lrlglDisableVertexAttribute( lua_State *L ) { */ /* -> success = RL.rlActiveTextureSlot( int slot ) +> RL.rlActiveTextureSlot( int slot ) Select and active a texture slot - -- Failure return false -- Success return true */ int lrlglActiveTextureSlot( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlActiveTextureSlot( int slot )" ); - lua_pushboolean( L, false ); - return 1; - } - rlActiveTextureSlot( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlActiveTextureSlot( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* -> success = RL.rlEnableTexture( int id ) +> RL.rlEnableTexture( int id ) Enable texture - -- Failure return false -- Success return true */ int lrlglEnableTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableTexture( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableTexture( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableTexture( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -614,23 +412,14 @@ int lrlglDisableTexture( lua_State *L ) { } /* -> success = RL.rlEnableTextureCubemap( int id ) +> RL.rlEnableTextureCubemap( int id ) Enable texture cubemap - -- Failure return false -- Success return true */ int lrlglEnableTextureCubemap( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableTextureCubemap( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableTextureCubemap( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableTextureCubemap( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -645,51 +434,33 @@ int lrlglDisableTextureCubemap( lua_State *L ) { } /* -> success = RL.rlTextureParameters( int id, int param, int value ) +> RL.rlTextureParameters( int id, int param, int value ) -Set texture parameters ( filter, wrap ) - -- Failure return false -- Success return true +Set texture parameters (filter, wrap) */ int lrlglTextureParameters( 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.rlTextureParameters( int id, int param, int value )" ); - lua_pushboolean( L, false ); - return 1; - } - unsigned int id = lua_tointeger( L, 1 ); - int param = lua_tointeger( L, 2 ); - int value = lua_tointeger( L, 3 ); + unsigned int id = luaL_checkinteger( L, 1 ); + int param = luaL_checkinteger( L, 2 ); + int value = luaL_checkinteger( L, 3 ); rlTextureParameters( id, param, value ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlCubemapParameters( int id, int param, int value ) - -Set cubemap parameters ( filter, wrap ) +> RL.rlCubemapParameters( int id, int param, int value ) -- Failure return false -- Success return true +Set cubemap parameters (filter, wrap) */ int lrlglCubemapParameters( 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.rlCubemapParameters( int id, int param, int value )" ); - lua_pushboolean( L, false ); - return 1; - } - unsigned int id = lua_tointeger( L, 1 ); - int param = lua_tointeger( L, 2 ); - int value = lua_tointeger( L, 3 ); + unsigned int id = luaL_checkinteger( L, 1 ); + int param = luaL_checkinteger( L, 2 ); + int value = luaL_checkinteger( L, 3 ); rlCubemapParameters( id, param, value ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -697,23 +468,14 @@ int lrlglCubemapParameters( lua_State *L ) { */ /* -> success = RL.rlEnableShader( int id ) +> RL.rlEnableShader( int id ) Enable shader program - -- Failure return false -- Success return true */ int lrlglEnableShader( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableShader( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableShader( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableShader( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -732,23 +494,14 @@ int lrlglDisableShader( lua_State *L ) { */ /* -> success = RL.rlEnableFramebuffer( int id ) +> RL.rlEnableFramebuffer( int id ) Enable render texture (fbo) - -- Failure return false -- Success return true */ int lrlglEnableFramebuffer( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlEnableFramebuffer( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlEnableFramebuffer( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlEnableFramebuffer( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -763,23 +516,14 @@ int lrlglDisableFramebuffer( lua_State *L ) { } /* -> success = RL.rlActiveDrawBuffers( int count ) +> RL.rlActiveDrawBuffers( int count ) Activate multiple draw color buffers - -- Failure return false -- Success return true */ int lrlglActiveDrawBuffers( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlActiveDrawBuffers( int count )" ); - lua_pushboolean( L, false ); - return 1; - } - rlActiveDrawBuffers( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlActiveDrawBuffers( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -875,23 +619,14 @@ int lrlglDisableBackfaceCulling( lua_State *L ) { } /* -> success = RL.rlSetCullFace( int mode ) +> RL.rlSetCullFace( int mode ) Set face culling mode - -- Failure return false -- Success return true */ int lrlglSetCullFace( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetCullFace( int mode )" ); - lua_pushboolean( L, false ); - return 1; - } - rlSetCullFace( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlSetCullFace( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -917,25 +652,16 @@ int lrlglDisableScissorTest( lua_State *L ) { } /* -> success = RL.rlScissor( Rectangle area ) +> RL.rlScissor( Rectangle area ) Scissor test - -- Failure return false -- Success return true */ int lrlglScissor( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlScissor( Rectangle area )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle area = uluaGetRectangleIndex( L, 1 ); rlScissor( area.x, area.y, area.width, area.height ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -961,23 +687,14 @@ int lrlglDisableWireMode( lua_State *L ) { } /* -> success = RL.rlSetLineWidth( float width ) +> RL.rlSetLineWidth( float width ) Set the line drawing width - -- Failure return false -- Success return true */ int lrlglSetLineWidth( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetLineWidth( float width )" ); - lua_pushboolean( L, false ); - return 1; - } - rlSetLineWidth( lua_tonumber( L, 1 ) ); - lua_pushboolean( L, true ); + rlSetLineWidth( luaL_checknumber( L, 1 ) ); - return 1; + return 0; } /* @@ -1051,31 +768,22 @@ int lrlglIsStereoRenderEnabled( lua_State *L ) { } /* -> success = RL.rlClearColor( Color color ) +> RL.rlClearColor( Color color ) Clear color buffer with color - -- Failure return false -- Success return true */ int lrlglClearColor( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlClearColor( Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Color color = uluaGetColorIndex( L, 1 ); rlClearColor( color.r, color.g, color.b, color.a ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* > RL.rlClearScreenBuffers() -Clear used screen buffers ( color and depth ) +Clear used screen buffers (color and depth) */ int lrlglClearScreenBuffers( lua_State *L ) { rlClearScreenBuffers(); @@ -1095,75 +803,47 @@ int lrlglCheckErrors( lua_State *L ) { } /* -> success = RL.rlSetBlendMode( int mode ) +> RL.rlSetBlendMode( int mode ) Set blending mode - -- Failure return false -- Success return true */ int lrlglSetBlendMode( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetBlendMode( int mode )" ); - lua_pushboolean( L, false ); - return 1; - } - rlSetBlendMode( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlSetBlendMode( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* -> success = RL.rlSetBlendFactors( int glSrcFactor, int glDstFactor, int glEquation ) - -Set blending mode factor and equation ( using OpenGL factors ) +> RL.rlSetBlendFactors( int glSrcFactor, int glDstFactor, int glEquation ) -- Failure return false -- Success return true +Set blending mode factor and equation (using OpenGL factors) */ int lrlglSetBlendFactors( 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.rlSetBlendFactors( int glSrcFactor, int glDstFactor, int glEquation )" ); - lua_pushboolean( L, false ); - return 1; - } - int glSrcFactor = lua_tointeger( L, 1 ); - int glDstFactor = lua_tointeger( L, 2 ); - int glEquation = lua_tointeger( L, 3 ); + int glSrcFactor = luaL_checkinteger( L, 1 ); + int glDstFactor = luaL_checkinteger( L, 2 ); + int glEquation = luaL_checkinteger( L, 3 ); rlSetBlendFactors( glSrcFactor, glDstFactor, glEquation ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlSetBlendFactorsSeparate( int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha ) +> RL.rlSetBlendFactorsSeparate( int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha ) -Set blending mode factors and equations separately ( using OpenGL factors ) - -- Failure return false -- Success return true +Set blending mode factors and equations separately (using OpenGL factors) */ int lrlglSetBlendFactorsSeparate( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetBlendFactorsSeparate( int glSrcRGB, int glDstRGB, int glSrcAlpha, int glDstAlpha, int glEqRGB, int glEqAlpha )" ); - lua_pushboolean( L, false ); - return 1; - } - int glSrcRGB = lua_tointeger( L, 1 ); - int glDstRGB = lua_tointeger( L, 2 ); - int glSrcAlpha = lua_tointeger( L, 3 ); - int glDstAlpha = lua_tointeger( L, 4 ); - int glEqRGB = lua_tointeger( L, 5 ); - int glEqAlpha = lua_tointeger( L, 6 ); + int glSrcRGB = luaL_checkinteger( L, 1 ); + int glDstRGB = luaL_checkinteger( L, 2 ); + int glSrcAlpha = luaL_checkinteger( L, 3 ); + int glDstAlpha = luaL_checkinteger( L, 4 ); + int glEqRGB = luaL_checkinteger( L, 5 ); + int glEqAlpha = luaL_checkinteger( L, 6 ); rlSetBlendFactorsSeparate( glSrcRGB, glDstRGB, glSrcAlpha, glDstAlpha, glEqRGB, glEqAlpha ); - lua_pushboolean( L, true ); - return 1; + return 0; } @@ -1204,38 +884,23 @@ int lrlglDrawRenderBatchActive( lua_State *L ) { Check internal buffer overflow for a given number of vertex and force a rlRenderBatch draw call if required -- Failure return nil - Success return bool */ int lrlglCheckRenderBatchLimit( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlCheckRenderBatchLimit( int vCount )" ); - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, rlCheckRenderBatchLimit( lua_tointeger( L, 1 ) ) ); + lua_pushboolean( L, rlCheckRenderBatchLimit( luaL_checkinteger( L, 1 ) ) ); return 1; } /* -> success = RL.rlSetTexture( int id ) +> RL.rlSetTexture( int id ) Set current texture for render batch and check buffers limits - -- Failure return false -- Success return true */ int lrlglSetTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetTexture( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlSetTexture( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlSetTexture( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -1260,17 +925,11 @@ int lrlglLoadVertexArray( lua_State *L ) { Load a vertex buffer attribute -- Failure return -1 - Success return int */ int lrlglLoadVertexBuffer( lua_State *L ) { - if ( !lua_isuserdata( L, 1 ) || !lua_isboolean( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer buffer, bool dynamic )" ); - lua_pushinteger( L, -1 ); - return 1; - } Buffer *buffer = luaL_checkudata( L, 1, "Buffer" ); - bool dynamic = lua_tointeger( L, 2 ); + bool dynamic = luaL_checkinteger( L, 2 ); lua_pushinteger( L, rlLoadVertexBuffer( buffer->data, buffer->size, dynamic ) ); @@ -1282,17 +941,11 @@ int lrlglLoadVertexBuffer( lua_State *L ) { Load a new attributes element buffer -- Failure return -1 - Success return int */ int lrlglLoadVertexBufferElement( lua_State *L ) { - if ( !lua_isuserdata( L, 1 ) || !lua_isboolean( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBufferElement( Buffer buffer, bool dynamic )" ); - lua_pushinteger( L, -1 ); - return 1; - } Buffer *buffer = luaL_checkudata( L, 1, "Buffer" ); - bool dynamic = lua_tointeger( L, 2 ); + bool dynamic = luaL_checkinteger( L, 2 ); lua_pushinteger( L, rlLoadVertexBufferElement( buffer->data, buffer->size, dynamic ) ); @@ -1300,160 +953,97 @@ int lrlglLoadVertexBufferElement( lua_State *L ) { } /* -> success = RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset ) +> RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset ) Update GPU buffer with new data - -- Failure return false -- Success return true */ int lrlglUpdateVertexBuffer( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isuserdata( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset )" ); - lua_pushboolean( L, false ); - return 1; - } - int bufferId = lua_tointeger( L, 1 ); + int bufferId = luaL_checkinteger( L, 1 ); Buffer *buffer = luaL_checkudata( L, 2, "Buffer" ); - int offset = lua_tointeger( L, 3 ); + int offset = luaL_checkinteger( L, 3 ); rlUpdateVertexBuffer( bufferId, buffer->data, buffer->size, offset ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset ) +> RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset ) Update vertex buffer elements with new data - -- Failure return false -- Success return true */ int lrlglUpdateVertexBufferElements( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isuserdata( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset )" ); - lua_pushboolean( L, false ); - return 1; - } - int bufferId = lua_tointeger( L, 1 ); + int bufferId = luaL_checkinteger( L, 1 ); Buffer *buffer = luaL_checkudata( L, 2, "Buffer" ); - int offset = lua_tointeger( L, 3 ); + int offset = luaL_checkinteger( L, 3 ); rlUpdateVertexBufferElements( bufferId, buffer->data, buffer->size, offset ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlUnloadVertexArray( int vaoId ) +> RL.rlUnloadVertexArray( int vaoId ) Unload vertex array object (VAO) - -- Failure return false -- Success return true */ int lrlglUnloadVertexArray( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadVertexArray( int vaoId )" ); - lua_pushboolean( L, false ); - return 1; - } - rlUnloadVertexArray( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlUnloadVertexArray( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* -> success = RL.rlUnloadVertexBuffer( int vboId ) +> RL.rlUnloadVertexBuffer( int vboId ) Unload vertex buffer (VBO) - -- Failure return false -- Success return true */ int lrlglUnloadVertexBuffer( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadVertexBuffer( int vboId )" ); - lua_pushboolean( L, false ); - return 1; - } - rlUnloadVertexBuffer( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlUnloadVertexBuffer( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* -> success = RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer ) +> RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer ) Set vertex attribute - -- Failure return false -- Success return true */ int lrlglSetVertexAttribute( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isboolean( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )" ); - lua_pushboolean( L, false ); - return 1; - } - int index = lua_tointeger( L, 1 ); - int compSize = lua_tointeger( L, 2 ); - int type = lua_tointeger( L, 3 ); + int index = luaL_checkinteger( L, 1 ); + int compSize = luaL_checkinteger( L, 2 ); + int type = luaL_checkinteger( L, 3 ); bool normalized = lua_toboolean( L, 4 ); - int stride = lua_tointeger( L, 5 ); - int pointer = lua_tointeger( L, 6 ); + int stride = luaL_checkinteger( L, 5 ); + int pointer = luaL_checkinteger( L, 6 ); rlSetVertexAttribute( index, compSize, type, normalized, stride, &pointer ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlSetVertexAttributeDivisor( int index, int divisor ) +> RL.rlSetVertexAttributeDivisor( int index, int divisor ) Set vertex attribute divisor - -- Failure return false -- Success return true */ int lrlglSetVertexAttributeDivisor( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttributeDivisor( int index, int divisor )" ); - lua_pushboolean( L, false ); - return 1; - } - unsigned int index = (unsigned int)lua_tointeger( L, 1 ); - int divisor = lua_tointeger( L, 2 ); + unsigned int index = (unsigned int)luaL_checkinteger( L, 1 ); + int divisor = luaL_checkinteger( L, 2 ); rlSetVertexAttributeDivisor( index, divisor ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType ) +> RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType ) Set vertex attribute default value - -- Failure return false -- Success return true */ int lrlglSetVertexAttributeDefault( 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.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType )" ); - lua_pushboolean( L, false ); - return 1; - } - int locIndex = lua_tointeger( L, 1 ); - int attribType = lua_tointeger( L, 3 ); + int locIndex = luaL_checkinteger( L, 1 ); + int attribType = luaL_checkinteger( L, 3 ); int count = uluaGetTableLenIndex( L, 2 ); float value[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; @@ -1462,110 +1052,73 @@ int lrlglSetVertexAttributeDefault( lua_State *L ) { lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { - value[i] = lua_tonumber( L, -1 ); + value[i] = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); i++; } rlSetVertexAttributeDefault( locIndex, value, attribType, count ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlDrawVertexArray( int offset, int count ) +> RL.rlDrawVertexArray( int offset, int count ) Draw vertex array - -- Failure return false -- Success return true */ int lrlglDrawVertexArray( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArray( int offset, int count )" ); - lua_pushboolean( L, false ); - return 1; - } - int offset = lua_tointeger( L, 1 ); - int count = lua_tointeger( L, 2 ); + int offset = luaL_checkinteger( L, 1 ); + int count = luaL_checkinteger( L, 2 ); rlDrawVertexArray( offset, count ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer ) +> RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer ) Draw vertex array elements - -- Failure return false -- Success return true */ int lrlglDrawVertexArrayElements( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isuserdata( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer )" ); - lua_pushboolean( L, false ); - return 1; - } - int offset = lua_tointeger( L, 1 ); - int count = lua_tointeger( L, 2 ); + int offset = luaL_checkinteger( L, 1 ); + int count = luaL_checkinteger( L, 2 ); Buffer *buffer = luaL_checkudata( L, 3, "Buffer" ); rlDrawVertexArrayElements( offset, count, buffer->data ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlDrawVertexArrayInstanced( int offset, int count, int instances ) +> RL.rlDrawVertexArrayInstanced( int offset, int count, int instances ) Draw vertex array instanced - -- Failure return false -- Success return true */ int lrlglDrawVertexArrayInstanced( 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.rlDrawVertexArrayInstanced( int offset, int count, int instances )" ); - lua_pushboolean( L, false ); - return 1; - } - int offset = lua_tointeger( L, 1 ); - int count = lua_tointeger( L, 2 ); - int instances = lua_tointeger( L, 3 ); + int offset = luaL_checkinteger( L, 1 ); + int count = luaL_checkinteger( L, 2 ); + int instances = luaL_checkinteger( L, 3 ); rlDrawVertexArrayInstanced( offset, count, instances ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances ) +> RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances ) Draw vertex array elements instanced - -- Failure return false -- Success return true */ int lrlglDrawVertexArrayElementsInstanced( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isuserdata( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances )" ); - lua_pushboolean( L, false ); - return 1; - } - int offset = lua_tointeger( L, 1 ); - int count = lua_tointeger( L, 2 ); + int offset = luaL_checkinteger( L, 1 ); + int count = luaL_checkinteger( L, 2 ); Buffer *buffer = luaL_checkudata( L, 3, "Buffer" ); - int instances = lua_tointeger( L, 4 ); + int instances = luaL_checkinteger( L, 4 ); rlDrawVertexArrayElementsInstanced( offset, count, buffer->data, instances ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -1577,18 +1130,12 @@ int lrlglDrawVertexArrayElementsInstanced( lua_State *L ) { Load texture in GPU -- Failure return -1 - Success return int */ int lrlglLoadTexture( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadTexture( Vector2 size, int format, int mipmapCount )" ); - lua_pushinteger( L, -1 ); - return 1; - } Vector2 size = uluaGetVector2Index( L, 1 ); - int format = lua_tointeger( L, 2 ); - int mipmapCount = lua_tointeger( L, 3 ); + int format = luaL_checkinteger( L, 2 ); + int mipmapCount = luaL_checkinteger( L, 3 ); lua_pushinteger( L, rlLoadTexture( NULL, size.x, size.y, format, mipmapCount ) ); @@ -1598,17 +1145,11 @@ int lrlglLoadTexture( lua_State *L ) { /* > id = RL.rlLoadTextureDepth( Vector2 size, bool useRenderBuffer ) -Load depth texture/renderbuffer ( to be attached to fbo ) +Load depth texture/renderbuffer (to be attached to fbo) -- Failure return -1 - Success return int */ int lrlglLoadTextureDepth( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isboolean( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadTextureDepth( Vector2 size, bool useRenderBuffer )" ); - lua_pushinteger( L, -1 ); - return 1; - } Vector2 size = uluaGetVector2Index( L, 1 ); bool useRenderBuffer = lua_toboolean( L, 2 ); @@ -1618,23 +1159,14 @@ int lrlglLoadTextureDepth( lua_State *L ) { } /* -> success = RL.rlUnloadTexture( int id ) +> RL.rlUnloadTexture( int id ) Unload texture from GPU memory - -- Failure return false -- Success return true */ int lrlglUnloadTexture( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadTexture( int id )" ); - lua_pushboolean( L, false ); - return 1; - } - rlUnloadTexture( lua_tointeger( L, 1 ) ); - lua_pushboolean( L, true ); + rlUnloadTexture( luaL_checkinteger( L, 1 ) ); - return 1; + return 0; } /* @@ -1646,15 +1178,9 @@ int lrlglUnloadTexture( lua_State *L ) { Load an empty framebuffer -- Failure return -1 - Success return int */ int lrlglLoadFramebuffer( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadFramebuffer( Vector2 size )" ); - lua_pushinteger( L, -1 ); - return 1; - } Vector2 size = uluaGetVector2Index( L, 1 ); lua_pushinteger( L, rlLoadFramebuffer( size.x, size.y ) ); @@ -1663,30 +1189,20 @@ int lrlglLoadFramebuffer( lua_State *L ) { } /* -> success = RL.rlFramebufferAttach( int fboId, int texId, int attachType, int texType, int mipLevel ) +> RL.rlFramebufferAttach( int fboId, int texId, int attachType, int texType, int mipLevel ) Attach texture/renderbuffer to a framebuffer - -- Failure return false -- Success return true */ int lrlglFramebufferAttach( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlFramebufferAttach( int fboId, int texId, int attachType, int texType, int mipLevel )" ); - lua_pushboolean( L, false ); - return 1; - } - unsigned int fboId = lua_tointeger( L, 1 ); - unsigned int texId = lua_tointeger( L, 2 ); - int attachType = lua_tointeger( L, 3 ); - int texType = lua_tointeger( L, 4 ); - int mipLevel = lua_tointeger( L, 5 ); + unsigned int fboId = luaL_checkinteger( L, 1 ); + unsigned int texId = luaL_checkinteger( L, 2 ); + int attachType = luaL_checkinteger( L, 3 ); + int texType = luaL_checkinteger( L, 4 ); + int mipLevel = luaL_checkinteger( L, 5 ); rlFramebufferAttach( fboId, texId, attachType, texType, mipLevel ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -1694,16 +1210,10 @@ int lrlglFramebufferAttach( lua_State *L ) { Verify framebuffer is complete -- Failure return nil - Success return bool */ int lrlglFramebufferComplete( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlFramebufferComplete( int id )" ); - lua_pushnil( L ); - return 1; - } - unsigned int id = lua_tointeger( L, 1 ); + unsigned int id = luaL_checkinteger( L, 1 ); lua_pushboolean( L, rlFramebufferComplete( id ) ); @@ -1711,25 +1221,16 @@ int lrlglFramebufferComplete( lua_State *L ) { } /* -> success = RL.rlUnloadFramebuffer( int id ) +> RL.rlUnloadFramebuffer( int id ) Delete framebuffer from GPU - -- Failure return nil -- Success return bool */ int lrlglUnloadFramebuffer( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUnloadFramebuffer( int id )" ); - lua_pushnil( L ); - return 1; - } - unsigned int id = lua_tointeger( L, 1 ); + unsigned int id = luaL_checkinteger( L, 1 ); rlUnloadFramebuffer( id ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -1803,16 +1304,10 @@ int lrlglGetMatrixTransform( lua_State *L ) { Get internal projection matrix for stereo render (selected eye) -- Failure return false - Success return Matrix */ int lrlglGetMatrixProjectionStereo( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlGetMatrixProjectionStereo( int eye )" ); - lua_pushboolean( L, false ); - return 1; - } - uluaPushMatrix( L, rlGetMatrixProjectionStereo( lua_tointeger( L, 1 ) ) ); + uluaPushMatrix( L, rlGetMatrixProjectionStereo( luaL_checkinteger( L, 1 ) ) ); return 1; } @@ -1822,96 +1317,54 @@ int lrlglGetMatrixProjectionStereo( lua_State *L ) { Get internal view offset matrix for stereo render (selected eye) -- Failure return false - Success return Matrix */ int lrlglGetMatrixViewOffsetStereo( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlGetMatrixViewOffsetStereo( int eye )" ); - lua_pushboolean( L, false ); - return 1; - } - uluaPushMatrix( L, rlGetMatrixViewOffsetStereo( lua_tointeger( L, 1 ) ) ); + uluaPushMatrix( L, rlGetMatrixViewOffsetStereo( luaL_checkinteger( L, 1 ) ) ); return 1; } /* -> success = RL.rlSetMatrixProjection( Matrix proj ) +> RL.rlSetMatrixProjection( Matrix proj ) Set a custom projection matrix (replaces internal projection matrix) - -- Failure return false -- Success return true */ int lrlglSetMatrixProjection( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixProjection( Matrix proj )" ); - lua_pushboolean( L, false ); - return 1; - } rlSetMatrixProjection( uluaGetMatrixIndex( L, 1 ) ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlSetMatrixModelview( Matrix view ) +> RL.rlSetMatrixModelview( Matrix view ) Set a custom modelview matrix (replaces internal modelview matrix) - -- Failure return false -- Success return true */ int lrlglSetMatrixModelview( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixModelview( Matrix view )" ); - lua_pushboolean( L, false ); - return 1; - } rlSetMatrixModelview( uluaGetMatrixIndex( L, 1 ) ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlSetMatrixProjectionStereo( Matrix right, Matrix left ) +> RL.rlSetMatrixProjectionStereo( Matrix right, Matrix left ) Set eyes projection matrices for stereo rendering - -- Failure return false -- Success return true */ int lrlglSetMatrixProjectionStereo( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixModelview( Matrix right, Matrix left )" ); - lua_pushboolean( L, false ); - return 1; - } rlSetMatrixProjectionStereo( uluaGetMatrixIndex( L, 1 ), uluaGetMatrixIndex( L, 2 ) ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.rlSetMatrixViewOffsetStereo( Matrix right, Matrix left ) +> RL.rlSetMatrixViewOffsetStereo( Matrix right, Matrix left ) Set eyes view offsets matrices for stereo rendering - -- Failure return false -- Success return true */ int lrlglSetMatrixViewOffsetStereo( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetMatrixViewOffsetStereo( Matrix right, Matrix left )" ); - lua_pushboolean( L, false ); - return 1; - } rlSetMatrixViewOffsetStereo( uluaGetMatrixIndex( L, 1 ), uluaGetMatrixIndex( L, 2 ) ); - lua_pushboolean( L, true ); - return 1; + return 0; } diff --git a/src/rmath.c b/src/rmath.c index 6effbd5..f1f4642 100644 --- a/src/rmath.c +++ b/src/rmath.c @@ -20,18 +20,12 @@ inline int imax( int a, int b ) { Clamp float value -- Failure return false - Success return float */ int lmathClamp( 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.Clamp( float value, float min, float max )" ); - lua_pushboolean( L, false ); - return 1; - } - float value = lua_tonumber( L, 1 ); - float min = lua_tonumber( L, 2 ); - float max = lua_tonumber( L, 3 ); + float value = luaL_checknumber( L, 1 ); + float min = luaL_checknumber( L, 2 ); + float max = luaL_checknumber( L, 3 ); lua_pushnumber( L, Clamp( value, min, max ) ); @@ -43,18 +37,12 @@ int lmathClamp( lua_State *L ) { Calculate linear interpolation between two floats -- Failure return false - Success return float */ int lmathLerp( 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.Lerp( float a, float b, float amount )" ); - lua_pushboolean( L, false ); - return 1; - } - float start = lua_tonumber( L, 1 ); - float end = lua_tonumber( L, 2 ); - float amount = lua_tonumber( L, 3 ); + float start = luaL_checknumber( L, 1 ); + float end = luaL_checknumber( L, 2 ); + float amount = luaL_checknumber( L, 3 ); lua_pushnumber( L, Lerp( start, end, amount ) ); @@ -66,18 +54,12 @@ int lmathLerp( lua_State *L ) { Normalize input value within input range -- Failure return false - Success return float */ int lmathNormalize( 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.Normalize( float value, float a, float b )" ); - lua_pushboolean( L, false ); - return 1; - } - float value = lua_tonumber( L, 1 ); - float start = lua_tonumber( L, 2 ); - float end = lua_tonumber( L, 3 ); + float value = luaL_checknumber( L, 1 ); + float start = luaL_checknumber( L, 2 ); + float end = luaL_checknumber( L, 3 ); lua_pushnumber( L, Normalize( value, start, end ) ); @@ -89,21 +71,14 @@ int lmathNormalize( lua_State *L ) { Remap input value within input range to output range -- Failure return false - Success return float */ int lmathRemap( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Remap( float value, float inputStart, float inputEnd, float outputStart, float outputEnd )" ); - lua_pushboolean( L, false ); - return 1; - } - float value = lua_tonumber( L, 1 ); - float inputStart = lua_tonumber( L, 2 ); - float inputEnd = lua_tonumber( L, 3 ); - float outputStart = lua_tonumber( L, 4 ); - float outputEnd = lua_tonumber( L, 5 ); + float value = luaL_checknumber( L, 1 ); + float inputStart = luaL_checknumber( L, 2 ); + float inputEnd = luaL_checknumber( L, 3 ); + float outputStart = luaL_checknumber( L, 4 ); + float outputEnd = luaL_checknumber( L, 5 ); lua_pushnumber( L, Remap( value, inputStart, inputEnd, outputStart, outputEnd ) ); @@ -115,18 +90,12 @@ int lmathRemap( lua_State *L ) { Wrap input value from min to max -- Failure return false - Success return float */ int lmathWrap( 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.Wrap( float value, float min, float max )" ); - lua_pushboolean( L, false ); - return 1; - } - float value = lua_tonumber( L, 1 ); - float min = lua_tonumber( L, 2 ); - float max = lua_tonumber( L, 3 ); + float value = luaL_checknumber( L, 1 ); + float min = luaL_checknumber( L, 2 ); + float max = luaL_checknumber( L, 3 ); lua_pushnumber( L, Wrap( value, min, max ) ); @@ -138,17 +107,11 @@ int lmathWrap( lua_State *L ) { Check whether two given floats are almost equal -- Failure return false - Success return int */ int lmathFloatEquals( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.FloatEquals( float x, float y )" ); - lua_pushboolean( L, false ); - return 1; - } - float x = lua_tonumber( L, 1 ); - float y = lua_tonumber( L, 2 ); + float x = luaL_checknumber( L, 1 ); + float y = luaL_checknumber( L, 2 ); lua_pushinteger( L, FloatEquals( x, y ) ); @@ -190,15 +153,9 @@ int lmathVector2One( lua_State *L ) { Add two vectors (v1 + v2) -- Failure return false - Success return Vector2 */ int lmathVector2Add( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Add( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -212,17 +169,11 @@ int lmathVector2Add( lua_State *L ) { Add vector and float value -- Failure return false - Success return Vector2 */ int lmathVector2AddValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2AddValue( Vector2 v, float add )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); - float add = lua_tonumber( L, 2 ); + float add = luaL_checknumber( L, 2 ); uluaPushVector2( L, Vector2AddValue( v, add ) ); @@ -234,15 +185,9 @@ int lmathVector2AddValue( lua_State *L ) { Subtract two vectors (v1 - v2) -- Failure return false - Success return Vector2 */ int lmathVector2Subtract( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Subtract( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -256,17 +201,11 @@ int lmathVector2Subtract( lua_State *L ) { Subtract vector by float value -- Failure return false - Success return Vector2 */ int lmathVector2SubtractValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2SubtractValue( Vector2 v, float sub )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); - float sub = lua_tonumber( L, 2 ); + float sub = luaL_checknumber( L, 2 ); uluaPushVector2( L, Vector2SubtractValue( v, sub ) ); @@ -278,15 +217,9 @@ int lmathVector2SubtractValue( lua_State *L ) { Calculate vector length -- Failure return false - Success return float */ int lmathVector2Length( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Length( vector2 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); lua_pushnumber( L, Vector2Length( v ) ); @@ -299,15 +232,9 @@ int lmathVector2Length( lua_State *L ) { Calculate vector square length -- Failure return false - Success return float */ int lmathVector2LengthSqr( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2LengthSqr( vector2 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); lua_pushnumber( L, Vector2LengthSqr( v ) ); @@ -320,15 +247,9 @@ int lmathVector2LengthSqr( lua_State *L ) { Calculate two vectors dot product -- Failure return false - Success return float */ int lmathVector2DotProduct( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2DotProduct( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -342,15 +263,9 @@ int lmathVector2DotProduct( lua_State *L ) { Calculate distance between two vectors -- Failure return false - Success return float */ int lmathVector2Distance( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Distance( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -364,15 +279,9 @@ int lmathVector2Distance( lua_State *L ) { Calculate square distance between two vectors -- Failure return false - Success return float */ int lmathVector2DistanceSqr( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2DistanceSqr( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -386,15 +295,9 @@ int lmathVector2DistanceSqr( lua_State *L ) { Calculate angle from two vectors -- Failure return false - Success return float */ int lmathVector2Angle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Angle( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -410,15 +313,9 @@ Calculate angle defined by a two vectors line. NOTE: Parameters need to be normalized. Current implementation should be aligned with glm::angle. -- Failure return false - Success return float */ int lmathVector2LineAngle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2LineAngle( Vector2 a, Vector2 b )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 start = uluaGetVector2Index( L, 1 ); Vector2 end = uluaGetVector2Index( L, 2 ); @@ -430,19 +327,13 @@ int lmathVector2LineAngle( lua_State *L ) { /* > result = RL.Vector2Scale( Vector2 v, float scale ) -Scale vector ( multiply by value ) +Scale vector (multiply by value) -- Failure return false - Success return Vector2 */ int lmathVector2Scale( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Scale( Vector2 v, float scale )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); - float scale = lua_tonumber( L, 2 ); + float scale = luaL_checknumber( L, 2 ); uluaPushVector2( L, Vector2Scale( v, scale ) ); @@ -454,15 +345,9 @@ int lmathVector2Scale( lua_State *L ) { Multiply vector by vector -- Failure return false - Success return Vector2 */ int lmathVector2Multiply( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Multiply( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -476,15 +361,9 @@ int lmathVector2Multiply( lua_State *L ) { Negate vector -- Failure return false - Success return Vector2 */ int lmathVector2Negate( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Negate( Vector2 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); uluaPushVector2( L, Vector2Negate( v ) ); @@ -497,15 +376,9 @@ int lmathVector2Negate( lua_State *L ) { Divide vector by vector -- Failure return false - Success return Vector2 */ int lmathVector2Divide( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Divide( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -519,15 +392,9 @@ int lmathVector2Divide( lua_State *L ) { Normalize provided vector -- Failure return false - Success return Vector2 */ int lmathVector2Normalize( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Normalize( Vector2 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); uluaPushVector2( L, Vector2Normalize( v ) ); @@ -540,15 +407,9 @@ int lmathVector2Normalize( lua_State *L ) { Transforms a Vector2 by a given Matrix -- Failure return false - Success return Vector2 */ int lmathVector2Transform( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Transform( Vector2 v, Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); Matrix mat = uluaGetMatrixIndex( L, 2 ); @@ -562,18 +423,12 @@ int lmathVector2Transform( lua_State *L ) { Calculate linear interpolation between two vectors -- Failure return false - Success return Vector2 */ int lmathVector2Lerp( 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.Vector2Lerp( Vector2 v1, Vector2 v2, float amount )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); - float amount = lua_tonumber( L, 3 ); + float amount = luaL_checknumber( L, 3 ); uluaPushVector2( L, Vector2Lerp( v1, v2, amount ) ); @@ -585,15 +440,9 @@ int lmathVector2Lerp( lua_State *L ) { Calculate reflected vector to normal -- Failure return false - Success return Vector2 */ int lmathVector2Reflect( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Reflect( Vector2 v, Vector2 normal )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -607,17 +456,11 @@ int lmathVector2Reflect( lua_State *L ) { Rotate vector by angle -- Failure return false - Success return Vector2 */ int lmathVector2Rotate( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Rotate( Vector2 v, float angle )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); - float degs = lua_tonumber( L, 2 ); + float degs = luaL_checknumber( L, 2 ); uluaPushVector2( L, Vector2Rotate( v, degs ) ); @@ -629,18 +472,12 @@ int lmathVector2Rotate( lua_State *L ) { Move Vector towards target -- Failure return false - Success return Vector2 */ int lmathVector2MoveTowards( 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.Vector2MoveTowards( Vector2 v, Vector2 target, float maxDistance )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); - float maxDistance = lua_tonumber( L, 3 ); + float maxDistance = luaL_checknumber( L, 3 ); uluaPushVector2( L, Vector2MoveTowards( v1, v2, maxDistance ) ); @@ -652,15 +489,9 @@ int lmathVector2MoveTowards( lua_State *L ) { Invert the given vector -- Failure return false - Success return Vector2 */ int lmathVector2Invert( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Invert( Vector2 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); uluaPushVector2( L, Vector2Invert( v ) ); @@ -674,15 +505,9 @@ int lmathVector2Invert( lua_State *L ) { Clamp the components of the vector between min and max values specified by the given vectors -- Failure return false - Success return Vector2 */ int lmathVector2Clamp( 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.Vector2Clamp( Vector2 v, Vector2 min, Vector2 max )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); Vector2 min = uluaGetVector2Index( L, 2 ); Vector2 max = uluaGetVector2Index( L, 3 ); @@ -697,18 +522,12 @@ int lmathVector2Clamp( lua_State *L ) { Clamp the magnitude of the vector between two min and max values -- Failure return false - Success return Vector2 */ int lmathVector2ClampValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2ClampValue( Vector2 v, float min, float max )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v = uluaGetVector2Index( L, 1 ); - float min = lua_tonumber( L, 2 ); - float max = lua_tonumber( L, 3 ); + float min = luaL_checknumber( L, 2 ); + float max = luaL_checknumber( L, 3 ); uluaPushVector2( L, Vector2ClampValue( v, min, max ) ); @@ -720,15 +539,9 @@ int lmathVector2ClampValue( lua_State *L ) { Check whether two given vectors are almost equal -- Failure return false - Success return int */ int lmathVector2Equals( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector2Equals( Vector2 v1, Vector2 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); @@ -772,15 +585,9 @@ int lmathVector3One( lua_State *L ) { Add two vectors -- Failure return false - Success return Vector3 */ int lmathVector3Add( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Add( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -794,17 +601,11 @@ int lmathVector3Add( lua_State *L ) { Add vector and float value -- Failure return false - Success return Vector3 */ int lmathVector3AddValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3AddValue( Vector3 v, float add )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); - float add = lua_tonumber( L, 2 ); + float add = luaL_checknumber( L, 2 ); uluaPushVector3( L, Vector3AddValue( v, add ) ); @@ -816,15 +617,9 @@ int lmathVector3AddValue( lua_State *L ) { Subtract two vectors -- Failure return false - Success return Vector3 */ int lmathVector3Subtract( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Subtract( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -838,17 +633,11 @@ int lmathVector3Subtract( lua_State *L ) { Subtract vector by float value -- Failure return false - Success return Vector3 */ int lmathVector3SubtractValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3SubtractValue( Vector3 v, float sub )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); - float sub = lua_tonumber( L, 2 ); + float sub = luaL_checknumber( L, 2 ); uluaPushVector3( L, Vector3SubtractValue( v, sub ) ); @@ -860,17 +649,11 @@ int lmathVector3SubtractValue( lua_State *L ) { Multiply vector by scalar -- Failure return false - Success return Vector3 */ int lmathVector3Scale( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Scale( Vector3 v, float scalar )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); - float scalar = lua_tonumber( L, 2 ); + float scalar = luaL_checknumber( L, 2 ); uluaPushVector3( L, Vector3Scale( v, scalar ) ); @@ -882,15 +665,9 @@ int lmathVector3Scale( lua_State *L ) { Multiply vector by vector -- Failure return false - Success return Vector3 */ int lmathVector3Multiply( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Multiply( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -904,15 +681,9 @@ int lmathVector3Multiply( lua_State *L ) { Calculate two vectors cross product -- Failure return false - Success return Vector3 */ int lmathVector3CrossProduct( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3CrossProduct( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -926,15 +697,9 @@ int lmathVector3CrossProduct( lua_State *L ) { Calculate one vector perpendicular vector -- Failure return false - Success return Vector3 */ int lmathVector3Perpendicular( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Perpendicular( Vector3 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); uluaPushVector3( L, Vector3Perpendicular( v ) ); @@ -947,15 +712,9 @@ int lmathVector3Perpendicular( lua_State *L ) { Calculate vector length -- Failure return false - Success return float */ int lmathVector3Length( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Length( Vector3 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); lua_pushnumber( L, Vector3Length( v ) ); @@ -968,15 +727,9 @@ int lmathVector3Length( lua_State *L ) { Calculate vector square length -- Failure return false - Success return float */ int lmathVector3LengthSqr( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3LengthSqr( Vector3 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); lua_pushnumber( L, Vector3LengthSqr( v ) ); @@ -989,15 +742,9 @@ int lmathVector3LengthSqr( lua_State *L ) { Calculate two vectors dot product -- Failure return false - Success return float */ int lmathVector3DotProduct( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3DotProduct( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1011,15 +758,9 @@ int lmathVector3DotProduct( lua_State *L ) { Calculate distance between two vectors -- Failure return false - Success return float */ int lmathVector3Distance( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Distance( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1033,15 +774,9 @@ int lmathVector3Distance( lua_State *L ) { Calculate square distance between two vectors -- Failure return false - Success return float */ int lmathVector3DistanceSqr( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3DistanceSqr( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1055,15 +790,9 @@ int lmathVector3DistanceSqr( lua_State *L ) { Calculate angle between two vectors -- Failure return false - Success return float */ int lmathVector3Angle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Angle( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1075,17 +804,11 @@ int lmathVector3Angle( lua_State *L ) { /* > result = RL.Vector3Negate( Vector3 v ) -Negate provided vector ( invert direction ) +Negate provided vector (invert direction) -- Failure return false - Success return Vector3 */ int lmathVector3Negate( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Negate( Vector3 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); uluaPushVector3( L, Vector3Negate( v ) ); @@ -1098,15 +821,9 @@ int lmathVector3Negate( lua_State *L ) { Divide vector by vector -- Failure return false - Success return Vector3 */ int lmathVector3Divide( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Divide( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1120,15 +837,9 @@ int lmathVector3Divide( lua_State *L ) { Normalize provided vector -- Failure return false - Success return Vector3 */ int lmathVector3Normalize( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Normalize( Vector3 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); uluaPushVector3( L, Vector3Normalize( v ) ); @@ -1142,15 +853,9 @@ int lmathVector3Normalize( lua_State *L ) { Orthonormalize provided vectors. Makes vectors normalized and orthogonal to each other. Gram-Schmidt function implementation -- Failure return false - Success return Vector3, Vector3 */ int lmathVector3OrthoNormalize( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3OrthoNormalize( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1167,15 +872,9 @@ int lmathVector3OrthoNormalize( lua_State *L ) { Transforms a Vector3 by a given Matrix -- Failure return false - Success return Vector3 */ int lmathVector3Transform( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Transform( Vector3 v, Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); Matrix mat = uluaGetMatrixIndex( L, 2 ); @@ -1189,15 +888,9 @@ int lmathVector3Transform( lua_State *L ) { Transform a vector by quaternion rotation -- Failure return false - Success return Vector3 */ int lmathVector3RotateByQuaternion( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3RotateByQuaternion( Vector3 v, Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); Quaternion q = uluaGetQuaternionIndex( L, 2 ); @@ -1211,18 +904,12 @@ int lmathVector3RotateByQuaternion( lua_State *L ) { Rotates a vector around an axis -- Failure return false - Success return Vector3 */ int lmathVector3RotateByAxisAngle( 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.Vector3RotateByAxisAngle( Vector3 v, Vector3 axis, float angle )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); Vector3 axis = uluaGetVector3Index( L, 2 ); - float angle = lua_tonumber( L, 3 ); + float angle = luaL_checknumber( L, 3 ); uluaPushVector3( L, Vector3RotateByAxisAngle( v, axis, angle ) ); @@ -1234,18 +921,12 @@ int lmathVector3RotateByAxisAngle( lua_State *L ) { Calculate linear interpolation between two vectors -- Failure return false - Success return Vector3 */ int lmathVector3Lerp( 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.Vector3Lerp( Vector3 v1, Vector3 v2, float amount )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); - float amount = lua_tonumber( L, 3 ); + float amount = luaL_checknumber( L, 3 ); uluaPushVector3( L, Vector3Lerp( v1, v2, amount ) ); @@ -1257,15 +938,9 @@ int lmathVector3Lerp( lua_State *L ) { Calculate reflected vector to normal -- Failure return false - Success return Vector3 */ int lmathVector3Reflect( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Reflect( Vector3 v, Vector3 normal )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); Vector3 normal = uluaGetVector3Index( L, 2 ); @@ -1279,15 +954,9 @@ int lmathVector3Reflect( lua_State *L ) { Get min value for each pair of components -- Failure return false - Success return Vector3 */ int lmathVector3Min( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Min( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1301,15 +970,9 @@ int lmathVector3Min( lua_State *L ) { Get max value for each pair of components -- Failure return false - Success return Vector3 */ int lmathVector3Max( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Max( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1321,18 +984,12 @@ int lmathVector3Max( lua_State *L ) { /* > result = RL.Vector3Barycenter( Vector3 p, Vector3 a, Vector3 b, Vector3 c ) -Compute barycenter coordinates ( u, v, w ) for point p with respect to triangle ( a, b, c ) +Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c) NOTE: Assumes P is on the plane of the triangle -- Failure return false - Success return Vector3 */ int lmathVector3Barycenter( 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.Vector3Barycenter( Vector3 p, Vector3 a, Vector3 b, Vector3 c )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 p = uluaGetVector3Index( L, 1 ); Vector3 a = uluaGetVector3Index( L, 2 ); Vector3 b = uluaGetVector3Index( L, 3 ); @@ -1349,15 +1006,9 @@ int lmathVector3Barycenter( lua_State *L ) { Projects a Vector3 from screen space into object space NOTE: We are avoiding calling other raymath functions despite available -- Failure return false - Success return Vector3 */ int lmathVector3Unproject( 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.Vector3Unproject( Vector3 source, Matrix projection, Matrix view )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 source = uluaGetVector3Index( L, 1 ); Matrix projection = uluaGetMatrixIndex( L, 2 ); Matrix view = uluaGetMatrixIndex( L, 3 ); @@ -1372,15 +1023,9 @@ int lmathVector3Unproject( lua_State *L ) { Invert the given vector -- Failure return false - Success return Vector3 */ int lmathVector3Invert( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Invert( Vector3 v )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); uluaPushVector3( L, Vector3Invert( v ) ); @@ -1394,15 +1039,9 @@ int lmathVector3Invert( lua_State *L ) { Clamp the components of the vector between min and max values specified by the given vectors -- Failure return false - Success return Vector3 */ int lmathVector3Clamp( 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.Vector3Clamp( Vector3 v, Vector3 min, Vector3 max )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); Vector3 min = uluaGetVector3Index( L, 2 ); Vector3 max = uluaGetVector3Index( L, 3 ); @@ -1417,18 +1056,12 @@ int lmathVector3Clamp( lua_State *L ) { Clamp the magnitude of the vector between two values -- Failure return false - Success return Vector3 */ int lmathVector3ClampValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3ClampValue( Vector3 v, float min, float max )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); - float min = lua_tonumber( L, 2 ); - float max = lua_tonumber( L, 3 ); + float min = luaL_checknumber( L, 2 ); + float max = luaL_checknumber( L, 3 ); uluaPushVector3( L, Vector3ClampValue( v, min, max ) ); @@ -1440,15 +1073,9 @@ int lmathVector3ClampValue( lua_State *L ) { Check whether two given vectors are almost equal -- Failure return false - Success return int */ int lmathVector3Equals( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.Vector3Equals( Vector3 v1, Vector3 v2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v1 = uluaGetVector3Index( L, 1 ); Vector3 v2 = uluaGetVector3Index( L, 2 ); @@ -1467,18 +1094,12 @@ and r specifies the ratio of the refractive index of the medium from where the ray comes to the refractive index of the medium on the other side of the surface -- Failure return false - Success return Vector3 */ int lmathVector3Refract( 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.Vector3Refract( Vector3 v, Vector3 n, float r )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); Vector3 n = uluaGetVector3Index( L, 2 ); - float r = lua_tonumber( L, 3 ); + float r = luaL_checknumber( L, 3 ); uluaPushVector3( L, Vector3Refract( v, n, r ) ); @@ -1494,15 +1115,9 @@ int lmathVector3Refract( lua_State *L ) { Compute matrix determinant -- Failure return false - Success return float */ int lmathMatrixDeterminant( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixDeterminant( Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat = uluaGetMatrixIndex( L, 1 ); lua_pushnumber( L, MatrixDeterminant( mat ) ); @@ -1513,17 +1128,11 @@ int lmathMatrixDeterminant( lua_State *L ) { /* > result = RL.MatrixTrace( Matrix mat ) -Get the trace of the matrix ( sum of the values along the diagonal ) +Get the trace of the matrix (sum of the values along the diagonal) -- Failure return false - Success return float */ int lmathMatrixTrace( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixTrace( Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat = uluaGetMatrixIndex( L, 1 ); lua_pushnumber( L, MatrixTrace( mat ) ); @@ -1536,15 +1145,9 @@ int lmathMatrixTrace( lua_State *L ) { Transposes provided matrix -- Failure return false - Success return Matrix */ int lmathMatrixTranspose( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixTranspose( Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat = uluaGetMatrixIndex( L, 1 ); uluaPushMatrix( L, MatrixTranspose( mat ) ); @@ -1557,15 +1160,9 @@ int lmathMatrixTranspose( lua_State *L ) { Invert provided matrix -- Failure return false - Success return Matrix */ int lmathMatrixInvert( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixInvert( Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat = uluaGetMatrixIndex( L, 1 ); uluaPushMatrix( L, MatrixInvert( mat ) ); @@ -1591,15 +1188,9 @@ int lmathMatrixIdentity( lua_State *L ) { Add two matrices -- Failure return false - Success return Matrix */ int lmathMatrixAdd( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixAdd( Matrix left, Matrix right )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat1 = uluaGetMatrixIndex( L, 1 ); Matrix mat2 = uluaGetMatrixIndex( L, 2 ); @@ -1613,15 +1204,9 @@ int lmathMatrixAdd( lua_State *L ) { Subtract two matrices (left - right) -- Failure return false - Success return Matrix */ int lmathMatrixSubtract( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixSubtract( Matrix left, Matrix right )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat1 = uluaGetMatrixIndex( L, 1 ); Matrix mat2 = uluaGetMatrixIndex( L, 2 ); @@ -1635,15 +1220,9 @@ int lmathMatrixSubtract( lua_State *L ) { Get two matrix multiplication -- Failure return false - Success return Matrix */ int lmathMatrixMultiply( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixMultiply( Matrix left, Matrix right )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat1 = uluaGetMatrixIndex( L, 1 ); Matrix mat2 = uluaGetMatrixIndex( L, 2 ); @@ -1657,15 +1236,9 @@ int lmathMatrixMultiply( lua_State *L ) { Get translation matrix -- Failure return false - Success return Matrix */ int lmathMatrixTranslate( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixTranslate( Vector3 translate )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); uluaPushMatrix( L, MatrixTranslate( v.x, v.y, v.z ) ); @@ -1678,17 +1251,11 @@ int lmathMatrixTranslate( lua_State *L ) { Create rotation matrix from axis and angle. NOTE: Angle should be provided in radians -- Failure return false - Success return Matrix */ int lmathMatrixRotate( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixRotate( Vector3 axis, float angle )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 axis = uluaGetVector3Index( L, 1 ); - float angle = lua_tonumber( L, 2 ); + float angle = luaL_checknumber( L, 2 ); uluaPushMatrix( L, MatrixRotate( axis, angle ) ); @@ -1698,18 +1265,12 @@ int lmathMatrixRotate( lua_State *L ) { /* > result = RL.MatrixRotateX( float angle ) -Get x-rotation matrix ( angle in radians ) +Get x-rotation matrix (angle in radians) -- Failure return false - Success return Matrix */ int lmathMatrixRotateX( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixRotateX( float angle )" ); - lua_pushboolean( L, false ); - return 1; - } - float angle = lua_tonumber( L, 1 ); + float angle = luaL_checknumber( L, 1 ); uluaPushMatrix( L, MatrixRotateX( angle ) ); @@ -1719,18 +1280,12 @@ int lmathMatrixRotateX( lua_State *L ) { /* > result = RL.MatrixRotateY( float angle ) -Get y-rotation matrix ( angle in radians ) +Get y-rotation matrix (angle in radians) -- Failure return false - Success return Matrix */ int lmathMatrixRotateY( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixRotateY( float angle )" ); - lua_pushboolean( L, false ); - return 1; - } - float angle = lua_tonumber( L, 1 ); + float angle = luaL_checknumber( L, 1 ); uluaPushMatrix( L, MatrixRotateY( angle ) ); @@ -1740,18 +1295,12 @@ int lmathMatrixRotateY( lua_State *L ) { /* > result = RL.MatrixRotateZ( float angle ) -Get z-rotation matrix ( angle in radians ) +Get z-rotation matrix (angle in radians) -- Failure return false - Success return Matrix */ int lmathMatrixRotateZ( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixRotateZ( float angle )" ); - lua_pushboolean( L, false ); - return 1; - } - float angle = lua_tonumber( L, 1 ); + float angle = luaL_checknumber( L, 1 ); uluaPushMatrix( L, MatrixRotateZ( angle ) ); @@ -1761,17 +1310,11 @@ int lmathMatrixRotateZ( lua_State *L ) { /* > result = RL.MatrixRotateXYZ( Vector3 angle ) -Get xyz-rotation matrix ( angles in radians ) +Get xyz-rotation matrix (angles in radians) -- Failure return false - Success return Matrix */ int lmathMatrixRotateXYZ( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixRotateXYZ( Vector3 angle )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 angle = uluaGetVector3Index( L, 1 ); uluaPushMatrix( L, MatrixRotateXYZ( angle ) ); @@ -1782,17 +1325,11 @@ int lmathMatrixRotateXYZ( lua_State *L ) { /* > result = RL.MatrixRotateZYX( Vector3 angle ) -Get zyx-rotation matrix ( angles in radians ) +Get zyx-rotation matrix (angles in radians) -- Failure return false - Success return Matrix */ int lmathMatrixRotateZYX( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixRotateZYX( Vector3 angle )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 angle = uluaGetVector3Index( L, 1 ); uluaPushMatrix( L, MatrixRotateZYX( angle ) ); @@ -1805,15 +1342,9 @@ int lmathMatrixRotateZYX( lua_State *L ) { Get scaling matrix -- Failure return false - Success return Matrix */ int lmathMatrixScale( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixScale( Vector3 scale )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 v = uluaGetVector3Index( L, 1 ); uluaPushMatrix( L, MatrixScale( v.x, v.y, v.z ) ); @@ -1826,22 +1357,15 @@ int lmathMatrixScale( lua_State *L ) { Get perspective projection matrix -- Failure return false - Success return Matrix */ int lmathMatrixFrustum( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixFrustum( double left, double right, double bottom, double top, double near, double far )" ); - lua_pushboolean( L, false ); - return 1; - } - float left = lua_tonumber( L, 1 ); - float right = lua_tonumber( L, 2); - float bottom = lua_tonumber( L, 3 ); - float top = lua_tonumber( L, 4 ); - float near = lua_tonumber( L, 5 ); - float far = lua_tonumber( L, 6 ); + float left = luaL_checknumber( L, 1 ); + float right = luaL_checknumber( L, 2); + float bottom = luaL_checknumber( L, 3 ); + float top = luaL_checknumber( L, 4 ); + float near = luaL_checknumber( L, 5 ); + float far = luaL_checknumber( L, 6 ); uluaPushMatrix( L, MatrixFrustum( left, right, bottom, top, near, far ) ); @@ -1853,19 +1377,13 @@ int lmathMatrixFrustum( lua_State *L ) { Get perspective projection matrix -- Failure return false - Success return Matrix */ int lmathMatrixPerspective( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixPerspective( double fovy, double aspect, double near, double far )" ); - lua_pushboolean( L, false ); - return 1; - } - float fovy = lua_tonumber( L, 1 ); - float aspect = lua_tonumber( L, 2 ); - float near = lua_tonumber( L, 3 ); - float far = lua_tonumber( L, 4 ); + float fovy = luaL_checknumber( L, 1 ); + float aspect = luaL_checknumber( L, 2 ); + float near = luaL_checknumber( L, 3 ); + float far = luaL_checknumber( L, 4 ); uluaPushMatrix( L, MatrixPerspective( fovy, aspect, near, far ) ); @@ -1877,22 +1395,15 @@ int lmathMatrixPerspective( lua_State *L ) { Get orthographic projection matrix -- Failure return false - Success return Matrix */ int lmathMatrixOrtho( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MatrixOrtho( double left, double right, double bottom, double top, double near, double far )" ); - lua_pushboolean( L, false ); - return 1; - } - float left = lua_tonumber( L, 1 ); - float right = lua_tonumber( L, 2 ); - float bottom = lua_tonumber( L, 3 ); - float top = lua_tonumber( L, 4 ); - float near = lua_tonumber( L, 5 ); - float far = lua_tonumber( L, 6 ); + float left = luaL_checknumber( L, 1 ); + float right = luaL_checknumber( L, 2 ); + float bottom = luaL_checknumber( L, 3 ); + float top = luaL_checknumber( L, 4 ); + float near = luaL_checknumber( L, 5 ); + float far = luaL_checknumber( L, 6 ); uluaPushMatrix( L, MatrixOrtho( left, right, bottom, top, near, far ) ); @@ -1902,17 +1413,11 @@ int lmathMatrixOrtho( lua_State *L ) { /* > result = RL.MatrixLookAt( Vector3 eye, Vector3 target, Vector3 up ) -Get camera look-at matrix ( View matrix ) +Get camera look-at matrix (View matrix) -- Failure return false - Success return Matrix */ int lmathMatrixLookAt( 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.MatrixLookAt( Vector3 eye, Vector3 target, Vector3 up )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 eye = uluaGetVector3Index( L, 1 ); Vector3 target = uluaGetVector3Index( L, 2 ); Vector3 up = uluaGetVector3Index( L, 3 ); @@ -1931,15 +1436,9 @@ int lmathMatrixLookAt( lua_State *L ) { Add two quaternions -- Failure return false - Success return Quaternion */ int lmathQuaternionAdd( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionAdd( Quaternion q1, Quaternion q2 )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); @@ -1953,17 +1452,11 @@ int lmathQuaternionAdd( lua_State *L ) { Add quaternion and float value -- Failure return false - Success return Quaternion */ int lmathQuaternionAddValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionAddValue( Quaternion q, float add )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); - float add = lua_tonumber( L, 2 ); + float add = luaL_checknumber( L, 2 ); uluaPushQuaternion( L, QuaternionAddValue( q, add ) ); @@ -1975,15 +1468,9 @@ int lmathQuaternionAddValue( lua_State *L ) { Subtract two quaternions -- Failure return false - Success return Quaternion */ int lmathQuaternionSubtract( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionSubtract( Quaternion q1, Quaternion q2 )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); @@ -1997,17 +1484,11 @@ int lmathQuaternionSubtract( lua_State *L ) { Subtract quaternion and float value -- Failure return false - Success return Quaternion */ int lmathQuaternionSubtractValue( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionSubtractValue( Quaternion q, float sub )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); - float sub = lua_tonumber( L, 2 ); + float sub = luaL_checknumber( L, 2 ); uluaPushQuaternion( L, QuaternionSubtractValue( q, sub ) ); @@ -2032,15 +1513,9 @@ int lmathQuaternionIdentity( lua_State *L ) { Computes the length of a quaternion -- Failure return false - Success return float */ int lmathQuaternionLength( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionLength( Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); lua_pushnumber( L, QuaternionLength( q ) ); @@ -2053,15 +1528,9 @@ int lmathQuaternionLength( lua_State *L ) { Normalize provided quaternion -- Failure return false - Success return Quaternion */ int lmathQuaternionNormalize( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionNormalize( Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); uluaPushQuaternion( L, QuaternionNormalize( q ) ); @@ -2074,15 +1543,9 @@ int lmathQuaternionNormalize( lua_State *L ) { Invert provided quaternion -- Failure return false - Success return Quaternion */ int lmathQuaternionInvert( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionInvert( Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); uluaPushQuaternion( L, QuaternionInvert( q ) ); @@ -2095,15 +1558,9 @@ int lmathQuaternionInvert( lua_State *L ) { Calculate two quaternion multiplication -- Failure return false - Success return Quaternion */ int lmathQuaternionMultiply( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionMultiply( Quaternion q1, Quaternion q2 )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); @@ -2117,17 +1574,11 @@ int lmathQuaternionMultiply( lua_State *L ) { Scale quaternion by float value -- Failure return false - Success return Quaternion */ int lmathQuaternionScale( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionScale( Quaternion q, float mul )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); - float mul = lua_tonumber( L, 2 ); + float mul = luaL_checknumber( L, 2 ); uluaPushQuaternion( L, QuaternionScale( q, mul ) ); @@ -2139,15 +1590,9 @@ int lmathQuaternionScale( lua_State *L ) { Divide two quaternions -- Failure return false - Success return Quaternion */ int lmathQuaternionDivide( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionDivide( Quaternion q1, Quaternion q2 )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); @@ -2161,18 +1606,12 @@ int lmathQuaternionDivide( lua_State *L ) { Calculate linear interpolation between two quaternions -- Failure return false - Success return Quaternion */ int lmathQuaternionLerp( 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.QuaternionLerp( Quaternion q1, Quaternion q2, float amount )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); - float amount = lua_tonumber( L, 3 ); + float amount = luaL_checknumber( L, 3 ); uluaPushQuaternion( L, QuaternionLerp( q1, q2, amount ) ); @@ -2184,18 +1623,12 @@ int lmathQuaternionLerp( lua_State *L ) { Calculate slerp-optimized interpolation between two quaternions -- Failure return false - Success return Quaternion */ int lmathQuaternionNlerp( 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.QuaternionNlerp( Quaternion q1, Quaternion q2, float amount )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); - float amount = lua_tonumber( L, 3 ); + float amount = luaL_checknumber( L, 3 ); uluaPushQuaternion( L, QuaternionNlerp( q1, q2, amount ) ); @@ -2207,18 +1640,12 @@ int lmathQuaternionNlerp( lua_State *L ) { Calculates spherical linear interpolation between two quaternions -- Failure return false - Success return Quaternion */ int lmathQuaternionSlerp( 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.QuaternionSlerp( Quaternion q1, Quaternion q2, float amount )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); - float amount = lua_tonumber( L, 3 ); + float amount = luaL_checknumber( L, 3 ); uluaPushQuaternion( L, QuaternionSlerp( q1, q2, amount ) ); @@ -2230,15 +1657,9 @@ int lmathQuaternionSlerp( lua_State *L ) { Calculate quaternion based on the rotation from one vector to another -- Failure return false - Success return Quaternion */ int lmathQuaternionFromVector3ToVector3( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionFromVector3ToVector3( Vector3 from, Vector3 to )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 from = uluaGetVector3Index( L, 1 ); Vector3 to = uluaGetVector3Index( L, 2 ); @@ -2252,15 +1673,9 @@ int lmathQuaternionFromVector3ToVector3( lua_State *L ) { Get a quaternion for a given rotation matrix -- Failure return false - Success return Quaternion */ int lmathQuaternionFromMatrix( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionFromMatrix( Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Matrix mat = uluaGetMatrixIndex( L, 1 ); uluaPushQuaternion( L, QuaternionFromMatrix( mat ) ); @@ -2273,15 +1688,9 @@ int lmathQuaternionFromMatrix( lua_State *L ) { Get a quaternion for a given rotation matrix -- Failure return false - Success return Matrix */ int lmathQuaternionToMatrix( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionToMatrix( Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); uluaPushMatrix( L, QuaternionToMatrix( q ) ); @@ -2295,17 +1704,11 @@ int lmathQuaternionToMatrix( lua_State *L ) { Get rotation quaternion for an angle and axis NOTE: angle must be provided in radians -- Failure return false - Success return Quaternion */ int lmathQuaternionFromAxisAngle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionFromAxisAngle( Vector3 axis, float angle )" ); - lua_pushboolean( L, false ); - return 1; - } Vector3 axis = uluaGetVector3Index( L, 1 ); - float angle = lua_tonumber( L, 2 ); + float angle = luaL_checknumber( L, 2 ); uluaPushQuaternion( L, QuaternionFromAxisAngle( axis, angle ) ); @@ -2317,15 +1720,9 @@ int lmathQuaternionFromAxisAngle( lua_State *L ) { Get the rotation angle and axis for a given quaternion -- Failure return false - Success return Vector3, float */ int lmathQuaternionToAxisAngle( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionToAxisAngle( Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); float angle = 0.0; Vector3 axis = { 0.0 }; @@ -2344,18 +1741,12 @@ int lmathQuaternionToAxisAngle( lua_State *L ) { Get the quaternion equivalent to Euler angles NOTE: Rotation order is ZYX -- Failure return false - Success return Quaternion */ int lmathQuaternionFromEuler( 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.QuaternionFromEuler( float pitch, float yaw, float roll )" ); - lua_pushboolean( L, false ); - return 1; - } - float pitch = lua_tonumber( L, 1 ); - float yaw = lua_tonumber( L, 2 ); - float roll = lua_tonumber( L, 3 ); + float pitch = luaL_checknumber( L, 1 ); + float yaw = luaL_checknumber( L, 2 ); + float roll = luaL_checknumber( L, 3 ); uluaPushQuaternion( L, QuaternionFromEuler( pitch, yaw, roll ) ); @@ -2368,15 +1759,9 @@ int lmathQuaternionFromEuler( lua_State *L ) { Get the Euler angles equivalent to quaternion (roll, pitch, yaw) NOTE: Angles are returned in a Vector3 struct in radians -- Failure return false - Success return Vector3 */ int lmathQuaternionToEuler( lua_State *L ) { - if ( !lua_istable( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionToEuler( Quaternion q )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); uluaPushVector3( L, QuaternionToEuler( q ) ); @@ -2389,15 +1774,9 @@ int lmathQuaternionToEuler( lua_State *L ) { Transform a quaternion given a transformation matrix -- Failure return false - Success return Quaternion */ int lmathQuaternionTransform( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionTransform( Quaternion q, Matrix mat )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q = uluaGetQuaternionIndex( L, 1 ); Matrix mat = uluaGetMatrixIndex( L, 2 ); @@ -2411,15 +1790,9 @@ int lmathQuaternionTransform( lua_State *L ) { Check whether two given quaternions are almost equal -- Failure return false - Success return int */ int lmathQuaternionEquals( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.QuaternionEquals( Quaternion q1, Quaternion q2 )" ); - lua_pushboolean( L, false ); - return 1; - } Quaternion q1 = uluaGetQuaternionIndex( L, 1 ); Quaternion q2 = uluaGetQuaternionIndex( L, 2 ); diff --git a/src/shapes.c b/src/shapes.c index 876520a..ed2af7a 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -25,147 +25,92 @@ int lshapesSetShapesTexture( lua_State *L ) { } /* -> success = RL.DrawPixel( Vector2 pos, Color color ) +> RL.DrawPixel( Vector2 pos, Color color ) Draw a pixel - -- Failure return false -- Success return true */ int lshapesDrawPixel( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawPixel( Vector2 pos, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 pos = uluaGetVector2Index( L, 1 ); Color color = uluaGetColorIndex( L, 2 ); DrawPixelV( pos, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color ) +> RL.DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color ) Draw a line defining thickness - -- Failure return false -- Success return true */ int lshapesDrawLine( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 startPos = uluaGetVector2Index( L, 1 ); Vector2 endPos = uluaGetVector2Index( L, 2 ); - float thickness = lua_tonumber( L, 3 ); + float thickness = luaL_checknumber( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawLineEx( startPos, endPos, thickness, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawLineBezier( Vector2 startPos, Vector2 endPos, float thickness, Color color ) +> RL.DrawLineBezier( Vector2 startPos, Vector2 endPos, float thickness, Color color ) Draw a line using cubic-bezier curves in-out - -- Failure return false -- Success return true */ int lshapesDrawLineBezier( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawLineBezier( Vector2 startPos, Vector2 endPos, float thickness, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 startPos = uluaGetVector2Index( L, 1 ); Vector2 endPos = uluaGetVector2Index( L, 2 ); - float thickness = lua_tonumber( L, 3 ); + float thickness = luaL_checknumber( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawLineBezier( startPos, endPos, thickness, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawLineBezierQuad( Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thickness, Color color ) +> RL.DrawLineBezierQuad( Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thickness, Color color ) Draw line using quadratic bezier curves with a control point - -- Failure return false -- Success return true */ int lshapesDrawLineBezierQuad( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawLineBezier( Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thickness, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 startPos = uluaGetVector2Index( L, 1 ); Vector2 endPos = uluaGetVector2Index( L, 2 ); Vector2 controlPos = uluaGetVector2Index( L, 3 ); - float thickness = lua_tonumber( L, 4 ); + float thickness = luaL_checknumber( L, 4 ); Color color = uluaGetColorIndex( L, 5 ); DrawLineBezierQuad( startPos, endPos, controlPos, thickness, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawLineBezierCubic( Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thickness, Color color ) +> RL.DrawLineBezierCubic( Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thickness, Color color ) Draw line using quadratic bezier curves with a control point - -- Failure return false -- Success return true */ int lshapesDrawLineBezierCubic( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !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.DrawLineBezierCubic( Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thickness, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 startPos = uluaGetVector2Index( L, 1 ); Vector2 endPos = uluaGetVector2Index( L, 2 ); Vector2 startControlPos = uluaGetVector2Index( L, 3 ); Vector2 endControlPos = uluaGetVector2Index( L, 4 ); - float thickness = lua_tonumber( L, 5 ); + float thickness = luaL_checknumber( L, 5 ); Color color = uluaGetColorIndex( L, 6 ); DrawLineBezierCubic( startPos, endPos, startControlPos, endControlPos, thickness, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawLineStrip( Vector2{} points, Color color ) +> RL.DrawLineStrip( Vector2{} points, Color color ) Draw lines sequence - -- Failure return false -- Success return true */ int lshapesDrawLineStrip( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawLineStrip( Vector2{} points, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } int pointsCount = uluaGetTableLenIndex( L, 1 ); Color color = uluaGetColorIndex( L, 2 ); @@ -180,361 +125,229 @@ int lshapesDrawLineStrip( lua_State *L ) { i++; lua_pop( L, 1 ); } - DrawLineStrip( points, pointsCount, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawCircle( Vector2 center, float radius, Color color ) +> RL.DrawCircle( Vector2 center, float radius, Color color ) Draw a color-filled circle - -- Failure return false -- Success return true */ int lshapesDrawCircle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCircle( Vector2 center, float radius, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radius = lua_tonumber( L, 2 ); + float radius = luaL_checknumber( L, 2 ); Color color = uluaGetColorIndex( L, 3 ); DrawCircleV( center, radius, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawCircleSector( Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color ) +> RL.DrawCircleSector( Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color ) Draw a piece of a circle - -- Failure return false -- Success return true */ int lshapesDrawCircleSector( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || - !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCircleSector( Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radius = lua_tonumber( L, 2 ); - float startAngle = lua_tonumber( L, 3 ); - float endAngle = lua_tonumber( L, 4 ); - int segments = lua_tointeger( L, 5 ); + float radius = luaL_checknumber( L, 2 ); + float startAngle = luaL_checknumber( L, 3 ); + float endAngle = luaL_checknumber( L, 4 ); + int segments = luaL_checkinteger( L, 5 ); Color color = uluaGetColorIndex( L, 6 ); DrawCircleSector( center, radius, startAngle, endAngle, segments, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawCircleSectorLines( Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color ) +> RL.DrawCircleSectorLines( Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color ) Draw circle sector outline - -- Failure return false -- Success return true */ int lshapesDrawCircleSectorLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || - !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCircleSectorLines( Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radius = lua_tonumber( L, 2 ); - float startAngle = lua_tonumber( L, 3 ); - float endAngle = lua_tonumber( L, 4 ); - int segments = lua_tointeger( L, 5 ); + float radius = luaL_checknumber( L, 2 ); + float startAngle = luaL_checknumber( L, 3 ); + float endAngle = luaL_checknumber( L, 4 ); + int segments = luaL_checkinteger( L, 5 ); Color color = uluaGetColorIndex( L, 6 ); DrawCircleSectorLines( center, radius, startAngle, endAngle, segments, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawCircleGradient( Vector2 center, float radius, Color color1, Color color2 ) +> RL.DrawCircleGradient( Vector2 center, float radius, Color color1, Color color2 ) Draw a gradient-filled circle - -- Failure return false -- Success return true */ int lshapesDrawCircleGradient( 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.DrawCircleGradient( Vector2 center, float radius, Color color1, Color color2 )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radius = lua_tonumber( L, 2 ); + float radius = luaL_checknumber( L, 2 ); Color color1 = uluaGetColorIndex( L, 3 ); Color color2 = uluaGetColorIndex( L, 4 ); DrawCircleGradient( center.x, center.y, radius, color1, color2 ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawCircleLines( Vector2 center, float radius, Color color ) +> RL.DrawCircleLines( Vector2 center, float radius, Color color ) Draw circle outline - -- Failure return false -- Success return true */ int lshapesDrawCircleLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCircleLines( Vector2 center, float radius, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radius = lua_tonumber( L, 2 ); + float radius = luaL_checknumber( L, 2 ); Color color = uluaGetColorIndex( L, 3 ); DrawCircleLines( center.x, center.y, radius, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawEllipse( Vector2 center, float radiusH, float radiusV, Color color ) +> RL.DrawEllipse( Vector2 center, float radiusH, float radiusV, Color color ) Draw ellipse - -- Failure return false -- Success return true */ int lshapesDrawEllipse( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawEllipse( Vector2 center, float radiusH, float radiusV, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radiusH = lua_tonumber( L, 2 ); - float radiusV = lua_tonumber( L, 3 ); + float radiusH = luaL_checknumber( L, 2 ); + float radiusV = luaL_checknumber( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawEllipse( center.x, center.y, radiusH, radiusV, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawEllipseLines( Vector2 center, float radiusH, float radiusV, Color color ) +> RL.DrawEllipseLines( Vector2 center, float radiusH, float radiusV, Color color ) Draw ellipse outline - -- Failure return false -- Success return true */ int lshapesDrawEllipseLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawEllipseLines( Vector2 center, float radiusH, float radiusV, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radiusH = lua_tonumber( L, 2 ); - float radiusV = lua_tonumber( L, 3 ); + float radiusH = luaL_checknumber( L, 2 ); + float radiusV = luaL_checknumber( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawEllipseLines( center.x, center.y, radiusH, radiusV, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRing( Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color ) +> RL.DrawRing( Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color ) Draw ring - -- Failure return false -- Success return true */ int lshapesDrawRing( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) || - !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_istable( L, 7 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRing( Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float innerRadius = lua_tonumber( L, 2 ); - float outerRadius = lua_tonumber( L, 3 ); - float startAngle = lua_tonumber( L, 4 ); - float endAngle = lua_tonumber( L, 5 ); - int segments = lua_tointeger( L, 6 ); + float innerRadius = luaL_checknumber( L, 2 ); + float outerRadius = luaL_checknumber( L, 3 ); + float startAngle = luaL_checknumber( L, 4 ); + float endAngle = luaL_checknumber( L, 5 ); + int segments = luaL_checkinteger( L, 6 ); Color color = uluaGetColorIndex( L, 7 ); DrawRing( center, innerRadius, outerRadius, startAngle, endAngle, segments, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRingLines( Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color ) +> RL.DrawRingLines( Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color ) Draw ring outline - -- Failure return false -- Success return true */ int lshapesDrawRingLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) || - !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_istable( L, 7 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRingLines( Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float innerRadius = lua_tonumber( L, 2 ); - float outerRadius = lua_tonumber( L, 3 ); - float startAngle = lua_tonumber( L, 4 ); - float endAngle = lua_tonumber( L, 5 ); - int segments = lua_tointeger( L, 6 ); + float innerRadius = luaL_checknumber( L, 2 ); + float outerRadius = luaL_checknumber( L, 3 ); + float startAngle = luaL_checknumber( L, 4 ); + float endAngle = luaL_checknumber( L, 5 ); + int segments = luaL_checkinteger( L, 6 ); Color color = uluaGetColorIndex( L, 7 ); DrawRingLines( center, innerRadius, outerRadius, startAngle, endAngle, segments, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangle( Rectangle rec, Color color ) +> RL.DrawRectangle( Rectangle rec, Color color ) Draw a color-filled rectangle - -- Failure return false -- Success return true */ int lshapesDrawRectangle( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectangle( Rectangle rec, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); Color color = uluaGetColorIndex( L, 2 ); DrawRectangleRec( rect, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color ) +> RL.DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color ) Draw a color-filled rectangle with pro parameters - -- Failure return false -- Success return true */ int lshapesDrawRectanglePro( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rec = uluaGetRectangleIndex( L, 1 ); Vector2 origin = uluaGetVector2Index( L, 2 ); - float rotation = lua_tonumber( L, 3 ); + float rotation = luaL_checknumber( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawRectanglePro( rec, origin, rotation, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleGradientV( Rectangle rectangle, Color color1, Color color2 ) +> RL.DrawRectangleGradientV( Rectangle rectangle, Color color1, Color color2 ) Draw a vertical-gradient-filled rectangle - -- Failure return false -- Success return true */ int lshapesDrawRectangleGradientV( 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.DrawRectangleGradientV( Rectangle rectangle, Color color1, Color color2 )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); Color color1 = uluaGetColorIndex( L, 2 ); Color color2 = uluaGetColorIndex( L, 3 ); DrawRectangleGradientV( rect.x, rect.y, rect.width, rect.height, color1, color2 ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleGradientH( Rectangle rectangle, Color color1, Color color2 ) +> RL.DrawRectangleGradientH( Rectangle rectangle, Color color1, Color color2 ) Draw a horizontal-gradient-filled rectangle - -- Failure return false -- Success return true */ int lshapesDrawRectangleGradientH( 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.DrawRectangleGradientH( Rectangle rectangle, Color color1, Color color2 )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); Color color1 = uluaGetColorIndex( L, 2 ); Color color2 = uluaGetColorIndex( L, 3 ); DrawRectangleGradientH( rect.x, rect.y, rect.width, rect.height, color1, color2 ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleGradientEx( Rectangle rectangle, Color col1, Color col2, Color col3, Color col4 ) +> RL.DrawRectangleGradientEx( Rectangle rectangle, Color col1, Color col2, Color col3, Color col4 ) Draw a gradient-filled rectangle with custom vertex colors - -- Failure return false -- Success return true */ int lshapesDrawRectangleGradientEx( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) - || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectangleGradientEx( Rectangle rectangle, Color col1, Color col2, Color col3, Color col4 )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); Color color1 = uluaGetColorIndex( L, 2 ); Color color2 = uluaGetColorIndex( L, 3 ); @@ -542,174 +355,110 @@ int lshapesDrawRectangleGradientEx( lua_State *L ) { Color color4 = uluaGetColorIndex( L, 5 ); DrawRectangleGradientEx( rect, color1, color2, color3, color4 ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleLines( Rectangle rec, Color color ) +> RL.DrawRectangleLines( Rectangle rec, Color color ) Draw rectangle outline - -- Failure return false -- Success return true */ int lshapesDrawRectangleLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectangleLines( Rectangle rec, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); Color color = uluaGetColorIndex( L, 2 ); DrawRectangleLines( rect.x, rect.y, rect.width, rect.height, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleLinesEx( Rectangle rec, int lineThick, Color color ) +> RL.DrawRectangleLinesEx( Rectangle rec, int lineThick, Color color ) Draw rectangle outline with extended parameters - -- Failure return false -- Success return true */ int lshapesDrawRectangleLinesEx( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectangleLinesEx( Rectangle rec, int lineThick, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); - int lineThick = lua_tointeger( L, 2 ); + int lineThick = luaL_checkinteger( L, 2 ); Color color = uluaGetColorIndex( L, 3 ); DrawRectangleLinesEx( rect, lineThick, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleRounded( Rectangle rec, float roundness, int segments, Color color ) +> RL.DrawRectangleRounded( Rectangle rec, float roundness, int segments, Color color ) Draw rectangle with rounded edges - -- Failure return false -- Success return true */ int lshapesDrawRectangleRounded( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectangleRounded( Rectangle rec, float roundness, int segments, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); - float roundness = lua_tonumber( L, 2 ); - int segments = lua_tointeger( L, 3 ); + float roundness = luaL_checknumber( L, 2 ); + int segments = luaL_checkinteger( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawRectangleRounded( rect, roundness, segments, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawRectangleRoundedLines( Rectangle rec, float roundness, int segments, int lineThick, Color color ) +> RL.DrawRectangleRoundedLines( Rectangle rec, float roundness, int segments, int lineThick, Color color ) Draw rectangle with rounded edges outline - -- Failure return false -- Success return true */ int lshapesDrawRectangleRoundedLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRectangleRoundedLines( Rectangle rec, float roundness, int segments, int lineThick, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Rectangle rect = uluaGetRectangleIndex( L, 1 ); - float roundness = lua_tonumber( L, 2 ); - int segments = lua_tointeger( L, 3 ); - int lineThick = lua_tointeger( L, 4 ); + float roundness = luaL_checknumber( L, 2 ); + int segments = luaL_checkinteger( L, 3 ); + int lineThick = luaL_checkinteger( L, 4 ); Color color = uluaGetColorIndex( L, 5 ); DrawRectangleRoundedLines( rect, roundness, segments, lineThick, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color ) +> RL.DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color ) -Draw a color-filled triangle ( Vertex in counter-clockwise order! ) - -- Failure return false -- Success return true +Draw a color-filled triangle (Vertex in counter-clockwise order!) */ int lshapesDrawTriangle( 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.DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); Vector2 v3 = uluaGetVector2Index( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawTriangle( v1, v2, v3, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color ) +> RL.DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color ) -Draw triangle outline ( Vertex in counter-clockwise order! ) - -- Failure return false -- Success return true +Draw triangle outline (Vertex in counter-clockwise order!) */ int lshapesDrawTriangleLines( 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.DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 v1 = uluaGetVector2Index( L, 1 ); Vector2 v2 = uluaGetVector2Index( L, 2 ); Vector2 v3 = uluaGetVector2Index( L, 3 ); Color color = uluaGetColorIndex( L, 4 ); DrawTriangleLines( v1, v2, v3, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawTriangleFan( Vector2{} points, Color color ) - -Draw a triangle fan defined by points ( first vertex is the center ) +> RL.DrawTriangleFan( Vector2{} points, Color color ) -- Failure return false -- Success return true +Draw a triangle fan defined by points (first vertex is the center) */ int lshapesDrawTriangleFan( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTriangleFan( Vector2{} points, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } int pointsCount = uluaGetTableLenIndex( L, 1 ); Color color = uluaGetColorIndex( L, 2 ); @@ -724,27 +473,17 @@ int lshapesDrawTriangleFan( lua_State *L ) { i++; lua_pop( L, 1 ); } - DrawTriangleFan( points, pointsCount, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawTriangleStrip( Vector2{} points, Color color ) +> RL.DrawTriangleStrip( Vector2{} points, Color color ) Draw a triangle strip defined by points - -- Failure return false -- Success return true */ int lshapesDrawTriangleStrip( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTriangleStrip( Vector2{} points, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } int pointsCount = uluaGetTableLenIndex( L, 1 ); Color color = uluaGetColorIndex( L, 2 ); @@ -759,93 +498,61 @@ int lshapesDrawTriangleStrip( lua_State *L ) { i++; lua_pop( L, 1 ); } - DrawTriangleStrip( points, pointsCount, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawPoly( Vector2 center, int sides, float radius, float rotation, Color color ) - -Draw a regular polygon ( Vector version ) +> RL.DrawPoly( Vector2 center, int sides, float radius, float rotation, Color color ) -- Failure return false -- Success return true +Draw a regular polygon (Vector version) */ int lshapesDrawPoly( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawPoly( Vector2 center, int sides, float radius, float rotation, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - int sides = lua_tointeger( L, 2 ); - float radius = lua_tonumber( L, 3 ); - float rotation = lua_tonumber( L, 4 ); + int sides = luaL_checkinteger( L, 2 ); + float radius = luaL_checknumber( L, 3 ); + float rotation = luaL_checknumber( L, 4 ); Color color = uluaGetColorIndex( L, 5 ); DrawPoly( center, sides, radius, rotation, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawPolyLines( Vector2 center, int sides, float radius, float rotation, Color color ) +> RL.DrawPolyLines( Vector2 center, int sides, float radius, float rotation, Color color ) Draw a polygon outline of n sides - -- Failure return false -- Success return true */ int lshapesDrawPolyLines( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) - || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawPolyLines( Vector2 center, int sides, float radius, float rotation, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - int sides = lua_tointeger( L, 2 ); - float radius = lua_tonumber( L, 3 ); - float rotation = lua_tonumber( L, 4 ); + int sides = luaL_checkinteger( L, 2 ); + float radius = luaL_checknumber( L, 3 ); + float rotation = luaL_checknumber( L, 4 ); Color color = uluaGetColorIndex( L, 5 ); DrawPolyLines( center, sides, radius, rotation, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* -> success = RL.DrawPolyLinesEx( Vector2 center, int sides, float radius, float rotation, float lineThick, Color color ) +> RL.DrawPolyLinesEx( Vector2 center, int sides, float radius, float rotation, float lineThick, Color color ) Draw a polygon outline of n sides with extended parameters - -- Failure return false -- Success return true */ int lshapesDrawPolyLinesEx( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || - !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawPolyLinesEx( Vector2 center, int sides, float radius, float rotation, float lineThick, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - int sides = lua_tointeger( L, 2 ); - float radius = lua_tonumber( L, 3 ); - float rotation = lua_tonumber( L, 4 ); - float lineThick = lua_tonumber( L, 5 ); + int sides = luaL_checkinteger( L, 2 ); + float radius = luaL_checknumber( L, 3 ); + float rotation = luaL_checknumber( L, 4 ); + float lineThick = luaL_checknumber( L, 5 ); Color color = uluaGetColorIndex( L, 6 ); DrawPolyLinesEx( center, sides, radius, rotation, lineThick, color ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -857,15 +564,9 @@ int lshapesDrawPolyLinesEx( lua_State *L ) { Check collision between two rectangles -- Failure return nil - Success return bool */ int lshapesCheckCollisionRecs( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionRecs( Rectangle rec1, Rectangle rec2 )" ); - lua_pushnil( L ); - return 1; - } Rectangle rect1 = uluaGetRectangleIndex( L, 1 ); Rectangle rect2 = uluaGetRectangleIndex( L, 2 ); @@ -879,19 +580,13 @@ int lshapesCheckCollisionRecs( lua_State *L ) { Check collision between two circles -- Failure return nil - Success return bool */ int lshapesCheckCollisionCircles( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionCircles( Vector2 center1, float radius1, Vector2 center2, float radius2 )" ); - lua_pushnil( L ); - return 1; - } Vector2 center1 = uluaGetVector2Index( L, 1 ); - float radius1 = lua_tonumber( L, 2 ); + float radius1 = luaL_checknumber( L, 2 ); Vector2 center2 = uluaGetVector2Index( L, 3 ); - float radius2 = lua_tonumber( L, 4 ); + float radius2 = luaL_checknumber( L, 4 ); lua_pushboolean( L, CheckCollisionCircles( center1, radius1, center2, radius2 ) ); @@ -903,17 +598,11 @@ int lshapesCheckCollisionCircles( lua_State *L ) { Check collision between circle and rectangle -- Failure return nil - Success return bool */ int lshapesCheckCollisionCircleRec( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionCircleRec( Vector2 center, float radius, Rectangle rec )" ); - lua_pushnil( L ); - return 1; - } Vector2 center = uluaGetVector2Index( L, 1 ); - float radius = lua_tonumber( L, 2 ); + float radius = luaL_checknumber( L, 2 ); Rectangle rec = uluaGetRectangleIndex( L, 3 ); lua_pushboolean( L, CheckCollisionCircleRec( center, radius, rec ) ); @@ -926,15 +615,9 @@ int lshapesCheckCollisionCircleRec( lua_State *L ) { Check if point is inside rectangle -- Failure return nil - Success return bool */ int lshapesCheckCollisionPointRec( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionPointRec( Vector2 point, Rectangle rec )" ); - lua_pushnil( L ); - return 1; - } Vector2 point = uluaGetVector2Index( L, 1 ); Rectangle rec = uluaGetRectangleIndex( L, 2 ); @@ -948,18 +631,12 @@ int lshapesCheckCollisionPointRec( lua_State *L ) { Check if point is inside circle -- Failure return nil - Success return bool */ int lshapesCheckCollisionPointCircle( 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.CheckCollisionPointCircle( Vector2 point, Vector2 center, float radius )" ); - lua_pushnil( L ); - return 1; - } Vector2 point = uluaGetVector2Index( L, 1 ); Vector2 center = uluaGetVector2Index( L, 2 ); - float radius = lua_tonumber( L, 3 ); + float radius = luaL_checknumber( L, 3 ); lua_pushboolean( L, CheckCollisionPointCircle( point, center, radius ) ); @@ -971,15 +648,9 @@ int lshapesCheckCollisionPointCircle( lua_State *L ) { Check if point is inside a triangle -- Failure return nil - Success return bool */ int lshapesCheckCollisionPointTriangle( 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.CheckCollisionPointTriangle( Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3 )" ); - lua_pushnil( L ); - return 1; - } Vector2 point = uluaGetVector2Index( L, 1 ); Vector2 p1 = uluaGetVector2Index( L, 2 ); Vector2 p2 = uluaGetVector2Index( L, 3 ); @@ -995,15 +666,9 @@ int lshapesCheckCollisionPointTriangle( lua_State *L ) { Check if point is within a polygon described by array of vertices -- Failure return nil - Success return bool */ int lshapesCheckCollisionPointPoly( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionPointPoly( Vector2 point, Vector2{} points )" ); - lua_pushnil( L ); - return 1; - } Vector2 point = uluaGetVector2Index( L, 1 ); int pointCount = uluaGetTableLenIndex( L, 2 ); Vector2 points[ pointCount ]; @@ -1017,7 +682,6 @@ int lshapesCheckCollisionPointPoly( lua_State *L ) { i++; lua_pop( L, 1 ); } - lua_pushboolean( L, CheckCollisionPointPoly( point, points, pointCount ) ); return 1; @@ -1028,15 +692,9 @@ int lshapesCheckCollisionPointPoly( lua_State *L ) { Check the collision between two lines defined by two points each, returns collision point by reference -- Failure return nil - Success return bool, Vector2 */ int lshapesCheckCollisionLines( 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.CheckCollisionLines( Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2 )" ); - lua_pushnil( L ); - return 1; - } Vector2 startPos1 = uluaGetVector2Index( L, 1 ); Vector2 endPos1 = uluaGetVector2Index( L, 2 ); Vector2 startPos2 = uluaGetVector2Index( L, 3 ); @@ -1055,19 +713,13 @@ int lshapesCheckCollisionLines( lua_State *L ) { Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] -- Failure return nil - Success return bool */ int lshapesCheckCollisionPointLine( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionPointLine( Vector2 point, Vector2 p1, Vector2 p2, int threshold )" ); - lua_pushnil( L ); - return 1; - } Vector2 point = uluaGetVector2Index( L, 1 ); Vector2 p1 = uluaGetVector2Index( L, 2 ); Vector2 p2 = uluaGetVector2Index( L, 3 ); - int threshold = lua_tointeger( L, 4 ); + int threshold = luaL_checkinteger( L, 4 ); lua_pushboolean( L, CheckCollisionPointLine( point, p1, p2, threshold ) ); @@ -1079,15 +731,9 @@ int lshapesCheckCollisionPointLine( lua_State *L ) { Get collision rectangle for two rectangles collision -- Failure return nil - Success return Rectangle */ int lshapesGetCollisionRec( lua_State *L ) { - if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetCollisionRec( Rectangle rec1, Rectangle rec2 )" ); - lua_pushnil( L ); - return 1; - } Rectangle rec1 = uluaGetRectangleIndex( L, 1 ); Rectangle rec2 = uluaGetRectangleIndex( L, 2 ); diff --git a/src/textures.c b/src/textures.c index 2ebf9cb..aa78ce8 100644 --- a/src/textures.c +++ b/src/textures.c @@ -276,30 +276,17 @@ int ltexturesImageFromImage( lua_State *L ) { Create an image from text (custom sprite font) -- Failure return -1 -- Success return int +- Success return Image */ 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 ( !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 ); + Font *font = luaL_checkudata( L, 1, "Font" ); + float fontSize = lua_tonumber( L, 3 ); + float spacing = lua_tonumber( L, 4 ); + Color tint = uluaGetColorIndex( L, 5 ); - return 0; + uluaPushImage( L, ImageTextEx( *font, luaL_checkstring( L, 2 ), fontSize, spacing, tint ) ); + + return 1; } /* |
