From 77a2b389bd6b5f4ad9a43183e7f8a075c13516c7 Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Wed, 28 Oct 2015 12:11:59 +0100 Subject: [PATCH] CLuaInstance: Add script function "createChannelIDfromUrl' to create... ...WebTV channel_id from a specified url - Set Lua api version to 1.6 --- src/gui/luainstance.cpp | 27 +++++++++++++++++++++++++++ src/gui/luainstance.h | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) 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 */