This was helpful for me (Lua for Python Programmers):
http://the4thwiki.com/lua/index.html

1 Like

@shreeswifty @murray Although I shouldn’t speak for Graham and Wes (I did contribute a tiny bit to the project back in the day) LuaAV is mostly dead at this point. It was pretty amazing what it could do, in particular the way it handled realtime, live-coded audio DSP written in Lua.

That said, I just downloaded and ran the build script from this repo:

… and it ran without any problems, at least under OS X.

1 Like

So I haven’t ordered a norns yet. I’d like to see the source code and make sure it ā€˜fits’ with my way of wanting to code. But I still can’t stop thinking through ideas…

Does anyone have any experience with declarative programming in Lua?

What I’m thinking is that I’m often going to want to write UI to edit a bunch of values, and have a set number of actions based on those edits (e.g. update the value in a SynthDef instance, run a Lua function, etc).

Rather than writing normal code for the UI, I’d much rather describe it, and either have that description be the code (e.g. a DSL), or have the description interpreted by something else. Ideally I could do this in such a way that the UI could adapt itself based on the hardware available (e.g. Arc, or a keyboard).

I’ve seen:

and

I’ve tried reading though the first, and it roughly makes sense (always returning functions so you can chain things together), a concrete understanding of it is beyond my reach with my current comprehension of Lua. The second link is completely out of my reach.

I’ve also wondered if just using vanilla Lua tables as the description medium would be more idiomatic and less ā€˜magical’.

So more experienced Lua programmers, any thoughts?

I’d love to get a decent handle on this, I think it has a lot of potential for writing grid user interfaces too.

I don’t think there is anything stopping you from going down this road - in fact I started experimenting with the idea of a more declarative style API for handling MIDI events (on norns). I wasn’t able to finish it in time for the release but if helps this might give you a better sense:

I’m not doing anything too fancy here. There are ā€œobjectsā€ which drive execution Input and Clock while Chain does all the book keeping with regard to allowing ā€œdevicesā€ within the chain to produce one (or more) output events in response to a given input event. My goal was really to build some high level components that I could easily rearrange (even on the fly) without having to rewire all the logic.

The focus at the moment is building out an internal scheduler to allow ā€œdevicesā€ to output events which are deferred until some future time…

norns provides the low level device registration and event callbacks (for connected devices), what happens after that is entirely up to you.

6 Likes

Thanks for the example code, that helps.

Still have to read everything twice, can’t handle the optional brackets yet!

Is there anything approaching a ā€˜style guide’ for Lua?


edit

W. T. F.

Let’s address the elephant in the room first. LuaRocks is indented with 3 spaces.

1 Like

Do you mean this sort of thing midi.Pattern{ pattern = 'as-played' }?

The trick is just recognizing that as sugar for midi.Pattern({ pattern = 'as-played' }). What is really happening is nothing more than a literal lua table being passed as the first (and only) argument to a function which is an object constructor…

The midi.Chain{ .... stuff ... } syntax works the same way. It is a literal Lua table but since there aren’t any keys defined then the resulting table is a Lua style array where the keys are ones based numeric index.

Hey, just wanted to say Thank you all :sunny: guys for those many interesting links and infos about Lua. Time to brush the dust off of some old knowledge and start refreshing :wink:

Hey everyone I just joined the community over the weekend having discovered Norns. I will have to admit I have zero knowledge in coding but I would like to begin my journey. Would it be wise to start with learning Java Script (which falls into the fact that I’m studying CCNA ) so I may be able to utilise java for my new norns endeavours, using the knowledge to then move to LUA?

so first off Java and Javascript are totally different things - as far as I know just a naming thing to help with a bandwagon. Ironically of course Javascript has survived much better (being the better language arguably - don’t ā€˜@’ me :wink: )

ok that out of the way: learning Javascript will do you no harm at all - it’s everywhere these days and knowing it will help you get work, or be a useful skill to have.

I would say though - if you want to use Lua - then learn Lua! It’s not a hard language. It’s nice and apart from one screaming oddness - 1 based arrays - pretty much everything else you will ever use starts indexing arrays at ā€˜0’ - it’s very similar to a lot the mainstream languages.

all programming is fairly similar- there are a few different classes or styles of languages but don’t worry about that too much to start with.

1 Like

If anyone’s thinking of starting to learn Lua, this might be a useful resource. It provides a set of programming challenges designed to test your understanding. Once you’ve submitted a solution you can see how others have solved the problem, and optionally get mentor feedback.

9 Likes

Fair enough, I’ve not been able to find a beginners guide regarding LUA , the only one I did find assumed you know coding and just need to learn it’s language. I’m starting from language ground zero so thought using the book elequent java script version 3 would be a good foundation for not only going onto understand LUA but adds to my profession as an ICT Tech currently studying for the CCNA Exam.

fair enough - see the post above yours though.

But yeah - I agree, if you can find a resource for a similar language that is what you need to learn then that’s one way to do it.

Learning is one of those personal things - everyone has advice about how they learn - you need to do what works for you

edit: I would also add: there isn’t a right way - if you do something and it causes you to come out the other end knowing something then that’s good. :slight_smile: the only thing that is absolutely guaranteed not to work is NOT doing anything to learn something…

2 Likes

Another way I could look at it is I learn Lua first as I want to create my own sonic soundscapes on norns and then that language will translate into JAVA Script

i am someone who is very very bad at making time to read technical information that i don’t absolutely need to know to complete my task, so the absence of comprehensive video tutorials for LUA has led to some substantial gaps in my knowledge of the fundamentals. when googling around to try to figure out what setmetatable() actually means, i actually found a full set on 5.2!

for some reason i had never been able to find these before, and the view counts are really low, so just passing them on in case others are in a similar position.

1 Like

you should be able to jump right into the norns studies; ideally they assume little programming background. (and where they do we should update them so they don’t.) for the intrepid, we should consider adding some ā€œforward pointersā€ in the studies too, linking out to places to dig deeper into relevant language concepts.

2 Likes

I’ll start next week :muscle:

1 Like

Perhaps not the discovery of the century but TIL multiple variable assignment on single lines is possible in Lua.

local x, y, z = 1, 2, {}
print(x, y, z) 1 2 table: 0x2408790

Pretty satisfied about that! Now to clean up some scripts…

6 Likes

anyone have a suggestion for which Lua for windows might be best?
I see LuaDist, Lua for Windows and Lua Rocks

it depends what you’re doing and also probably doesn’t matter much.

but to get started: LuaDist if you like cmake, or just the language sources if you prefer some other build system.

alternatively, using lua binaries ensures a standard environment.

LuaRocks is a package manager (written in lua) and also the main central repository for packages. if you want to explore packages that’s probably the best way.

NB that the chocolatey Lua package installes Lua for Windows which seems a bit rotted.