我如何创建一个Lua表在C++、并通过它向Lua功能?
题
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);
}
与右类型为地图中取代..
不隶属于 StackOverflow