I am writing a table-lua, however the table_lua_update function doesn't appear
to be called.
Here are relevant pieces of the code.
The lookup function works. However, it would be more ideal to have the update()
called early
to fill in the tables for the other functions. As is the lookup() has to do the
work of both.
Any help is appreciated.
Thanks,
Edgar
table_lua.c
static int
table_lua_update(void)
{
int ret;
lua_getglobal(L, "update");
lua_pushnil(L);
if (lua_pcall(L, 1, 1, 0)) {
log_warnx("warn: update: %s", lua_tostring(L, -1));
return -1;
}
ret = lua_toboolean(L, -1);
log_warnx("\t\tlua-update: %d\n", ret);
return ret;
}
int
main(int argc, char **argv)
{
int ch;
char *path;
log_init(1);
while ((ch = getopt(argc, argv, "")) != -1) {
switch (ch) {
default:
fatalx("bad option");
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;
if (argc == 0)
fatalx("missing path");
path = argv[0];
L = luaL_newstate();
make_global_table(L, "service", services);
make_global_table(L, "Lookup", NULL);
make_global_table(L, "Fetch", NULL);
make_global_table(L, "Check", NULL);
make_global_table(L, "Update", NULL);
luaL_openlibs(L);
if (luaL_loadfile(L, path) || lua_pcall(L, 0, 0, 0))
fatalx("%s", lua_tostring(L, -1));
log_debug("debug: starting...");
table_api_on_update(table_lua_update);
table_api_on_check(table_lua_check);
table_api_on_lookup(table_lua_lookup);
table_api_on_fetch(table_lua_fetch);
table_api_dispatch();
log_debug("debug: exiting");
lua_close(L);
return 1;
}
table.lua
function update ()
io.stderr:write("\n\t\ttable-lua is updating\n")
return true
end