CLuaInstance: Add versions definition for lua api in luainstance.h

- Version is defined in lua script as APIVERSION.MAJOR, APIVERSION.MINOR
- Set Lua API version to 1.0
This commit is contained in:
M. Liebmann
2015-09-04 13:09:34 +02:00
parent d2035b91fc
commit 00dff2c598
6 changed files with 49 additions and 0 deletions

View File

@@ -866,6 +866,8 @@ lua.boolparam_deprecated3 für einen Boolean Parameter ist veraltet.\n
lua.function_deprecated1 Achtung! lua.function_deprecated1 Achtung!
lua.function_deprecated2 Die Funktion lua.function_deprecated2 Die Funktion
lua.function_deprecated3 ist veraltet,\n bitte nutzen Sie 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.audioplayer Audioplayer
mainmenu.channels Kanalliste mainmenu.channels Kanalliste
mainmenu.clearsectionsd Lösche EPG Cache mainmenu.clearsectionsd Lösche EPG Cache

View File

@@ -867,6 +867,8 @@ lua.boolparam_deprecated3 for a Boolean parameter is deprecated.\n
lua.function_deprecated1 Caution! lua.function_deprecated1 Caution!
lua.function_deprecated2 Function lua.function_deprecated2 Function
lua.function_deprecated3 is deprecated,\n please use 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.audioplayer Audioplayer
mainmenu.channels Channels mainmenu.channels Channels
mainmenu.clearsectionsd Clear EPG Cache mainmenu.clearsectionsd Clear EPG Cache

View File

@@ -278,6 +278,13 @@ static void set_lua_variables(lua_State *L)
{ NULL, 0 } { 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 */ /* list of environment variable arrays to be exported */
lua_envexport e[] = lua_envexport e[] =
{ {
@@ -286,6 +293,7 @@ static void set_lua_variables(lua_State *L)
{ "FONT", fontlist }, { "FONT", fontlist },
{ "CORNER", corners }, { "CORNER", corners },
{ "MENU_RETURN", menureturn }, { "MENU_RETURN", menureturn },
{ "APIVERSION", apiversion },
{ NULL, NULL } { NULL, NULL }
}; };
@@ -511,6 +519,7 @@ const luaL_Reg CLuaInstance::methods[] =
{ "PlayFile", CLuaInstance::PlayFile }, { "PlayFile", CLuaInstance::PlayFile },
{ "strFind", CLuaInstance::strFind }, { "strFind", CLuaInstance::strFind },
{ "strSub", CLuaInstance::strSub }, { "strSub", CLuaInstance::strSub },
{ "checkVersion", CLuaInstance::checkVersion },
{ NULL, NULL } { 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;
}
// --------------------------------------------------------------------------------

View File

@@ -33,6 +33,9 @@ extern "C" {
#include <configfile.h> #include <configfile.h>
#include <vector> #include <vector>
#define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 0
/* this is stored as userdata in the lua_State */ /* this is stored as userdata in the lua_State */
struct CLuaData struct CLuaData
{ {
@@ -308,6 +311,8 @@ private:
static bool tableLookup(lua_State*, const char*, lua_Unsigned&); static bool tableLookup(lua_State*, const char*, lua_Unsigned&);
static bool tableLookup(lua_State*, const char*, void**); static bool tableLookup(lua_State*, const char*, void**);
static bool tableLookup(lua_State*, const char*, bool &value); static bool tableLookup(lua_State*, const char*, bool &value);
static int checkVersion(lua_State *L);
}; };
#endif /* _LUAINSTANCE_H */ #endif /* _LUAINSTANCE_H */

View File

@@ -894,6 +894,8 @@ typedef enum
LOCALE_LUA_FUNCTION_DEPRECATED1, LOCALE_LUA_FUNCTION_DEPRECATED1,
LOCALE_LUA_FUNCTION_DEPRECATED2, LOCALE_LUA_FUNCTION_DEPRECATED2,
LOCALE_LUA_FUNCTION_DEPRECATED3, LOCALE_LUA_FUNCTION_DEPRECATED3,
LOCALE_LUA_VERSIONSCHECK1,
LOCALE_LUA_VERSIONSCHECK2,
LOCALE_MAINMENU_AUDIOPLAYER, LOCALE_MAINMENU_AUDIOPLAYER,
LOCALE_MAINMENU_CHANNELS, LOCALE_MAINMENU_CHANNELS,
LOCALE_MAINMENU_CLEARSECTIONSD, LOCALE_MAINMENU_CLEARSECTIONSD,

View File

@@ -894,6 +894,8 @@ const char * locale_real_names[] =
"lua.function_deprecated1", "lua.function_deprecated1",
"lua.function_deprecated2", "lua.function_deprecated2",
"lua.function_deprecated3", "lua.function_deprecated3",
"lua.versionscheck1",
"lua.versionscheck2",
"mainmenu.audioplayer", "mainmenu.audioplayer",
"mainmenu.channels", "mainmenu.channels",
"mainmenu.clearsectionsd", "mainmenu.clearsectionsd",