在 C++ 中,我有一个 map<string, string>
,包含未知数量的条目。我如何将其传递给 Lua 函数,以便 Lua 函数可以将数据用作表格?
最佳答案
如果你想要一个真正的lua表:
lua_newtable(L);
int top = lua_gettop(L);
for (std::map::iterator it = mymap.begin(); it != mymap.end(); ++it) {
const char* key = it->first.c_str();
const char* value = it->second.c_str();
lua_pushlstring(L, key, it->first.size());
lua_pushlstring(L, value, it->second.size());
lua_settable(L, top);
}
将正确的 map 类型替换为......
关于c++ - 如何在 C++ 中创建 Lua 表,并将其传递给 Lua 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/453769/