summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-26 12:17:55 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commitbbb4351eab7476be9a93f0248860ac0d1574d8a6 (patch)
tree1c5624454be5fc37828341b20de2f2e79fc90013
parent1480ff8d68ee4b923596d8178e37eba7b9202a30 (diff)
Make calling lua2c function from lua works
Change-Id: I56d78a3fe567d1f7a6c675f6a56473f96d325c85 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--conf.d/project/etc/init-daemon.json2
-rw-r--r--conf.d/project/lua.d/init-daemon-04-oncall.lua4
-rw-r--r--controller/ctl-action.c4
-rw-r--r--controller/ctl-lua.c4
-rw-r--r--controller/ctl-plugin.c12
-rw-r--r--controller/ctl-plugin.h9
-rw-r--r--plugins/lua2c-interface.c7
7 files changed, 28 insertions, 14 deletions
diff --git a/conf.d/project/etc/init-daemon.json b/conf.d/project/etc/init-daemon.json
index bc7bd5a..635b697 100644
--- a/conf.d/project/etc/init-daemon.json
+++ b/conf.d/project/etc/init-daemon.json
@@ -26,7 +26,7 @@
"version": "1.0",
"info": "Lua2C Interface",
"basename": "lua2c-interface",
- "lua2c": ["_setSignalValue"]
+ "lua2c": ["setSignalValueWrap"]
}
]
}
diff --git a/conf.d/project/lua.d/init-daemon-04-oncall.lua b/conf.d/project/lua.d/init-daemon-04-oncall.lua
index 8912f26..04b6080 100644
--- a/conf.d/project/lua.d/init-daemon-04-oncall.lua
+++ b/conf.d/project/lua.d/init-daemon-04-oncall.lua
@@ -54,7 +54,7 @@ function _Unit_Converter(source, args, event)
print("Value in", targetunits, "is", value/base)
_result["result"] = value/base
- _setsignalValue(source, _result)
+ lua2c["setSignalValueWrap"](source, _result)
elseif sourcei>targeti then
@@ -66,7 +66,7 @@ function _Unit_Converter(source, args, event)
print("Value in ", targetunits, "is", value*base)
_result["result"] = value/base
- _setsignalValue(source, _result)
+ lua2c["setSignalValueWrap"](source, _result)
else
print("No conversion")
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)
diff --git a/plugins/lua2c-interface.c b/plugins/lua2c-interface.c
index 0bff8d6..1da8f17 100644
--- a/plugins/lua2c-interface.c
+++ b/plugins/lua2c-interface.c
@@ -33,11 +33,11 @@ CTLP_REGISTER("lua2c-interface");
typedef struct {
struct pluginCBT* pluginHandle;
-} lowCANCtxT;
+} CtxT;
// Call at initialisation time
CTLP_ONLOAD(plugin, handle) {
- lowCANCtxT *pluginCtx= (lowCANCtxT*)calloc (1, sizeof(lowCANCtxT));
+ CtxT *pluginCtx= (CtxT*)calloc (1, sizeof(CtxT));
pluginCtx->pluginHandle = (struct pluginCBT*)handle;
AFB_NOTICE ("Low-can plugin: label='%s' version='%s' info='%s'",
@@ -48,8 +48,9 @@ CTLP_ONLOAD(plugin, handle) {
return (void*)pluginCtx;
}
-CTLP_LUA2C (_setsignalValue, label, argsJ)
+CTLP_LUA2C (setSignalValueWrap, label, argsJ)
{
AFB_NOTICE("label: %s, argsJ: %s", label, json_object_to_json_string(argsJ));
+
return 0;
}