We all (the whole Renoise team) are new to Lua as well, have not used Lua before it got part of Renoise, so here are some general Tips & Tricks from my past months experience. Maye this helps someone to dig into all the Lua stuff.
Completely new to Lua?
Then start right here: Programming in Lua (introduction) or Lua Reference Manual (reference)
Looking for general Lua code snippets (how to do what in Lua)?
Then this is a good source: Lua user Wiki
Lua counts from 1:
But Renoise counts from 0 in many areas in its GUI. Instruments for example start at 0 in Renoise. To access Renoise instrument no. 0 in Lua, you’ll have to use renoise.song().instruments[1].
Tables:
Lua basically “just” is one of many imperative programming languages. If you have done things with C or Python or JavaScript, then you should quickly find your way. One special thing in Lua is the use of “tables” though. They are used for nearly every complex data types in Lua and are damn powerful, but also need some time to get used to. The meta table concept can be quite irritating as well first, but will make sense at some time. Don’t poke your head too much with meta table in the beginning, but just see/use tables as associative arrays, which can be used as maps, or number based arrays - just like you look at them and need them. This at least helped me dealing with them…
Numbers:
Lua only has one type of numbers, a double precision floating point value. Most of the time this just works. Sometimes, when doing arithmetic stuff with indices, remind taking the floor of the numbers -> my_octave_table[math.floor(note / 12)]
OO programming:
Lua has no classes or real built in OO support, but Renoises Lua impl has. See XRNX docs (classes.lua) for a small rundown
Mind the colon:
Especially when dealing with classes, the use of a dot vs. a colon can be quite confusing at first. Don’t worry, this will make sense at some point. A colon just means: pass whats’s left to it to the called function -> call a method:
some_object.some_function(some_object)
--- is the same as:
some_object:some_function()
-- or
renoise.app():show_error("Ouch!")
basically just syntactic sugar.
but properties need no colon. They are no functions:
some_object.some_property -- "member"
-- or
renoise.song().transport.bpm
Out of the box, Lua is extremely lightweight
… so we’ve added the rest to make it comfortable for us. Probably you have to add some more stuff to make it comfortable for you. A lot of also very low level stuff has been extended in Renoise to make do so. And all this is Renoise specific. You won’t find info on the web or user wiki about this, but only here: Renoise Lua docs