summaryrefslogtreecommitdiffstats
path: root/Controler-afb/ctl-binding.h
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-08-16 18:25:05 +0200
committerFulup Ar Foll <fulup@iot.bzh>2017-08-16 18:25:05 +0200
commit61f0f263c335ad403c6693a1b8b6f5428ac180a8 (patch)
tree80b49b996a1a67f164643d6fdac5645801cc6fe5 /Controler-afb/ctl-binding.h
parent4ca8fd4015479fa758a789d137a693c30fec8cae (diff)
Fixed LUA Nested Table Issues. Added LUA2C for User Defined Plugins
Diffstat (limited to 'Controler-afb/ctl-binding.h')
-rw-r--r--Controler-afb/ctl-binding.h52
1 files changed, 39 insertions, 13 deletions
diff --git a/Controler-afb/ctl-binding.h b/Controler-afb/ctl-binding.h
index a2cedbf..33a9049 100644
--- a/Controler-afb/ctl-binding.h
+++ b/Controler-afb/ctl-binding.h
@@ -25,6 +25,12 @@
#include <filescan-utils.h>
#include <wrap-json.h>
+#ifdef CONTROL_SUPPORT_LUA
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#endif
+
#ifndef PUBLIC
#define PUBLIC
#endif
@@ -35,15 +41,6 @@
#define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
#endif
-// sharelib ctl-plugin*
-typedef struct {
- long magic;
- char *label;
-} CtlPluginMagicT;
-
-#define CTL_PLUGIN_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel}; struct afb_binding_data_v2;
-
-
// polctl-binding.c
PUBLIC int CtlBindingInit ();
@@ -71,15 +68,23 @@ typedef struct DispatchActionS{
const char* call;
json_object *argsJ;
int timeout;
- int (*actionCB)(struct DispatchActionS *action, json_object *queryJ, void *context);
+ int (*actionCB)(const char*label, json_object *argsJ, json_object *queryJ, void *context);
} DispatchActionT;
+typedef int (*Lua2cFunctionT)(char *funcname, json_object *argsJ, void*context);
PUBLIC int DispatchInit(void);
-PUBLIC int DispatchOneOnLoad(const char *onLoadLabel);
+PUBLIC int DispatchOnLoad(const char *onLoadLabel);
PUBLIC void DispatchOneEvent(const char *evtLabel, json_object *eventJ);
-PUBLIC void ctlapi_dispatch (char* control, afb_req request);
+PUBLIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT callback);
+PUBLIC void ctlapi_dispatch (afb_req request);
+#ifdef CONTROL_SUPPORT_LUA
// ctl-lua.c
+typedef int (*Lua2cWrapperT) (lua_State* luaState, char *funcname, Lua2cFunctionT callback);
+
+#define CTLP_LUA2C(FuncName,label,argsJ, context) static int FuncName(char*label,json_object*argsJ, void*context);\
+ int lua2c_ ## FuncName(lua_State* luaState){return((*Lua2cWrap)(luaState, MACRO_STR_VALUE(FuncName), FuncName));};\
+ static int FuncName(char* label, json_object* argsJ, void* context)
typedef enum {
LUA_DOCALL,
@@ -88,9 +93,30 @@ typedef enum {
} LuaDoActionT;
PUBLIC int LuaLibInit ();
+PUBLIC void LuaL2cNewLib(const char *label, luaL_Reg *l2cFunc, int count);
+PUBLIC int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback, void *context);
PUBLIC int LuaCallFunc (DispatchActionT *action, json_object *queryJ);
PUBLIC void ctlapi_lua_docall (afb_req request);
PUBLIC void ctlapi_lua_dostring (afb_req request);
PUBLIC void ctlapi_lua_doscript (afb_req request);
-#endif
+#else
+ typedef void* Lua2cWrapperT;
+#endif // CONTROL_SUPPORT_LUA
+
+
+// sharelib ctl-plugin*
+typedef struct {
+ long magic;
+ char *label;
+} CtlPluginMagicT;
+
+
+#define MACRO_STR_VALUE(arg) #arg
+#define CTLP_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel}; struct afb_binding_data_v2; Lua2cWrapperT Lua2cWrap;
+#define CTLP_ONLOAD(label,version,info) void* CtlPluginOnload(char* label, char* version, char* info)
+#define CTLP_CAPI(funcname,label,argsJ, queryJ, context) int funcname(char* label, json_object* argsJ, json_object* queryJ, void* context)
+
+
+
+#endif // CONTROLER_BINDING_INCLUDE