mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 23:13:13 +02:00
Adaptation of CLuaInstance
This commit is contained in:
@@ -26,10 +26,9 @@
|
|||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <system/settings.h>
|
#include <system/settings.h>
|
||||||
#include <gui/widget/msgbox.h>
|
#include <gui/widget/msgbox.h>
|
||||||
#ifdef MARTII
|
#include <gui/widget/messagebox.h>
|
||||||
#include <gui/filebrowser.h>
|
#include <gui/filebrowser.h>
|
||||||
#include <driver/pictureviewer/pictureviewer.h>
|
#include <driver/pictureviewer/pictureviewer.h>
|
||||||
#endif
|
|
||||||
#include <neutrino.h>
|
#include <neutrino.h>
|
||||||
|
|
||||||
#include "luainstance.h"
|
#include "luainstance.h"
|
||||||
@@ -123,8 +122,7 @@ static void set_lua_variables(lua_State *L)
|
|||||||
{ "mute_off", CRCInput::RC_mute_off },
|
{ "mute_off", CRCInput::RC_mute_off },
|
||||||
{ "analog_on", CRCInput::RC_analog_on },
|
{ "analog_on", CRCInput::RC_analog_on },
|
||||||
{ "analog_off", CRCInput::RC_analog_off },
|
{ "analog_off", CRCInput::RC_analog_off },
|
||||||
#ifdef MARTII
|
#if !HAVE_COOL_HARDWARE
|
||||||
/* SPARK keys */
|
|
||||||
{ "find", CRCInput::RC_find },
|
{ "find", CRCInput::RC_find },
|
||||||
{ "pip", CRCInput::RC_pip },
|
{ "pip", CRCInput::RC_pip },
|
||||||
{ "folder", CRCInput::RC_archive },
|
{ "folder", CRCInput::RC_archive },
|
||||||
@@ -242,7 +240,6 @@ static void set_lua_variables(lua_State *L)
|
|||||||
{ "END_Y", g_settings.screen_EndY },
|
{ "END_Y", g_settings.screen_EndY },
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
#ifdef MARTII
|
|
||||||
table_key menureturn[] =
|
table_key menureturn[] =
|
||||||
{
|
{
|
||||||
{ "NONE", menu_return::RETURN_NONE },
|
{ "NONE", menu_return::RETURN_NONE },
|
||||||
@@ -252,7 +249,6 @@ static void set_lua_variables(lua_State *L)
|
|||||||
{ "EXIT_REPAINT", menu_return::RETURN_EXIT_REPAINT },
|
{ "EXIT_REPAINT", menu_return::RETURN_EXIT_REPAINT },
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
/* list of environment variable arrays to be exported */
|
/* list of environment variable arrays to be exported */
|
||||||
lua_envexport e[] =
|
lua_envexport e[] =
|
||||||
@@ -262,9 +258,7 @@ static void set_lua_variables(lua_State *L)
|
|||||||
{ "SCREEN", screenopts },
|
{ "SCREEN", screenopts },
|
||||||
{ "FONT", fontlist },
|
{ "FONT", fontlist },
|
||||||
{ "CORNER", corners },
|
{ "CORNER", corners },
|
||||||
#ifdef MARTII
|
|
||||||
{ "MENU_RETURN", menureturn },
|
{ "MENU_RETURN", menureturn },
|
||||||
#endif
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -346,12 +340,10 @@ const luaL_Reg CLuaInstance::methods[] =
|
|||||||
{ "PaintIcon", CLuaInstance::PaintIcon },
|
{ "PaintIcon", CLuaInstance::PaintIcon },
|
||||||
{ "GetInput", CLuaInstance::GetInput },
|
{ "GetInput", CLuaInstance::GetInput },
|
||||||
{ "FontHeight", CLuaInstance::FontHeight },
|
{ "FontHeight", CLuaInstance::FontHeight },
|
||||||
#ifdef MARTII
|
|
||||||
{ "GetSize", CLuaInstance::GetSize },
|
{ "GetSize", CLuaInstance::GetSize },
|
||||||
{ "DisplayImage", CLuaInstance::DisplayImage },
|
{ "DisplayImage", CLuaInstance::DisplayImage },
|
||||||
{ "Blit", CLuaInstance::Blit },
|
{ "Blit", CLuaInstance::Blit },
|
||||||
{ "GetLanguage", CLuaInstance::GetLanguage },
|
{ "GetLanguage", CLuaInstance::GetLanguage },
|
||||||
#endif
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -393,7 +385,9 @@ void CLuaInstance::registerFunctions()
|
|||||||
luaopen_string(lua);
|
luaopen_string(lua);
|
||||||
luaopen_math(lua);
|
luaopen_math(lua);
|
||||||
#ifndef DYNAMIC_LUAPOSIX
|
#ifndef DYNAMIC_LUAPOSIX
|
||||||
|
#if !HAVE_COOL_HARDWARE
|
||||||
luaopen_posix_c(lua);
|
luaopen_posix_c(lua);
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
dolibrary(lua,"posix");
|
dolibrary(lua,"posix");
|
||||||
#endif
|
#endif
|
||||||
@@ -514,7 +508,6 @@ int CLuaInstance::PaintIcon(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MARTII
|
|
||||||
extern CPictureViewer * g_PicViewer;
|
extern CPictureViewer * g_PicViewer;
|
||||||
|
|
||||||
int CLuaInstance::DisplayImage(lua_State *L)
|
int CLuaInstance::DisplayImage(lua_State *L)
|
||||||
@@ -547,7 +540,6 @@ int CLuaInstance::GetSize(lua_State *L)
|
|||||||
lua_pushinteger(L, h);
|
lua_pushinteger(L, h);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int CLuaInstance::RenderString(lua_State *L)
|
int CLuaInstance::RenderString(lua_State *L)
|
||||||
{
|
{
|
||||||
@@ -641,61 +633,34 @@ int CLuaInstance::GCWindow(lua_State *L)
|
|||||||
delete w;
|
delete w;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef MARTII
|
|
||||||
|
#if HAVE_COOL_HARDWARE
|
||||||
|
int CLuaInstance::Blit(lua_State *)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
int CLuaInstance::Blit(lua_State *L)
|
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->blit((int)lua_tonumber(L, 2)); // enable/disable automatic blit
|
||||||
else
|
else
|
||||||
W->fbwin->blit();
|
W->fbwin->blit();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int CLuaInstance::GetLanguage(lua_State *L)
|
int CLuaInstance::GetLanguage(lua_State *L)
|
||||||
{
|
{
|
||||||
// FIXME -- should conform to ISO 639-1/ISO 3166-1
|
// FIXME -- should conform to ISO 639-1/ISO 3166-1
|
||||||
lua_pushstring(L, g_settings.language);
|
lua_pushstring(L, g_settings.language.c_str());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
local m = menue.new{name="mytitle", icon="myicon", hide_parent=true}
|
|
||||||
m:addItem{type="back"}
|
|
||||||
m:addItem{type="separator"}
|
|
||||||
|
|
||||||
function talk(a, b)
|
|
||||||
print(">talk")
|
|
||||||
print(a .. " => " b)
|
|
||||||
print("<talk")
|
|
||||||
return MENU_RETURN["RETURN_REPAINT"]
|
|
||||||
end
|
|
||||||
|
|
||||||
function anotherMenue()
|
|
||||||
print(">>anothermenue");
|
|
||||||
local m = menue.new{name="anothermenue", icon="settings"}
|
|
||||||
m:addItem{type="back"}
|
|
||||||
m:addItem{type="separator"}
|
|
||||||
m:addItem{type="numeric", name="testnumeric"}
|
|
||||||
m:exec()
|
|
||||||
print("<<anothermenue");
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
m:addItem{type="chooser", name="testchooser", action="talk", options={ "on", "off", "auto" }, icon=
|
|
||||||
m:addItem{type="forwarder", name="testforwarder", action="anotherMenue", icon="network"}
|
|
||||||
m:addItem{type="separator"}
|
|
||||||
m:addItem{type="numeric", name="testnumeric", id="a", action="talk"}
|
|
||||||
m:addItem{type="separator"}
|
|
||||||
m:addItem{type="filebrowser", name="fbrowser", id="b", action="talk"}
|
|
||||||
m:addItem{type="separator"}
|
|
||||||
m:addItem{type="stringinput", name="stringinput", id="c", action="talk"}
|
|
||||||
m:exec()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool CLuaInstance::tableLookup(lua_State *L, const char *what, std::string &value)
|
bool CLuaInstance::tableLookup(lua_State *L, const char *what, std::string &value)
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
@@ -731,7 +696,7 @@ bool CLuaMenuChangeObserver::changeNotify(lua_State *L, const std::string &luaAc
|
|||||||
lua_pcall(L, 2 /* two args */, 1 /* one result */, 0);
|
lua_pcall(L, 2 /* two args */, 1 /* one result */, 0);
|
||||||
double res = lua_isnumber(L, -1) ? lua_tonumber(L, -1) : 0;
|
double res = lua_isnumber(L, -1) ? lua_tonumber(L, -1) : 0;
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
return res == menu_return::RETURN_REPAINT || res == menu_return::RETURN_EXIT_REPAINT;
|
return ((res == menu_return::RETURN_REPAINT) || (res == menu_return::RETURN_EXIT_REPAINT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLuaInstance::MenuRegister(lua_State *L)
|
void CLuaInstance::MenuRegister(lua_State *L)
|
||||||
@@ -825,14 +790,14 @@ int CLuaMenuFilebrowser::exec(CMenuTarget* /*parent*/, const std::string& /*acti
|
|||||||
if (!filter.empty())
|
if (!filter.empty())
|
||||||
fileBrowser.Filter = &fileFilter;
|
fileBrowser.Filter = &fileFilter;
|
||||||
|
|
||||||
if (fileBrowser.exec(value) == true)
|
if (fileBrowser.exec(value->c_str()) == true)
|
||||||
strcpy(value, fileBrowser.getSelectedFile()->Name.c_str());
|
*value = fileBrowser.getSelectedFile()->Name;
|
||||||
|
|
||||||
if (!luaAction.empty()){
|
if (!luaAction.empty()){
|
||||||
lua_pushglobaltable(L);
|
lua_pushglobaltable(L);
|
||||||
lua_getfield(L, -1, luaAction.c_str());
|
lua_getfield(L, -1, luaAction.c_str());
|
||||||
lua_remove(L, -2);
|
lua_remove(L, -2);
|
||||||
lua_pushstring(L, value);
|
lua_pushstring(L, value->c_str());
|
||||||
lua_pcall(L, 1 /* one arg */, 1 /* one result */, 0);
|
lua_pcall(L, 1 /* one arg */, 1 /* one result */, 0);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
@@ -866,7 +831,7 @@ int CLuaMenuStringinput::exec(CMenuTarget* /*parent*/, const std::string & /*act
|
|||||||
lua_getfield(L, -1, luaAction.c_str());
|
lua_getfield(L, -1, luaAction.c_str());
|
||||||
lua_remove(L, -2);
|
lua_remove(L, -2);
|
||||||
lua_pushstring(L, luaId.c_str());
|
lua_pushstring(L, luaId.c_str());
|
||||||
lua_pushstring(L, value);
|
lua_pushstring(L, value->c_str());
|
||||||
lua_pcall(L, 2 /* two args */, 1 /* one result */, 0);
|
lua_pcall(L, 2 /* two args */, 1 /* one result */, 0);
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
}
|
}
|
||||||
@@ -952,7 +917,7 @@ int CLuaInstance::MenuAddItem(lua_State *L)
|
|||||||
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 CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, b->name.c_str(), NONEXISTANT_LOCALE));
|
||||||
} else {
|
} else {
|
||||||
m->m->addItem(GenericMenuSeparatorLine);
|
m->m->addItem(GenericMenuSeparatorLine);
|
||||||
}
|
}
|
||||||
@@ -997,7 +962,7 @@ int CLuaInstance::MenuAddItem(lua_State *L)
|
|||||||
m->tofree.push_back(kext);
|
m->tofree.push_back(kext);
|
||||||
lua_pushstring(L, "options");
|
lua_pushstring(L, "options");
|
||||||
lua_gettable(L, -2);
|
lua_gettable(L, -2);
|
||||||
b->i = 0;
|
b->int_val = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
if (lua_istable(L, -1))
|
if (lua_istable(L, -1))
|
||||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
|
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
|
||||||
@@ -1009,7 +974,7 @@ int CLuaInstance::MenuAddItem(lua_State *L)
|
|||||||
kext[j].valname = strdup(val);
|
kext[j].valname = strdup(val);
|
||||||
m->tofree.push_back((void *)kext[j].valname);
|
m->tofree.push_back((void *)kext[j].valname);
|
||||||
if (!strcmp(value.c_str(), kext[j].valname))
|
if (!strcmp(value.c_str(), kext[j].valname))
|
||||||
b->i = kext[j].key;
|
b->int_val = kext[j].key;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
@@ -1022,7 +987,7 @@ int CLuaInstance::MenuAddItem(lua_State *L)
|
|||||||
b->str_val = value;
|
b->str_val = value;
|
||||||
mi = new CMenuOptionStringChooser(b->name.c_str(), &b->str_val, enabled, m->observ, directkey, icon.c_str(), pulldown);
|
mi = new CMenuOptionStringChooser(b->name.c_str(), &b->str_val, enabled, m->observ, directkey, icon.c_str(), pulldown);
|
||||||
} else if (type == "stringinput") {
|
} else if (type == "stringinput") {
|
||||||
strncpy(b->s, value.c_str(), sizeof(b->s));
|
b->str_val = value;
|
||||||
std::string valid_chars = "abcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?-. ";
|
std::string valid_chars = "abcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?-. ";
|
||||||
tableLookup(L, "valid_chars", valid_chars);
|
tableLookup(L, "valid_chars", valid_chars);
|
||||||
int sms = 0; tableLookup(L, "sms", sms);
|
int sms = 0; tableLookup(L, "sms", sms);
|
||||||
@@ -1031,7 +996,7 @@ int CLuaInstance::MenuAddItem(lua_State *L)
|
|||||||
mi = new CMenuForwarder(b->name, enabled, b->str_val, stringinput, NULL/*ActionKey*/, directkey, icon.c_str(), right_icon.c_str());
|
mi = new CMenuForwarder(b->name, enabled, b->str_val, stringinput, NULL/*ActionKey*/, directkey, icon.c_str(), right_icon.c_str());
|
||||||
m->targets.push_back(stringinput);
|
m->targets.push_back(stringinput);
|
||||||
} else if (type == "filebrowser") {
|
} else if (type == "filebrowser") {
|
||||||
strncpy(b->s, value.c_str(), sizeof(b->s));
|
b->str_val = value;
|
||||||
int dirMode = 0; tableLookup(L, "dir_mode", dirMode);
|
int dirMode = 0; tableLookup(L, "dir_mode", dirMode);
|
||||||
CLuaMenuFilebrowser *filebrowser = new CLuaMenuFilebrowser(L, action, id, &b->str_val, dirMode);
|
CLuaMenuFilebrowser *filebrowser = new CLuaMenuFilebrowser(L, action, id, &b->str_val, dirMode);
|
||||||
lua_pushstring(L, "filter");
|
lua_pushstring(L, "filter");
|
||||||
@@ -1304,7 +1269,7 @@ int CLuaInstance::MessageboxExec(lua_State *L)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = ShowMsgUTF(name.c_str(), text.c_str(), (CMessageBox::result_) default_button, (CMessageBox::buttons_) show_buttons, icon.empty() ? NULL : icon.c_str(), width, timeout, return_default_on_timeout);
|
int res = ShowMsgUTF(name, text, (CMessageBox::result_) default_button, (CMessageBox::buttons_) show_buttons, icon.empty() ? NULL : icon.c_str(), width, timeout, return_default_on_timeout);
|
||||||
|
|
||||||
tmp = "cancel";
|
tmp = "cancel";
|
||||||
for (int i = 0; mbr[i].name; i++)
|
for (int i = 0; mbr[i].name; i++)
|
||||||
@@ -1316,4 +1281,3 @@ int CLuaInstance::MessageboxExec(lua_State *L)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
@@ -26,11 +26,9 @@ extern "C" {
|
|||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
}
|
}
|
||||||
#include <driver/fb_window.h>
|
#include <driver/fb_window.h>
|
||||||
#ifdef MARTII
|
|
||||||
#include <gui/widget/menue.h>
|
#include <gui/widget/menue.h>
|
||||||
#include <gui/widget/hintbox.h>
|
#include <gui/widget/hintbox.h>
|
||||||
#include <gui/widget/messagebox.h>
|
#include <gui/widget/messagebox.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
/* this is stored as userdata in the lua_State */
|
/* this is stored as userdata in the lua_State */
|
||||||
struct CLuaData
|
struct CLuaData
|
||||||
@@ -41,11 +39,8 @@ struct CLuaData
|
|||||||
|
|
||||||
struct CLuaMenuItem
|
struct CLuaMenuItem
|
||||||
{
|
{
|
||||||
union //value
|
int int_val;
|
||||||
{
|
std::string str_val;
|
||||||
int i;
|
|
||||||
char s[255];
|
|
||||||
};
|
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,7 +76,7 @@ class CLuaMenuForwarder : public CMenuTarget
|
|||||||
class CLuaMenuFilebrowser : public CLuaMenuForwarder
|
class CLuaMenuFilebrowser : public CLuaMenuForwarder
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
char *value;
|
std::string *value;
|
||||||
bool dirMode;
|
bool dirMode;
|
||||||
std::vector<std::string> filter;
|
std::vector<std::string> filter;
|
||||||
public:
|
public:
|
||||||
@@ -93,7 +88,7 @@ class CLuaMenuFilebrowser : public CLuaMenuForwarder
|
|||||||
class CLuaMenuStringinput : public CLuaMenuForwarder
|
class CLuaMenuStringinput : public CLuaMenuForwarder
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
char *value;
|
std::string *value;
|
||||||
std::string valid_chars;
|
std::string valid_chars;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *icon;
|
const char *icon;
|
||||||
@@ -122,7 +117,7 @@ class CLuaMessagebox
|
|||||||
~CLuaMessagebox();
|
~CLuaMessagebox();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* inspired by Steve Kemp http://www.steve.org.uk/ */
|
/* inspired by Steve Kemp http://www.steve.org.uk/ */
|
||||||
class CLuaInstance
|
class CLuaInstance
|
||||||
@@ -147,7 +142,6 @@ private:
|
|||||||
static int FontHeight(lua_State *L);
|
static int FontHeight(lua_State *L);
|
||||||
static int GetInput(lua_State *L);
|
static int GetInput(lua_State *L);
|
||||||
static int GCWindow(lua_State *L);
|
static int GCWindow(lua_State *L);
|
||||||
#ifdef MARTII
|
|
||||||
static int Blit(lua_State *L);
|
static int Blit(lua_State *L);
|
||||||
static int GetLanguage(lua_State *L);
|
static int GetLanguage(lua_State *L);
|
||||||
static int GetSize(lua_State *L);
|
static int GetSize(lua_State *L);
|
||||||
@@ -176,7 +170,6 @@ private:
|
|||||||
|
|
||||||
static bool tableLookup(lua_State*, const char*, std::string&);
|
static bool tableLookup(lua_State*, const char*, std::string&);
|
||||||
static bool tableLookup(lua_State*, const char*, int&);
|
static bool tableLookup(lua_State*, const char*, int&);
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _LUAINSTANCE_H */
|
#endif /* _LUAINSTANCE_H */
|
||||||
|
Reference in New Issue
Block a user