diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-26 12:17:55 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | bbb4351eab7476be9a93f0248860ac0d1574d8a6 (patch) | |
tree | 1c5624454be5fc37828341b20de2f2e79fc90013 /controller | |
parent | 1480ff8d68ee4b923596d8178e37eba7b9202a30 (diff) |
Make calling lua2c function from lua works
Change-Id: I56d78a3fe567d1f7a6c675f6a56473f96d325c85
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'controller')
-rw-r--r-- | controller/ctl-action.c | 4 | ||||
-rw-r--r-- | controller/ctl-lua.c | 4 | ||||
-rw-r--r-- | controller/ctl-plugin.c | 12 | ||||
-rw-r--r-- | controller/ctl-plugin.h | 9 |
4 files changed, 21 insertions, 8 deletions
diff --git a/controller/ctl-action.c b/controller/ctl-action.c index 8955adc..ff618d6 100644 --- a/controller/ctl-action.c +++ b/controller/ctl-action.c @@ -23,7 +23,9 @@ #include <string.h> #include "ctl-config.h" - +#ifdef CONTROL_SUPPORT_LUA +#include "ctl-lua.h" +#endif int ActionExecOne(CtlActionT* action, json_object *queryJ) { int err; diff --git a/controller/ctl-lua.c b/controller/ctl-lua.c index 7e51d2a..518ff85 100644 --- a/controller/ctl-lua.c +++ b/controller/ctl-lua.c @@ -282,7 +282,6 @@ static json_object *LuaPopArgs (lua_State* luaState, int start) { return NULL; } - STATIC int LuaFormatMessage(lua_State* luaState, LuaAfbMessageT action) { char *message; @@ -618,6 +617,7 @@ int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback) { // push response to LUA lua_pushinteger(luaState, response); + return 1; } @@ -963,7 +963,7 @@ void LuaL2cNewLib(const char *label, 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); + luaL_setfuncs(luaState, l2cFunc, 0); lua_setglobal(luaState, label); } diff --git a/controller/ctl-plugin.c b/controller/ctl-plugin.c index 550924f..1be97d4 100644 --- a/controller/ctl-plugin.c +++ b/controller/ctl-plugin.c @@ -173,14 +173,14 @@ STATIC int PluginLoadOne (CtlPluginT *ctlPlugin, json_object *pluginJ, void* han return 0; } - int errCount = 0; + int errCount = 0, count = 0; luaL_Reg *l2cFunc = NULL; // look on l2c command and push them to LUA if (json_object_get_type(lua2csJ) == json_type_array) { int length = json_object_array_length(lua2csJ); l2cFunc = calloc(length + 1, sizeof (luaL_Reg)); - for (int count = 0; count < length; count++) { + for (count = 0; count < length; count++) { int err; const char *l2cName = json_object_get_string(json_object_array_get_idx(lua2csJ, count)); err = Lua2cAddOne(l2cFunc, l2cName, count); @@ -190,11 +190,19 @@ STATIC int PluginLoadOne (CtlPluginT *ctlPlugin, json_object *pluginJ, void* han l2cFunc = calloc(2, sizeof (luaL_Reg)); const char *l2cName = json_object_get_string(lua2csJ); errCount = Lua2cAddOne(l2cFunc, l2cName, 0); + count = 1; } if (errCount) { AFB_ERROR("CTL-PLUGIN-LOADONE %d symbols not found in plugin='%s'", errCount, pluginpath); goto OnErrorExit; } + else { + ctlPlugin->l2cFunc = l2cFunc; + ctlPlugin->l2cCount = count; + LuaL2cNewLib (ctlPlugin->label, + ctlPlugin->l2cFunc, + ctlPlugin->l2cCount); + } } #endif diff --git a/controller/ctl-plugin.h b/controller/ctl-plugin.h index 7934d8d..361fd34 100644 --- a/controller/ctl-plugin.h +++ b/controller/ctl-plugin.h @@ -43,6 +43,8 @@ extern "C" { #define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x #endif +typedef struct luaL_Reg luaL_Reg; + typedef struct { char *label; char *info; @@ -50,25 +52,26 @@ typedef struct { void *context; } CtlSourceT; - typedef struct { long magic; const char *label; void *handle; } CtlPluginMagicT; - typedef struct { const char *label; const char *info; const char *version; void *context; void *dlHandle; +#ifdef CONTROL_SUPPORT_LUA + luaL_Reg *l2cFunc; + int l2cCount; +#endif } CtlPluginT; typedef void*(*DispatchPluginInstallCbT)(CtlPluginT *plugin, void* handle); - #define MACRO_STR_VALUE(arg) #arg #define CTLP_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel,.handle=NULL}; struct afb_binding_data_v2; #define CTLP_ONLOAD(plugin, handle) void* CtlPluginOnload(CtlPluginT *plugin, void* handle) |