<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 函数?

      How do I create a Lua Table in C++, and pass it to a Lua function?(如何在 C++ 中创建 Lua 表,并将其传递给 Lua 函数?)
      <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 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)

                <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>

                      <tbody id='xpmee'></tbody>
                    • <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>