Architect: Lua - require, loadfile, dofile?

Official support for: loomer.co.uk
Post Reply New Topic
RELATED
PRODUCTS

Post

Is it possible to use require and/or loadfile/dofile in the Lua script node? I've got a bunch of Lua libraries that I wrote for clocking/sequencing/modulating my monome norns that I'd be interested in adapting for use in Architect.

Post

`require` does work: it uses the "package.path" variable to find source files, so if you place your script where Lua can find them, it should work.

`loadfile` and `dofile` are currently not supported. I say they are not supported - I actually just exclude them from the sandbox that Lua runs in. It wouldn't be any trouble to allow these functions, but I'll need to think carefully about the security aspects of opening things up like this. I'm tempted to allow these in the next release as the actually "dangerous" functions - arbitrary file access - can remain firmly forbidden.
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

Awesome. Thanks, Colin.

Post

threw my Lua files in /usr/local/share/lua/5.3/ and require works!

couple of things that I noticed though...

1. print() statements in the required files seem to get swallowed, is it possible to allow those to bubble up into the console?

2. I couldn't access the built-in `arc` module from inside my required files, would that be possible somehow?

... also, would be great if you could open source the Lua API! :pray:

Post

disc0head wrote: Wed Mar 30, 2022 4:53 am
1. print() statements in the required files seem to get swallowed, is it possible to allow those to bubble up into the console?
I recently noticed that too - pretty confusing as I assumed that the module wasn't loading: it was, but as you say, swallowing the prints. I have to do some sneaky things to redirect printed output to the main console, mini console in the Lua script properties, or console in the Lua editor dialog, so I would guess that I'm missing something here. I'll look into it.
2. I couldn't access the built-in `arc` module from inside my required files, would that be possible somehow?
Ah, that's interesting. I assumed it would be available as external and internal scripts should be running in the same sandbox. I'll look into that too!
... also, would be great if you could open source the Lua API! :pray:
I don't have a problem with that, although most of the Lua API is actually library (i.e. C) code that wraps existing Arc functions. There isn't a huge amount of Lua, per se, directly in the product.
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

thanks again Colin. very happy customer here, my little norns Lua libraries worked with almost no modifications, they're mostly pattern and modulation generators. absolutely loving Architect so far, keep up the great work!

Post

FYI: I've now fixed both the problem with `print` statements being swallowed, and `arc` module not being available in `require`d modules. In fact, they were the same issue, whereby the environment was incorrectly set in an externally loaded module.

As a work-around until the release is out, you can fix the issue by putting the following line of code at the top of any imported Lua modules:

Code: Select all

local _ENV = _G
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

Nice! Just now seeing this, dunno how I missed it.

Unrelated question, any plans to support editing Lua scripts from an external text editor?

Post

I assume you mean, basically opening up the script, probably as a temp file, in an external editor and then having the Lua module "watch" this file for changes and recompiling the script when they occur? Actually, now I've stated the issue, I've realised that it's probably quite simple, so I guess the short answer is: yes! Thanks for the suggestion.
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

colin@loomer wrote: Fri May 27, 2022 7:53 am I assume you mean, basically opening up the script, probably as a temp file, in an external editor and then having the Lua module "watch" this file for changes and recompiling the script when they occur? Actually, now I've stated the issue, I've realised that it's probably quite simple, so I guess the short answer is: yes! Thanks for the suggestion.
Yes, that's exactly what I mean... aaaand that's awesome! :pray:

Post Reply

Return to “Loomer”