Sharing files among different tools?

I wrote some code for a custom OSC handler, a way to grab a send device on a track and alter the Receiver value. I stuck it in my GLobalOscActions.lua but I might also add it to a tool.

I wanted to be able to do the same thing using my Launchpad so I added code to a MIDI-handling tool I wrote.

The code for locating the tracks and altering the send device is the same in both. In cases like these I’d prefer to have a single file with that code and reference in the various tools that use it. Then if I fix a bug or otherwise change it I only have to do it in one place.

Is there a way to do this in Renoise?

I can think of some workarounds (e.g. use a local build tool to copy shared files to all the places it needs to be and then package stuff up) but was curiuos if there was a more Renoise way to do this.

After some Googling and experimenting I found a way.

Lua has a thing called package.path.

You can mess with it.

You can create a Renoise tool that does nothing, but has useful files.

In main.lua in a tool where you want to use the shared code you add a relative path pointing to the shared-code tool

package.path = "../com.neurogami.SharedCode.xrns/?.lua;" .. package.path

Now you can call ‘require’ with the name of a file in that added path: you can load files from other tool folders.

Downside: path-munging might lead to unexpected results such as loading the wrong file or interfering with normal file loading.

Upside: shared lbraries!