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 17, 2021
1 parent 1e7e766 commit 6c8fe65
Show file tree
Hide file tree
Showing 2 changed files with 13 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
10 changes: 9 additions & 1 deletion Source/Lua/EventParametersProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 &&
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 6c8fe65

Please sign in to comment.