luabind - My lua script load .so library, how can I write the host program with Lua 5.2? -
i searched , tried days. problem this:
i wrote script load shared library locker.so
, runs lua interpretor, can not write out correct host program.
my lua script load_so.lua
simple:
locker = require("locker") print(type(locker)) k, v in pairs(locker) print(k, v) end
my host program is:
int main(int argc, const char *argv[]) { lua_state * l = lual_newstate(); lual_openlibs(l); if (lual_dofile(l, "load_so.lua") != 0) { fprintf(stderr, "lual_dofile error: %s\n", lua_tostring(l, -1)); lua_pop(l, 1); } lua_close(l); return 0; }
when run host program, error print out:
lual_dofile error: error loading module 'locker' file './locker.so': ./locker.so: undefined symbol: lua_pushstring
and locker.c:
static int elock_get(lua_state * l) {...} static int elock_set(lua_state * l) {...} static const struct lual_reg lockerlib[] = { {"get", elock_get}, {"set", elock_set}, {null, null} }; int luaopen_locker(lua_state *l) { //lual_newlib(l, lockerlib); //lua_pushvalue(l, -1); //lua_setglobal(l, locker_libname); //set_info(l); lual_newlibtable(l, lockerlib); lual_setfuncs(l, lockerlib, 0); return 1; }
most articles, books, questions shows how in lua 5.1, , yes, program runs correctly in lua 5.1. how can make support lua 5.2, , why?
p.s: don't want load library in c host program lual_requiref(l, "locker", luaopen_locker, 1)
, because don't know .so library load in lua script.
thanks.
in linux, if you're linking liblua.a
statically main program, need use -wl,-e
when linking export lua api symbols; how standard command line interpreter built.
Comments
Post a Comment