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

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

        <bdo id='NknI8'></bdo><ul id='NknI8'></ul>
      <tfoot id='NknI8'></tfoot>
      1. <legend id='NknI8'><style id='NknI8'><dir id='NknI8'><q id='NknI8'></q></dir></style></legend>

      2. 通过 Swig 在 C++ 和 Lua 之间传递变量

        Pass variables between C++ and Lua via Swig(通过 Swig 在 C++ 和 Lua 之间传递变量)
      3. <small id='h0JZh'></small><noframes id='h0JZh'>

              <tbody id='h0JZh'></tbody>

              • <legend id='h0JZh'><style id='h0JZh'><dir id='h0JZh'><q id='h0JZh'></q></dir></style></legend>
                  <bdo id='h0JZh'></bdo><ul id='h0JZh'></ul>
                  <i id='h0JZh'><tr id='h0JZh'><dt id='h0JZh'><q id='h0JZh'><span id='h0JZh'><b id='h0JZh'><form id='h0JZh'><ins id='h0JZh'></ins><ul id='h0JZh'></ul><sub id='h0JZh'></sub></form><legend id='h0JZh'></legend><bdo id='h0JZh'><pre id='h0JZh'><center id='h0JZh'></center></pre></bdo></b><th id='h0JZh'></th></span></q></dt></tr></i><div id='h0JZh'><tfoot id='h0JZh'></tfoot><dl id='h0JZh'><fieldset id='h0JZh'></fieldset></dl></div>
                  <tfoot id='h0JZh'></tfoot>
                • 本文介绍了通过 Swig 在 C++ 和 Lua 之间传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在处理一个包含大量类(150 多个)的 C++ 项目,每个类都有 10 到 300 个左右的字段.我真的希望能够提供一个用于测试目的的脚本接口,以便我可以编写不需要任何重新编译的回调.我想在 Lua 中执行此操作,因为我对它的 C API 比对 Python 更熟悉,但如果这样可以省去麻烦,我很乐意在 Python 中执行此操作.

                  I'm working on a C++ project with a large number of classes (150+), each of which has anywhere from 10 to 300 fields or so. I would really like to be able to provide a scripting interface for testing purposes so that I can code callbacks that don't require any re-compilation. I'd like to do this in Lua since I'm more familiar with its C API than I am with Python's, but if it will save headaches I'd be happy to do it in Python.

                  我对如何从我的 C++ 调用 Lua 函数有一个很好的掌握,反之亦然,并且我知道如何来回传递基本数据类型.我的问题是如何使用 SWIG 在两者之间共享用户指定的数据类型.

                  I've got a solid grasp on how to call Lua functions from my C++ and vice versa, and I know how to pass basic data types back and forth. The question I have is how to share user-specified data types between the two using SWIG.

                  例如,在我的 C++ 中的某个时刻,我可能想要评估具有 250 个字段的对象中的几个成员数据.我希望能够将该对象交给 Lua,然后 Lua 可以(希望?)使用生成的 SWIG 包装器来操作该对象,显示某些字段,然后将(可能已更改的)对象传递回 C++ 以继续使用.

                  For example, at some point in my C++, I might want to evaluate a couple of pieces of member data in an object that has 250 fields. I'd like to be able to hand that object off to Lua which could then (hopefully?) use the generated SWIG wrappers to manipulate that object, display certain fields, and then pass the (potentially changed) object back to C++ for continued use.

                  我还希望能够使用包装器在 Lua 中实例化对象的实例,并将其传递给 C++ 以用作对象的普通 C++ 版本.

                  I would also like to be able to instantiate an instance of the object in Lua using the wrappers and pass it off to C++ to be used as a normal C++ version of the object.

                  这可能吗?有人可以指出我的教程或明确的例子吗?

                  Is this possible? Could somebody point me towards a tutorial or an explicit example?

                  感谢您提供的任何帮助!

                  Thanks for any help you can offer!

                  推荐答案

                  只要您使用 Swig 接口包装用户定义的类型(请参阅 此处 有关 Swig-Lua API 的文档),交互应该是无缝的.提供的 Swig 包装器将允许您实例化新对象,将它们传递给 C++,反之亦然.

                  As long as you wrap your user-defined types using Swig interfaces (see here for documentation on Swig-Lua API), the interaction should be seamless. The provided Swig wrappers will allow you to instantiate new objects, pass them along to C++ and vice-versa.

                  我不认为 Swig-Lua 包装支持导演类,这意味着扩展现有类、实例化它们并将它们传递回 C++ 是不可能的.不过,控制器支持 Python、Java、C# 等语言.

                  I do not believe that Swig-Lua wrapping supports director classes yet, which means that extending existing classes, instantiating them and passing them back to C++ is not possible. Directors are supported for languages such as Python, Java, C# though.

                  这篇关于通过 Swig 在 C++ 和 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(使用非平凡的构造函数初始化联合)

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

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

                    1. <legend id='KMRNK'><style id='KMRNK'><dir id='KMRNK'><q id='KMRNK'></q></dir></style></legend>

                              <tbody id='KMRNK'></tbody>
                            <tfoot id='KMRNK'></tfoot>