我将Lua嵌入到C/C++应用程序中.有没有办法从C/C++调用Lua函数而不先执行整个脚本?
我试过这样做:
//call lua script from C/C++ program luaL_loadfile(L,"hello.lua"); //call lua function from C/C++ program lua_getglobal(L,"bar"); lua_call(L,0);
但它给了我这个:
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
我这样做时只能调用bar():
//call lua script from C/C++ program luaL_dofile(L,"hello.lua"); //this executes the script once,which I don't like //call lua function from C/C++ program lua_getglobal(L,0);
但它给了我这个:
hello stackoverflow!!
我想要这个:
stackoverflow!
这是我的lua脚本:
print("hello"); function bar() print("stackoverflow!"); end