agreed. i think i’ve said this, but we should really discourage require. we use it in core libs, but in scripts it is a pointless optimization and actually hinders development of user libraries. (b/c caching)

3 Likes

they do different things: dofile parses and executes, loadfile parses and returns a function but doesn’t execute.

loadfile does allow for better error handling if the file failed to parse. (it actually has two return values - an unusual feature of lua - a function and an error.) so we could make better use of this in include().

1 Like

i was under the assumption that our design of include accommodated the standard use case for using libs.

can someone explain to me the use case that it does not accommodate?

to be clear, i don’t think there’s anything wrong with the way include() works, but the conventions and assumptions could maybe be more explicit.

namely:
include('foo') assumes that one of these exists:
~/dust/code/foo.lua
or
~/dust/code/last_script_parent_dir/foo.lua

so far i’ve seen both of the following more than once, which don’t work:

  • installing scripts somewhere besides ~/dust/code (e.g. ~/norns/lua/ - don’t put scripts there, it’s for system stuff)
  • trying to include('foo') from ~/dust/code/baz/foo.lua when the current script is in ~dust/code/bar (instead, include('baz/foo'))

When I load a different engine.load('Why'), it doesn’t update engine.name, but I feel like it should. Any thoughts on this?

Also, what is the proper way to outload an engine, for example, self-playing engines like Why and SineTest, will keep on playing after a new engine has been loaded, some engines have removeVoice, but not all?

What is the right way to handle this, see context.

6 posts were merged into an existing topic: Norns: Development

Is there an issue with the script reference for include()? The docs says:

include('lib/somelib.lua') will first look in the directory of the current script. This allows using relative paths to use libraries local to the script.

My current folder structure:

script.lua
lib/
  target.lua

In script.lua, include('lib/target.lua') results in:

including /home/we/dust/code/lib/target.lua.lua
### SCRIPT ERROR: load fail
cannot open /home/we/dust/code/lib/target.lua.lua: No such file or directory

It seems like if .lua is present in the include’s filename, it adds it again.

This is true and the doc is incorrect

include attempts to follow the syntax of require (which is a builtin)

1 Like

What would be the easiest way to get a 3d perlin noise function in a lua script? Is it possible to expose the Perlin3 function of Supercollider or embed a C file?

Here’s an example where I use a few functions similar to Perlin3 (Brownian, Lorenz, and a few others) in SuperCollider that then effect Lua code via polls:

It and it’s accompanying lua code is a big mess right now, I’d love to wrap it up into a shareable modulator library at some point.

5 Likes

seems like just… coding it up in lua? would be the most straightforward.

When I tried to use a Perlin noise function I found a gist of in Lua at 15fps it ended up causing the controls and menu to get a little unresponsive. It could have been particularly inefficient or just be the cumulative effect of a lot of stuff I was doing in the draw loop, but things felt a lot snappier after I pushed it to SC and used a poll.

Yea that makes sense too. I can imagine a naive LERP in lua being pretty rough

e.g., people forget that the # operator loops over the table!

@neauoire i don’t remember where you originally asked, but

norns.script.clear()

will clear the current script.

theoretically maiden could have ;clear mapped to this.

note: it doesn’t perform the menu magic to disable toggling into PLAY mode, however.

1 Like

Being able to to stop a crashing script on the fly with a quick shortcut would be very useful, sometimes i get error debug logs 15fps and totally makes the input field too sluggish to type in.

2 Likes

This is definitely something that happens to me. Having an easy way out would be awesome.

2 Likes

What is the function that fires on quit? Let say I have noteOn messages to release when I shut down the norns, or when I change library, is there something like on_quit that I can override?

function cleanup()
  -- executed on script close/change/quit
end
1 Like

Thank you :slight_smile: I’ve updated the tutorials.