lua 5.2 - "require" not work in embeded lua -
in code load , run test.lua
file
int main (){ l = lual_newstate(); lual_openlibs(l); lual_dofile(l, "test.lua"); lua_close(l); return 0; }
my test.lua file contents
print ("s1"); r=require 'simple'; print ("s2");
the simple
module installed before
when run ./lua_c
; output only: s1
but when run lua test.lua
; output
s1 s2
and r
in't nil
simple
failing load or parse or execute. find problem, use lual_loadfile
instead of lual_dofile
, check return value. if non zero, there load error, can pop off lua stack , print. if no error, lua_pcall(l, 0, lua_multret, 0))
run chuck created loadfile, , again check return code error, pop off stack , print. somehting this:
int main () { l = lual_newstate(); lual_openlibs(l); if (lual_loadfile(l, "test.lua")) { cout << "error: " << lua_tostring(l, -1) << endl; } else if (lua_pcall(l, 0, lua_multret, 0)) { cout << "error: " << lua_tostring(l, -1) << endl; } else { // call successful } lua_close(l); return 0; }
update: know error message simple.so has undefined symbol: lua_gettop
, know there link error. perhaps simple.so
isn't linked lua51.so
, since works lua.exe, linked lua lib, 1 would work app, surely linked too. possibility lua.exe statically linked simple.so not linked. verify simple.so
linked lua51.so , lib links can found such via ld_library_path
. verify lua.exe linked same .so.
Comments
Post a Comment