lua related fixes

Signed-off-by: M. Liebmann <tuxcode.bbg@gmail.com>
This commit is contained in:
martii
2013-05-08 18:25:30 +02:00
committed by M. Liebmann
parent a568f3004e
commit c6912180ee

View File

@@ -610,9 +610,9 @@ int CLuaInstance::Blit(lua_State *L)
{ {
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (W && W->fbwin) { if (W && W->fbwin) {
if (lua_isnumber(L, 2)) { if (lua_isnumber(L, 2))
W->fbwin->mayBlit = (int)lua_tonumber(L, 2); // enable/disable automatic blit W->fbwin->mayBlit = (int)lua_tonumber(L, 2); // enable/disable automatic blit
} else else
W->fbwin->blit(); W->fbwin->blit();
} }
return 0; return 0;
@@ -887,17 +887,17 @@ int CLuaInstance::MenueAddItem(lua_State *L)
if (type == "back") { if (type == "back") {
m->m->addItem(GenericMenuBack); m->m->addItem(GenericMenuBack);
} else if (type == "separator") { } else if (type == "separator") {
if (!b->name.empty()) if (!b->name.empty()) {
m->m->addItem(new CNonLocalizedMenuSeparator(b->name.c_str(), NONEXISTANT_LOCALE)); m->m->addItem(new CNonLocalizedMenuSeparator(b->name.c_str(), NONEXISTANT_LOCALE));
else } else {
m->m->addItem(GenericMenuSeparatorLine); m->m->addItem(GenericMenuSeparatorLine);
}
} else { } else {
std::string right_icon; tableLookup(L, "right_icon", right_icon); std::string right_icon; tableLookup(L, "right_icon", right_icon);
std::string action; tableLookup(L, "action", action); std::string action; tableLookup(L, "action", action);
std::string value; tableLookup(L, "value", value); std::string value; tableLookup(L, "value", value);
std::string tmp; std::string tmp;
int directkey = CRCInput::RC_nokey; int directkey = CRCInput::RC_nokey; tableLookup(L, "directkey", directkey);
tableLookup(L, "directkey", directkey);
int pulldown = false; tableLookup(L, "pulldown", pulldown); int pulldown = false; tableLookup(L, "pulldown", pulldown);
tmp = "true"; tmp = "true";
tableLookup(L, "enabled", tmp) || tableLookup(L, "active", tmp); tableLookup(L, "enabled", tmp) || tableLookup(L, "active", tmp);
@@ -919,10 +919,11 @@ int CLuaInstance::MenueAddItem(lua_State *L)
int options_count = 0; int options_count = 0;
lua_pushstring(L, "options"); lua_pushstring(L, "options");
lua_gettable(L, -2); lua_gettable(L, -2);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) { if (lua_istable(L, -1))
lua_pushvalue(L, -2); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
options_count++; lua_pushvalue(L, -2);
} options_count++;
}
lua_pop(L, 1); lua_pop(L, 1);
CMenuOptionChooser::keyval_ext *kext = (CMenuOptionChooser::keyval_ext *)calloc(options_count, sizeof(CMenuOptionChooser::keyval_ext)); CMenuOptionChooser::keyval_ext *kext = (CMenuOptionChooser::keyval_ext *)calloc(options_count, sizeof(CMenuOptionChooser::keyval_ext));
@@ -931,18 +932,19 @@ int CLuaInstance::MenueAddItem(lua_State *L)
lua_gettable(L, -2); lua_gettable(L, -2);
b->i = 0; b->i = 0;
int j = 0; int j = 0;
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) { if (lua_istable(L, -1))
lua_pushvalue(L, -2); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
const char *key = lua_tostring(L, -1); lua_pushvalue(L, -2);
const char *val = lua_tostring(L, -2); const char *key = lua_tostring(L, -1);
kext[j].key = atoi(key); const char *val = lua_tostring(L, -2);
kext[j].value = NONEXISTANT_LOCALE; kext[j].key = atoi(key);
kext[j].valname = strdup(val); kext[j].value = NONEXISTANT_LOCALE;
m->tofree.push_back((void *)kext[j].valname); kext[j].valname = strdup(val);
if (!strcmp(value.c_str(), kext[j].valname)) m->tofree.push_back((void *)kext[j].valname);
b->i = kext[j].key; if (!strcmp(value.c_str(), kext[j].valname))
j++; b->i = kext[j].key;
} j++;
}
lua_pop(L, 1); lua_pop(L, 1);
CMenuItem *mi = new CMenuOptionChooser(b->name.c_str(), &b->i, kext, options_count, enabled, m->observ, directkey, icon.c_str(), pulldown); CMenuItem *mi = new CMenuOptionChooser(b->name.c_str(), &b->i, kext, options_count, enabled, m->observ, directkey, icon.c_str(), pulldown);
mi->luaAction = action; mi->luaAction = action;
@@ -980,14 +982,14 @@ int CLuaInstance::MenueAddItem(lua_State *L)
strncpy(b->s, value.c_str(), sizeof(b->s)); strncpy(b->s, value.c_str(), sizeof(b->s));
int dirMode = 0; tableLookup(L, "dir_mode", dirMode); int dirMode = 0; tableLookup(L, "dir_mode", dirMode);
CLuaMenueFilebrowser *filebrowser = new CLuaMenueFilebrowser(L, action, b->s, dirMode); CLuaMenueFilebrowser *filebrowser = new CLuaMenueFilebrowser(L, action, b->s, dirMode);
lua_pushstring(L, "filter"); lua_pushstring(L, "filter");
lua_gettable(L, -2); lua_gettable(L, -2);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) { if (lua_istable(L, -1))
lua_pushvalue(L, -2); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
const char *val = lua_tostring(L, -2); lua_pushvalue(L, -2);
filebrowser->addFilter(val); const char *val = lua_tostring(L, -2);
} filebrowser->addFilter(val);
}
lua_pop(L, 1); lua_pop(L, 1);
CMenuItem *mi = new CMenuForwarderNonLocalized( CMenuItem *mi = new CMenuForwarderNonLocalized(
@@ -998,7 +1000,7 @@ int CLuaInstance::MenueAddItem(lua_State *L)
m->targets.push_back(filebrowser); m->targets.push_back(filebrowser);
} }
} }
return 1; return 0;
} }
int CLuaInstance::MenueHide(lua_State *L) int CLuaInstance::MenueHide(lua_State *L)