diff options
author | Lauri Aarnio <Lauri.Aarnio@iki.fi> | 2008-09-16 18:38:46 +0300 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2008-09-27 00:02:42 +0300 |
commit | 759aec56c7e0edbe3ee9aaf625e1352ae3ce6dbd (patch) | |
tree | 88cb5e9eb66d3ed5e5a6f2bc9eac9eb3c5d177c3 /luaif | |
parent | bfa948dd17f22f444ddec99225120fc6d0e4911d (diff) |
sb2-show can be used to query string variables from the Lua engine - Also introduces a new C function, sb2__read_string_variable_from_lua__(), which can be used to replace getenv() for variables that have been moved or will be moved away from environment
Diffstat (limited to 'luaif')
-rw-r--r-- | luaif/luaif.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/luaif/luaif.c b/luaif/luaif.c index af9ef05..af1bab2 100644 --- a/luaif/luaif.c +++ b/luaif/luaif.c @@ -246,6 +246,30 @@ void sb2_lua_init(void) lua_engine_state = LES_READY; } +/* Read string variables from lua. + * Note that this function is exported from libsb2.so (for sb2-show etc): */ +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); +} + + /* "sb.decolonize_path", to be called from lua code */ static int lua_sb_decolonize_path(lua_State *l) { |