From bbb4351eab7476be9a93f0248860ac0d1574d8a6 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 26 Sep 2017 12:17:55 +0200 Subject: Make calling lua2c function from lua works Change-Id: I56d78a3fe567d1f7a6c675f6a56473f96d325c85 Signed-off-by: Romain Forlot --- controller/ctl-plugin.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'controller/ctl-plugin.c') 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 -- cgit 1.2.3-korg