diff options
author | Lauri Aarnio <Lauri.Aarnio@iki.fi> | 2008-09-24 11:07:35 +0300 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2008-09-27 00:02:43 +0300 |
commit | 4a036760f6479eb56ad9d32146b3282c42f7b65d (patch) | |
tree | fe8b3f96f75734ca8eb2f9667895f2eea87ff8d0 /luaif | |
parent | 7a11a69b9d527c5de43316416109d82f68bdc959 (diff) |
Added interface version check to the C/Lua script interface. - Backgroud: If the "ld.so-trick" is used to start tools from tools_root so that shared libraries are also used from tools_root, another instance of libsb2.so must be installed to tools_root. That libsb2.so must be compiled against the libc, which is available at tools_root => there will be two separately compiled versions of libsb2.so. These must be compiled from the same source, but the binaries are very probably slightly different, if the host os version != tools_root distribution. And still these must use the same lua scripts. Forgetting to update one libsb2.so can cause all kinds of strange side-effects (already tried that :-)
Diffstat (limited to 'luaif')
-rw-r--r-- | luaif/luaif.c | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/luaif/luaif.c b/luaif/luaif.c index a48bb44..a4cfc16 100644 --- a/luaif/luaif.c +++ b/luaif/luaif.c @@ -106,6 +106,26 @@ static int lua_bind_sb_functions(lua_State *l); static pthread_key_t lua_key; static pthread_once_t lua_key_once = PTHREAD_ONCE_INIT; +static char *read_string_variable_from_lua( + struct lua_instance *luaif, + const char *name) +{ + char *result = NULL; + + if (luaif && name && *name) { + lua_getglobal(luaif->lua, name); + result = (char *)lua_tostring(luaif->lua, -1); + if (result) { + result = strdup(result); + } + SB_LOG(SB_LOGLEVEL_DEBUG, + "Lua variable %s = '%s', gettop=%d", + name, (result ? result : "<NULL>"), + lua_gettop(luaif->lua)); + } + return(result); +} + static void free_lua(void *buf) { free(buf); @@ -132,6 +152,7 @@ static void alloc_lua(void) { struct lua_instance *tmp; char *main_lua_script = NULL; + char *lua_if_version = NULL; check_pthread_library(); @@ -198,6 +219,25 @@ static void alloc_lua(void) } lua_call(tmp->lua, 0, 0); enable_mapping(tmp); + + /* check Lua/C interface version. */ + lua_if_version = read_string_variable_from_lua(tmp, + "sb2_lua_c_interface_version"); + if (!lua_if_version) { + SB_LOG(SB_LOGLEVEL_ERROR, "FATAL ERROR: " + "sb2's Lua scripts didn't provide" + " 'sb2_lua_c_interface_version' identifier!"); + exit(1); + } + if (strcmp(lua_if_version, SB2_LUA_C_INTERFACE_VERSION)) { + SB_LOG(SB_LOGLEVEL_ERROR, "FATAL ERROR: " + "sb2's Lua script interface version mismatch:" + " scripts provide '%s', but '%s' was expected", + lua_if_version, SB2_LUA_C_INTERFACE_VERSION); + exit(1); + } + free(lua_if_version); + SB_LOG(SB_LOGLEVEL_DEBUG, "lua initialized."); SB_LOG(SB_LOGLEVEL_NOISE, "gettop=%d", lua_gettop(tmp->lua)); @@ -261,22 +301,9 @@ void sb2_lua_init(void) char *sb2__read_string_variable_from_lua__(const char *name) { struct lua_instance *luaif; - char *result = NULL; luaif = get_lua(); - - if (luaif && name && *name) { - lua_getglobal(luaif->lua, name); - result = (char *)lua_tostring(luaif->lua, -1); - if (result) { - result = strdup(result); - } - SB_LOG(SB_LOGLEVEL_DEBUG, - "Lua variable %s = '%s', gettop=%d", - name, (result ? result : "<NULL>"), - lua_gettop(luaif->lua)); - } - return(result); + return(read_string_variable_from_lua(luaif, name)); } |