config data available to lua script
This commit is contained in:
parent
1f5605b795
commit
da7bdfa3f9
@ -62,10 +62,11 @@ typedef struct lua_worker_handle_s lua_worker_handle_t;
|
||||
int lua_init(cfgl_t *cfg, void **handle) {
|
||||
lua_container_handle_t *lch;
|
||||
char *lualibname, *lualibnames;
|
||||
int res;
|
||||
int res, cnt;
|
||||
char *lua_filename;
|
||||
const luaL_reg *lualib;
|
||||
|
||||
cfgl_t *cfgl_iter;
|
||||
|
||||
lch = (lua_container_handle_t*) malloc(sizeof(lua_container_handle_t));
|
||||
lch->cfg = cfg;
|
||||
|
||||
@ -87,7 +88,8 @@ int lua_init(cfgl_t *cfg, void **handle) {
|
||||
|
||||
for (lualib = lualibs; lualib->func != NULL; lualib++) {
|
||||
if (0 == strcmp(lualib->name, lualibname)) {
|
||||
lualib->func(lch->l);
|
||||
res = lualib->func(lch->l);
|
||||
/* syslog(LOG_DEBUG, "lua_init %s loaded, result %d", lualibname, res); */
|
||||
lua_settop(lch->l, 0);
|
||||
break;
|
||||
}
|
||||
@ -103,14 +105,31 @@ int lua_init(cfgl_t *cfg, void **handle) {
|
||||
}
|
||||
syslog(LOG_DEBUG, "lua_init: lua file %s loaded and compiled", lua_filename);
|
||||
|
||||
lua_newtable(lch->l);
|
||||
cnt = 0;
|
||||
for (cfgl_iter = lch->cfg; cfgl_iter != NULL; cfgl_iter = cfgl_iter->next) {
|
||||
lua_pushstring(lch->l, cfgl_iter->name);
|
||||
lua_pushstring(lch->l, cfgl_iter->value);
|
||||
lua_rawset(lch->l, -3);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
lua_pushliteral(lch->l, "n"); /* Pushes the literal */
|
||||
lua_pushnumber(lch->l, cnt); /* Pushes the total number of cells */
|
||||
lua_rawset(lch->l, -3); /* Stores the pair in the table */
|
||||
|
||||
lua_setglobal(lch->l, "config");
|
||||
|
||||
res = lua_pcall(lch->l, 0, 0, 0);
|
||||
if (0 != res) {
|
||||
syslog(LOG_ERR, "lua_init: unable to execute lua file %s", lua_filename);
|
||||
lua_close(lch->l);
|
||||
free(lch);
|
||||
return -1;
|
||||
}
|
||||
syslog(LOG_DEBUG, "lua_init: lua file %s executed", lua_filename);
|
||||
|
||||
|
||||
|
||||
|
||||
*handle = lch;
|
||||
return 0;
|
||||
|
@ -1,5 +1,6 @@
|
||||
function f (i)
|
||||
io.write("[lua] output from lua\n")
|
||||
io.write("[lua] ", i, "\n")
|
||||
io.write("[lua] entrypoint: ", config["entrypoint"], "\n")
|
||||
return 1, string.upper(i)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user