How can I install this module I found (inspect)?

There’s a library on github called Inspect (https://github.com/kikito/inspect.lua) which looks like it could be handy for inspecting objects, however I’ve not been able to get it to work in the Lua environment. I’ve tried importing it as suggested in the tool’s instructions, copying/pasting into the terminal, and all to no avail. It tells me inspect isn’t declared.

>>> local inspect = require 'inspect'
>>> inspect(renoise.song().instruments)
*** [string "inspect(renoise.song().instruments)"]:1: variable 'inspect' is not declared
*** stack traceback:
*** [C]: in function '_error'
*** [string "local mt = getmetatable(_G)..."]:29: in function <[string "local mt = getmetatable(_G)..."]:24>
*** [string "inspect(renoise.song().instruments)"]:1: in main chunk

Lua code needs to know where to look for files when you invoke “require”

Lua uses a thing called “package.path” to track possible locations.

I was curious what this was for Renoise. You can see for yourself by running (in the terminal/editor thing):

rprint(package.path)

In my case it showed that, among the paths listed, there was one that would work well for me because it was part of my Renoise user data:

C:\Users\james\AppData\Roaming\Renoise\V3.1.1\Scripts\Libraries\?.lua

There was no existing “Scripts\Libraries” folder, so I made one.

Then I added a file, inspect_tool.lua, with the code from Github.

I was then able to do this:

local i = require "inspect_tool"
  rprint(i)

and get some interesting output.

The details of package.path can be found here:https://www.lua.org/pil/8.1.html

Thanks! Looks like I was just using it incorrectly (apparently, if you just try to run the function on an object, it isn’t happy. You have to nest it in a print function).

Also, it doesn’t seem to do what I thought it would do, that being giving me some useful data about the complete table. Since it doesn’t do what I’m hoping it would do, could I ask: has anyone made a function that will print the entire structure of renoise.song()? Like, the tables, the properties, and the methods? I want to get a “feel” for the structure and how everything works so I can start making some useful utilities.

One way to get an idea of songs in general is to look at the Renoise song API listing. But I find it overwhelming. (What I really want is the API docs as dynamic tree that I can expand/collapse.)

renoise.song() does not return a table, I found some code that should do recursive table inspection:

https://gist.githubusercontent.com/hashmal/874792/raw/224f33102108f6b2a393ceeac3088631bbe60d25/gistfile1.lua

But when passed renoise.song() it complains that it was given userdata, not a table.

bad argument #1 to ‘pairs’ (table expected, got userdata)

Update: Info on “userdata” https://stackoverflow.com/questions/15175859/how-to-inspect-userdata-in-lua

FYI I started working on a simple interactive browser for the lua _G table. It should help new users to familiarize themselves with the API.

https://www.dropbox.com/s/xdtzoi7z3ristox/gbrowser.png

The more complex thing about it is to view objects with properties and methods, like you say, but it should be totally doable by using objinfo, loadstring/pcall and string manipulation… I’m on it :slight_smile:

joule, that sounds awesome. I understand a lot of the limitations of Lua are deliberate (so it could be more portable), but using Lua feels like programming blindfolded a lot of the time. Something like what you’re working on is absolutely brilliant.

What I think would really help though would be a slightly easier-to-navigate set of docs. They’re not the worst I’ve seen, but they could be better. Honestly, a webpage with a sidebar you can browse would do the job. I may end up trying to work on something like that once I get my head around Lua and Renoise.

Thank you Neurogami and joule for your help–there’s very few places to turn for help on Renoise/Lua (although the guys in the Lua Reddit have helped a bit as well).

Still wish they went with Python for the scripting language :slight_smile:

Quick question: can you alter package.path? I have Lua 5.3 installed on my computer (OS X) and want it to search for libraries there (for debugging purposes).

Quick question: can you alter package.path? I have Lua 5.3 installed on my computer (OS X) and want it to search for libraries there (for debugging purposes).

Yes. It’s similar to $PATH in *nix environments, except it doesn’t store paths, exactly, but path/patterns.

I wrote about tweaking it in Renoise:http://jamesbritt.com/posts/sharing-lua-script-files-among-renoise-tools.html

Very cool! I will have to read all your articles now :slight_smile:

What I think would really help though would be a slightly easier-to-navigate set of docs. They’re not the worst I’ve seen, but they could be better. Honestly, a webpage with a sidebar you can browse would do the job. I may end up trying to work on something like that once I get my head around Lua and Renoise.

Nice idea. I once made an extraction script for the Renoise LUA API that also extracted the hierarchy/structure of renoise.* with all comments.

I’ll try to use all this API data in the _G browser as well.

I think LUA is a very elegant and simple language really. But a doc interface like this should be able to help minimize the initial “scare factor”.

As already mentioned, Steinberg seems to use a proper tool to auto generate the lua docs for halion. It looks pretty pro.