<legend id='fJf0w'><style id='fJf0w'><dir id='fJf0w'><q id='fJf0w'></q></dir></style></legend>
  1. <i id='fJf0w'><tr id='fJf0w'><dt id='fJf0w'><q id='fJf0w'><span id='fJf0w'><b id='fJf0w'><form id='fJf0w'><ins id='fJf0w'></ins><ul id='fJf0w'></ul><sub id='fJf0w'></sub></form><legend id='fJf0w'></legend><bdo id='fJf0w'><pre id='fJf0w'><center id='fJf0w'></center></pre></bdo></b><th id='fJf0w'></th></span></q></dt></tr></i><div id='fJf0w'><tfoot id='fJf0w'></tfoot><dl id='fJf0w'><fieldset id='fJf0w'></fieldset></dl></div>
    1. <small id='fJf0w'></small><noframes id='fJf0w'>

      • <bdo id='fJf0w'></bdo><ul id='fJf0w'></ul>

    2. <tfoot id='fJf0w'></tfoot>

    3. 如何在 C++ 中创建 Lua 表,并将其传递给 Lua 函数?

      时间:2023-09-27
      <tfoot id='zBrCp'></tfoot>

        <small id='zBrCp'></small><noframes id='zBrCp'>

            <i id='zBrCp'><tr id='zBrCp'><dt id='zBrCp'><q id='zBrCp'><span id='zBrCp'><b id='zBrCp'><form id='zBrCp'><ins id='zBrCp'></ins><ul id='zBrCp'></ul><sub id='zBrCp'></sub></form><legend id='zBrCp'></legend><bdo id='zBrCp'><pre id='zBrCp'><center id='zBrCp'></center></pre></bdo></b><th id='zBrCp'></th></span></q></dt></tr></i><div id='zBrCp'><tfoot id='zBrCp'></tfoot><dl id='zBrCp'><fieldset id='zBrCp'></fieldset></dl></div>

                <tbody id='zBrCp'></tbody>
            • <legend id='zBrCp'><style id='zBrCp'><dir id='zBrCp'><q id='zBrCp'></q></dir></style></legend>
                <bdo id='zBrCp'></bdo><ul id='zBrCp'></ul>
                本文介绍了如何在 C++ 中创建 Lua 表,并将其传递给 Lua 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 C++ 中,我有一个 map,其中包含未知数量的条目.如何将其传递给 Lua 函数,以便 Lua 函数可以将数据用作表?

                In C++, I have a map<string, string>, containing an unknown number of entries. How can I pass this to a Lua function, so that the Lua function can use the data as a table?

                推荐答案

                如果你想要一个真正的lua表:

                if you want a real lua table:

                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);
                }
                

                用正确的地图类型替换...

                with the right types for your map substituted in..

                这篇关于如何在 C++ 中创建 Lua 表,并将其传递给 Lua 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用 C API 创建嵌套的 Lua 表 下一篇:在 C++ 和 Lua 之间来回发送变量指针?

                相关文章

                <small id='xpmee'></small><noframes id='xpmee'>

              • <tfoot id='xpmee'></tfoot>
              • <legend id='xpmee'><style id='xpmee'><dir id='xpmee'><q id='xpmee'></q></dir></style></legend>

                  • <bdo id='xpmee'></bdo><ul id='xpmee'></ul>
                  <i id='xpmee'><tr id='xpmee'><dt id='xpmee'><q id='xpmee'><span id='xpmee'><b id='xpmee'><form id='xpmee'><ins id='xpmee'></ins><ul id='xpmee'></ul><sub id='xpmee'></sub></form><legend id='xpmee'></legend><bdo id='xpmee'><pre id='xpmee'><center id='xpmee'></center></pre></bdo></b><th id='xpmee'></th></span></q></dt></tr></i><div id='xpmee'><tfoot id='xpmee'></tfoot><dl id='xpmee'><fieldset id='xpmee'></fieldset></dl></div>