Sign in to follow this  

Problems with reading global data with luabind [SOLVED]

This topic is 2793 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();
    luabind::open(configState);
    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;
        }

        gameConfig.ParseLuaTable(configTable);
    }
    lua_close(configState);
    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

This topic is 2793 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this