Codea Tutorials: Tutorial 25 - A Lua Primer for Codea

Every year around Christmas I notice a surge of activity on the forums as folks get their new iDevices and download Codea. This has prompted a number of common questions on my tutorials, so i thought I would try and fill in some of the gaps with a quick primer on Lua (particularly in the Codea context).

As usual comments and suggestions are very welcome. I plan on covering the Lua libraries in a separate tutorial.

The tutorial is available here: http://codeatuts.blogspot.com/2013/01/tutorial-25-lua-primer-for-codea-part-1.html?spref=tw

Great tuto! Your style is so clear… I think this tuto is really useful to beginners.
Some possible precisions:

  • defined variables are accessible only after the line they are declared.
  • You can’t concatenate a boolean. When you need to, use tostring() function.
  • comparison operators (== ~= < > <= >=) do not coerce their arguments. When you need to use tonumber() function.
  • you can check the type of myvar by type(myvar).
  • userdata: all special objects defined by Codea api are of type ‘userdata’.
  • Try converting the Ship class so that it uses a global variable points instead of self.points.
  • i think it wouldnt harm to say:
    function Ship:hit( damage ) is equivalent to function Ship.hit( self, damage ).
    ship:hit( 20 ) is equivalent to ship.hit( ship, 20 ).
    This helps to understand the error message when you type ship.hit by accident.

Thanks @Jmv38 - all good comments. I will update the tute accordingly on the weekend.