Jump to content
  • Advertisement
Sign in to follow this  

Problems with reading global data with luabind [SOLVED]

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

EDIT- Turns out it was a problem with the lua file format. This version works fine:
ConfigTable =
MaxFps = 50,
Fullscreen = 0,

GraphicsFolder = "../data/graphics/",
AnimationFolder = "../data/animation/",
EntityFolder = "../data/entity/"

I just started adding lua scripting support with luabind for my game and ran into a problem with accessing global data from lua_State. I have the game configuration options in following file: CONFIG.lua
ConfigTable = {}

configTable["MaxFps"] = 50
configTable["Fullscreen"] = 0

configTable["GraphicsFolder"] = "../data/graphics/"
configTable["AnimationFolder"] = "../data/animation/"
configTable["EntityFolder"] = "../data/entity/"

I then load the file with this code:

VInitialize(char const * initFileName, GameConfig & gameConfig)
lua_State * configState = luaL_newstate();
    luaL_dofile(configState, initFileName);
        luabind::object global = luabind::globals(configState);

        luabind::object configTable = global["ConfigTable"];

        if( luabind::type(configTable) != LUA_TTABLE )
            LogError("Config file ConfigTable is not a table!");
            return false;

    return true;

So far all works well. But in then...
bool GameConfig::ParseLuaTable(luabind::adl::object const & configTable)
    m_maxFps            = luabind::object_cast<int>(configTable["MaxFps"]);
    m_startInFullscreen = luabind::object_cast<int>(configTable["Fullscreen"]);

    m_folders[eCONFIG_GRAPHICS]   = luabind::object_cast<std::string>(configTable["GraphicsFolder"]);
    m_folders[eCONFIG_ANIMATIONS] = luabind::object_cast<std::string>(configTable["AnimationFolder"]);
    m_folders[eCONFIG_ENTITIES]   = luabind::object_cast<std::string>(configTable["EntityFolder"]);

    return true;

Here the program crashes on the first object_cast with the following error: terminate called after throwing an instance of 'luabind::cast_failed' what(): unable to make cast It seems like the data in ConfigTable isn't defined properly, or something. The code worked when I retrieved the table by making the lua script a function returning it, but shouldn't the current version work as well? I'm just trying to access global data defined in the lua file. This is my first time using lua, so please tell me if I'm doing something really wrong here. Thanks in advance. [Edited by - Hlan on April 24, 2010 2:36:18 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!