问题描述
我正在使用 luabridge 将 C++ 绑定到 Lua。我想使用自定义引用计数指针。
这就是我尝试这样做的方式:
luabridge::getGlobalNamespace(m_L)
.beginClass<SubTexture>("SubTexture")
.addFunction("SetTexture",&SubTexture::SetTexture)
.addFunction("SetCoords",&SubTexture::SetCoords)
.endClass()
.beginClass<Ref<SubTexture>>("RefSubTexture")
.addFunction("Get",&Ref<SubTexture>::Get)
.addStaticFunction("Create",&CreateSubTexture)
.endClass();
我希望它能像那样工作:
local subTexture = RefSubTexture.Create(texture,coords)
subTexture:Get():SetTexture(texture)
它没有。它向我显示了错误:尝试调用 nill 值。
我发现如果我删除 :Get() 就可以正常工作。然后我尝试使用另一个具有成员变量的类
Ref 所以根据之前的经验,我希望它能像这样工作: 不幸的是它没有,我不得不使用 :Get() 进入Refluabridge::getGlobalNamespace(m_L)
.beginClass<SpriteRenderer>("SpriteRenderer")
.addProperty("SubTexture",&SpriteRenderer::SubTexture)
.addProperty("Color",&SpriteRenderer::Color)
.endClass();
spriteRenderer.SubTexture:SetTexture(texture)
spriteRenderer.SubTexture:Get():SetTexture(texture)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)