From f27a87dea44b7f073bbc68033ea386253e61ec9b Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Tue, 17 May 2016 23:41:05 +0200 Subject: [PATCH] toInt16 function added --- radio/src/lua/api_general.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 390c69662..b2bdaf3ee 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -754,6 +754,24 @@ static int luaPopupInput(lua_State *L) return 1; } +/*luadoc +@function toInt16(value) + +Convert an unsigned value to signed + +@param value (unsigned number) + +@retval number (signed number) + +@status current Introduced in 2.0.0 +*/ +static int luaToInt16(lua_State * L) +{ + int16_t val = (int16_t)luaL_checkunsigned(L, 1); + lua_pushinteger(L, val); + return 1; +} + /*luadoc @function defaultStick(channel) @@ -815,6 +833,7 @@ const luaL_Reg opentxLib[] = { { "defaultStick", luaDefaultStick }, { "defaultChannel", luaDefaultChannel }, { "killEvents", luaKillEvents }, + { "toInt16", luaToInt16 }, #if !defined(COLORLCD) { "GREY", luaGrey }, #endif