RTT-Lua and vectors

Hi,

I have a 'PlanningState' type that is a struct, added to the Orocos "Types"
as a StructTypeInfo, whose elements are correctly displayed and assignable
in Lua.

I have also added a SequenceTypeInfo for std::vector<PlanningState>.

I can see the elements of this vector, use 'resize' and 'fromtab' to manage
them, but I cannot use table functions (such as ipairs) to iterate over my
vector elements.

Are vector<T> interpreted by Lua as table? They seem to be userdata as
other "elementary" types.

Is their a way to say to Lua that this type is actually a table?

Thanks,

Charles.

RTT-Lua and vectors

Hi Charles,

On Fri, Apr 13, 2012 at 08:30:48AM +0200, Charles Lesire-Cabaniols wrote:

> I have a 'PlanningState' type that is a struct, added to the Orocos "Types" as
> a StructTypeInfo, whose elements are correctly displayed and assignable in Lua.
>
> I have also added a SequenceTypeInfo for std::vector<PlanningState>.
>
> I can see the elements of this vector, use 'resize' and 'fromtab' to manage
> them, but I cannot use table functions (such as ipairs) to iterate over my
> vector elements.

Correct.

> Are vector<T> interpreted by Lua as table? They seem to be userdata as other
> "elementary" types.
> Is their a way to say to Lua that this type is actually a table?

Short story: it is possible but not implemented. The simple solution
is to iterate using numerical indices as below:

x=rtt.Variable("ints")
x:resize(10)
for i=0,x.size-1 do print(x[i]) end

A vector always has the fields "size" and "capacity", they are just
ommitted by the standard array printer.

Markus

Longer story: The "ugly" internal issue prohibiting this extension is
that there is really no way to know if a type is a vector or
not. Currently this is "inferred" by checking if there are "capacity"
and "size" fields.