【问题标题】:LuaBridge doesnt create the constructor rightLuaBridge 没有正确创建构造函数
【发布时间】:2012-08-27 09:29:47
【问题描述】:

我使用 LuaBridge 将一些类和函数移植到 Lua。我目前正在调试,我总是得到

main.lua:1: attempt to call method 'new' (a nil value)

这是 main.lua :

v = TexVector:new( 1, 2 )
v.X = 0
v.Y = 0
print( v.X, v.Y ) -- print and explicit binded functions work

这是 TexVector 的初始化代码:

luabridge::getGlobalNamespace( L ).
    beginClass< Cheap::Math::TexVector >( "TexVector" ).
        addConstructor< void (*) ( ) >( ).
        addConstructor< void (*) ( const double& , const double& ) >( ).
        addData( "X", &Cheap::Math::TexVector::X ).
        addData( "Y", &Cheap::Math::TexVector::Y ).
        addFunction( "Add", &Cheap::Math::TexVector::Add ).
        addFunction( "Sub", &Cheap::Math::TexVector::Sub ).
        addFunction( "Mul", &Cheap::Math::TexVector::Mul ).
        addFunction( "Div", &Cheap::Math::TexVector::Div ).
        addFunction( "Eq", &Cheap::Math::TexVector::Eq ).
        addFunction( "Apply", &Cheap::Math::TexVector::Apply ).
    endClass( );

AFAIK 是 :new Lua-“类”的构造函数。初始化或 Lua 脚本有问题吗?

【问题讨论】:

  • "AFAIK 是 :new Lua-"classes" 的构造函数。"询问 LuaBridge 文档。

标签: c++ lua luabridge


【解决方案1】:

LuaBridge 只支持一种构造函数。这并不能阻止您拥有多个命名的静态构造函数,例如 Nicol Bolas 建议的 :new。

【讨论】:

    【解决方案2】:

    我必须使用 .operator 进行初始化,并且只注册一个构造函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多