summaryrefslogtreecommitdiff
path: root/src/rgui.c
diff options
context:
space:
mode:
authorjussi2023-10-29 15:21:10 +0200
committerjussi2023-10-29 15:21:10 +0200
commit0df40e2ac080364bcebd4fe0445b814230545477 (patch)
tree36be0ab558d6642352c0bb3034b6e6b32471716d /src/rgui.c
parent76911d45a879838047b2845cd6124e9ca3af083a (diff)
downloadreilua-enhanced-0df40e2ac080364bcebd4fe0445b814230545477.tar.gz
reilua-enhanced-0df40e2ac080364bcebd4fe0445b814230545477.tar.bz2
reilua-enhanced-0df40e2ac080364bcebd4fe0445b814230545477.zip
Shapes, RLGL, Math, Gui and Easings to new style.
Diffstat (limited to 'src/rgui.c')
-rw-r--r--src/rgui.c559
1 files changed, 127 insertions, 432 deletions
diff --git a/src/rgui.c b/src/rgui.c
index 2a8e290..ce6c4a7 100644
--- a/src/rgui.c
+++ b/src/rgui.c
@@ -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 ) );