Using trace() to view data for debugging

Tracing multiple variables

In this example we created four variables and showed various trace() options:

  • Tracing one or more parameters.
  • Tracing an updated numeric variable.
  • Tracing an updated string variable.

Screen Shot 2014-05-27 at 14.47.11

Here is the code if you want to try it out:

function main(Data)
   local age     = 10
   local age_str = '10'
   local c       = 'place'
   local d       = 'holder'
   
   -- we can trace one or more parameters
   trace(age)
   trace(age, age_str)
   trace(age, age_str, c)
   trace(age, age_str, c, d)
   
   -- not sure why you would want to do this - but you can
   trace(_, age)
   trace(_,_, age)
   trace(nil, nil, age)
   
   -- imagine that "age_from db" was retrieved from a database
   local age_from_db = 33
   age = age_from_db
   age_str = tostring(age_from_db)
   
   -- show that "age" and age_str were updated
   trace(age, age_str)
   
end