John Labenski wrote:
> On Sat, Oct 25, 2008 at 1:05 PM, klaas.holwerda <[EMAIL PROTECTED]> 
> wrote:
>> Hi John,
>>
>> %operator a2dCanvasObjectListIter& operator--(int)
>>
>> If you change it to generate this, down here, it will work:
>>
>>  *returns = ((*self).operator++(arg1));
>
> I don't think that post-incrementing makes much sense for Lua. 

I would be very happy if you could still change it to become like the 
above, since else i can't get it compiled for STL lists. Its iterator 
does not accept the pre-incr only, or the other way around.

I try to explain how i do it now, and it works, if i do the needed 
modification to the generated C++ wrapping, in order to fit the STL 
operators, which i can not change.

First i already have a subclassed list based on STL and smart pointers.
The members lbegin and lend i had to add to satisfy lua, it does not 
like function called end(). All the rest of the STL list functions and 
iterator functions, i do add in lua.

class A2DCANVASDLLEXP a2dCanvasObjectList: public 
a2dSmrtPtrList<a2dCanvasObject>
{

public:
    a2dCanvasObjectList();

    ~a2dCanvasObjectList();

    iterator lbegin();

    iterator lend();

    .... all other members ...

}

Next i make a typedef for this list its iterator in order to have a non 
template iterator for wxLua. Understand that i do not subclass the 
iterator, and that this would make the trick impossible. The iterator 
above is a fixed subclass of the STL template list class, and i can not 
modify it or use another subclass of this iterator. That is why i need 
to use the operators of the base STL iterator, and i need to use them 
from wxLua directly also, or at least the code generated in C++ by the 
wrapper, must fit the STL iterator class directly.

typedef a2dCanvasObjectList::iterator a2dCanvasObjectListIter;

Now this is how the list is wrapped, notice the extra functions, which 
are not part of a2dCanvasObjectList directly, only of the lowest STL 
list base class.

%include "canvas/include/objlist.h"
%class %noclassinfo a2dCanvasObjectList, a2dSmrtPtrList
    a2dCanvasObjectList()

    a2dCanvasObjectListIter lbegin()
    a2dCanvasObjectListIter lend()

    bool empty()
    size_t size()
    a2dCanvasObject* front()
    a2dCanvasObject* back()
    void push_front( a2dCanvasObject* obj )
    void pop_front()
    void push_back( a2dCanvasObject* obj )
    void pop_back()
    %operator a2dCanvasObjectList& operator=( const a2dCanvasObjectList& 
other )
    
    // REST here

%endclass


And now the wrapping code for the iterator. In principle i just add all 
function of STL list it's iterator. But first only the operator ones, 
because the are the key factor to succeed.

%class %encapsulate %noclassinfo a2dCanvasObjectListIter
    a2dCanvasObjectListIter()

        %operator a2dCanvasObjectPtr operator*() const

    
        %operator a2dCanvasObjectListIter& operator=(const 
a2dCanvasObjectListIter& other)

        %operator bool operator ==( const a2dCanvasObjectListIter& iter 
) const
        %operator bool operator !=( const a2dCanvasObjectListIter& iter 
) const

        %operator a2dCanvasObjectListIter& operator++()
        %operator a2dCanvasObjectListIter& operator++( int )

        %operator a2dCanvasObjectListIter& operator--()
        %operator a2dCanvasObjectListIter& operator--(int)

%endclass


And at last a working wxLua script with the above.

iter3 = childs:lbegin()
iter4 = childs:lend()

if iter3:op_eq(iter4) then
    cmdh:Message("list is empty"..tostring(iter3)..tostring(iter4) )
else
    cmdh:Message("list has "..childs:size().." elements" )
end

nameOfobj = ""
iter3 = childs:lbegin()
for i=1,childs:size() do
    obj = iter3:op_mul()
    nameOfobj = nameOfobj.."\n"..obj:Get():GetName()
    iter3:op_inc()
end
cmdh:Message("names are:\n"..nameOfobj)


The only thing i do not like in this script is the name op_mul() to get 
a reference to the object in the list. A name like op_deref() would be 
much better.
If we can get the operators to work (generate working code) for STL, in 
think that it is a nice way to use STL lists in lua. And the effort is 
very reasonable.

But i need you to make it happen, because i can't make bananas of 
genwxbind.lua :-)

Thanks,

Klaas



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
wxlua-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to