4
我試圖學習與C++接口Lua的基礎知識,但我遇到了一個問題。 我想調用一個返回字符串的函數,然後使用C++端的字符串,但luaL_dostring似乎沒有在Lua棧上放置任何東西。luaL_dostring什麼都不放在堆棧上?
即使是一個簡單的測試,似乎沒有正常工作:
lua_State* lua = lua_open();
luaL_openlibs(lua);
//Test dostring.
luaL_dostring(lua, "return 'derp'");
int top = lua_gettop(lua);
cout << "stack top is " <<top << endl;
//Next, test pushstring.
lua_pushstring(lua, "derp");
top = lua_gettop(lua);
cout << "stack top is " << top << endl;
輸出:
stack top is 0
stack top is 1
任何想法?
如果該功能在您的Lua環境已經存在,那麼你就可以直接推它和它的ARGS到堆棧中,並通過lua_call調用它的更好() 。 –