luabind not making changes to pointer mingw

186 Views Asked by At

I have fixed the linker errors I had in this question, but now I am having another problem. I create my objects by calling createObject() in lua and that creates a boost::shared_ptr to a new object, adds it to a list, and returns it.

On windows with mingw when I make changes in lua the changes do not get applied to the C++ object. it cannot be a problem with my code because I built the same thing on Linux and it worked fine.

ObjectPtr createObject(PlayerPtr player){
    ObjectPtr obj(new Object(player));
    window->world.objects.push_back(obj);
    return obj;
}

bool setup(lua_State* luastate, Window* caller){
    open(luastate);

    // initialize some other classes here.

    class_<Player, PlayerPtr> Player("Player");
    Player.def_readwrite("playerColor", &Player::playerColor);
    Player.def_readwrite("displayName", &Player::displayName);

    class_<Object, ObjectPtr> Object("WorldObject");
    Object.def_readwrite("health", &Object::health);
    Object.def_readwrite("maxHealth", &Object::maxHealth);
    Object.def_readwrite("mesh", &Object::mesh);
    Object.def_readwrite("location", &Object::location);
    Object.property("player", &Object::getPlayer, &Object::setPlayer);
    Object.def("setOnDeath", &Object::setOnDeath);

    module(luastate)[
        vec3,
        color,
        Player,
        WorldObject,
        def("isWindowOpen", &isWindowOpen),
        def("loadMesh", &MeshManager::LoadMesh),
        def("createObject", &createObject),
        def("createPlayer", &createPlayer),
        ];

    window = caller;
}

ObjectPtr and PlayerPtr are boost::shared_ptr of Object and Player, window is a static Window pointer, and createPlayer() is the same as createObject() without any arguments and using Player instead of Object.

in lua:

red = createPlayer()
red.playerColor = Color(255,0,0)
red.displayName = "Red"

obj = createObject(red)
obj.location = vec3(10,10,0)

print(obj.player.displayName)

results in "Red" being put in the console. but in C++ the value is just "".

I debugged it and the objects do get created and added to the list in C++, but no changes were ever made, as all variables are in there default state.

I think it is a problem with luabind and mingw, or just something wrong with the build,

the only things I changed from the default build setup were 2 things I needed to do to get it to compile at all: I set LUA_PATH in the jamfile to point to the directory lua is in (rather than getting it from an environmental variable) and I changed

#elif BOOST_PP_ITERATION_FLAGS() == 1

to

#else
#if BOOST_PP_ITERATION_FLAGS() == 1

because mingw did not like the ( for some reason... (and yes I did add the #endif in the right place)

UPDATE: I have tried using msvc10 also, and it still has the same problem. I have also tried building it against the same version of boost that is on my Linux. but to no avail.

0

There are 0 best solutions below