diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index d73810b50..4b40cfc3f 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -866,6 +866,8 @@ lua.boolparam_deprecated3 für einen Boolean Parameter ist veraltet.\n lua.function_deprecated1 Achtung! lua.function_deprecated2 Die Funktion lua.function_deprecated3 ist veraltet,\n bitte nutzen Sie +lua.versionscheck1 Ihre Lua API Version ist zu alt +lua.versionscheck2 Erforderlich ist mindestens mainmenu.audioplayer Audioplayer mainmenu.channels Kanalliste mainmenu.clearsectionsd Lösche EPG Cache diff --git a/data/locale/english.locale b/data/locale/english.locale index 1131bd941..e0f36c8e8 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -867,6 +867,8 @@ lua.boolparam_deprecated3 for a Boolean parameter is deprecated.\n lua.function_deprecated1 Caution! lua.function_deprecated2 Function lua.function_deprecated3 is deprecated,\n please use +lua.versionscheck1 Your Lua API version is too old +lua.versionscheck2 This requires at least mainmenu.audioplayer Audioplayer mainmenu.channels Channels mainmenu.clearsectionsd Clear EPG Cache diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index 6587ef0c3..18641b641 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -278,6 +278,13 @@ static void set_lua_variables(lua_State *L) { NULL, 0 } }; + table_key apiversion[] = + { + { "MAJOR", LUA_API_VERSION_MAJOR }, + { "MINOR", LUA_API_VERSION_MINOR }, + { NULL, 0 } + }; + /* list of environment variable arrays to be exported */ lua_envexport e[] = { @@ -286,6 +293,7 @@ static void set_lua_variables(lua_State *L) { "FONT", fontlist }, { "CORNER", corners }, { "MENU_RETURN", menureturn }, + { "APIVERSION", apiversion }, { NULL, NULL } }; @@ -511,6 +519,7 @@ const luaL_Reg CLuaInstance::methods[] = { "PlayFile", CLuaInstance::PlayFile }, { "strFind", CLuaInstance::strFind }, { "strSub", CLuaInstance::strSub }, + { "checkVersion", CLuaInstance::checkVersion }, { NULL, NULL } }; @@ -2611,3 +2620,30 @@ int CLuaInstance::LuaConfigFileDelete(lua_State *L) } // -------------------------------------------------------------------------------- + +int CLuaInstance::checkVersion(lua_State *L) +{ + int numargs = lua_gettop(L); + if (numargs < 3) { + printf("CLuaInstance::%s: not enough arguments (%d, expected 2)\n", __func__, numargs); + lua_pushnil(L); + return 1; + } + int major=0, minor=0, ret=1; + major = luaL_checkint(L, 2); + minor = luaL_checkint(L, 3); + if ((major > LUA_API_VERSION_MAJOR) || ((major == LUA_API_VERSION_MAJOR) && (minor > LUA_API_VERSION_MINOR))) { + ret = 0; + char msg[1024]; + snprintf(msg, sizeof(msg)-1, "%s (v%d.%d)\n%s v%d.%d", + g_Locale->getText(LOCALE_LUA_VERSIONSCHECK1), + LUA_API_VERSION_MAJOR, LUA_API_VERSION_MINOR, + g_Locale->getText(LOCALE_LUA_VERSIONSCHECK2), + major, minor); + ShowMsg(LOCALE_MESSAGEBOX_ERROR, msg, CMessageBox::mbrBack, CMessageBox::mbBack, NEUTRINO_ICON_ERROR); + } + lua_pushinteger(L, ret); + return 1; +} + +// -------------------------------------------------------------------------------- diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 89956fed2..98389ef58 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -33,6 +33,9 @@ extern "C" { #include #include +#define LUA_API_VERSION_MAJOR 1 +#define LUA_API_VERSION_MINOR 0 + /* this is stored as userdata in the lua_State */ struct CLuaData { @@ -308,6 +311,8 @@ private: static bool tableLookup(lua_State*, const char*, lua_Unsigned&); static bool tableLookup(lua_State*, const char*, void**); static bool tableLookup(lua_State*, const char*, bool &value); + + static int checkVersion(lua_State *L); }; #endif /* _LUAINSTANCE_H */ diff --git a/src/system/locals.h b/src/system/locals.h index ed425dc62..0d018f975 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -894,6 +894,8 @@ typedef enum LOCALE_LUA_FUNCTION_DEPRECATED1, LOCALE_LUA_FUNCTION_DEPRECATED2, LOCALE_LUA_FUNCTION_DEPRECATED3, + LOCALE_LUA_VERSIONSCHECK1, + LOCALE_LUA_VERSIONSCHECK2, LOCALE_MAINMENU_AUDIOPLAYER, LOCALE_MAINMENU_CHANNELS, LOCALE_MAINMENU_CLEARSECTIONSD, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index a0c126740..cb3bc3013 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -894,6 +894,8 @@ const char * locale_real_names[] = "lua.function_deprecated1", "lua.function_deprecated2", "lua.function_deprecated3", + "lua.versionscheck1", + "lua.versionscheck2", "mainmenu.audioplayer", "mainmenu.channels", "mainmenu.clearsectionsd",