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*
に「キャストダウン」するにはどうすればよいですか? Foo*
Lua/LuaBridge はこれをサポートしていますか?