首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LuaBridge与继承

LuaBridge与继承
EN

Stack Overflow用户
提问于 2013-11-26 20:50:29
回答 1查看 871关注 0票数 1

我试图使用C++将一个对象通过基类指针从LuaBridge传递到Lua。派生类和基类都在LuaBridge中正确注册。

在C++方面:

代码语言:javascript
复制
// 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方面:

代码语言:javascript
复制
function bar(foo)
    foo.a -- This is ok
    foo.b -- This is nil
end

我怎样才能从FooBase*Foo*在Lua‘下注’呢?Lua/LuaBridge甚至支持这一点吗?

EN

回答 1

Stack Overflow用户

发布于 2013-11-26 22:22:45

可能不会,而且需要这样做,可能会在您的代码中显示出一个设计错误。在C++中预先格式化转换,您比Lua更了解类型,因此函数栏接受Foo*,或者在调用函数之前执行下播操作。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20227690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档