summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-26 18:19:19 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2018-07-27 12:39:42 +0000
commit61cbc9a5e0729fe4e0274186b0137f5d1f1b75d6 (patch)
tree7dd5d95f4004f8984dfc856405a63d77715cfea7 /ctl-lib
parent535df7f1adb71c90612079e6b35754ed20b099df (diff)
More precise log message when loading a Lua file
This will indicates what is the error at the LUA file loading Change-Id: I258bf43a2200577998e05cf7b2253bdd510a468e Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-lua.c21
-rw-r--r--ctl-lib/ctl-lua.h2
-rw-r--r--ctl-lib/ctl-plugin.c4
3 files changed, 15 insertions, 12 deletions
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index ac22767..ecfd0f3 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -748,19 +748,26 @@ int LuaCallFunc(CtlSourceT *source, CtlActionT *action, json_object *queryJ) {
return rc;
}
-int LuaLoadScript(const char *luaScriptPath) {
+int LuaLoadScript(AFB_ApiT apiHandle, const char *luaScriptPath) {
int err = 0;
- if (!luaScriptPath)
+ if (!luaScriptPath) {
+ AFB_ApiError(apiHandle, "Error: provided path is NULL");
return -1;
+ }
err = luaL_loadfile(luaState, luaScriptPath);
- if (err)
+ if (err) {
+ AFB_ApiError(apiHandle, "Error at load for %s: %s", luaScriptPath, lua_tostring(luaState, -1));
return err;
+ }
// Script was loaded we need to parse to make it executable
err = lua_pcall(luaState, 0, 0, 0);
-
+ if (err) {
+ AFB_ApiError(apiHandle, "Error at execution for %s: %s", luaScriptPath, lua_tostring(luaState, -1));
+ return err;
+ }
return err;
}
@@ -819,11 +826,9 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) {
}
}
- err = LuaLoadScript(luaScriptPath);
- if (err) {
- AFB_ApiError(source->api, "LUA-DOSCRIPT HOOPs Error in LUA loading scripts=%s err=%s", luaScriptPath, lua_tostring(luaState, -1));
+ err = LuaLoadScript(source->api, luaScriptPath);
+ if (err)
return -1;
- }
// load function (should exist in CONTROL_PATH_LUA
lua_getglobal(luaState, func);
diff --git a/ctl-lib/ctl-lua.h b/ctl-lib/ctl-lua.h
index 0ec4960..a02c6e1 100644
--- a/ctl-lib/ctl-lua.h
+++ b/ctl-lib/ctl-lua.h
@@ -52,7 +52,7 @@ typedef enum {
} LuaDoActionT;
extern const char *lua_utils;
-extern int LuaLoadScript(const char *luaScriptPath);
+extern int LuaLoadScript(AFB_ApiT apiHandle, const char *luaScriptPath);
extern int LuaConfigLoad (AFB_ApiT apiHandle, const char *prefix);
extern void LuaL2cNewLib(luaL_Reg *l2cFunc, int count, const char *prefix);
extern int Lua2cWrapper(void* luaHandle, char *funcname, Lua2cFunctionT callback);
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index 182b34f..0c0bacc 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -226,10 +226,8 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob
else if(ext && !strcasecmp(ext, CTL_SCRIPT_EXT)) {
ctlPlugin->api = apiHandle;
ctlPlugin->context = handle;
- if(LuaLoadScript(pluginpath)) {
- AFB_ApiError(apiHandle, "There was an error loading the lua file %s", pluginpath);
+ if(LuaLoadScript(apiHandle, pluginpath))
return -1;
- }
}
}