Copying a container on function call... (Was Re: return_stl_iterator acting as const?)

John Smith <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
So I'm still having a problem with this, looking into it more it seems that
the problem is the Copy Construct is being called via:

server.exe!luabind::detail::value_converter::apply<ContainedObject>(lua_State
* L=0x00f45ca8, const ContainedObject& ref={...})  Line 299 + 0x2f bytes
C++
     server.exe!luabind::detail::convert_to_lua<ContainedObject>(lua_State *
L=0x00f45ca8, const ContainedObject& v={...})  Line 74    C++

server.exe!luabind::detail::iterator<std::_Vector_iterator<ContainedObject,std::allocator<ContainedObject>
> >::next(lua_State * L=0x00f45ca8)  Line 24 + 0x12 bytes    C++
specifically:
object_ptr = new T(ref);

So we're deffinetly making a copy of the vector when we go into the function
exec.  Is there anyway to specify to pass the member variable by reference
and not by copy?  Due to some constraints of other APIs I'm using, I have to
store some objects I'm trying to expose to lua in the container, I can't
just pass them by a pointer.

Any thoughts as to things to try?


On Tue, Mar 3, 2009 at 2:04 AM, John Smith <[email protected]> wrote:

> I hate replying to myself but I also noticed that this problem is only in
> the case where the vector is storing an object not a pointer to an object.
> (Which is why I think I'm hitting a copy constructor at some point instead
> of having it pass by reference)
>
> If I was to modify the container to be std::vector<ContainedObject *> vec;,
> and modify the test code to be:
> ContainerObject cont;
> ContainedObject* Obj = new ContainedObject;
>
> Obj->value = 10;
>
> cont.push_back(Obj);
>
> Then when I come out of the call_function Obj has the expected value of 5.
>
>
> Anyone have other ideas/thoughts?
>
>
> On Tue, Mar 3, 2009 at 1:57 AM, John Smith <[email protected]> wrote:
>
>> I don't believe so, changing that to be : gave the following errors:
>> print(cont:containervalue)
>> function arguments expected near ')' for that line
>>
>> for things in cont:vec
>> gave the error:
>>  function arguments expected near 'do'
>>
>> My understanding of the : notation was that it was a shorthand of:
>> x:y is equivilant to x.y(x)
>>
>> Therefore, trying:
>> for things in cont:vec()
>>
>> gave a luabind exception of 'No such operator defined'
>>
>>
>>
>> On Tue, Mar 3, 2009 at 1:26 AM, James Porter <[email protected]>wrote:
>>
>>> John Smith wrote:
>>> > 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
>>>
>>> It looks like you're using the wrong syntax for getting at your members.
>>> In Lua, "." is similar to "::" in C++, while ":" in Lua is similar to
>>> "." in C++. You want cont:containervalue, cont:vec, and so on. The
>>> former is working because you're defining a new static variable,
>>> essentially.
>>>
>>> - Jim
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> 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
>>>
>>
>>
>

------------------------------------------------------------------------------
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.