Hi Gianni,
On Thu, May 31, 2012 at 10:53:18AM +0200, Gianni Borghesan wrote:
> I have a veeeeery stupid question,
Not at all :-) , it's a common pitfall when going from RTT scripting
to Lua, hence I'm CC'ing the ML.
> i was tring to add a variable in the itasc stuff...
> I have already in the file (working)
> Loc1 = rtt.Variable("KDL.Frame")
> Loc2 = rtt.Variable("KDL.Frame")
> Loc1:fromtab( {M={X_x=1, Y_x=0, Z_x=0, X_y=0, Y_y=1, Z_y=0, X_z=0,
> Y_z=0, Z_z=1}, p={X=0.2, Y=0.1, Z=0.58}} )
> Loc2:fromtab( {M={X_x=0, Y_x=1, Z_x=0, X_y=0, Y_y=0, Z_y=1, X_z=1,
> Y_z=0, Z_z=0}, p={X=0.3, Y=0.0, Z=0.45}} )
>
> i wanted to add a double (or float), so i added
>
> TimeTrj = rtt.Variable("float")
> TimeTrj = 10.0
Instead of the last line you need to write
TimeTrj:assign(10.0)
for basic types.
> because they are declared in the same place and then used in the
> same place, i didn't expected problem.
> if i try to print it where i was supposed to use it, i get a "nil"
> (that is the same result if it is not declared at all)...
> What i am doing wrong?
By writing TimeTrj = 10.0 you set your Variable TimeTrj to point to a
Lua number 10.0 and your reference to your RTT float is lost. For
complex types it workes as expected, i.e. you can write Loc1.M.X_x=3.1
(because we can catch this case and do the right thing
internally). The rule of thumb is to use 'fromtab' for complex types
and 'assign' for basic ones.
Markus