Jump to content
  • Advertisement
Sign in to follow this  
jackiechan

luabind::object help

This topic is 4968 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 just bought AI Programming by Example written by Matt Buckland and it's not a bad book. I ran into a little problem where he was accessing a lua table through the luabind::object. Let me illustrate: -- lua code -- State_Idle = {} State_Idle["Enter"] = function( entity ) -- dosomething end State_Idle["Execute"] = function( entity ) --dosomething end State_Idle["Exit"] = function( entity ) --dosomething end In his class, he had variable: luabind::object m_CurrentState; he tried to access the table with: m_CurrentState.at( "Execute" )( entity ) I know that's won't work because it's trying to call a function named Execute and not the table like the author intended. I know this was a long wind up and here's my question: how do I access the table and index it through luabind::object?

Share this post


Link to post
Share on other sites
Advertisement
To be honest that code looks fine to me. The at("execute") returns whatever is stored in that position, which happens to be a function. Then the '(entity)' bit calls that function, passing an entity to it. If it's wrong, I assume it's through some subtlety of Luabind that I'm unfamiliar with.

If you really do believe it's an error in the book, contact the author. You can view his post here and click the PM button to send him a message.

Share this post


Link to post
Share on other sites
Here's some code of mine (not using functions but accessing items in a table):


luabind::object display = globals["DisplaySettings"];
if (display) {
x = luabind::object_cast<uShort>(display["x"]);
y = luabind::object_cast<uShort>(display["y"]);
}


Seems to me that [] and at() do the same thing.

Share this post


Link to post
Share on other sites
tentoid you are the man! Buckland didn't specify a table in the examples that was in the book. The luabind documentation for the luabind::object didn't help much. Thanks!

BTW: Buckland is my hero.

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!