【发布时间】:2013-12-12 05:20:27
【问题描述】:
我正在尝试使用 LuaBridge 通过基类指针将对象从 C++ 传递到 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
如何在 Lua 中将 FooBase* 'cast-down' 到 Foo*? Lua/LuaBridge 甚至支持这个吗?
【问题讨论】:
标签: c++ inheritance lua luabridge