summaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-lua.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-12 18:18:01 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-17 12:30:55 +0200
commit88892db78f2f5b047923af5b36169052c96bc3c0 (patch)
treed0e6a7f5cfcc9824c0990b5dc6457892734ed62a /ctl-lib/ctl-lua.c
parent440be0984f16562fdf321c770d65787ecea0e36d (diff)
Use prefix variable to find controller's plugins
Prefix is the most reliable variable to find files or variables for a controller, so this lets you access it wherever it is needed without using global hardcoded variables. This helps to search for controller's plugins in several locations depending on environment variables and hardcoded variables (CONTROL_PLUGIN_PATH, CONTROL_CONFIG_PATH). This implies also a change a LUA interpreter loading step to correctly set the package.path variables with the environment variables, too. Correct the missing 'extern' in function declarations. Depends-On: Ic448ff017e6158bec05895d63688b8968b5c6434 Change-Id: I0ad19242612559d1f4b66b6f9af9e7032d4675a8 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-lua.c')
-rw-r--r--ctl-lib/ctl-lua.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index 55cc18c..ab0abb6 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -1294,10 +1294,11 @@ int LuaConfigExec(AFB_ApiT apiHandle) {
// Load Lua Interpreter
-int LuaConfigLoad(AFB_ApiT apiHandle) {
+int LuaConfigLoad(AFB_ApiT apiHandle, const char *prefix) {
+ size_t total_len = 0, base_len = 0, spath_len = 0;
static int luaLoaded = 0;
- int i;
- //int err = 0;
+ int token_nb = 0, i = 0;
+ char *spath = NULL, *sep = NULL, *lua_str = NULL;
// Lua loads only once
if (luaLoaded) return 0;
@@ -1320,20 +1321,20 @@ int LuaConfigLoad(AFB_ApiT apiHandle) {
// set package.path lua variable use the CONTROL_PLUGIN_PATH as it could
// have to find external lua packages in those directories
- size_t base_len = strlen(LUA_PATH_VALUE);
- size_t spath_len = strlen(CONTROL_PLUGIN_PATH);
+ base_len = strlen(LUA_PATH_VALUE);
+ spath_len = strlen(CONTROL_PLUGIN_PATH);
- int token_nb = spath_len ? 1:0;
- char *spath = strdup(CONTROL_PLUGIN_PATH);
- char *sep = spath;
+ token_nb = spath_len ? 1:0;
+ spath = GetDefaultPluginSearchPath(apiHandle, prefix);
+ sep = spath;
while((sep = strchr(sep, ':')) != NULL) {
token_nb++;
sep++;
}
// token + the lua glob pattern which is 7 char length
- size_t total_len = base_len + spath_len + token_nb * 7 + 1;
- char *lua_str = malloc(total_len + 1);
+ total_len = base_len + spath_len + token_nb * 7 + 1;
+ lua_str = malloc(total_len + 1);
strncpy(lua_str, LUA_PATH_VALUE, total_len);
for (i = 0; i < token_nb; i++) {
sep = strsep(&spath, ":");