Eliot’s Tips and Tricks

The colon operator

Lua has a bit of syntactic sugar that allows one to have object orientated semantics. When you see:


It’s equivalent to:

O.blah(O, A)

i.e., call the function that is defined using the property ‘blah’ of object O and call it with the object O as the first parameter. Hopefully this screen snap of the Translator gives more clarity.

The example shows different ways we can invoke the Lua “sub” function which gives a substring. The sub function is defined in a special Lua table called ‘string’. Strings in Lua have a set of library functions which are very handy in manipulating Lua strings.

Functions are first class values in Lua, which means they can be assigned to variables, as you can see in the above code.

Its very easy to extend and define new extension string and node handling methods like this.


One Comment

  1. Pingback: Will You Share Your Code? - iNTERFACEWARE Inc.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.