From 1cbadf56f33641e85fc634a326c0db6935947c23 Mon Sep 17 00:00:00 2001 From: jussi Date: Mon, 10 Apr 2023 14:33:15 +0300 Subject: New argument style for gui and easings. --- src/rgui.c | 577 +++++++++++++++++++++++-------------------------------------- 1 file changed, 220 insertions(+), 357 deletions(-) (limited to 'src/rgui.c') diff --git a/src/rgui.c b/src/rgui.c index ee55067..57f4a4d 100644 --- a/src/rgui.c +++ b/src/rgui.c @@ -76,12 +76,14 @@ Set gui controls alpha ( global state ), alpha goes from 0.0f to 1.0f - Success return true */ int lguiGuiFade( lua_State *L ) { - if ( !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiFade( float alpha )" ); lua_pushboolean( L, false ); return 1; } - GuiFade( lua_tonumber( L, -1 ) ); + float alpha = lua_tonumber( L, 1 ); + + GuiFade( alpha ); lua_pushboolean( L, true ); return 1; @@ -96,12 +98,14 @@ Set gui state ( global state ) - Success return true */ int lguiGuiSetState( lua_State *L ) { - if ( !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiSetState( int state )" ); lua_pushboolean( L, false ); return 1; } - GuiSetState( lua_tointeger( L, -1 ) ); + int state = lua_tointeger( L, 1 ); + + GuiSetState( state ); lua_pushboolean( L, true ); return 1; @@ -133,12 +137,14 @@ Set gui custom font ( Global state ) - Success return true */ int lguiGuiSetFont( lua_State *L ) { - if ( !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiSetFont( Font font )" ); lua_pushboolean( L, false ); return 1; } - GuiSetFont( *state->fonts[ lua_tointeger( L, -1 ) ] ); + size_t fontId = lua_tointeger( L, 1 ); + + GuiSetFont( *state->fonts[ fontId ] ); lua_pushboolean( L, true ); return 1; @@ -157,12 +163,16 @@ Set one style property - Success return true */ int lguiGuiSetStyle( lua_State *L ) { - if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiSetStyle( int control, int property, int value )" ); lua_pushboolean( L, false ); return 1; } - GuiSetStyle( lua_tointeger( L, -3 ), lua_tointeger( L, -2 ), lua_tointeger( L, -1 ) ); + int control = lua_tointeger( L, 1 ); + int property = lua_tointeger( L, 2 ); + int value = lua_tointeger( L, 3 ); + + GuiSetStyle( control, property, value ); lua_pushboolean( L, true ); return 1; @@ -177,18 +187,21 @@ Get one style property - Success return int */ int lguiGuiGetStyle( lua_State *L ) { - if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiGetStyle( int control, int property )" ); lua_pushboolean( L, false ); return 1; } - lua_pushinteger( L, GuiGetStyle( lua_tointeger( L, -2 ), lua_tointeger( L, -1 ) ) ); + int control = lua_tointeger( L, 1 ); + int property = lua_tointeger( L, 2 ); + + lua_pushinteger( L, GuiGetStyle( control, property ) ); return 1; } /* -> success = RL.GuiLoadStyle( int control, int property ) +> success = RL.GuiLoadStyle( string fileName ) Load style file over global style variable ( .rgs ) @@ -196,13 +209,21 @@ Load style file over global style variable ( .rgs ) - Success return true */ int lguiGuiLoadStyle( lua_State *L ) { - if ( !lua_isstring( L, -1 ) ) { + if ( !lua_isstring( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiLoadStyle( string fileName )" ); lua_pushboolean( L, false ); return 1; } - GuiLoadStyle( lua_tostring( L, -1 ) ); - lua_pushboolean( L, true ); + + if ( FileExists( lua_tostring( L, 1 ) ) ) { + GuiLoadStyle( lua_tostring( L, 1 ) ); + lua_pushboolean( L, true ); + return 1; + } + else { + lua_pushboolean( L, false ); + return 1; + } return 1; } @@ -231,17 +252,14 @@ Window Box control, shows a window that can be closed - Success return bool */ int lguiGuiWindowBox( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiWindowBox( Rectangle bounds, string title )" ); lua_pushnil( L ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushboolean( L, GuiWindowBox( bounds, text ) ); + lua_pushboolean( L, GuiWindowBox( bounds, lua_tostring( L, 2 ) ) ); return 1; } @@ -255,17 +273,14 @@ Group Box control with text name - Success return true */ int lguiGuiGroupBox( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiGroupBox( Rectangle bounds, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiGroupBox( bounds, text ); + GuiGroupBox( bounds, lua_tostring( L, 2 ) ); lua_pushboolean( L, true ); return 1; @@ -280,17 +295,14 @@ Line separator control, could contain text - Success return true */ int lguiGuiLine( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiLine( Rectangle bounds, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiLine( bounds, text ); + GuiLine( bounds, lua_tostring( L, 2 ) ); lua_pushboolean( L, true ); return 1; @@ -305,17 +317,14 @@ Panel control, useful to group controls - Success return true */ int lguiGuiPanel( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiPanel( Rectangle bounds, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiPanel( bounds, text ); + GuiPanel( bounds, lua_tostring( L, 2 ) ); lua_pushboolean( L, true ); return 1; @@ -330,21 +339,16 @@ Scroll Panel control - Success return Rectangle, Vector2 */ int lguiGuiScrollPanel( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiScrollPanel( Rectangle bounds, string text, Rectangle content, Vector2 scroll )" ); lua_pushboolean( L, false ); return 1; } - Vector2 scroll = uluaGetVector2( L ); - lua_pop( L, 1 ); - Rectangle content = uluaGetRectangle( L ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - uluaPushRectangle( L, GuiScrollPanel( bounds, text, content, &scroll ) ); + 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 ) ); uluaPushVector2( L, scroll ); return 2; @@ -363,17 +367,14 @@ Label control, shows text - Success return true */ int lguiGuiLabel( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiLabel( Rectangle bounds, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiLabel( bounds, text ); + GuiLabel( bounds, lua_tostring( L, 2 ) ); lua_pushboolean( L, true ); return 1; @@ -388,17 +389,14 @@ Button control, returns true when clicked - Success return boolean */ int lguiGuiButton( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiButton( Rectangle bounds, string text )" ); lua_pushnil( L ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushboolean( L, GuiButton( bounds, text ) ); + lua_pushboolean( L, GuiButton( bounds, lua_tostring( L, 2 ) ) ); return 1; } @@ -412,17 +410,14 @@ Label button control, show true when clicked - Success return boolean */ int lguiGuiLabelButton( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiLabelButton( Rectangle bounds, string text )" ); lua_pushnil( L ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - lua_pushboolean( L, GuiLabelButton( bounds, text ) ); + lua_pushboolean( L, GuiLabelButton( bounds, lua_tostring( L, 2 ) ) ); return 1; } @@ -436,19 +431,15 @@ Toggle Button control, returns true when active - Success return boolean */ int lguiGuiToggle( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isboolean( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isboolean( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiToggle( Rectangle bounds, string text, bool active )" ); lua_pushnil( L ); return 1; } - bool checked = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + bool checked = lua_toboolean( L, 3 ); - lua_pushboolean( L, GuiToggle( bounds, text, checked ) ); + lua_pushboolean( L, GuiToggle( bounds, lua_tostring( L, 2 ), checked ) ); return 1; } @@ -462,19 +453,15 @@ Toggle Group control, returns active toggle index - Success return int */ int lguiGuiToggleGroup( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiToggleGroup( Rectangle bounds, string text, bool active )" ); lua_pushboolean( L, false ); return 1; } - int active = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int active = lua_tointeger( L, 3 ); - lua_pushinteger( L, GuiToggleGroup( bounds, text, active ) ); + lua_pushinteger( L, GuiToggleGroup( bounds, lua_tostring( L, 2 ), active ) ); return 1; } @@ -488,19 +475,15 @@ Check Box control, returns true when active - Success return boolean */ int lguiGuiCheckBox( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isboolean( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isboolean( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiCheckBox( Rectangle bounds, string text, bool checked )" ); lua_pushnil( L ); return 1; } - bool checked = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + bool checked = lua_toboolean( L, 3 ); - lua_pushboolean( L, GuiCheckBox( bounds, text, checked ) ); + lua_pushboolean( L, GuiCheckBox( bounds, lua_tostring( L, 2 ), checked ) ); return 1; } @@ -514,19 +497,15 @@ Combo Box control, returns selected item index - Success return int */ int lguiGuiComboBox( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiComboBox( Rectangle bounds, string text, int active )" ); lua_pushnil( L ); return 1; } - int active = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int active = lua_tointeger( L, 3 ); - lua_pushinteger( L, GuiComboBox( bounds, text, active ) ); + lua_pushinteger( L, GuiComboBox( bounds, lua_tostring( L, 2 ), active ) ); return 1; } @@ -540,19 +519,17 @@ Text Box control, updates input text - Success return boolean, string */ int lguiGuiTextBox( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isboolean( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )" ); lua_pushnil( L ); return 1; } - bool editMode = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - int textSize = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int textSize = lua_tointeger( L, 3 ); + // char text[ STRING_LEN ] = { '\0' }; + char text[ textSize + 1 ]; + strcpy( text, lua_tostring( L, 2 ) ); + bool editMode = lua_toboolean( L, 4 ); lua_pushboolean( L, GuiTextBox( bounds, text, textSize, editMode ) ); lua_pushstring( L, text ); @@ -569,19 +546,17 @@ Text Box control with multiple lines - Success return boolean, string */ int lguiGuiTextBoxMulti( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isboolean( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiTextBoxMulti( Rectangle bounds, string text, int textSize, bool editMode )" ); lua_pushnil( L ); return 1; } - bool editMode = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - int textSize = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int textSize = lua_tointeger( L, 3 ); + // char text[ STRING_LEN ] = { '\0' }; + char text[ textSize + 1 ]; + strcpy( text, lua_tostring( L, 2 ) ); + bool editMode = lua_toboolean( L, 4 ); lua_pushboolean( L, GuiTextBoxMulti( bounds, text, textSize, editMode ) ); lua_pushstring( L, text ); @@ -598,26 +573,19 @@ Spinner control, returns selected value - Success return boolean, int */ int lguiGuiSpinner( lua_State *L ) { - if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isnumber( L, -4 ) - || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) { + 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( LOG_WARNING, "%s", "Bad call of function. RL.GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" ); lua_pushnil( L ); return 1; } - bool editMode = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - int maxValue = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int minValue = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int value = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushboolean( L, GuiSpinner( bounds, text, &value, minValue, maxValue, editMode ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int value = lua_tointeger( L, 3 ); + int minValue = lua_tointeger( L, 4 ); + int maxValue = lua_tointeger( L, 5 ); + bool editMode = lua_toboolean( L, 6 ); + + lua_pushboolean( L, GuiSpinner( bounds, lua_tostring( L, 2 ), &value, minValue, maxValue, editMode ) ); lua_pushinteger( L, value ); return 2; @@ -632,26 +600,19 @@ Value Box control, updates input text with numbers - Success return boolean, int */ int lguiGuiValueBox( lua_State *L ) { - if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isnumber( L, -4 ) - || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) { + 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( LOG_WARNING, "%s", "Bad call of function. RL.GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" ); lua_pushnil( L ); return 1; } - bool editMode = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - int maxValue = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int minValue = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int value = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushboolean( L, GuiValueBox( bounds, text, &value, minValue, maxValue, editMode ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int value = lua_tointeger( L, 3 ); + int minValue = lua_tointeger( L, 4 ); + int maxValue = lua_tointeger( L, 5 ); + bool editMode = lua_toboolean( L, 6 ); + + lua_pushboolean( L, GuiValueBox( bounds, lua_tostring( L, 2 ), &value, minValue, maxValue, editMode ) ); lua_pushinteger( L, value ); return 2; @@ -666,27 +627,18 @@ Slider control, returns selected value - Success return float */ int lguiGuiSlider( lua_State *L ) { - if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 ) - || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + 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( LOG_WARNING, "%s", "Bad call of function. RL.GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" ); lua_pushnil( L ); return 1; } - float maxValue = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - float minValue = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - float value = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - char textRight[ STRING_LEN ] = { '\0' }; - strcpy( textRight, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char textLeft[ STRING_LEN ] = { '\0' }; - strcpy( textLeft, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushnumber( L, GuiSlider( bounds, textLeft, textRight, value, minValue, maxValue ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + float value = lua_tonumber( L, 4 ); + float minValue = lua_tonumber( L, 5 ); + float maxValue = lua_tonumber( L, 6 ); + + lua_pushnumber( L, GuiSlider( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), value, minValue, maxValue ) ); return 1; } @@ -700,27 +652,18 @@ Slider Bar control, returns selected value - Success return float */ int lguiGuiSliderBar( lua_State *L ) { - if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 ) - || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + 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( LOG_WARNING, "%s", "Bad call of function. RL.GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" ); lua_pushnil( L ); return 1; } - float maxValue = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - float minValue = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - float value = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - char textRight[ STRING_LEN ] = { '\0' }; - strcpy( textRight, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char textLeft[ STRING_LEN ] = { '\0' }; - strcpy( textLeft, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushnumber( L, GuiSliderBar( bounds, textLeft, textRight, value, minValue, maxValue ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + float value = lua_tonumber( L, 4 ); + float minValue = lua_tonumber( L, 5 ); + float maxValue = lua_tonumber( L, 6 ); + + lua_pushnumber( L, GuiSliderBar( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), value, minValue, maxValue ) ); return 1; } @@ -734,27 +677,18 @@ Progress Bar control, shows current progress value - Success return float */ int lguiGuiProgressBar( lua_State *L ) { - if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 ) - || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + 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( LOG_WARNING, "%s", "Bad call of function. RL.GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" ); lua_pushnil( L ); return 1; } - float maxValue = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - float minValue = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - float value = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - char textRight[ STRING_LEN ] = { '\0' }; - strcpy( textRight, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char textLeft[ STRING_LEN ] = { '\0' }; - strcpy( textLeft, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushnumber( L, GuiProgressBar( bounds, textLeft, textRight, value, minValue, maxValue ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + float value = lua_tonumber( L, 4 ); + float minValue = lua_tonumber( L, 5 ); + float maxValue = lua_tonumber( L, 6 ); + + lua_pushnumber( L, GuiProgressBar( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), value, minValue, maxValue ) ); return 1; } @@ -768,18 +702,15 @@ Scroll Bar control - Success return int */ int lguiGuiScrollBar( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue )" ); lua_pushnil( L ); return 1; } - int maxValue = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int minValue = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int value = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int value = lua_tointeger( L, 2 ); + int minValue = lua_tointeger( L, 3 ); + int maxValue = lua_tointeger( L, 4 ); lua_pushinteger( L, GuiScrollBar( bounds, value, minValue, maxValue ) ); @@ -795,21 +726,16 @@ Dropdown Box control, returns selected item - Success return bool, int */ int lguiGuiDropdownBox( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isboolean( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiDropdownBox( Rectangle bounds, string text, int active, bool editMode )" ); lua_pushnil( L ); return 1; } - bool editMode = lua_toboolean( L, -1 ); - lua_pop( L, 1 ); - int active = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushboolean( L, GuiDropdownBox( bounds, text, &active, editMode ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int active = lua_tointeger( L, 3 ); + bool editMode = lua_toboolean( L, 4 ); + + lua_pushboolean( L, GuiDropdownBox( bounds, lua_tostring( L, 2 ), &active, editMode ) ); lua_pushinteger( L, active ); return 2; @@ -824,17 +750,14 @@ Status Bar control, shows info text - Success return true */ int lguiGuiStatusBar( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiStatusBar( Rectangle bounds, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiStatusBar( bounds, text ); + GuiStatusBar( bounds, lua_tostring( L, 2 ) ); lua_pushboolean( L, true ); return 1; @@ -849,17 +772,14 @@ Dummy control for placeholders - Success return true */ int lguiGuiDummyRec( lua_State *L ) { - if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiDummyRec( Rectangle bounds, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - GuiDummyRec( bounds, text ); + GuiDummyRec( bounds, lua_tostring( L, 2 ) ); lua_pushboolean( L, true ); return 1; @@ -874,21 +794,16 @@ Grid control, returns mouse cell position - Success return Vector2 */ int lguiGuiGrid( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiGrid( Rectangle bounds, string text, float spacing, int subdivs )" ); lua_pushboolean( L, false ); return 1; } - int subdivs = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - float spacing = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + float spacing = lua_tonumber( L, 3 ); + int subdivs = lua_tointeger( L, 4 ); - uluaPushVector2( L, GuiGrid( bounds, text, spacing, subdivs ) ); + uluaPushVector2( L, GuiGrid( bounds, lua_tostring( L, 2 ), spacing, subdivs ) ); return 1; } @@ -906,21 +821,16 @@ List View control, returns selected list item index and scroll index - Success return int, int */ int lguiGuiListView( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiListView( Rectangle bounds, string text, int scrollIndex, int active )" ); lua_pushnil( L ); return 1; } - int active = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int scrollIndex = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushinteger( L, GuiListView( bounds, text, &scrollIndex, active ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int scrollIndex = lua_tointeger( L, 3 ); + int active = lua_tointeger( L, 4 ); + + lua_pushinteger( L, GuiListView( bounds, lua_tostring( L, 2 ), &scrollIndex, active ) ); lua_pushinteger( L, scrollIndex ); return 2; @@ -935,22 +845,18 @@ List View with extended parameters, returns selected list item index, scroll ind - Success return int, int, int */ int lguiGuiListViewEx( lua_State *L ) { - if ( !lua_istable( L, -5 ) || !lua_isstring( L, -4 ) || !lua_isnumber( L, -3 ) - || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) + || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiListViewEx( Rectangle bounds, string text, int focus, int scrollIndex, int active )" ); lua_pushnil( L ); return 1; } - int active = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int scrollIndex = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int focus = lua_tointeger( L, -1 ); - lua_pop( L, 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 count = 0; - const char **text = GuiTextSplit( lua_tostring( L, -1 ), &count, NULL ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + const char **text = GuiTextSplit( lua_tostring( L, 2 ), &count, NULL ); lua_pushinteger( L, GuiListViewEx( bounds, text, count, &focus, &scrollIndex, active ) ); lua_pushinteger( L, scrollIndex ); @@ -968,23 +874,14 @@ Message Box control, displays a message, returns button index ( 0 is x button ) - Success return int */ int lguiGuiMessageBox( lua_State *L ) { - if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) || !lua_isstring( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiMessageBox( Rectangle bounds, string title, string message, string buttons )" ); lua_pushboolean( L, false ); return 1; } - char buttons[ STRING_LEN ] = { '\0' }; - strcpy( buttons, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char message[ STRING_LEN ] = { '\0' }; - strcpy( message, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char title[ STRING_LEN ] = { '\0' }; - strcpy( title, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushinteger( L, GuiMessageBox( bounds, title, message, buttons ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + + lua_pushinteger( L, GuiMessageBox( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), lua_tostring( L, 4 ) ) ); return 1; } @@ -998,30 +895,19 @@ Text Input Box control, ask for text, supports secret - Success return int, string, int */ int lguiGuiTextInputBox( lua_State *L ) { - if ( !lua_istable( L, -7 ) || !lua_isstring( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + 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( LOG_WARNING, "%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; } - int secretViewActive = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - int textMaxSize = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char buttons[ STRING_LEN ] = { '\0' }; - strcpy( buttons, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char message[ STRING_LEN ] = { '\0' }; - strcpy( message, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - char title[ STRING_LEN ] = { '\0' }; - strcpy( title, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); - - lua_pushinteger( L, GuiTextInputBox( bounds, title, message, buttons, text, textMaxSize, &secretViewActive ) ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + int textMaxSize = lua_tointeger( L, 6 ); + int secretViewActive = lua_tointeger( L, 7 ); + char text[ textMaxSize + 1 ]; + strcpy( text, lua_tostring( L, 5 ) ); + + lua_pushinteger( L, GuiTextInputBox( bounds, lua_tostring( L, 2 ), lua_tostring( L, 3 ), lua_tostring( L, 4 ), text, textMaxSize, &secretViewActive ) ); lua_pushstring( L, text ); lua_pushinteger( L, secretViewActive ); @@ -1037,19 +923,15 @@ Color Picker control ( multiple color controls ) - Success return Color */ int lguiGuiColorPicker( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiColorPicker( Rectangle bounds, string text, Color color )" ); lua_pushboolean( L, false ); return 1; } - Color color = uluaGetColor( L ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + Color color = uluaGetColorIndex( L, 3 ); - uluaPushColor( L, GuiColorPicker( bounds, text, color ) ); + uluaPushColor( L, GuiColorPicker( bounds, lua_tostring( L, 2 ), color ) ); return 1; } @@ -1063,19 +945,15 @@ Color Panel control - Success return Color */ int lguiGuiColorPanel( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiColorPanel( Rectangle bounds, string text, Color color )" ); lua_pushboolean( L, false ); return 1; } - Color color = uluaGetColor( L ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + Color color = uluaGetColorIndex( L, 3 ); - uluaPushColor( L, GuiColorPanel( bounds, text, color ) ); + uluaPushColor( L, GuiColorPanel( bounds, lua_tostring( L, 2 ), color ) ); return 1; } @@ -1089,19 +967,15 @@ Color Bar Alpha control - Success return float */ int lguiGuiColorBarAlpha( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiColorBarAlpha( Rectangle bounds, string text, float alpha )" ); lua_pushboolean( L, false ); return 1; } - float alpha = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + float alpha = lua_tonumber( L, 3 ); - lua_pushnumber( L, GuiColorBarAlpha( bounds, text, alpha ) ); + lua_pushnumber( L, GuiColorBarAlpha( bounds, lua_tostring( L, 2 ), alpha ) ); return 1; } @@ -1115,19 +989,15 @@ Color Bar Hue control - Success return float */ int lguiGuiColorBarHue( lua_State *L ) { - if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_istable( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiColorBarHue( Rectangle bounds, string text, float value )" ); lua_pushboolean( L, false ); return 1; } - float value = lua_tonumber( L, -1 ); - lua_pop( L, 1 ); - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - Rectangle bounds = uluaGetRectangle( L ); + Rectangle bounds = uluaGetRectangleIndex( L, 1 ); + float value = lua_tonumber( L, 3 ); - lua_pushnumber( L, GuiColorBarHue( bounds, text, value ) ); + lua_pushnumber( L, GuiColorBarHue( bounds, lua_tostring( L, 2 ), value ) ); return 1; } @@ -1145,21 +1015,18 @@ Get text with icon id prepended ( if supported ) - Success return string */ int lguiGuiIconText( lua_State *L ) { - if ( !lua_isnumber( L, -2 ) || !lua_isstring( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiIconText( int iconId, string text )" ); lua_pushboolean( L, false ); return 1; } - char text[ STRING_LEN ] = { '\0' }; - strcpy( text, lua_tostring( L, -1 ) ); - lua_pop( L, 1 ); - int iconId = lua_tointeger( L, -1 ); + int iconId = lua_tointeger( L, 1 ); - if ( TextIsEqual( text, "" ) ) { + if ( TextIsEqual( lua_tostring( L, 2 ), "" ) ) { lua_pushstring( L, GuiIconText( iconId, NULL ) ); } else { - lua_pushstring( L, GuiIconText( iconId, text ) ); + lua_pushstring( L, GuiIconText( iconId, lua_tostring( L, 2 ) ) ); } return 1; @@ -1174,18 +1041,15 @@ Draw icon - Success return true */ int lguiGuiDrawIcon( lua_State *L ) { - if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiDrawIcon( int iconId, Vector2 pos, int pixelSize, Color color )" ); lua_pushboolean( L, false ); return 1; } - Color color = uluaGetColor( L ); - lua_pop( L, 1 ); - int pixelSize = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - Vector2 pos = uluaGetVector2( L ); - lua_pop( L, 1 ); - int iconId = lua_tointeger( L, -1 ); + int iconId = lua_tointeger( L, 1 ); + Vector2 pos = uluaGetVector2Index( L, 2 ); + int pixelSize = lua_tointeger( L, 3 ); + Color color = uluaGetColorIndex( L, 4 ); GuiDrawIcon( iconId, pos.x, pos.y, pixelSize, color ); lua_pushboolean( L, true ); @@ -1202,12 +1066,14 @@ Set icon scale ( 1 by default ) - Success return true */ int lguiGuiSetIconScale( lua_State *L ) { - if ( !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiSetIconScale( int scale )" ); lua_pushboolean( L, false ); return 1; } - GuiSetIconScale( (unsigned int)lua_tointeger( L, -1 ) ); + unsigned int scale = lua_tointeger( L, 1 ); + + GuiSetIconScale( scale ); lua_pushboolean( L, true ); return 1; @@ -1222,14 +1088,13 @@ Set icon pixel value - Success return true */ int lguiGuiSetIconPixel( lua_State *L ) { - if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiSetIconPixel( int iconId, Vector2 pos )" ); lua_pushboolean( L, false ); return 1; } - Vector2 pos = uluaGetVector2( L ); - lua_pop( L, 1 ); - int iconId = lua_tointeger( L, -1 ); + int iconId = lua_tointeger( L, 1 ); + Vector2 pos = uluaGetVector2Index( L, 2 ); GuiSetIconPixel( iconId, pos.x, pos.y ); lua_pushboolean( L, true ); @@ -1246,14 +1111,13 @@ Clear icon pixel value - Success return true */ int lguiGuiClearIconPixel( lua_State *L ) { - if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiClearIconPixel( int iconId, Vector2 pos )" ); lua_pushboolean( L, false ); return 1; } - Vector2 pos = uluaGetVector2( L ); - lua_pop( L, 1 ); - int iconId = lua_tointeger( L, -1 ); + int iconId = lua_tointeger( L, 1 ); + Vector2 pos = uluaGetVector2Index( L, 2 ); GuiClearIconPixel( iconId, pos.x, pos.y ); lua_pushboolean( L, true ); @@ -1270,14 +1134,13 @@ Check icon pixel value - Success return bool */ int lguiGuiCheckIconPixel( lua_State *L ) { - if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GuiCheckIconPixel( int iconId, Vector2 pos )" ); lua_pushnil( L ); return 1; } - Vector2 pos = uluaGetVector2( L ); - lua_pop( L, 1 ); - int iconId = lua_tointeger( L, -1 ); + int iconId = lua_tointeger( L, 1 ); + Vector2 pos = uluaGetVector2Index( L, 2 ); lua_pushboolean( L, GuiCheckIconPixel( iconId, pos.x, pos.y ) ); -- cgit v1.2.3