From 8966c16ad298f94be1f4542afa6b081a1d286eda Mon Sep 17 00:00:00 2001 From: Kahrl Date: Fri, 23 Aug 2013 12:24:11 +0200 Subject: Add formspec table --- src/script/lua_api/l_mainmenu.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') 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 @@ -183,18 +183,25 @@ 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); -- cgit v1.2.3