CLuaInstance: Add script function 'setActive' to enable or disable...

...individual menu items.

 - Set Lua api version to 1.2
This commit is contained in:
M. Liebmann
2015-09-14 17:11:40 +02:00
parent e0bfbfe9e3
commit 39d10e03df
2 changed files with 25 additions and 1 deletions

View File

@@ -1050,6 +1050,7 @@ void CLuaInstance::MenuRegister(lua_State *L)
{ "addItem", CLuaInstance::MenuAddItem },
{ "exec", CLuaInstance::MenuExec },
{ "hide", CLuaInstance::MenuHide },
{ "setActive", CLuaInstance::MenuSetActive },
{ "__gc", CLuaInstance::MenuDelete },
{ NULL, NULL }
};
@@ -1272,6 +1273,28 @@ int CLuaInstance::MenuAddKey(lua_State *L)
return 0;
}
int CLuaInstance::MenuSetActive(lua_State *L)
{
CLuaMenu *m = MenuCheck(L, 1);
if (!m)
return 0;
lua_assert(lua_istable(L, 2));
lua_Integer id; tableLookup(L, "item", id);
bool activ; tableLookup(L, "activ", activ);
CMenuItem* item = NULL;
for (itemmap_iterator_t it = m->itemmap.begin(); it != m->itemmap.end(); ++it) {
if (it->first == id) {
item = it->second;
break;
}
}
if (item)
item->setActive(activ);
return 0;
}
int CLuaInstance::MenuAddItem(lua_State *L)
{
CLuaMenu *m = MenuCheck(L, 1);

View File

@@ -34,7 +34,7 @@ extern "C" {
#include <vector>
#define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 1
#define LUA_API_VERSION_MINOR 2
/* this is stored as userdata in the lua_State */
struct CLuaData
@@ -243,6 +243,7 @@ private:
static int MenuHide(lua_State *L);
static int MenuExec(lua_State *L);
static CLuaMenu *MenuCheck(lua_State *L, int n);
static int MenuSetActive(lua_State *L);
void HintboxRegister(lua_State *L);
static int HintboxNew(lua_State *L);