Advertisement

luabind::object help

Started by January 08, 2005 01:37 AM
2 comments, last by jackiechan 19 years, 8 months ago
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?
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.
Advertisement
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.
Ad: Ancamnia
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.

This topic is closed to new replies.

Advertisement