return_stl_iterator acting as const?

John Smith <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Greetings all,

I'm having a problem setting the value of a class contained within a
std::vector from lua, I have the following code:

C++:
class ContainedObject
{
public:
    int value;
};

class ContainerObject
{
public:
    std::vector<ContainedObject> vec;
    int containervalue;
};


luabind::module(L)
[
    luabind::class<ContainedObject>("ContainedObject")
    .def(luabind::constructor<>())
    .def_readwrite("value", &ContainedObject::value),

    luabind::class_<ContainerObject>("ContainerObject")
    .def_readwrite("containervalue",    &ContainerObject::containervalue)
    .def_readwrite("vec",            &ContainerObject::vec,
luabind::return_stl_iterator)
];

ContainerObject cont;
ContainedObject Obj;

Obj.value = 10;

cont.push_back(Obj);
cont.containervalue = 15;

luabind::call_function<void>(L, "LuaFunction", &cont);

std::cout << cont.containervalue << std::endl;
std::cout << cont.vec[0].value << std::endl;



Lua code:
function LuaFunction( cont )
    print (cont.containervalue)
    cont.containervalue = 30
    for things in cont.vec
    do
        print (things.value)
        things.vlaue = 5
    end
end


Which prints out:
15
10
30
10
So I am able to modify the containervalue of ContainerObject, but I am not
able to modify the ContainedObject value.  Any thoughts here?  Is luabind
making a copy of the vector as it passes it off?  If so is there a by
reference way possible?

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.