diff --git a/src/gui/lua/lua_misc.cpp b/src/gui/lua/lua_misc.cpp index e1c02bf76..03b396975 100644 --- a/src/gui/lua/lua_misc.cpp +++ b/src/gui/lua/lua_misc.cpp @@ -42,16 +42,42 @@ CLuaInstMisc* CLuaInstMisc::getInstance() return LuaInstMisc; } -CLuaData *CLuaInstMisc::CheckData(lua_State *L, int narg) +CLuaMisc *CLuaInstMisc::MiscCheckData(lua_State *L, int n) { - luaL_checktype(L, narg, LUA_TUSERDATA); - void *ud = luaL_checkudata(L, narg, LUA_CLASSNAME); - if (!ud) - fprintf(stderr, "[CLuaInstMisc::%s] wrong type %p, %d, %s\n", __func__, L, narg, LUA_CLASSNAME); - return *(CLuaData **)ud; // unbox pointer + return *(CLuaMisc **) luaL_checkudata(L, n, LUA_MISC_CLASSNAME); } -int CLuaInstMisc::strFind_old(lua_State *L) +void CLuaInstMisc::LuaMiscRegister(lua_State *L) +{ + luaL_Reg meth[] = { + { "new", CLuaInstMisc::MiscNew }, + { "strFind", CLuaInstMisc::strFind }, + { "strSub", CLuaInstMisc::strSub }, + { "enableInfoClock", CLuaInstMisc::enableInfoClock }, + { "runScript", CLuaInstMisc::runScriptExt }, + { "GetRevision", CLuaInstMisc::GetRevision }, + { "checkVersion", CLuaInstMisc::checkVersion }, + { "__gc", CLuaInstMisc::MiscDelete }, + { NULL, NULL } + }; + + luaL_newmetatable(L, LUA_MISC_CLASSNAME); + luaL_setfuncs(L, meth, 0); + lua_pushvalue(L, -1); + lua_setfield(L, -1, "__index"); + lua_setglobal(L, LUA_MISC_CLASSNAME); +} + +int CLuaInstMisc::MiscNew(lua_State *L) +{ + CLuaMisc **udata = (CLuaMisc **) lua_newuserdata(L, sizeof(CLuaMisc *)); + *udata = new CLuaMisc(); + luaL_getmetatable(L, LUA_MISC_CLASSNAME); + lua_setmetatable(L, -2); + return 1; +} + +int CLuaInstMisc::strFind(lua_State *L) { int numargs = lua_gettop(L); if (numargs < 3) { @@ -75,7 +101,7 @@ int CLuaInstMisc::strFind_old(lua_State *L) else ret = str.find(s2, pos); -// printf("####[%s:%d] str_len: %d, s2: %s, pos: %d, n: %d, ret: %d\n", __func__, __LINE__, str.length(), s2, pos, n, ret); + LUA_DEBUG("####[%s:%d] str_len: %d, s2: %s, pos: %d, n: %d, ret: %d\n", __func__, __LINE__, str.length(), s2, pos, n, ret); if (ret == (int)std::string::npos) lua_pushnil(L); else @@ -83,7 +109,7 @@ int CLuaInstMisc::strFind_old(lua_State *L) return 1; } -int CLuaInstMisc::strSub_old(lua_State *L) +int CLuaInstMisc::strSub(lua_State *L) { int numargs = lua_gettop(L); if (numargs < 3) { @@ -102,35 +128,12 @@ int CLuaInstMisc::strSub_old(lua_State *L) std::string str(s1); ret = str.substr(pos, len); -// printf("####[%s:%d] str_len: %d, pos: %d, len: %d, ret_len: %d\n", __func__, __LINE__, str.length(), pos, len, ret.length()); + LUA_DEBUG("####[%s:%d] str_len: %d, pos: %d, len: %d, ret_len: %d\n", __func__, __LINE__, str.length(), pos, len, ret.length()); lua_pushstring(L, ret.c_str()); return 1; } -int CLuaInstMisc::createChannelIDfromUrl_old(lua_State *L) -{ - int numargs = lua_gettop(L); - if (numargs < 2) { - printf("CLuaInstMisc::%s: no arguments\n", __func__); - lua_pushnil(L); - return 1; - } - - const char *url = luaL_checkstring(L, 2); - if (strlen(url) < 1 ) { - lua_pushnil(L); - return 1; - } - - t_channel_id id = CREATE_CHANNEL_ID(0, 0, 0, url); - char id_str[17]; - snprintf(id_str, sizeof(id_str), "%" PRIx64, id); - - lua_pushstring(L, id_str); - return 1; -} - -int CLuaInstMisc::enableInfoClock_old(lua_State *L) +int CLuaInstMisc::enableInfoClock(lua_State *L) { bool enable = true; int numargs = lua_gettop(L); @@ -140,11 +143,8 @@ int CLuaInstMisc::enableInfoClock_old(lua_State *L) return 0; } -int CLuaInstMisc::runScriptExt_old(lua_State *L) +int CLuaInstMisc::runScriptExt(lua_State *L) { - CLuaData *W = CheckData(L, 1); - if (!W) return 0; - int numargs = lua_gettop(L); const char *script = luaL_checkstring(L, 2); std::vector args; @@ -161,7 +161,7 @@ int CLuaInstMisc::runScriptExt_old(lua_State *L) return 0; } -int CLuaInstMisc::GetRevision_old(lua_State *L) +int CLuaInstMisc::GetRevision(lua_State *L) { unsigned int rev = 0; std::string hw = ""; @@ -174,7 +174,7 @@ int CLuaInstMisc::GetRevision_old(lua_State *L) return 2; } -int CLuaInstMisc::checkVersion_old(lua_State *L) +int CLuaInstMisc::checkVersion(lua_State *L) { int numargs = lua_gettop(L); if (numargs < 3) { @@ -197,3 +197,61 @@ int CLuaInstMisc::checkVersion_old(lua_State *L) lua_pushinteger(L, 1); /* for backward compatibility */ return 1; } + +int CLuaInstMisc::MiscDelete(lua_State *L) +{ + CLuaMisc *D = MiscCheckData(L, 1); + delete D; + return 0; +} + +/* -------------------------------------------------------------- + deprecated functions + --------------------------------------------------------------- */ + +//#define MISC_FUNC_DEPRECATED miscFunctionDeprecated +#define MISC_FUNC_DEPRECATED(...) + +void CLuaInstMisc::miscFunctionDeprecated(lua_State *L, std::string oldFunc) +{ + std::string of = std::string("n:") + oldFunc + "()"; + std::string nf = std::string("M = misc.new(); M:") + oldFunc + "()"; + functionDeprecated(L, of.c_str(), nf.c_str()); + printf(" [see also] \33[33m%s\33[0m\n", LUA_WIKI "/Kategorie:Lua:Neutrino-API:SonstigeFunktionen:de"); +} + +int CLuaInstMisc::strFind_old(lua_State *L) +{ + MISC_FUNC_DEPRECATED(L, "strFind"); + return strFind(L); +} + +int CLuaInstMisc::strSub_old(lua_State *L) +{ + MISC_FUNC_DEPRECATED(L, "strSub"); + return strSub(L); +} + +int CLuaInstMisc::enableInfoClock_old(lua_State *L) +{ + MISC_FUNC_DEPRECATED(L, "enableInfoClock"); + return enableInfoClock(L); +} + +int CLuaInstMisc::runScriptExt_old(lua_State *L) +{ + MISC_FUNC_DEPRECATED(L, "runScript"); + return runScriptExt(L); +} + +int CLuaInstMisc::GetRevision_old(lua_State *L) +{ + MISC_FUNC_DEPRECATED(L, "GetRevision"); + return GetRevision(L); +} + +int CLuaInstMisc::checkVersion_old(lua_State *L) +{ + MISC_FUNC_DEPRECATED(L, "checkVersion"); + return checkVersion(L); +} diff --git a/src/gui/lua/lua_misc.h b/src/gui/lua/lua_misc.h index 44c41f467..3c6d7b55c 100644 --- a/src/gui/lua/lua_misc.h +++ b/src/gui/lua/lua_misc.h @@ -21,34 +21,41 @@ #ifndef _LUAMISCFUNCS_H #define _LUAMISCFUNCS_H -/* class CLuaMisc { public: CLuaMisc() {}; ~CLuaMisc() {}; }; -*/ class CLuaInstMisc { - static CLuaData *CheckData(lua_State *L, int narg); public: CLuaInstMisc() {}; ~CLuaInstMisc() {}; static CLuaInstMisc* getInstance(); -// static void MiscRegister(lua_State *L); + static void LuaMiscRegister(lua_State *L); + /* deprecated functions */ static int strFind_old(lua_State *L); static int strSub_old(lua_State *L); - static int createChannelIDfromUrl_old(lua_State *L); static int enableInfoClock_old(lua_State *L); static int runScriptExt_old(lua_State *L); static int GetRevision_old(lua_State *L); static int checkVersion_old(lua_State *L); -// private: -// static CLuaMisc *MiscCheck(lua_State *L, int n); + private: + static CLuaMisc *MiscCheckData(lua_State *L, int n); + static int MiscNew(lua_State *L); + static int strFind(lua_State *L); + static int strSub(lua_State *L); + static int enableInfoClock(lua_State *L); + static int runScriptExt(lua_State *L); + static int GetRevision(lua_State *L); + static int checkVersion(lua_State *L); + static int MiscDelete(lua_State *L); + + static void miscFunctionDeprecated(lua_State *L, std::string oldFunc); }; #endif //_LUAMISCFUNCS_H diff --git a/src/gui/lua/lua_video.cpp b/src/gui/lua/lua_video.cpp index 0503fa325..c1f7207b4 100644 --- a/src/gui/lua/lua_video.cpp +++ b/src/gui/lua/lua_video.cpp @@ -45,16 +45,43 @@ CLuaInstVideo* CLuaInstVideo::getInstance() return LuaInstVideo; } -CLuaData *CLuaInstVideo::CheckData(lua_State *L, int narg) +CLuaVideo *CLuaInstVideo::VideoCheckData(lua_State *L, int n) { - luaL_checktype(L, narg, LUA_TUSERDATA); - void *ud = luaL_checkudata(L, narg, LUA_CLASSNAME); - if (!ud) - fprintf(stderr, "[CLuaInstVideo::%s] wrong type %p, %d, %s\n", __func__, L, narg, LUA_CLASSNAME); - return *(CLuaData **)ud; // unbox pointer + return *(CLuaVideo **) luaL_checkudata(L, n, LUA_VIDEO_CLASSNAME); } -int CLuaInstVideo::setBlank_old(lua_State *L) +void CLuaInstVideo::LuaVideoRegister(lua_State *L) +{ + luaL_Reg meth[] = { + { "new", CLuaInstVideo::VideoNew }, + { "setBlank", CLuaInstVideo::setBlank }, + { "ShowPicture", CLuaInstVideo::ShowPicture }, + { "StopPicture", CLuaInstVideo::StopPicture }, + { "PlayFile", CLuaInstVideo::PlayFile }, + { "zapitStopPlayBack", CLuaInstVideo::zapitStopPlayBack }, + { "channelRezap", CLuaInstVideo::channelRezap }, + { "createChannelIDfromUrl", CLuaInstVideo::createChannelIDfromUrl }, + { "__gc", CLuaInstVideo::VideoDelete }, + { NULL, NULL } + }; + + luaL_newmetatable(L, LUA_VIDEO_CLASSNAME); + luaL_setfuncs(L, meth, 0); + lua_pushvalue(L, -1); + lua_setfield(L, -1, "__index"); + lua_setglobal(L, LUA_VIDEO_CLASSNAME); +} + +int CLuaInstVideo::VideoNew(lua_State *L) +{ + CLuaVideo **udata = (CLuaVideo **) lua_newuserdata(L, sizeof(CLuaVideo *)); + *udata = new CLuaVideo(); + luaL_getmetatable(L, LUA_VIDEO_CLASSNAME); + lua_setmetatable(L, -2); + return 1; +} + +int CLuaInstVideo::setBlank(lua_State *L) { bool enable = true; int numargs = lua_gettop(L); @@ -64,22 +91,22 @@ int CLuaInstVideo::setBlank_old(lua_State *L) return 0; } -int CLuaInstVideo::ShowPicture_old(lua_State *L) +int CLuaInstVideo::ShowPicture(lua_State *L) { const char *fname = luaL_checkstring(L, 2); CFrameBuffer::getInstance()->showFrame(fname); return 0; } -int CLuaInstVideo::StopPicture_old(lua_State */*L*/) +int CLuaInstVideo::StopPicture(lua_State */*L*/) { CFrameBuffer::getInstance()->stopFrame(); return 0; } -int CLuaInstVideo::PlayFile_old(lua_State *L) +int CLuaInstVideo::PlayFile(lua_State *L) { - printf("CLuaInstVideo::%s %d\n", __func__, lua_gettop(L)); + LUA_DEBUG("CLuaInstVideo::%s %d\n", __func__, lua_gettop(L)); int numargs = lua_gettop(L); if (numargs < 3) { @@ -87,13 +114,8 @@ int CLuaInstVideo::PlayFile_old(lua_State *L) return 0; } - CLuaData *W = CheckData(L, 1); - if (!W) - return 0; - if (W->moviePlayerBlocked == false) { + if (CMoviePlayerGui::getInstance().getBlockedFromPlugin() == false) CMoviePlayerGui::getInstance().setBlockedFromPlugin(true); - W->moviePlayerBlocked = true; - } const char *title; const char *info1 = ""; @@ -118,7 +140,7 @@ int CLuaInstVideo::PlayFile_old(lua_State *L) return 1; } -int CLuaInstVideo::zapitStopPlayBack_old(lua_State *L) +int CLuaInstVideo::zapitStopPlayBack(lua_State *L) { bool stop = true; int numargs = lua_gettop(L); @@ -133,10 +155,100 @@ int CLuaInstVideo::zapitStopPlayBack_old(lua_State *L) return 0; } -int CLuaInstVideo::channelRezap_old(lua_State */*L*/) +int CLuaInstVideo::channelRezap(lua_State */*L*/) { CNeutrinoApp::getInstance()->channelRezap(); if (CNeutrinoApp::getInstance()->getMode() == CNeutrinoApp::mode_radio) CFrameBuffer::getInstance()->showFrame("radiomode.jpg"); return 0; } + +int CLuaInstVideo::createChannelIDfromUrl(lua_State *L) +{ + int numargs = lua_gettop(L); + if (numargs < 2) { + printf("CLuaInstVideo::%s: no arguments\n", __func__); + lua_pushnil(L); + return 1; + } + + const char *url = luaL_checkstring(L, 2); + if (strlen(url) < 1 ) { + lua_pushnil(L); + return 1; + } + + t_channel_id id = CREATE_CHANNEL_ID(0, 0, 0, url); + char id_str[17]; + snprintf(id_str, sizeof(id_str), "%" PRIx64, id); + + lua_pushstring(L, id_str); + return 1; +} + +int CLuaInstVideo::VideoDelete(lua_State *L) +{ + CLuaVideo *D = VideoCheckData(L, 1); + delete D; + return 0; +} + + +/* -------------------------------------------------------------- + deprecated functions + --------------------------------------------------------------- */ + +//#define VIDEO_FUNC_DEPRECATED videoFunctionDeprecated +#define VIDEO_FUNC_DEPRECATED(...) + +void CLuaInstVideo::videoFunctionDeprecated(lua_State *L, std::string oldFunc) +{ + std::string of = std::string("n:") + oldFunc + "()"; + std::string nf = std::string("video = video.new(); video:") + oldFunc + "()"; + functionDeprecated(L, of.c_str(), nf.c_str()); + printf(" [see also] \33[33m%s\33[0m\n", LUA_WIKI "/Kategorie:Lua:Neutrino-API:Videofunktionen:de"); +} + +int CLuaInstVideo::setBlank_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "setBlank"); + return setBlank(L); +} + +int CLuaInstVideo::ShowPicture_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "ShowPicture"); + return ShowPicture(L); +} + +int CLuaInstVideo::StopPicture_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "StopPicture"); + return StopPicture(L); +} + +int CLuaInstVideo::PlayFile_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "PlayFile"); + return PlayFile(L); +} + +int CLuaInstVideo::zapitStopPlayBack_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "zapitStopPlayBack"); + return zapitStopPlayBack(L); +} + +int CLuaInstVideo::channelRezap_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "channelRezap"); + return channelRezap(L); +} + +int CLuaInstVideo::createChannelIDfromUrl_old(lua_State *L) +{ + VIDEO_FUNC_DEPRECATED(L, "createChannelIDfromUrl"); + return createChannelIDfromUrl(L); +} + +/* --------------------------------------------------------------- */ diff --git a/src/gui/lua/lua_video.h b/src/gui/lua/lua_video.h index 07904cddd..39edbe122 100644 --- a/src/gui/lua/lua_video.h +++ b/src/gui/lua/lua_video.h @@ -20,32 +20,43 @@ #ifndef _LUAVIDEO_H #define _LUAVIDEO_H -/* class CLuaVideo { public: CLuaVideo() {}; ~CLuaVideo() {}; }; -*/ class CLuaInstVideo { - static CLuaData *CheckData(lua_State *L, int narg); public: CLuaInstVideo() {}; ~CLuaInstVideo() {}; static CLuaInstVideo* getInstance(); -// static void LuaVideoRegister(lua_State *L); + static void LuaVideoRegister(lua_State *L); + /* deprecated functions */ static int setBlank_old(lua_State *L); static int ShowPicture_old(lua_State *L); static int StopPicture_old(lua_State *L); static int PlayFile_old(lua_State *L); static int zapitStopPlayBack_old(lua_State *L); static int channelRezap_old(lua_State *L); + static int createChannelIDfromUrl_old(lua_State *L); -// private: + private: + static CLuaVideo *VideoCheckData(lua_State *L, int n); + static int VideoNew(lua_State *L); + static int setBlank(lua_State *L); + static int ShowPicture(lua_State *L); + static int StopPicture(lua_State *L); + static int PlayFile(lua_State *L); + static int zapitStopPlayBack(lua_State *L); + static int channelRezap(lua_State *L); + static int createChannelIDfromUrl(lua_State *L); + static int VideoDelete(lua_State *L); + + static void videoFunctionDeprecated(lua_State *L, std::string oldFunc); }; #endif //_LUAVIDEO_H diff --git a/src/gui/lua/luainstance.cpp b/src/gui/lua/luainstance.cpp index be7127538..7e34b3510 100644 --- a/src/gui/lua/luainstance.cpp +++ b/src/gui/lua/luainstance.cpp @@ -495,7 +495,6 @@ const luaL_Reg CLuaInstance::methods[] = */ { "strFind", CLuaInstMisc::getInstance()->strFind_old }, { "strSub", CLuaInstMisc::getInstance()->strSub_old }, - { "createChannelIDfromUrl", CLuaInstMisc::getInstance()->createChannelIDfromUrl_old }, { "enableInfoClock", CLuaInstMisc::getInstance()->enableInfoClock_old }, { "runScript", CLuaInstMisc::getInstance()->runScriptExt_old }, { "GetRevision", CLuaInstMisc::getInstance()->GetRevision_old }, @@ -511,6 +510,7 @@ const luaL_Reg CLuaInstance::methods[] = { "PlayFile", CLuaInstVideo::getInstance()->PlayFile_old }, { "zapitStopPlayBack", CLuaInstVideo::getInstance()->zapitStopPlayBack_old }, { "channelRezap", CLuaInstVideo::getInstance()->channelRezap_old }, + { "createChannelIDfromUrl", CLuaInstVideo::getInstance()->createChannelIDfromUrl_old }, { NULL, NULL } }; @@ -559,6 +559,8 @@ void CLuaInstance::registerFunctions() CLuaInstHintbox::getInstance()->HintboxRegister(lua); CLuaInstMenu::getInstance()->MenuRegister(lua); CLuaInstMessagebox::getInstance()->MessageboxRegister(lua); + CLuaInstMisc::getInstance()->LuaMiscRegister(lua); + CLuaInstVideo::getInstance()->LuaVideoRegister(lua); } CLuaData *CLuaInstance::CheckData(lua_State *L, int narg) @@ -589,7 +591,6 @@ int CLuaInstance::NewWindow(lua_State *L) CFBWindow *W = new CFBWindow(x, y, w, h); D->fbwin = W; D->rcinput = g_RCInput; - D->moviePlayerBlocked = false; lua_boxpointer(L, D); luaL_getmetatable(L, className); lua_setmetatable(L, -2); @@ -613,14 +614,13 @@ int CLuaInstance::GCWindow(lua_State *L) CNeutrinoFonts::getInstance()->deleteDynFontExtAll(); /* restoreNeutrino at plugin closing, when blocked from plugin */ - if (w->moviePlayerBlocked && - CMoviePlayerGui::getInstance().getBlockedFromPlugin() && + LUA_DEBUG(">>>>[%s:%d] (restoreNeutrino()) BlockedFromPlugin: %d, Playing: %d\n", __func__, __LINE__, + CMoviePlayerGui::getInstance().getBlockedFromPlugin, CMoviePlayerGui::getInstance().Playing()); + if (CMoviePlayerGui::getInstance().getBlockedFromPlugin() && CMoviePlayerGui::getInstance().Playing()) { -// printf(">>>>[%s:%d] (restoreNeutrino()) moviePlayerBlocked: %d\n", __func__, __LINE__, w->moviePlayerBlocked); - CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); - w->moviePlayerBlocked = false; - CMoviePlayerGui::getInstance().restoreNeutrino(); - } + CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); + CMoviePlayerGui::getInstance().restoreNeutrino(); + } delete w->fbwin; w->rcinput = NULL; diff --git a/src/gui/lua/luainstance.h b/src/gui/lua/luainstance.h index d686a8196..5913edb32 100644 --- a/src/gui/lua/luainstance.h +++ b/src/gui/lua/luainstance.h @@ -31,7 +31,7 @@ extern "C" { #include "luainstance_helpers.h" #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 22 +#define LUA_API_VERSION_MINOR 23 /* inspired by Steve Kemp http://www.steve.org.uk/ */ class CLuaInstance diff --git a/src/gui/lua/luainstance_helpers.h b/src/gui/lua/luainstance_helpers.h index fc3badcd9..c3ac68039 100644 --- a/src/gui/lua/luainstance_helpers.h +++ b/src/gui/lua/luainstance_helpers.h @@ -25,7 +25,12 @@ //#define LUA_DEBUG printf #define LUA_DEBUG(...) -#define LUA_CLASSNAME "neutrino" +#define LUA_CLASSNAME "neutrino" +#define LUA_VIDEO_CLASSNAME "video" +#define LUA_MISC_CLASSNAME "misc" + +//#define LUA_WIKI "http://wiki.tuxbox.org/....." +#define LUA_WIKI "https://slknet.de/wiki/w" /* the magic color that tells us we are using one of the palette colors */ #define MAGIC_COLOR 0x42424200 @@ -72,7 +77,6 @@ struct CLuaData CRCInput *rcinput; fontmap_t fontmap; screenmap_t screenmap; - bool moviePlayerBlocked; }; bool _luaL_checkbool(lua_State *L, int numArg);