Inspect contents of a variable


(tunabee) #1

So I’m trying to play around with Lua in Renoise, and trying to understand what’s inside of the various variables/properties listed in the API.

So let’s say I wanted to see what’s in renoise.song().file_name. I figured you would just do something like this, but:

>>> print("Hello");
Hello
>>> print(renoise.song().file_name);
>>> renoise.song().file_name;
*** [string "renoise.song().file_name;"]:1: '=' expected near ';'

Harder Drums (hardstyle)
(dblue) #2

renoise.song().file_name is a property, not a function, so you cannot simply call it directly and expect something to happen.

If you want to print the current file name, then you can do:

print(renoise.song().file_name)

One important thing to keep in mind: If you’re running scripts on a new/empty song that has not yet been saved, then file_name will of course be empty, so printing it will result in nothing.

Also, the ; is not necessary at the end of each line, so you can skip that.

If you want to dig deeper into the structure of various objects, then you can use the oprint() function.

Take a look at the output from this:

oprint(renoise.song())

Then start digging deeper into each property/function that you see listed.


(tunabee) #3

Thank you! This makes more sense to me now.


(Conner_Bw) #4

Here’s a function that will print whatever you throw at it. Maybe it can help you?

Example: dbug(renoise.song().file_name)

-- Debug print
function dbug(msg)
 local base_types = {
  ["nil"]=true, ["boolean"]=true, ["number"]=true,
  ["string"]=true, ["thread"]=true, ["table"]=true
 }
 if not base_types[type(msg)] then oprint(msg)
 elseif type(msg) == 'table' then rprint(msg)
 else print(msg) end
end

(tunabee) #5

Thanks, man, very cool. I also found some code to print the parameters of an audio device (which I’ve turned into a helper function):

function deviceparams(track)                     
 local devices = renoise.song().tracks[track].devices        
 for _ = 1, #devices do                       
  for __ = 1, #devices[_].parameters do              
   rprint ("Device [".._.."] Parameter ["..__.."] -> "..devices[_].
  end                               
 end                                
end

I’ve also started reading the documentation on the Github site and looking at the example tools (which I now realize aren’t installed by default), which has been super helpful.