我將Lua嵌入到C/C++應用程序中。有沒有辦法從C/C++調用Lua函數而不先執行整個腳本?在不執行腳本的情況下調用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,0);
但它給我:
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
我只能叫巴()當我這樣做:
//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);
但它給了我這個:
hello
stackoverflow!!
我想這一點:
stackoverflow!
這是我的LUA腳本:
print("hello");
function bar()
print("stackoverflow!");
end
既然你要運行腳本來獲取Lua的VM看到它像伊坦表示你必須把解壓出來'功能欄()'到不同的文件,並運行該文件。 – greatwolf 2013-01-28 03:11:45