相关疑难解决方法(0)

luaL_dostring什么都不放在堆栈上?

我正在尝试学习Lua与C++接口的基础知识,但我遇到了一个问题.我想调用一个返回字符串的函数,然后使用C++端的字符串,但是luaL_dostring似乎没有在Lua堆栈上放任何东西.

即使是简单的测试似乎也不能正常工作:

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;
Run Code Online (Sandbox Code Playgroud)

输出:

stack top is 0
stack top is 1
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

c++ lua lua-c++-connection

4
推荐指数
1
解决办法
2214
查看次数

标签 统计

c++ ×1

lua ×1

lua-c++-connection ×1