A bit of an aside, but: is there any reason why Lua on the norns is 5.1.5 (dated Feb 2012)? Latest official release is 5.3.5.

no… that’s weird. it must be whatever comes with raspbian stretch.

the lua environment that actually runs norns scripts is 5.3 (we just link from liblua5.3-dev)

Oh - it never occurred to me that the norms environment would be running something other than the default /usr/bin/lua. Does the 5.3 installation have a command line component? I want something for running unit tests. (Matron might do that for me, but I’m not seeing any summary output from them.)

I ran into this the other day when trying to run some unit tests. The lua 5.3.x command line is available as a separate package (which is not installed in the norns image by default). I did the following on my dev device.

  • sudo apt-get install lua5.3
  • Install luarocks
  • luarocks install luaunit

One has to invoke lua5.3 explicitly to get the newer runtime.

1 Like

Thanks for that - I was wondering about the wisdom of doing an apt-get install - though as a Mac user I suppose I could just SMB-mount the norns drive and run a Homebrew-installed Lua from macOS instead…

I find it useful to have a functional environment on both the device and my laptop. When working on particularly ambitious projects I separate code into norns specific and platform independent so that a subset of the tests can be run off device.

Quite so. The lower-level grid driving code probably won’t get added to the tests, but I’ll keep that as simple as possible. The complex higher level stuff is (or will be) pure Lua, and I can probably mock the lower-level stuff for testing if I need to.

out of curiosity have any first time programmers had success reading through Programming in Lua?

I thought it was pretty well written but I had prior programming experience before going into it

2 Likes

Nope, might try gradually

seems comprehensive (and therefore somewhat daunting)

2 Likes

same. looks like a great resource, but today i was reading microsound, then started max/msp free trial, and then tried reading this and it was a bit of an overload lol :face_with_head_bandage: thanks 4 sharing tho ~

1 Like

yea, fair enough, i was relying on it more for the advanced topics but the starter pages are probably a little too dense

how do people feel about the english language syntax in lua (i.e. if then end do) ? as an experienced programmer it’s a minor annoyance, but for newcomers, I’m curious if it’s helped anyone come to grips with the logical operations or made code more readable compared to c-style:

if (true) {
    thing()
} else {
    otherthing()
}

technically lua was my first programming language and my intro to these concepts, but I do not remember back that far : )

I forget the then almost every time

1 Like

don’t get me started on if do

the thing that bothers me is the other way round, writing some javascript after a session of lua writing adding in then from muscle memory constantly

I think it’s especially weird if you take C code (or most other languages) and directly translate it to Lua. On the other hand, if you change your naming conventions to fit it can be very elegant IMO.

A bad example: if shirt:isdirty() then wash() end.

If you see then and end as syntax, it’s kinda the same thing. then == {, and end == }.

3 Likes

the way i approached the book was to make notes about anything i found weird coming to it from java/c#/c background. there are several notes that end with ā€œreally?!ā€ or ā€œwtf?ā€. i think one was about the way the ternary if is done…

lua’s ternary if kinda feels like a secret key combo power move in a video game : )

not highly readable though, especially when the condition has and or or

1 Like

yep! this all sounded familiar, that’s because i posted about it before: (grid) Code examples

I had a laugh writing this today

return (type(x) == 'number') and ((i > 1) and 0 or x) or (x[i] or x[i-1] or ((i > 1) and 0 or x[1]))

(it works!)