Question

I use LuaBridge to port some classes and functions to Lua. I'm currently debugging and I always get

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

this is main.lua :

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

this is the initialization code for 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 is :new the constructor function of the Lua-"classes". Is there something wrong on initialization or in the Lua-script ?

Was it helpful?

Solution

LuaBridge supports only one constructor. That doesn't stop you from having multiple named static constructors, such as :new as Nicol Bolas is suggesting.

OTHER TIPS

I had to use the .operator for initilization and only register one constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top