Jump to content
  • Advertisement
Sign in to follow this  
thelovegoose

Luabind & stl

This topic is 3211 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to be able to do the following: Pass a container to a lua function Return the container to the c++ calling code Pass the container to another lua function Add to and remove from the container in lua Iterate over the container in lua Edit a particular element from the container in lua So far I've been trying to achieve this through combinations of exposing or wrapping stl containers, using return_stl_iterator, using luabind::newTable to create a table from a container. Can anyone reccomend a way to achieve the above requirements - or advise if I'm attacking this in the wrong way? If I can provide more info please let me know, Many thanks in advance,

Share this post


Link to post
Share on other sites
Advertisement
Hello,

Having looked at several different ways of achieving what I want, the standout option by far (provided I can get this to work) is to be able to use at least
push_back, push_front, pop_back, pop_front, back, front and at where applicable from the stl containers in LUA. I don't particularly need iterators as I can get by with the above functions.

Push & pop are simple enough to expose and use, but I'm struggling with back.

Heres my code to expose vector<T>::back :



luabind::module(mLuaState) [
luabind::class_<std::vector<Gaia::Vector2>>("V2vector")
.def(luabind::constructor<>())
.def("push_back",&std::vector<Gaia::Vector2>::push_back)
.def("back",(Gaia::Vector2&(std::vector<Gaia::Vector2>::*)(void))&std::vector<Gaia::Vector2>::back, luabind::dependency(luabind::result, _1))
];

luabind::module(mLuaState) [
luabind::class_<Gaia::Vector2>("Vector2")
.def(luabind::constructor<>())
.def_readwrite("x", &Gaia::Vector2::x)
.def_readwrite("y", &Gaia::Vector2::y)
];








and here is the attempt to call in lua:


path = BehaviourManager:getPath(currentPos, AIArgs.targetPoint, unitSize);

testz = path:back();







(BehaviourManager is correctly defined as a global, getPath definitely returns a std::vector<Vector2>)

the (custom) lua error is :

[LUA] Error : ..\Data\media\scripting\lua\testIdle.lua:43: attempt to call method 'back' (a nil value) source : @..\Data\media\scripting\lua\testIdle.lua what : Lua line : 8

I expect that its something to do with the return type of back - ie that its a reference, or that there are 2 overloads of back (returning reference or const reference) but I don't see why thats a problem?

Is anyone kind hearted enough to help? This is really holding me up so any suggestions would be very welcome :)


[Edited by - thelovegoose on November 5, 2009 5:59:48 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!