summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp22
-rw-r--r--src/script/lua_api/l_mainmenu.h2
2 files changed, 17 insertions, 7 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index abf2a8f81..ef16efde2 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -184,17 +184,24 @@ int ModApiMainMenu::l_set_clouds(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_get_textlist_index(lua_State *L)
{
+ // get_table_index accepts both tables and textlists
+ return l_get_table_index(L);
+}
+
+/******************************************************************************/
+int ModApiMainMenu::l_get_table_index(lua_State *L)
+{
GUIEngine* engine = getGuiEngine(L);
assert(engine != 0);
- std::string listboxname(luaL_checkstring(L, 1));
+ std::wstring tablename(narrow_to_wide(luaL_checkstring(L, 1)));
+ GUITable *table = engine->m_menu->getTable(tablename);
+ s32 selection = table ? table->getSelected() : 0;
- int selection = engine->m_menu->getListboxIndex(listboxname);
-
- if (selection >= 0)
- selection++;
-
- lua_pushinteger(L, selection);
+ if (selection >= 1)
+ lua_pushinteger(L, selection);
+ else
+ lua_pushnil(L);
return 1;
}
@@ -1026,6 +1033,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(update_formspec);
API_FCT(set_clouds);
API_FCT(get_textlist_index);
+ API_FCT(get_table_index);
API_FCT(get_worlds);
API_FCT(get_games);
API_FCT(start);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index db11ae794..69011c7b5 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -97,6 +97,8 @@ private:
static int l_get_textlist_index(lua_State *L);
+ static int l_get_table_index(lua_State *L);
+
static int l_set_background(lua_State *L);
static int l_update_formspec(lua_State *L);