Skip to content

Commit

Permalink
Fix ElementTabSet using 0-based indexes in Lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
nimble0 committed Oct 27, 2021
1 parent 735de1f commit ae02e25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Source/Lua/Elements/ElementTabSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Lua {
int ElementTabSetSetPanel(lua_State* L, ElementTabSet* obj)
{
RMLUI_CHECK_OBJ(obj);
int index = (int)luaL_checkinteger(L,1);
int index = GetIndex(L,1);
const char* rml = luaL_checkstring(L,2);

obj->SetPanel(index,rml);
Expand All @@ -48,7 +48,7 @@ int ElementTabSetSetPanel(lua_State* L, ElementTabSet* obj)
int ElementTabSetSetTab(lua_State* L, ElementTabSet* obj)
{
RMLUI_CHECK_OBJ(obj);
int index = (int)luaL_checkinteger(L,1);
int index = GetIndex(L,1);
const char* rml = luaL_checkstring(L,2);

obj->SetTab(index,rml);
Expand All @@ -62,7 +62,7 @@ int ElementTabSetGetAttractive_tab(lua_State* L)
ElementTabSet* obj = LuaType<ElementTabSet>::check(L,1);
RMLUI_CHECK_OBJ(obj);
int tab = obj->GetActiveTab();
lua_pushinteger(L,tab);
PushIndex(L,tab);
return 1;
}

Expand All @@ -81,7 +81,7 @@ int ElementTabSetSetAttractive_tab(lua_State* L)
{
ElementTabSet* obj = LuaType<ElementTabSet>::check(L,1);
RMLUI_CHECK_OBJ(obj);
int tab = (int)luaL_checkinteger(L,2);
int tab = GetIndex(L,2);
obj->SetActiveTab(tab);
return 0;
}
Expand Down
11 changes: 10 additions & 1 deletion Source/Lua/EventParametersProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <RmlUi/Core/Variant.h>
#include <RmlUi/Core/Dictionary.h>
#include "Pairs.h"
#include <cstring>


namespace Rml {
Expand All @@ -55,7 +56,15 @@ int EventParametersProxy__index(lua_State* L)
const char* key = lua_tostring(L,2);
auto it = obj->owner->GetParameters().find(key);
const Variant* param = (it == obj->owner->GetParameters().end() ? nullptr : &it->second);
PushVariant(L,param);
if (obj->owner->GetId() == EventId::Tabchange &&
std::strcmp(key, "tab_index") == 0 &&
param &&
param->GetType() == Variant::Type::INT)
{
PushIndex(L,param->Get<int>());
}
else
PushVariant(L,param);
return 1;
}
else
Expand Down

0 comments on commit ae02e25

Please sign in to comment.