Jump to content
  • Advertisement
Sign in to follow this  

Luabind::object .at() problem

This topic is 3722 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

Hi, I have a problem, i have set up a table in a LUA script that has a function stored in it:
State_Guard = {}

State_Guard["Execute"] = function(unit)

	print("Inside executing...")
I try to access it the following way from the Cpp (where m_CurrentState is a luabind::object)
//This is in the init code to set a starting state
m_CurrentState = luabind::get_globals(m_LuaState)["State_Guard"];


//This is called every cycle
It gets through the first cycle fine, and displays the print out in the script file, before this point 'm_CurrentState' had a type of 5 (which is the luabind enum for a table, which is correct). But after the .at() function has been called 'm_CurrentState' now has a type of 3 (which is the luabind enum for a number). So the next time it comes back around to call this .at() statement 'm_CurrentState' is a number, not a table!, and it crashes when trying to access it as a table. To me this makes no sense because i dont know how it can be cast into a number from a table just by calling the .at function(). Ive been trying to solve it for ages, I would be very thankful for any help, I really need to solve this :( ps. I know im using an older version of lua/luabind, but i dont really have the time to switch at this present moment.

Share this post

Link to post
Share on other sites
Tried this code

lua_State *myLuaState = lua_open();

// ...and here ;)
"State_Guard = {}\n"
"State_Guard[\"Execute\"] = function(unit)\n"
" print(\"Inside executing...\")\n"

luabind::object guard = luabind::globals(myLuaState)["State_Guard"];


And it prints "Inside executing..." three times. Using Lua 5.1.3, LuaBind from 2008-02-08 with Boost 1.14.1.

I've got the binaries (and sources) of what I'm using for download linked on my page: Quick Introduction to LuaBind.

Sorry, but I can't think of any other option than to upgrade.

Well, on the other hand, maybe there's a chance that your LuaBind version doesn't clean up the lua stack correctly and you could achieve something by either pushing an additional null value onto the stack before invoking the function or by popping one more value from the stack after calling the function. Maybe it also changes the behavior if the function returns something.

Share this post

Link to post
Share on other sites
Thank you so much for taking the time to respond so quickly :)

I just had a question, will the binaries on your site work on Microsoft Visual Studio 2003, or are they specifically for Visual Studio 2005/2008?

If they are 2005 specific, i would really appreciate it if you could give me a quick tut (or point me in the right direction) on how to compile the LUA libraries for 2003? :)


Share this post

Link to post
Share on other sites
I've included binaries for Visual C++ 2005 SP1 and Visual C++ 2008, but I doubt any of them would work for the 2003 edition.

The archive on my site contains a file named library_sources.zip with the exact Lua and LuaBind snapshots I used to build the binaries. Maybe those could be used to compile Lua and LuaBind for Visual Studio 2003 (project files can be found in the "Build" subfolders).

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!