aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_mainmenu.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2013-08-23 12:24:11 +0200
committerShadowNinja <shadowninja@minetest.net>2014-01-13 18:11:08 -0500
commit8966c16ad298f94be1f4542afa6b081a1d286eda (patch)
tree00e50224528a7f0bbb46cb05d81177f5e8086c41 /src/script/lua_api/l_mainmenu.cpp
parent2b1eff772524fca8249fd64028e5cbfeabc127a0 (diff)
downloadminetest-8966c16ad298f94be1f4542afa6b081a1d286eda.tar.gz
minetest-8966c16ad298f94be1f4542afa6b081a1d286eda.tar.bz2
minetest-8966c16ad298f94be1f4542afa6b081a1d286eda.zip
Add formspec table
Diffstat (limited to 'src/script/lua_api/l_mainmenu.cpp')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp22
1 files changed, 15 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);