루아를 C/C++ 애플리케이션에 임베드 할 예정입니다. 먼저 전체 스크립트를 실행하지 않고 C/C++에서 루아 함수를 호출하는 방법이 있습니까?스크립트를 실행하지 않고 루아 함수 호출하기
나는이 일을 시도했다 :
//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);
를하지만 나에게이 제공 :
//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);
:
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
난 단지 호출 할 수있는 바() 나는이 작업을 수행 할 때 그러나 그것은 나에게 이것을 준다 :
hello
stackoverflow!!
012 단순히 그 시점에서, 호출 가능한 덩어리로 파일을 컴파일 단지는 Freenode luaL_loadfile에 #lua에서 논의 된
print("hello");
function bar()
print("stackoverflow!");
end
당신이 ETAN은 당신이 밖으로 추출해야 표시처럼 루아 VM이 그것을보고 얻을 수있는 스크립트를 실행해야하기 때문에' function bar()'를 다른 파일로 옮기고 그 파일을 실행하면됩니다. – greatwolf