Jump to content


Photo

Inspect contents of a variable


  • Please log in to reply
4 replies to this topic

#1 tunabee

tunabee

    Member

  • Normal Members
  • PipPip
  • 59 posts

Posted 18 December 2015 - 22:38

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 ';'

 



#2 dblue

dblue

    Dodgy Geezer

  • Admins
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5607 posts
  • Gender:Male
  • Location:Berlin
  • Interests:Code. Music. Graphics.

Posted 18 December 2015 - 23:01

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.
  • Neurogami likes this

#3 tunabee

tunabee

    Member

  • Normal Members
  • PipPip
  • 59 posts

Posted 19 December 2015 - 08:15

Thank you! This makes more sense to me now. 



#4 Conner_Bw

Conner_Bw

    Probably More God or Borg Than Human Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 7083 posts
  • Gender:Male
  • Location:Montreal, Quebec, Canada

Posted 19 December 2015 - 08:36

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

cpu Lenovo X220, Intel i7-2640M @ 2.80GHz ×4 os Windows 10 / Ubuntu 16.04 LTS
My Homepage » : My Renoise Tools » : Normalize Your Sig » : One million clicks! »


#5 tunabee

tunabee

    Member

  • Normal Members
  • PipPip
  • 59 posts

Posted 19 December 2015 - 21:25

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.