return values of rttlua functions

On Tue, Dec 04, 2012 at 02:12:37PM +0100, Dominick Vanthienen wrote:
> hi,
>
> I've a question regarding return values of rttlua functions. I'll start with an example:
> If you ask a TaskContext in C++ for a non-existing property, it will return 0, without an error (mytask.getProperty("myprop") -> 0)
> If you do the same using rttlua, it will result in an error, even
> with pcall around it: (pcall(mytask:getProperty("myprop")) ->

Check the docs of pcall. You are pcall'ing the result of
mytask:getProperty("myprop"), not the function itself. The correct
syntax would be something like:

pcall(mytask.getProperty, mytask, "myprop")

but see below for an easier way.

> stdin:1: /home/orocos_toolchain/ocl/lua/rtt.cpp failed. No such property
> stack traceback:
> [C]: in function 'getProperty'
> stdin:1: in main chunk
> [C]: ?
>
> How to deal with this properly?
> I just want to know whether my component has this property or
> not. That the component doesn't have this property isn't necessary
> an error.

Better use
rttlib.tc_has_property(tc, name)

> The only way I see it now, is to get a table of all property names
> (getPropertyNames()) and then loop through it and check for a match
> with the property name I'm looking for...

The above function does exactly that for you.

Markus

return values of rttlua functions

On 12/04/2012 02:37 PM, Markus Klotzbuecher wrote:
> On Tue, Dec 04, 2012 at 02:12:37PM +0100, Dominick Vanthienen wrote:
>> hi,
>>
>> I've a question regarding return values of rttlua functions. I'll start with an example:
>> If you ask a TaskContext in C++ for a non-existing property, it will return 0, without an error (mytask.getProperty("myprop") -> 0)
>> If you do the same using rttlua, it will result in an error, even
>> with pcall around it: (pcall(mytask:getProperty("myprop")) ->
>
> Check the docs of pcall. You are pcall'ing the result of
> mytask:getProperty("myprop"), not the function itself. The correct
> syntax would be something like:
>
> pcall(mytask.getProperty, mytask, "myprop")
>
> but see below for an easier way.
>
>> stdin:1: /home/orocos_toolchain/ocl/lua/rtt.cpp failed. No such property
>> stack traceback:
>> [C]: in function 'getProperty'
>> stdin:1: in main chunk
>> [C]: ?
>>
>> How to deal with this properly?
>> I just want to know whether my component has this property or
>> not. That the component doesn't have this property isn't necessary
>> an error.
>
> Better use
> rttlib.tc_has_property(tc, name)
thanks!

this functionality isn't applied to toolchain-2.5 though
>
>> The only way I see it now, is to get a table of all property names
>> (getPropertyNames()) and then loop through it and check for a match
>> with the property name I'm looking for...
>
> The above function does exactly that for you.
>
> Markus
>
nick

return values of rttlua functions

hi,

I've a question regarding return values of rttlua functions. I'll start with an example:
If you ask a TaskContext in C++ for a non-existing property, it will return 0, without an error (mytask.getProperty("myprop") -> 0)
If you do the same using rttlua, it will result in an error, even with pcall around it: (pcall(mytask:getProperty("myprop")) ->
stdin:1: /home/orocos_toolchain/ocl/lua/rtt.cpp failed. No such property
stack traceback:
[C]: in function 'getProperty'
stdin:1: in main chunk
[C]: ?

How to deal with this properly?
I just want to know whether my component has this property or not. That the component doesn't have this property isn't necessary an error.

The only way I see it now, is to get a table of all property names (getPropertyNames()) and then loop through it and check for a match with the property name I'm looking for...

thanks in advance

Nick