我试图使用C++将一个对象通过基类指针从LuaBridge传递到Lua。派生类和基类都在LuaBridge中正确注册。
在C++方面:
// Assume both Foo and FooBase are registered properly with LuaBridge,
// exposing the a, b, and c properties
struct FooBase
{
int a;
// ...
};
struct Foo : public FooBase
{
int b;
int c;
// ...
};
// ... other code ...
void Bar(const FooBase* foo)
{
// Assume that 'foo' is a pointer to a valid 'Foo' object
luabridge::LuaRef ref = luabridge::getGlobal(L, "bar");
ref(foo);
} 在Lua方面:
function bar(foo)
foo.a -- This is ok
foo.b -- This is nil
end我怎样才能从FooBase*到Foo*在Lua‘下注’呢?Lua/LuaBridge甚至支持这一点吗?
发布于 2013-11-26 22:22:45
可能不会,而且需要这样做,可能会在您的代码中显示出一个设计错误。在C++中预先格式化转换,您比Lua更了解类型,因此函数栏接受Foo*,或者在调用函数之前执行下播操作。
https://stackoverflow.com/questions/20227690
复制相似问题