LuaBridge不能正确创建构造函数。

我使用 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( );

据我所知,:new 是 Lua-"classes" 的构造函数。初始化代码或 Lua 脚本是否有问题?

点赞
用户1203643
用户1203643

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

2012-09-03 04:07:39
用户847349
用户847349

LuaBridge 仅支持一个构造函数。这并不妨碍您拥有多个命名的静态构造函数,例如 Nicol Bolas 建议的 :new

2012-09-04 08:41:32