summaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-lua.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-14 23:21:32 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 23:34:15 +0100
commite241d7fd03df9f2c8813f3da10a3f3970c601de9 (patch)
tree8cedc7321a1d5346ee5b3968ec3a86e031686160 /ctl-lib/ctl-lua.c
parent7eba3c57c97aa4cae102f4f13eaa1cfa939719c7 (diff)
Get back on track l2c functions.
Change-Id: I8425f0de60a35b4e287c8829fe72cbca80bc55df Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-lua.c')
-rw-r--r--ctl-lib/ctl-lua.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index f8ab69d..f487ed4 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -31,7 +31,7 @@
#include "ctl-config.h"
-#define LUA_FIST_ARG 2 // when using luaL_newlib calllback receive libtable as 1st arg
+#define LUA_FIST_ARG 2 // when using luaL_newlib calllback receive libtable as 1st arg
#define LUA_MSG_MAX_LENGTH 512
#define JSON_ERROR (json_object*)-1
@@ -666,19 +666,22 @@ OnErrorExit:
}
// Function call from LUA when lua2c plugin L2C is used
+// Rfor: Not using LUA_FIRST_ARG here because we didn't use
+// luaL_newlib function, so first args is on stack at first
+// position.
PUBLIC int Lua2cWrapper(void* luaHandle, char *funcname, Lua2cFunctionT callback) {
lua_State* luaState = (lua_State*)luaHandle;
json_object *responseJ=NULL;
- CtlSourceT *source= LuaSourcePop(luaState, LUA_FIST_ARG);
+ CtlSourceT *source= LuaSourcePop(luaState, 1);
- json_object *argsJ= LuaPopArgs(source, luaState, LUA_FIST_ARG+1);
+ json_object *argsJ= LuaPopArgs(source, luaState, 2);
int err= (*callback) (source, argsJ, &responseJ);
// push error code and eventual response to LUA
int count=1;
lua_pushinteger (luaState, err);
- if (!responseJ) count += LuaPushArgument (source, responseJ);
+ count += LuaPushArgument (source, responseJ);
return count;
}
@@ -1202,12 +1205,12 @@ OnErrorExit:
// Register a new L2c list of LUA user plugin commands
-PUBLIC void LuaL2cNewLib(const char *uid, luaL_Reg *l2cFunc, int count) {
+PUBLIC void LuaL2cNewLib(luaL_Reg *l2cFunc, int count) {
// luaL_newlib(luaState, l2cFunc); macro does not work with pointer :(
luaL_checkversion(luaState);
lua_createtable(luaState, 0, count+1);
luaL_setfuncs(luaState,l2cFunc,0);
- lua_setglobal(luaState, uid);
+ lua_setglobal(luaState, "_lua2c");
}
static const luaL_Reg afbFunction[] = {