luainstance: formatting code using astyle

Origin commit data
------------------
Branch: ni/coolstream
Commit: 4775115a23
Author: vanhofen <vanhofen@gmx.de>
Date: 2021-11-19 (Fri, 19 Nov 2021)

Origin message was:
------------------
- luainstance: formatting code using astyle

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2021-11-19 23:05:40 +01:00
parent d11867e88c
commit 1f2888ad27
2 changed files with 309 additions and 238 deletions

View File

@@ -62,8 +62,8 @@
/* autogenerated from luainstance.h */ /* autogenerated from luainstance.h */
#include "lua_api_version.h" #include "lua_api_version.h"
extern CPictureViewer * g_PicViewer; extern CPictureViewer *g_PicViewer;
extern cVideo * videoDecoder; extern cVideo *videoDecoder;
static void set_lua_variables(lua_State *L) static void set_lua_variables(lua_State *L)
{ {
@@ -213,44 +213,44 @@ static void set_lua_variables(lua_State *L)
{ "PROGRESSBAR_PASSIVE", MAGIC_COLOR | (COL_PROGRESSBAR_PASSIVE_PLUS_0) }, { "PROGRESSBAR_PASSIVE", MAGIC_COLOR | (COL_PROGRESSBAR_PASSIVE_PLUS_0) },
{ "BACKGROUND", MAGIC_COLOR | (COL_BACKGROUND) }, { "BACKGROUND", MAGIC_COLOR | (COL_BACKGROUND) },
{ "COLORED_EVENTS_TEXT", (lua_Unsigned) (COL_COLORED_EVENTS_TEXT) }, { "COLORED_EVENTS_TEXT", (lua_Unsigned)(COL_COLORED_EVENTS_TEXT) },
{ "INFOBAR_TEXT", (lua_Unsigned) (COL_INFOBAR_TEXT) }, { "INFOBAR_TEXT", (lua_Unsigned)(COL_INFOBAR_TEXT) },
/* obsolete */ { "INFOBAR_SHADOW_TEXT", (lua_Unsigned) (COL_MENUFOOT_TEXT) }, // just here to stay backward compatible /* obsolete */ { "INFOBAR_SHADOW_TEXT", (lua_Unsigned)(COL_MENUFOOT_TEXT) }, // just here to stay backward compatible
{ "MENUHEAD_TEXT", (lua_Unsigned) (COL_MENUHEAD_TEXT) }, { "MENUHEAD_TEXT", (lua_Unsigned)(COL_MENUHEAD_TEXT) },
{ "MENUCONTENT_TEXT", (lua_Unsigned) (COL_MENUCONTENT_TEXT) }, { "MENUCONTENT_TEXT", (lua_Unsigned)(COL_MENUCONTENT_TEXT) },
{ "MENUCONTENT_TEXT_PLUS_1", (lua_Unsigned) (COL_MENUCONTENT_TEXT_PLUS_1) }, { "MENUCONTENT_TEXT_PLUS_1", (lua_Unsigned)(COL_MENUCONTENT_TEXT_PLUS_1) },
{ "MENUCONTENT_TEXT_PLUS_2", (lua_Unsigned) (COL_MENUCONTENT_TEXT_PLUS_2) }, { "MENUCONTENT_TEXT_PLUS_2", (lua_Unsigned)(COL_MENUCONTENT_TEXT_PLUS_2) },
{ "MENUCONTENT_TEXT_PLUS_3", (lua_Unsigned) (COL_MENUCONTENT_TEXT_PLUS_3) }, { "MENUCONTENT_TEXT_PLUS_3", (lua_Unsigned)(COL_MENUCONTENT_TEXT_PLUS_3) },
{ "MENUCONTENTDARK_TEXT", (lua_Unsigned) (COL_MENUCONTENTDARK_TEXT) }, { "MENUCONTENTDARK_TEXT", (lua_Unsigned)(COL_MENUCONTENTDARK_TEXT) },
{ "MENUCONTENTDARK_TEXT_PLUS_1", (lua_Unsigned) (COL_MENUCONTENTDARK_TEXT_PLUS_1) }, { "MENUCONTENTDARK_TEXT_PLUS_1", (lua_Unsigned)(COL_MENUCONTENTDARK_TEXT_PLUS_1) },
{ "MENUCONTENTDARK_TEXT_PLUS_2", (lua_Unsigned) (COL_MENUCONTENTDARK_TEXT_PLUS_2) }, { "MENUCONTENTDARK_TEXT_PLUS_2", (lua_Unsigned)(COL_MENUCONTENTDARK_TEXT_PLUS_2) },
{ "MENUCONTENTSELECTED_TEXT", (lua_Unsigned) (COL_MENUCONTENTSELECTED_TEXT) }, { "MENUCONTENTSELECTED_TEXT", (lua_Unsigned)(COL_MENUCONTENTSELECTED_TEXT) },
{ "MENUCONTENTSELECTED_TEXT_PLUS_1", (lua_Unsigned) (COL_MENUCONTENTSELECTED_TEXT_PLUS_1) }, { "MENUCONTENTSELECTED_TEXT_PLUS_1", (lua_Unsigned)(COL_MENUCONTENTSELECTED_TEXT_PLUS_1) },
{ "MENUCONTENTSELECTED_TEXT_PLUS_2", (lua_Unsigned) (COL_MENUCONTENTSELECTED_TEXT_PLUS_2) }, { "MENUCONTENTSELECTED_TEXT_PLUS_2", (lua_Unsigned)(COL_MENUCONTENTSELECTED_TEXT_PLUS_2) },
{ "MENUCONTENTINACTIVE_TEXT", (lua_Unsigned) (COL_MENUCONTENTINACTIVE_TEXT) }, { "MENUCONTENTINACTIVE_TEXT", (lua_Unsigned)(COL_MENUCONTENTINACTIVE_TEXT) },
{ "MENUFOOT_TEXT", (lua_Unsigned) (COL_MENUFOOT_TEXT) }, { "MENUFOOT_TEXT", (lua_Unsigned)(COL_MENUFOOT_TEXT) },
{ "SHADOW_PLUS_0", (lua_Unsigned) (COL_SHADOW_PLUS_0) }, { "SHADOW_PLUS_0", (lua_Unsigned)(COL_SHADOW_PLUS_0) },
{ "MENUHEAD_PLUS_0", (lua_Unsigned) (COL_MENUHEAD_PLUS_0) }, { "MENUHEAD_PLUS_0", (lua_Unsigned)(COL_MENUHEAD_PLUS_0) },
{ "MENUCONTENT_PLUS_0", (lua_Unsigned) (COL_MENUCONTENT_PLUS_0) }, { "MENUCONTENT_PLUS_0", (lua_Unsigned)(COL_MENUCONTENT_PLUS_0) },
{ "MENUCONTENT_PLUS_1", (lua_Unsigned) (COL_MENUCONTENT_PLUS_1) }, { "MENUCONTENT_PLUS_1", (lua_Unsigned)(COL_MENUCONTENT_PLUS_1) },
{ "MENUCONTENT_PLUS_2", (lua_Unsigned) (COL_MENUCONTENT_PLUS_2) }, { "MENUCONTENT_PLUS_2", (lua_Unsigned)(COL_MENUCONTENT_PLUS_2) },
{ "MENUCONTENT_PLUS_3", (lua_Unsigned) (COL_MENUCONTENT_PLUS_3) }, { "MENUCONTENT_PLUS_3", (lua_Unsigned)(COL_MENUCONTENT_PLUS_3) },
{ "MENUCONTENT_PLUS_4", (lua_Unsigned) (COL_MENUCONTENT_PLUS_4) }, { "MENUCONTENT_PLUS_4", (lua_Unsigned)(COL_MENUCONTENT_PLUS_4) },
{ "MENUCONTENT_PLUS_5", (lua_Unsigned) (COL_MENUCONTENT_PLUS_5) }, { "MENUCONTENT_PLUS_5", (lua_Unsigned)(COL_MENUCONTENT_PLUS_5) },
{ "MENUCONTENT_PLUS_6", (lua_Unsigned) (COL_MENUCONTENT_PLUS_6) }, { "MENUCONTENT_PLUS_6", (lua_Unsigned)(COL_MENUCONTENT_PLUS_6) },
{ "MENUCONTENT_PLUS_7", (lua_Unsigned) (COL_MENUCONTENT_PLUS_7) }, { "MENUCONTENT_PLUS_7", (lua_Unsigned)(COL_MENUCONTENT_PLUS_7) },
{ "MENUCONTENTDARK_PLUS_0", (lua_Unsigned) (COL_MENUCONTENTDARK_PLUS_0) }, { "MENUCONTENTDARK_PLUS_0", (lua_Unsigned)(COL_MENUCONTENTDARK_PLUS_0) },
{ "MENUCONTENTDARK_PLUS_2", (lua_Unsigned) (COL_MENUCONTENTDARK_PLUS_2) }, { "MENUCONTENTDARK_PLUS_2", (lua_Unsigned)(COL_MENUCONTENTDARK_PLUS_2) },
{ "MENUCONTENTSELECTED_PLUS_0", (lua_Unsigned) (COL_MENUCONTENTSELECTED_PLUS_0) }, { "MENUCONTENTSELECTED_PLUS_0", (lua_Unsigned)(COL_MENUCONTENTSELECTED_PLUS_0) },
{ "MENUCONTENTSELECTED_PLUS_2", (lua_Unsigned) (COL_MENUCONTENTSELECTED_PLUS_2) }, { "MENUCONTENTSELECTED_PLUS_2", (lua_Unsigned)(COL_MENUCONTENTSELECTED_PLUS_2) },
{ "MENUCONTENTINACTIVE_PLUS_0", (lua_Unsigned) (COL_MENUCONTENTINACTIVE_PLUS_0) }, { "MENUCONTENTINACTIVE_PLUS_0" , (lua_Unsigned)(COL_MENUCONTENTINACTIVE_PLUS_0) },
{ "MENUFOOT_PLUS_0", (lua_Unsigned) (COL_MENUFOOT_PLUS_0) }, { "MENUFOOT_PLUS_0", (lua_Unsigned)(COL_MENUFOOT_PLUS_0) },
{ "FRAME_PLUS_0", (lua_Unsigned) (COL_FRAME_PLUS_0) }, { "FRAME_PLUS_0", (lua_Unsigned)(COL_FRAME_PLUS_0) },
{ "SCROLLBAR_PLUS_0", (lua_Unsigned) (COL_SCROLLBAR_PLUS_0) }, { "SCROLLBAR_PLUS_0", (lua_Unsigned)(COL_SCROLLBAR_PLUS_0) },
{ "SCROLLBAR_ACTIVE_PLUS_0", (lua_Unsigned) (COL_SCROLLBAR_ACTIVE_PLUS_0) }, { "SCROLLBAR_ACTIVE_PLUS_0", (lua_Unsigned)(COL_SCROLLBAR_ACTIVE_PLUS_0) },
{ "SCROLLBAR_PASSIVE_PLUS_0", (lua_Unsigned) (COL_SCROLLBAR_PASSIVE_PLUS_0) }, { "SCROLLBAR_PASSIVE_PLUS_0", (lua_Unsigned)(COL_SCROLLBAR_PASSIVE_PLUS_0) },
{ "PROGRESSBAR_ACTIVE_PLUS_0", (lua_Unsigned) (COL_PROGRESSBAR_ACTIVE_PLUS_0) }, { "PROGRESSBAR_ACTIVE_PLUS_0", (lua_Unsigned)(COL_PROGRESSBAR_ACTIVE_PLUS_0) },
{ "PROGRESSBAR_PASSIVE_PLUS_0", (lua_Unsigned) (COL_PROGRESSBAR_PASSIVE_PLUS_0) }, { "PROGRESSBAR_PASSIVE_PLUS_0", (lua_Unsigned)(COL_PROGRESSBAR_PASSIVE_PLUS_0) },
{ NULL, 0 } { NULL, 0 }
}; };
@@ -290,7 +290,7 @@ static void set_lua_variables(lua_State *L)
{ "BUTTON_TEXT", SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT }, { "BUTTON_TEXT", SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT },
{ "WINDOW_GENERAL", SNeutrinoSettings::FONT_TYPE_WINDOW_GENERAL }, { "WINDOW_GENERAL", SNeutrinoSettings::FONT_TYPE_WINDOW_GENERAL },
{ "RADIOTEXT_TITLE", SNeutrinoSettings::FONT_TYPE_WINDOW_RADIOTEXT_TITLE }, { "RADIOTEXT_TITLE", SNeutrinoSettings::FONT_TYPE_WINDOW_RADIOTEXT_TITLE },
{ "WINDOW_RADIOTEXT_DESC", SNeutrinoSettings::FONT_TYPE_WINDOW_RADIOTEXT_DESC }, { "WINDOW_RADIOTEXT_DESC", SNeutrinoSettings::FONT_TYPE_WINDOW_RADIOTEXT_DESC },
{ NULL, 0 } { NULL, 0 }
}; };
@@ -352,11 +352,11 @@ static void set_lua_variables(lua_State *L)
table_key playstate[] = table_key playstate[] =
{ {
{ "NORMAL", CMoviePlayerGui::PLUGIN_PLAYSTATE_NORMAL }, { "NORMAL", CMoviePlayerGui::PLUGIN_PLAYSTATE_NORMAL },
{ "STOP", CMoviePlayerGui::PLUGIN_PLAYSTATE_STOP }, { "STOP", CMoviePlayerGui::PLUGIN_PLAYSTATE_STOP },
{ "NEXT", CMoviePlayerGui::PLUGIN_PLAYSTATE_NEXT }, { "NEXT", CMoviePlayerGui::PLUGIN_PLAYSTATE_NEXT },
{ "PREV", CMoviePlayerGui::PLUGIN_PLAYSTATE_PREV }, { "PREV", CMoviePlayerGui::PLUGIN_PLAYSTATE_PREV },
{ "LEAVE_ALL", CMoviePlayerGui::PLUGIN_PLAYSTATE_LEAVE_ALL }, { "LEAVE_ALL", CMoviePlayerGui::PLUGIN_PLAYSTATE_LEAVE_ALL },
{ NULL, 0 } { NULL, 0 }
}; };
@@ -396,25 +396,25 @@ static void set_lua_variables(lua_State *L)
table_key neutrino_mode[] = table_key neutrino_mode[] =
{ {
{ "UNKNOWN", (lua_Integer)NeutrinoModes::mode_unknown }, { "UNKNOWN", (lua_Integer)NeutrinoModes::mode_unknown },
{ "TV", (lua_Integer)NeutrinoModes::mode_tv }, { "TV", (lua_Integer)NeutrinoModes::mode_tv },
{ "RADIO", (lua_Integer)NeutrinoModes::mode_radio }, { "RADIO", (lua_Integer)NeutrinoModes::mode_radio },
{ "AVINPUT", (lua_Integer)NeutrinoModes::mode_avinput }, { "AVINPUT", (lua_Integer)NeutrinoModes::mode_avinput },
{ "STANDBY", (lua_Integer)NeutrinoModes::mode_standby }, { "STANDBY", (lua_Integer)NeutrinoModes::mode_standby },
{ "AUDIO", (lua_Integer)NeutrinoModes::mode_audio }, { "AUDIO", (lua_Integer)NeutrinoModes::mode_audio },
{ "PIC", (lua_Integer)NeutrinoModes::mode_pic }, { "PIC", (lua_Integer)NeutrinoModes::mode_pic },
{ "TS", (lua_Integer)NeutrinoModes::mode_ts }, { "TS", (lua_Integer)NeutrinoModes::mode_ts },
{ "OFF", (lua_Integer)NeutrinoModes::mode_off }, { "OFF", (lua_Integer)NeutrinoModes::mode_off },
{ "WEBTV", (lua_Integer)NeutrinoModes::mode_webtv }, { "WEBTV", (lua_Integer)NeutrinoModes::mode_webtv },
{ "WEBRADIO", (lua_Integer)NeutrinoModes::mode_webradio }, { "WEBRADIO", (lua_Integer)NeutrinoModes::mode_webradio },
{ "MASK", (lua_Integer)NeutrinoModes::mode_mask }, { "MASK", (lua_Integer)NeutrinoModes::mode_mask },
{ "NOREZAP", (lua_Integer)NeutrinoModes::norezap }, { "NOREZAP", (lua_Integer)NeutrinoModes::norezap },
{ NULL, 0 } { NULL, 0 }
}; };
table_key post_msg[] = table_key post_msg[] =
{ {
{ "STANDBY_ON", (lua_Integer)CLuaInstMisc::POSTMSG_STANDBY_ON }, { "STANDBY_ON", (lua_Integer)CLuaInstMisc::POSTMSG_STANDBY_ON },
{ NULL, 0 } { NULL, 0 }
}; };
@@ -424,9 +424,9 @@ static void set_lua_variables(lua_State *L)
*/ */
table_key text_alignment[] = table_key text_alignment[] =
{ {
{ "DEFAULT", (lua_Integer)CTextBox::NO_AUTO_LINEBREAK}, { "DEFAULT", (lua_Integer)CTextBox::NO_AUTO_LINEBREAK},
{ "CENTER", (lua_Integer)CTextBox::CENTER}, { "CENTER", (lua_Integer)CTextBox::CENTER},
{ "RIGHT", (lua_Integer)CTextBox::RIGHT}, { "RIGHT", (lua_Integer)CTextBox::RIGHT},
{ NULL, 0 } { NULL, 0 }
}; };
@@ -475,23 +475,25 @@ static void set_lua_variables(lua_State *L)
{ "FONT", fontlist }, { "FONT", fontlist },
{ "CORNER", corners }, { "CORNER", corners },
{ "OFFSET", offsets }, { "OFFSET", offsets },
{ "MENU_RETURN", menureturn }, { "MENU_RETURN", menureturn },
{ "APIVERSION", apiversion }, { "APIVERSION", apiversion },
{ "PLAYSTATE", playstate }, { "PLAYSTATE", playstate },
{ "CC", ccomponents }, { "CC", ccomponents },
{ "DYNFONT", dynfont }, { "DYNFONT", dynfont },
{ "CURL", curl_status }, { "CURL", curl_status },
{ "NMODE", neutrino_mode }, { "NMODE", neutrino_mode },
{ "POSTMSG", post_msg }, { "POSTMSG", post_msg },
{ "TEXT_ALIGNMENT", text_alignment }, { "TEXT_ALIGNMENT", text_alignment },
{ NULL, NULL } { NULL, NULL }
}; };
int i = 0; int i = 0;
while (e[i].name) { while (e[i].name)
{
int j = 0; int j = 0;
lua_newtable(L); lua_newtable(L);
while (e[i].t[j].name) { while (e[i].t[j].name)
{
lua_pushstring(L, e[i].t[j].name); lua_pushstring(L, e[i].t[j].name);
lua_pushinteger(L, e[i].t[j].code); lua_pushinteger(L, e[i].t[j].code);
lua_settable(L, -3); lua_settable(L, -3);
@@ -508,10 +510,12 @@ static void set_lua_variables(lua_State *L)
}; };
i = 0; i = 0;
while (e_u[i].name) { while (e_u[i].name)
{
int j = 0; int j = 0;
lua_newtable(L); lua_newtable(L);
while (e_u[i].t[j].name) { while (e_u[i].t[j].name)
{
lua_pushstring(L, e_u[i].t[j].name); lua_pushstring(L, e_u[i].t[j].name);
lua_pushunsigned(L, e_u[i].t[j].code); lua_pushunsigned(L, e_u[i].t[j].code);
lua_settable(L, -3); lua_settable(L, -3);
@@ -528,10 +532,12 @@ static void set_lua_variables(lua_State *L)
}; };
i = 0; i = 0;
while (e_s[i].name) { while (e_s[i].name)
{
int j = 0; int j = 0;
lua_newtable(L); lua_newtable(L);
while (e_s[i].t[j].name) { while (e_s[i].t[j].name)
{
lua_pushstring(L, e_s[i].t[j].name); lua_pushstring(L, e_s[i].t[j].name);
lua_pushstring(L, e_s[i].t[j].code); lua_pushstring(L, e_s[i].t[j].code);
lua_settable(L, -3); lua_settable(L, -3);
@@ -547,7 +553,7 @@ const char CLuaInstance::className[] = LUA_CLASSNAME;
CLuaInstance::CLuaInstance() CLuaInstance::CLuaInstance()
{ {
DisableAbort = true; DisableAbort = true;
/* Create the intepreter object. */ /* Create the intepreter object. */
lua = luaL_newstate(); lua = luaL_newstate();
/* register standard + custom functions. */ /* register standard + custom functions. */
@@ -576,11 +582,12 @@ void CLuaInstance::runScript(const char *fileName, std::vector<std::string> *arg
// luaL_dofile(lua, fileName); // luaL_dofile(lua, fileName);
/* run the script */ /* run the script */
int status = luaL_loadfile(lua, fileName); int status = luaL_loadfile(lua, fileName);
if (status) { if (status)
bool isString = lua_isstring(lua,-1); {
bool isString = lua_isstring(lua, -1);
const char *null = "NULL"; const char *null = "NULL";
fprintf(stderr, "[CLuaInstance::%s] Can't load file: %s\n", __func__, isString ? lua_tostring(lua, -1):null); fprintf(stderr, "[CLuaInstance::%s] Can't load file: %s\n", __func__, isString ? lua_tostring(lua, -1) : null);
DisplayErrorMessage(isString ? lua_tostring(lua, -1):null, "Lua Script Error:"); DisplayErrorMessage(isString ? lua_tostring(lua, -1) : null, "Lua Script Error:");
if (error_string) if (error_string)
*error_string = std::string(lua_tostring(lua, -1)); *error_string = std::string(lua_tostring(lua, -1));
return; return;
@@ -596,10 +603,13 @@ void CLuaInstance::runScript(const char *fileName, std::vector<std::string> *arg
lua_pushstring(lua, fileName); lua_pushstring(lua, fileName);
lua_rawseti(lua, -2, n++); lua_rawseti(lua, -2, n++);
if (argv && (!argv->empty())) { if (argv && (!argv->empty()))
{
std::string abort = "DisableAbort"; std::string abort = "DisableAbort";
for(std::vector<std::string>::iterator it = argv->begin(); it != argv->end(); ++it) { for (std::vector<std::string>::iterator it = argv->begin(); it != argv->end(); ++it)
if (!it->compare(abort)) { {
if (!it->compare(abort))
{
DisableAbort = false; DisableAbort = false;
continue; continue;
} }
@@ -615,22 +625,25 @@ void CLuaInstance::runScript(const char *fileName, std::vector<std::string> *arg
*result_string = std::string(lua_tostring(lua, -1)); *result_string = std::string(lua_tostring(lua, -1));
if (status) if (status)
{ {
bool isString = lua_isstring(lua,-1); bool isString = lua_isstring(lua, -1);
const char *null = "NULL"; const char *null = "NULL";
fprintf(stderr, "[CLuaInstance::%s] error in script: %s\n", __func__, isString ? lua_tostring(lua, -1):null); fprintf(stderr, "[CLuaInstance::%s] error in script: %s\n", __func__, isString ? lua_tostring(lua, -1) : null);
DisplayErrorMessage(isString ? lua_tostring(lua, -1):null, "Lua Script Error:"); DisplayErrorMessage(isString ? lua_tostring(lua, -1) : null, "Lua Script Error:");
if (error_string) if (error_string)
*error_string = std::string(lua_tostring(lua, -1)); *error_string = std::string(lua_tostring(lua, -1));
/* restoreNeutrino at plugin crash, when blocked from plugin */ /* restoreNeutrino at plugin crash, when blocked from plugin */
if (CMoviePlayerGui::getInstance().getBlockedFromPlugin()) { if (CMoviePlayerGui::getInstance().getBlockedFromPlugin())
{
CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); CMoviePlayerGui::getInstance().setBlockedFromPlugin(false);
CMoviePlayerGui::getInstance().restoreNeutrino(); CMoviePlayerGui::getInstance().restoreNeutrino();
} else if (videoDecoder->getBlank()) }
else if (videoDecoder->getBlank())
CLuaInstVideo::getInstance()->channelRezap(lua); CLuaInstVideo::getInstance()->channelRezap(lua);
} }
else else
{ {
if (CLuaInstVideo::getInstance() && CMoviePlayerGui::getInstance().getBlockedFromPlugin()){ if (CLuaInstVideo::getInstance() && CMoviePlayerGui::getInstance().getBlockedFromPlugin())
{
CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); CMoviePlayerGui::getInstance().setBlockedFromPlugin(false);
CMoviePlayerGui::getInstance().restoreNeutrino(); CMoviePlayerGui::getInstance().restoreNeutrino();
} }
@@ -647,16 +660,18 @@ void CLuaInstance::runScript(const char *fileName, const char *arg0, ...)
args.push_back(arg0); args.push_back(arg0);
va_list list; va_list list;
va_start(list, arg0); va_start(list, arg0);
const char* temp = va_arg(list, const char*); const char *temp = va_arg(list, const char *);
while (temp != NULL) { while (temp != NULL)
if (i >= 64) { {
if (i >= 64)
{
fprintf(stderr, "CLuaInstance::runScript: too many arguments!\n"); fprintf(stderr, "CLuaInstance::runScript: too many arguments!\n");
args.clear(); args.clear();
va_end(list); va_end(list);
return; return;
} }
args.push_back(temp); args.push_back(temp);
temp = va_arg(list, const char*); temp = va_arg(list, const char *);
i++; i++;
} }
va_end(list); va_end(list);
@@ -671,7 +686,7 @@ static void abortHook(lua_State *lua, lua_Debug *)
void CLuaInstance::abortScript() void CLuaInstance::abortScript()
{ {
if(DisableAbort) if (DisableAbort)
lua_sethook(lua, &abortHook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); lua_sethook(lua, &abortHook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
else else
fprintf(stderr, "DisableAbort Script is aktiv\n"); fprintf(stderr, "DisableAbort Script is aktiv\n");
@@ -681,7 +696,7 @@ void CLuaInstance::abortScript()
#ifdef STATIC_LUAPOSIX #ifdef STATIC_LUAPOSIX
/* hack: we link against luaposix, which is included in our /* hack: we link against luaposix, which is included in our
* custom built lualib */ * custom built lualib */
extern "C" { LUAMOD_API int (luaopen_posix_c) (lua_State *L); } extern "C" { LUAMOD_API int (luaopen_posix_c)(lua_State *L); }
#endif #endif
/* load basic functions and register our own C callbacks */ /* load basic functions and register our own C callbacks */
@@ -794,11 +809,12 @@ CLuaData *CLuaInstance::CheckData(lua_State *L, int narg)
{ {
luaL_checktype(L, narg, LUA_TUSERDATA); luaL_checktype(L, narg, LUA_TUSERDATA);
void *ud = luaL_checkudata(L, narg, className); void *ud = luaL_checkudata(L, narg, className);
if (!ud) { if (!ud)
{
fprintf(stderr, "[CLuaInstance::%s] wrong type %p, %d, %s\n", __func__, L, narg, className); fprintf(stderr, "[CLuaInstance::%s] wrong type %p, %d, %s\n", __func__, L, narg, className);
return NULL; return NULL;
} }
return *(CLuaData **)ud; // unbox pointer return *(CLuaData **)ud; // unbox pointer
} }
int CLuaInstance::NewWindow(lua_State *L) int CLuaInstance::NewWindow(lua_State *L)
@@ -831,8 +847,10 @@ int CLuaInstance::GCWindow(lua_State *L)
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaData *w = (CLuaData *)lua_unboxpointer(L, 1); CLuaData *w = (CLuaData *)lua_unboxpointer(L, 1);
if (w && w->fbwin) { if (w && w->fbwin)
for (screenmap_iterator_t it = w->screenmap.begin(); it != w->screenmap.end(); ++it) { {
for (screenmap_iterator_t it = w->screenmap.begin(); it != w->screenmap.end(); ++it)
{
if (it->second != NULL) if (it->second != NULL)
delete[] it->second; delete[] it->second;
} }
@@ -846,15 +864,17 @@ int CLuaInstance::GCWindow(lua_State *L)
bool block = CMoviePlayerGui::getInstance().getBlockedFromPlugin(); bool block = CMoviePlayerGui::getInstance().getBlockedFromPlugin();
bool play = CMoviePlayerGui::getInstance().Playing(); bool play = CMoviePlayerGui::getInstance().Playing();
LUA_DEBUG(">>>>[%s:%d] (restoreNeutrino()) BlockedFromPlugin: %d, Playing: %d\n", __func__, __LINE__, block, play); LUA_DEBUG(">>>>[%s:%d] (restoreNeutrino()) BlockedFromPlugin: %d, Playing: %d\n", __func__, __LINE__, block, play);
if (block && play) { if (block && play)
{
CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); CMoviePlayerGui::getInstance().setBlockedFromPlugin(false);
CMoviePlayerGui::getInstance().restoreNeutrino(); CMoviePlayerGui::getInstance().restoreNeutrino();
} }
else if (videoDecoder->getBlank()) else if (videoDecoder->getBlank())
CLuaInstVideo::getInstance()->channelRezap(L); CLuaInstVideo::getInstance()->channelRezap(L);
if(w){ if (w)
if(w->fbwin) {
if (w->fbwin)
delete w->fbwin; delete w->fbwin;
w->rcinput = NULL; w->rcinput = NULL;
delete w; delete w;
@@ -869,7 +889,8 @@ int CLuaInstance::GetInput(lua_State *L)
neutrino_msg_t msg; neutrino_msg_t msg;
neutrino_msg_data_t data; neutrino_msg_data_t data;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W) return 0; if (!W)
return 0;
if (numargs > 1) if (numargs > 1)
timeout = luaL_checkint(L, 2); timeout = luaL_checkint(L, 2);
W->rcinput->getMsg_ms(&msg, &data, timeout); W->rcinput->getMsg_ms(&msg, &data, timeout);
@@ -895,7 +916,8 @@ int CLuaInstance::Blit(lua_State *)
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->blit((int)lua_tonumber(L, 2)); // enable/disable automatic blit W->fbwin->blit((int)lua_tonumber(L, 2)); // enable/disable automatic blit
else else
@@ -923,7 +945,8 @@ int CLuaInstance::PaintBox(lua_State *L)
lua_Unsigned c; lua_Unsigned c;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
x = luaL_checkint(L, 2); x = luaL_checkint(L, 2);
y = luaL_checkint(L, 3); y = luaL_checkint(L, 3);
w = luaL_checkint(L, 4); w = luaL_checkint(L, 4);
@@ -955,7 +978,8 @@ int CLuaInstance::paintHLineRel(lua_State *L)
lua_Unsigned c; lua_Unsigned c;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
x = luaL_checkint(L, 2); x = luaL_checkint(L, 2);
dx = luaL_checkint(L, 3); dx = luaL_checkint(L, 3);
y = luaL_checkint(L, 4); y = luaL_checkint(L, 4);
@@ -978,7 +1002,8 @@ int CLuaInstance::paintVLineRel(lua_State *L)
lua_Unsigned c; lua_Unsigned c;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
x = luaL_checkint(L, 2); x = luaL_checkint(L, 2);
y = luaL_checkint(L, 3); y = luaL_checkint(L, 3);
dy = luaL_checkint(L, 4); dy = luaL_checkint(L, 4);
@@ -1000,7 +1025,7 @@ int CLuaInstance::paintVLineRel(lua_State *L)
int CLuaInstance::RenderString(lua_State *L) int CLuaInstance::RenderString(lua_State *L)
{ {
int x, y, w, boxh, center; int x, y, w, boxh, center;
Font* font = NULL; Font *font = NULL;
lua_Unsigned c; lua_Unsigned c;
const char *text; const char *text;
int numargs = lua_gettop(L); int numargs = lua_gettop(L);
@@ -1010,54 +1035,62 @@ int CLuaInstance::RenderString(lua_State *L)
center = 0; center = 0;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
int step = 0; int step = 0;
bool isDynFont = false; bool isDynFont = false;
if (lua_isboolean(L, 2)) { if (lua_isboolean(L, 2))
{
if (lua_toboolean(L, 2) == true) if (lua_toboolean(L, 2) == true)
isDynFont = true; isDynFont = true;
step = 1; step = 1;
} }
if (!isDynFont) { if (!isDynFont)
int f = luaL_checkint(L, 2+step); /* font number, use FONT_TYPE_XXX in the script */ {
int f = luaL_checkint(L, 2 + step); /* font number, use FONT_TYPE_XXX in the script */
if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0) if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0)
f = SNeutrinoSettings::FONT_TYPE_MENU; f = SNeutrinoSettings::FONT_TYPE_MENU;
font = g_Font[f]; font = g_Font[f];
} }
else { else
int id = luaL_checkint(L, 2+step); /* dynfont */ {
for (fontmap_iterator_t it = W->fontmap.begin(); it != W->fontmap.end(); ++it) { int id = luaL_checkint(L, 2 + step); /* dynfont */
if (it->first == id) { for (fontmap_iterator_t it = W->fontmap.begin(); it != W->fontmap.end(); ++it)
{
if (it->first == id)
{
font = it->second; font = it->second;
break; break;
} }
} }
if (font == NULL) { if (font == NULL)
{
printf("[CLuaInstance::%s:%d] no font found\n", __func__, __LINE__); printf("[CLuaInstance::%s:%d] no font found\n", __func__, __LINE__);
lua_pushinteger(L, 0); /* no font found */ lua_pushinteger(L, 0); /* no font found */
return 1; return 1;
} }
} }
text = luaL_checkstring(L, 3+step); /* text */ text = luaL_checkstring(L, 3 + step); /* text */
x = luaL_checkint(L, 4+step); x = luaL_checkint(L, 4 + step);
y = luaL_checkint(L, 5+step); y = luaL_checkint(L, 5 + step);
if (numargs > 5+step) if (numargs > 5 + step)
c = luaL_checkunsigned(L, 6+step); c = luaL_checkunsigned(L, 6 + step);
if (numargs > 6+step) if (numargs > 6 + step)
w = luaL_checkint(L, 7+step); w = luaL_checkint(L, 7 + step);
else else
w = W->fbwin->dx - x; w = W->fbwin->dx - x;
if (numargs > 7+step) if (numargs > 7 + step)
boxh = luaL_checkint(L, 8+step); boxh = luaL_checkint(L, 8 + step);
if (numargs > 8+step) if (numargs > 8 + step)
center = luaL_checkint(L, 9+step); center = luaL_checkint(L, 9 + step);
int rwidth = font->getRenderWidth(text); int rwidth = font->getRenderWidth(text);
if (center) { /* center the text inside the box */ if (center) /* center the text inside the box */
{
if (rwidth < w) if (rwidth < w)
x += (w - rwidth) / 2; x += (w - rwidth) / 2;
} }
@@ -1070,43 +1103,50 @@ int CLuaInstance::RenderString(lua_State *L)
int CLuaInstance::getRenderWidth(lua_State *L) int CLuaInstance::getRenderWidth(lua_State *L)
{ {
Font* font = NULL; Font *font = NULL;
const char *text; const char *text;
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W) return 0; if (!W)
return 0;
int step = 0; int step = 0;
bool isDynFont = false; bool isDynFont = false;
if (lua_isboolean(L, 2)) { if (lua_isboolean(L, 2))
{
if (lua_toboolean(L, 2) == true) if (lua_toboolean(L, 2) == true)
isDynFont = true; isDynFont = true;
step = 1; step = 1;
} }
if (!isDynFont) { if (!isDynFont)
int f = luaL_checkint(L, 2+step); /* font number, use FONT_TYPE_XXX in the script */ {
int f = luaL_checkint(L, 2 + step); /* font number, use FONT_TYPE_XXX in the script */
if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0) if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0)
f = SNeutrinoSettings::FONT_TYPE_MENU; f = SNeutrinoSettings::FONT_TYPE_MENU;
font = g_Font[f]; font = g_Font[f];
} }
else { else
int id = luaL_checkint(L, 2+step); /* dynfont */ {
for (fontmap_iterator_t it = W->fontmap.begin(); it != W->fontmap.end(); ++it) { int id = luaL_checkint(L, 2 + step); /* dynfont */
if (it->first == id) { for (fontmap_iterator_t it = W->fontmap.begin(); it != W->fontmap.end(); ++it)
{
if (it->first == id)
{
font = it->second; font = it->second;
break; break;
} }
} }
if (font == NULL) { if (font == NULL)
{
printf("[CLuaInstance::%s:%d] no font found\n", __func__, __LINE__); printf("[CLuaInstance::%s:%d] no font found\n", __func__, __LINE__);
lua_pushinteger(L, 0); /* no font found */ lua_pushinteger(L, 0); /* no font found */
return 1; return 1;
} }
} }
text = luaL_checkstring(L, 3+step); /* text */ text = luaL_checkstring(L, 3 + step); /* text */
lua_pushinteger(L, (int)font->getRenderWidth(text)); lua_pushinteger(L, (int)font->getRenderWidth(text));
return 1; return 1;
@@ -1114,35 +1154,42 @@ int CLuaInstance::getRenderWidth(lua_State *L)
int CLuaInstance::FontHeight(lua_State *L) int CLuaInstance::FontHeight(lua_State *L)
{ {
Font* font = NULL; Font *font = NULL;
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W) return 0; if (!W)
return 0;
int step = 0; int step = 0;
bool isDynFont = false; bool isDynFont = false;
if (lua_isboolean(L, 2)) { if (lua_isboolean(L, 2))
{
if (lua_toboolean(L, 2) == true) if (lua_toboolean(L, 2) == true)
isDynFont = true; isDynFont = true;
step = 1; step = 1;
} }
if (!isDynFont) { if (!isDynFont)
int f = luaL_checkint(L, 2+step); /* font number, use FONT_TYPE_XXX in the script */ {
int f = luaL_checkint(L, 2 + step); /* font number, use FONT_TYPE_XXX in the script */
if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0) if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0)
f = SNeutrinoSettings::FONT_TYPE_MENU; f = SNeutrinoSettings::FONT_TYPE_MENU;
font = g_Font[f]; font = g_Font[f];
} }
else { else
int id = luaL_checkint(L, 2+step); /* dynfont */ {
for (fontmap_iterator_t it = W->fontmap.begin(); it != W->fontmap.end(); ++it) { int id = luaL_checkint(L, 2 + step); /* dynfont */
if (it->first == id) { for (fontmap_iterator_t it = W->fontmap.begin(); it != W->fontmap.end(); ++it)
{
if (it->first == id)
{
font = it->second; font = it->second;
break; break;
} }
} }
if (font == NULL) { if (font == NULL)
{
printf("[CLuaInstance::%s:%d] no font found\n", __func__, __LINE__); printf("[CLuaInstance::%s:%d] no font found\n", __func__, __LINE__);
lua_pushinteger(L, 0); /* no font found */ lua_pushinteger(L, 0); /* no font found */
return 1; return 1;
@@ -1157,15 +1204,18 @@ int CLuaInstance::getDynFont(lua_State *L)
{ {
int numargs = lua_gettop(L); int numargs = lua_gettop(L);
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
if (numargs < 3) { if (numargs < 3)
{
printf("CLuaInstance::%s: not enough arguments (%d, expected 2)\n", __func__, numargs); printf("CLuaInstance::%s: not enough arguments (%d, expected 2)\n", __func__, numargs);
return 0; return 0;
} }
lua_Integer fontID = W->fontmap.size(); lua_Integer fontID = W->fontmap.size();
if (fontID >= CNeutrinoFonts::DYNFONTEXT_MAX) { if (fontID >= CNeutrinoFonts::DYNFONTEXT_MAX)
{
lua_pushnil(L); lua_pushnil(L);
lua_pushinteger(L, DYNFONT_MAXIMUM_FONTS); lua_pushinteger(L, DYNFONT_MAXIMUM_FONTS);
return 2; return 2;
@@ -1173,29 +1223,32 @@ int CLuaInstance::getDynFont(lua_State *L)
int dx = 0, dy = 0; int dx = 0, dy = 0;
lua_Integer style = CNeutrinoFonts::FONT_STYLE_REGULAR; lua_Integer style = CNeutrinoFonts::FONT_STYLE_REGULAR;
std::string text=""; std::string text = "";
dx = luaL_checkint(L, 2); dx = luaL_checkint(L, 2);
if (dx > (lua_Integer)CFrameBuffer::getInstance()->getScreenWidth(true)) { if (dx > (lua_Integer)CFrameBuffer::getInstance()->getScreenWidth(true))
{
lua_pushnil(L); lua_pushnil(L);
lua_pushinteger(L, DYNFONT_TOO_WIDE); lua_pushinteger(L, DYNFONT_TOO_WIDE);
return 2; return 2;
} }
dy = luaL_checkint(L, 3); dy = luaL_checkint(L, 3);
if (dy > 100) { if (dy > 100)
{
lua_pushnil(L); lua_pushnil(L);
lua_pushinteger(L, DYNFONT_TOO_HIGH); lua_pushinteger(L, DYNFONT_TOO_HIGH);
return 2; return 2;
} }
if (numargs > 3) if (numargs > 3)
text = luaL_checkstring(L, 4); text = luaL_checkstring(L, 4);
if (numargs > 4) { if (numargs > 4)
{
style = luaL_checkint(L, 5); style = luaL_checkint(L, 5);
if (style > CNeutrinoFonts::FONT_STYLE_ITALIC) if (style > CNeutrinoFonts::FONT_STYLE_ITALIC)
style = CNeutrinoFonts::FONT_STYLE_REGULAR; style = CNeutrinoFonts::FONT_STYLE_REGULAR;
} }
Font* f = CNeutrinoFonts::getInstance()->getDynFontExt(dx, dy, fontID, text, style); Font *f = CNeutrinoFonts::getInstance()->getDynFontExt(dx, dy, fontID, text, style);
lua_Integer id = fontID + 1; lua_Integer id = fontID + 1;
W->fontmap.insert(fontmap_pair_t(id, f)); W->fontmap.insert(fontmap_pair_t(id, f));
@@ -1214,7 +1267,8 @@ int CLuaInstance::PaintIcon(lua_State *L)
const char *fname; const char *fname;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
fname = luaL_checkstring(L, 2); fname = luaL_checkstring(L, 2);
x = luaL_checkint(L, 3); x = luaL_checkint(L, 3);
y = luaL_checkint(L, 4); y = luaL_checkint(L, 4);
@@ -1227,7 +1281,8 @@ int CLuaInstance::PaintIcon(lua_State *L)
int CLuaInstance::DisplayImage(lua_State *L) int CLuaInstance::DisplayImage(lua_State *L)
{ {
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W) return 0; if (!W)
return 0;
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
int x, y, w, h; int x, y, w, h;
const char *fname; const char *fname;
@@ -1247,7 +1302,8 @@ int CLuaInstance::DisplayImage(lua_State *L)
int CLuaInstance::GetSize(lua_State *L) int CLuaInstance::GetSize(lua_State *L)
{ {
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W) return 0; if (!W)
return 0;
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
int w = 0, h = 0; int w = 0, h = 0;
const char *fname; const char *fname;
@@ -1264,9 +1320,10 @@ int CLuaInstance::GetSize(lua_State *L)
int CLuaInstance::saveScreen(lua_State *L) int CLuaInstance::saveScreen(lua_State *L)
{ {
int x, y, w, h; int x, y, w, h;
fb_pixel_t* buf; fb_pixel_t *buf;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
x = luaL_checkint(L, 2); x = luaL_checkint(L, 2);
y = luaL_checkint(L, 3); y = luaL_checkint(L, 3);
w = luaL_checkint(L, 4); w = luaL_checkint(L, 4);
@@ -1283,10 +1340,11 @@ int CLuaInstance::saveScreen(lua_State *L)
int CLuaInstance::restoreScreen(lua_State *L) int CLuaInstance::restoreScreen(lua_State *L)
{ {
int x, y, w, h, id; int x, y, w, h, id;
fb_pixel_t* buf = NULL; fb_pixel_t *buf = NULL;
bool del; bool del;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
x = luaL_checkint(L, 2); x = luaL_checkint(L, 2);
y = luaL_checkint(L, 3); y = luaL_checkint(L, 3);
w = luaL_checkint(L, 4); w = luaL_checkint(L, 4);
@@ -1294,8 +1352,10 @@ int CLuaInstance::restoreScreen(lua_State *L)
id = luaL_checkint(L, 6); id = luaL_checkint(L, 6);
del = _luaL_checkbool(L, 7); del = _luaL_checkbool(L, 7);
for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it) { for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it)
if (it->first == id) { {
if (it->first == id)
{
buf = it->second; buf = it->second;
if (del) if (del)
it->second = NULL; it->second = NULL;
@@ -1311,12 +1371,16 @@ int CLuaInstance::deleteSavedScreen(lua_State *L)
{ {
int id; int id;
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
id = luaL_checkint(L, 2); id = luaL_checkint(L, 2);
for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it) { for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it)
if (it->first == id) { {
if (it->second != NULL) { if (it->first == id)
{
if (it->second != NULL)
{
delete[] it->second; delete[] it->second;
it->second = NULL; it->second = NULL;
} }
@@ -1329,12 +1393,13 @@ int CLuaInstance::deleteSavedScreen(lua_State *L)
int CLuaInstance::scale2Res(lua_State *L) int CLuaInstance::scale2Res(lua_State *L)
{ {
CLuaData *W = CheckData(L, 1); CLuaData *W = CheckData(L, 1);
if (!W || !W->fbwin) return 0; if (!W || !W->fbwin)
return 0;
int value, ret; int value, ret;
value = luaL_checkint(L, 2); value = luaL_checkint(L, 2);
/* Remove this when pu/fb-setmode branch is merged to master */ /* Remove this when pu/fb-setmode branch is merged to master */
#ifdef SCALE2RES_DEFINED #ifdef SCALE2RES_DEFINED
ret = CFrameBuffer::getInstance()->scale2Res(value); ret = CFrameBuffer::getInstance()->scale2Res(value);
#else #else
@@ -1346,38 +1411,43 @@ int CLuaInstance::scale2Res(lua_State *L)
#if LUA_COMPAT_5_2 #if LUA_COMPAT_5_2
void lua_pushunsigned (lua_State *L, lua_Unsigned n) { void lua_pushunsigned(lua_State *L, lua_Unsigned n)
lua_pushnumber(L, lua_unsigned2number(n)); {
lua_pushnumber(L, lua_unsigned2number(n));
} }
lua_Unsigned luaL_checkunsigned (lua_State *L, int i) { lua_Unsigned luaL_checkunsigned(lua_State *L, int i)
lua_Unsigned result; {
lua_Number n = lua_tonumber(L, i); lua_Unsigned result;
if (n == 0 && !lua_isnumber(L, i)) lua_Number n = lua_tonumber(L, i);
luaL_checktype(L, i, LUA_TNUMBER); if (n == 0 && !lua_isnumber(L, i))
lua_number2unsigned(result, n); luaL_checktype(L, i, LUA_TNUMBER);
return result; lua_number2unsigned(result, n);
return result;
} }
int lua_absindex (lua_State *L, int i) { int lua_absindex(lua_State *L, int i)
if (i < 0 && i > LUA_REGISTRYINDEX) {
i += lua_gettop(L) + 1; if (i < 0 && i > LUA_REGISTRYINDEX)
return i; i += lua_gettop(L) + 1;
return i;
} }
void lua_rawgetp (lua_State *L, int i, const void *p) { void lua_rawgetp(lua_State *L, int i, const void *p)
int abs_i = lua_absindex(L, i); {
lua_pushlightuserdata(L, (void*)p); int abs_i = lua_absindex(L, i);
lua_rawget(L, abs_i); lua_pushlightuserdata(L, (void *)p);
lua_rawget(L, abs_i);
} }
void lua_rawsetp (lua_State *L, int i, const void *p) { void lua_rawsetp(lua_State *L, int i, const void *p)
int abs_i = lua_absindex(L, i); {
luaL_checkstack(L, 1, "not enough stack slots"); int abs_i = lua_absindex(L, i);
lua_pushlightuserdata(L, (void*)p); luaL_checkstack(L, 1, "not enough stack slots");
lua_insert(L, -2); lua_pushlightuserdata(L, (void *)p);
lua_rawset(L, abs_i); lua_insert(L, -2);
lua_rawset(L, abs_i);
} }
#endif #endif

View File

@@ -30,53 +30,54 @@ extern "C" {
#include "luainstance_helpers.h" #include "luainstance_helpers.h"
void LuaInstRegisterFunctions(lua_State *L, bool fromThreads=false); void LuaInstRegisterFunctions(lua_State *L, bool fromThreads = false);
/* inspired by Steve Kemp http://www.steve.org.uk/ */ /* inspired by Steve Kemp http://www.steve.org.uk/ */
class CLuaInstance class CLuaInstance
{ {
static const char className[]; static const char className[];
static CLuaData *CheckData(lua_State *L, int narg); static CLuaData *CheckData(lua_State *L, int narg);
public: public:
CLuaInstance(); CLuaInstance();
~CLuaInstance(); ~CLuaInstance();
void runScript(const char *fileName, std::vector<std::string> *argv = NULL, std::string *result_code = NULL, std::string *result_string = NULL, std::string *error_string = NULL); void runScript(const char *fileName, std::vector<std::string> *argv = NULL, std::string *result_code = NULL, std::string *result_string = NULL, std::string *error_string = NULL);
void abortScript(); void abortScript();
bool DisableAbort; bool DisableAbort;
enum { enum
DYNFONT_NO_ERROR = 0, {
DYNFONT_MAXIMUM_FONTS = 1, DYNFONT_NO_ERROR = 0,
DYNFONT_TOO_WIDE = 2, DYNFONT_MAXIMUM_FONTS = 1,
DYNFONT_TOO_HIGH = 3 DYNFONT_TOO_WIDE = 2,
}; DYNFONT_TOO_HIGH = 3
};
// Example: runScript(fileName, "Arg1", "Arg2", "Arg3", ..., NULL); // Example: runScript(fileName, "Arg1", "Arg2", "Arg3", ..., NULL);
// Type of all parameters: const char* // Type of all parameters: const char*
// The last parameter to NULL is imperative. // The last parameter to NULL is imperative.
void runScript(const char *fileName, const char *arg0, ...); void runScript(const char *fileName, const char *arg0, ...);
static int NewWindow(lua_State *L); static int NewWindow(lua_State *L);
static int GCWindow(lua_State *L); static int GCWindow(lua_State *L);
static int GetInput(lua_State *L); static int GetInput(lua_State *L);
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 PaintBox(lua_State *L); static int PaintBox(lua_State *L);
static int paintHLineRel(lua_State *L); static int paintHLineRel(lua_State *L);
static int paintVLineRel(lua_State *L); static int paintVLineRel(lua_State *L);
static int RenderString(lua_State *L); static int RenderString(lua_State *L);
static int getRenderWidth(lua_State *L); static int getRenderWidth(lua_State *L);
static int FontHeight(lua_State *L); static int FontHeight(lua_State *L);
static int getDynFont(lua_State *L); static int getDynFont(lua_State *L);
static int PaintIcon(lua_State *L); static int PaintIcon(lua_State *L);
static int DisplayImage(lua_State *L); static int DisplayImage(lua_State *L);
static int GetSize(lua_State *L); static int GetSize(lua_State *L);
static int saveScreen(lua_State *L); static int saveScreen(lua_State *L);
static int restoreScreen(lua_State *L); static int restoreScreen(lua_State *L);
static int deleteSavedScreen(lua_State *L); static int deleteSavedScreen(lua_State *L);
static int scale2Res(lua_State *L); static int scale2Res(lua_State *L);
private: private:
lua_State* lua; lua_State *lua;
}; };