通过Swig在C ++和Lua之间传递变量 [英] Pass variables between C++ and Lua via Swig

查看:204
本文介绍了通过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.

这是可能吗?

感谢您提供任何帮助!

推荐答案

只要使用Swig接口封装用户定义的类型(参见这里关于Swig-Lua API的文档),交互应该是无缝的。

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之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆