I embed Lua in a C / C ++ application. Is there a way to call a Lua function from C / C ++ without executing the whole script?
I tried to do this:
//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,0);
But this gives me the following:
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
I can call bar () when I do this:
//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,"bar"); lua_call(L,0,0);
But this gives me the following:
hello stackoverflow!!
I want this:
stackoverflow!
This is my lua script:
print("hello"); function bar() print("stackoverflow!"); end
c ++ c lua
Person
source share