diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index e88ce2bcb..e10306763 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "luainstance.h" #include @@ -529,6 +530,7 @@ const luaL_Reg CLuaInstance::methods[] = { "strFind", CLuaInstance::strFind }, { "strSub", CLuaInstance::strSub }, { "checkVersion", CLuaInstance::checkVersion }, + { "createChannelIDfromUrl", CLuaInstance::createChannelIDfromUrl }, { NULL, NULL } }; @@ -2708,3 +2710,28 @@ int CLuaInstance::checkVersion(lua_State *L) } // -------------------------------------------------------------------------------- + +int CLuaInstance::createChannelIDfromUrl(lua_State *L) +{ + int numargs = lua_gettop(L); + if (numargs < 2) { + printf("CLuaInstance::%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), "%llx", id); + + lua_pushstring(L, id_str); + return 1; +} + +// -------------------------------------------------------------------------------- diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 2420c0368..e670b2237 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -34,7 +34,7 @@ extern "C" { #include #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 5 +#define LUA_API_VERSION_MINOR 6 /* this is stored as userdata in the lua_State */ struct CLuaData @@ -319,6 +319,7 @@ private: static bool tableLookup(lua_State*, const char*, bool &value); static int checkVersion(lua_State *L); + static int createChannelIDfromUrl(lua_State *L); }; #endif /* _LUAINSTANCE_H */