Posts

Showing posts from December, 2015

Learning Lua

Image
Learning Lua Table of Contents Background Tables metatable functions coroutine Lua as Object-oriented programming 1 Background Lua as an embedded language was popular in the game industry and also in any embedded scenario. I tried to wrote a Lua module for Nginx, which already has a ported Lua environment inside. And since this is my first time to get familiar with Lua, and to enjoy its simplicity. My learning materials were no special, but its official document . I wrote my notes down in order for future review. 2 Tables To understand table is to understand Lua, or in another word, Lua's syntax was nothing but just tables, no more. Tables in Lua is in similar with the dictionary in Python, in my view. a = {} a.x = 1 a[ 'x' ] = 1 2.1 metatable Lua's metatable is similar to magic methods in python. 3 functions Lua as a functional programming language, because the function is also the first-class variable. That'