Trouble binding a class - should be simple
Simon Pickles <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I am trying to expose part of the btVector3 class from BulletPhysics to Lua:
http://www.bulletphysics.com/Bullet/BulletFull/classbtVector3.html
My first attempt:
// C++
void RegisterPhysicsTypesWithLua( lua_State* lua )
{
module( lua )
[
class_<btVector3>( "btVector3" )
.def( "getX",&btVector3::getX )
.def( "getY",&btVector3::getY )
.def( "getZ",&btVector3::getZ )
.def( "setX",&btVector3::setX )
.def( "setY",&btVector3::setY )
.def( "setZ",&btVector3::setZ )
];
}
--Lua
print("Testing btVector3 in lua")
v = btVector3()
print("btVector3 created")
print( "x = " .. v.getX() ) -- should print x = 0.0
v.setX(99.9)
print( "x = " .. v.getX() ) -- should print x = 99.9
------------------------------------------
This first attempt produces the error:
"Attempt to call a nil value"
So I added a constructor and tried again:
// C++
void RegisterPhysicsTypesWithLua( lua_State* lua )
{
module( lua )
[
class_<btVector3>( "btVector3" )
.def( constructor< float, float, float>() )
.def( "getX",&btVector3::getX )
.def( "getY",&btVector3::getY )
.def( "getZ",&btVector3::getZ )
.def( "setX",&btVector3::setX )
.def( "setY",&btVector3::setY )
.def( "setZ",&btVector3::setZ )
];
}
--Lua
print("Testing btVector3 in lua")
v = btVector3(1.0,2.0,3.0)
print("btVector3 created")
print( "x = " .. v.getX() ) -- should print x = 1.0
v.setX(99.9)
print( "x = " .. v.getX() ) -- should print x = 99.9
------------------------------------------
This second attempt produces the error:
"No such operator defined"
I have double checked that I am definately calling the
RegisterPhysicsTypesWithLua with the correct LuaState.
I expected this to be reasonably trivial as I have been exposing my own
classes with ease. This is however, the first time I have tried to
expose a 3rd party class. Am I missing something obvious?
Thanks very much
Simon
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd