summaryrefslogtreecommitdiffstats
path: root/ctl-lua.c
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-08-22 13:58:57 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:59:11 +0100
commit45e0b5c46bf419e6a7453ea9c59655583135b555 (patch)
tree0b9d3b57f09ffc2a0cd25dfe24daa3259a56c5b3 /ctl-lua.c
parentbc1ed1eba6571dd80f519ea11ad67862edb92e9e (diff)
Minor Fix on LUA script search path
Diffstat (limited to 'ctl-lua.c')
-rw-r--r--ctl-lua.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/ctl-lua.c b/ctl-lua.c
index 412a158..2aaa3a5 100644
--- a/ctl-lua.c
+++ b/ctl-lua.c
@@ -698,24 +698,29 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) {
}
case LUA_DOSCRIPT: { // Fulup need to fix argument passing
- const char *script;
- char*func=NULL;
char *filename; char*fullpath;
char luaScriptPath[CONTROL_MAXPATH_LEN];
- json_object *argsJ=NULL;
int index;
// scan luascript search path once
static json_object *luaScriptPathJ =NULL;
- err= wrap_json_unpack (queryJ, "{s:s, s?s s?o !}", "target", &script,"function", &func, "args", &argsJ);
+ // extract value from query
+ const char *target=NULL,*func=NULL;
+ json_object *argsJ=NULL;
+ err= wrap_json_unpack (queryJ, "{s:s,s?s,s?s,s?o !}","target", &target,"path",&luaScriptPathJ,"function",&func,"args",&argsJ);
if (err) {
- AFB_ERROR ("LUA-DOSCRIPT-SYNTAX:missing script|(args,arg) query=%s", json_object_get_string(queryJ));
+ AFB_ERROR ("LUA-DOSCRIPT-SYNTAX:missing target|[path]|[function]|[args] query=%s", json_object_get_string(queryJ));
goto OnErrorExit;
}
// search for filename=script in CONTROL_LUA_PATH
- if (!luaScriptPathJ) luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,CONTROL_DOSCRIPT_PRE "-", script);
+ if (!luaScriptPathJ) {
+ strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, sizeof(luaScriptPath));
+ strncat(luaScriptPath,"-", sizeof(luaScriptPath));
+ strncat(luaScriptPath,target, sizeof(luaScriptPath));
+ luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,luaScriptPath,".lua");
+ }
for (index=0; index < json_object_array_length(luaScriptPathJ); index++) {
json_object *entryJ=json_object_array_get_idx(luaScriptPathJ, index);
@@ -801,7 +806,7 @@ PUBLIC void ctlapi_request (afb_req request) {
LuaDoAction (LUA_DOCALL, request);
}
-PUBLIC void ctlapi_scriptlua (afb_req request) {
+PUBLIC void ctlapi_debuglua (afb_req request) {
LuaDoAction (LUA_DOSCRIPT, request);
}