lua by the eyes of a perl developer - github...

201
Lua by the eyes of a Perl developer Ilya Chesnokov

Upload: others

Post on 23-Jul-2020

27 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua by the eyes of a Perl developer

Ilya Chesnokov

Page 2: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Prehistory

Page 3: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

I have a friend

Page 4: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 5: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Once upon a time he asked me to write a trading bot...

Page 6: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 7: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

...in Lua

Page 8: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 9: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

That time I only knew that Lua has a nice community

:-)

Page 10: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is...

Fast

Page 11: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is...

Fast

Portable

Page 12: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is...

Fast

Portable

Embeddable

Page 13: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is...

Fast

Portable

Embeddable

Small

Page 14: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is...

Fast

Portable

Embeddable

Powerful (but simple)

Small

Page 15: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is...

Fast

Portable

Embeddable

Powerful (but simple)

Small

Free

Page 16: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Can be learned in virtually no time!

Page 17: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Sounds nice, right?

Page 18: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Let's learn it!

Page 19: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 20: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

The Book

Page 21: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 22: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 23: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

~400 in Russian and English

Page 24: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua

Page 25: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Programming in Lua (the book)

• 1st edition - Lua 5.0

• 2nd edition - Lua 5.1

• 3nd edition - Lua 5.2

• 4th edition - Lua 5.3

Page 26: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

What version to learn / use?

Page 27: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua 5.x versions

• Lua 5.0 (Apr 2003)

• Lua 5.1 (Feb 2006)

• Lua 5.2 (Dec 2011)

• Lua 5.3 (Jan 2015)

Page 28: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

LuaJIT (5.1-compatible)

Page 29: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

LuaJIT primary changes• JIT compiler (overall much faster than Lua 5.1)

• With controllable behavior

• Bit library

• FFI library

• C API extensions

Page 30: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Perl 6 - the ideal from the future

Page 31: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Perl 6 - the ideal from the future

LuaJIT - the ideal from the past

Page 32: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua 5.2 primary changes

• goto statement

• New library for bitwise operations

• "Official" support for table finalizers

• _ENV variable

Page 33: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua 5.3 primary changes

• Integers

• Bitwise operators

• Basic UTF-8 support

• Functions for packing and unpacking values

Page 34: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is NOT backward compatible!

Page 35: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Always check your target environment!

Page 36: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Getting the interpreter

Page 37: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Requirements: Lua + LuaRocks

Page 38: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

*nix: use package manager

Page 39: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

MacOS X: homebrew

Page 40: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Windows: it's complicated

Page 41: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Official site (manual installation)• lua.org - Lua interpreter

• luarocks.org - LuaRocks package manager

• "make" command: cmake.org

• C compiler: MSVC, MinGW or TDM-GCC

• Have to adjust linker configuration for MSVCRT or MinGW

• Conflicts with Strawberry Perl utils in your path (or I failed to configure)

Page 42: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Automated installation

• luadist.org - "batteries included" distribution

• Good documentation of installation process for Windows users

• Fails to compile / install some versions of Lua

Page 43: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Automated installation

• LuaForWindows - another "batteries included" environment

• Lua 5.1 only

Page 44: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Automated installation

• hererocks - Python script for installing Lua(JIT) and LuaRocks

• Requires Python

• Suitable for other OS'es

Page 45: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

LuaRocks ships Lua 5.1

Page 46: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

LuaRocks ships Lua 5.1 (you still need make & C)

Page 47: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Useful tools

Page 48: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Editors

• Zero Brain Studio - for Windows

• Only supports UTF-8 text

Page 49: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Editors

• Zero Brain Studio - for Windows

• Only supports UTF-8 text

• Many others

• I ended up with Vim + Lua plugins

Page 50: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

LuaFormatter simplistic analog

of PerlTidy for Lua

Page 51: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

luacheck static analyser / linter

Page 52: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

luacheck• Detects

• undefined global variables

• unused variables and values

• unreachable code

• ...etc

Page 53: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

luacheck

• Similar to perlcritic

• "Must have" in your Lua test suite

Page 54: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua syntax

Page 55: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Blocks

• Block - list of statements, executed sequentially

• Explicitly delimited block:

do block end

Page 56: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Chunks• Unit of compilation of Lua

• can be precompiled into binary form and stored

• Syntactically it's a block

• Semantically it's an anonymous function

• can have arguments

• can return values

Page 57: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Variables: global and local

a = 1 -- global variable, visible everywhere, -- slow access

Page 58: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Variables: global and local

a = 1 -- global variable, visible everywhere, -- slow access

local x -- local variable, -- only visible in the current block, -- fast access

Page 59: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Strings'abcd' -- single line only, no interpolation

"ab\ncd" -- single line only, interpolates -- escape sequences (\n, \t, etc)

[[abcd efgh]] -- multiline, no interpolation

[=[abcd efgh]=] -- same thing

Page 60: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Strings'abcd' -- single line only, no interpolation

"ab\ncd" -- single line only, interpolates -- escape sequences (\n, \t, etc)

[[abcd efgh]] -- multiline, no interpolation

[=[abcd efgh]=] -- same thing

Page 61: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Strings'abcd' -- single line only, no interpolation

"ab\ncd" -- single line only, interpolates -- escape sequences (\n, \t, etc)

[[abcd efgh]] -- multiline, no interpolation

[=[abcd efgh]=] -- same thing

Page 62: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Strings'abcd' -- single line only, no interpolation

"ab\ncd" -- single line only, interpolates -- escape sequences (\n, \t, etc)

[[abcd efgh]] -- multiline, no interpolation

[=[abcd efgh]=] -- same thing

Page 63: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Strings'abcd' -- single line only, no interpolation

"ab\ncd" -- single line only, interpolates -- escape sequences (\n, \t, etc)

[[abcd efgh]] -- multiline, no interpolation

[=[abcd efgh]=] -- same thing

Page 64: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

String concatenation: ..

'abcd' .. '123' == 'abcd123'

Page 65: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Comments

-- This is a one-line comment

--[[ This is a multiline comment ]]

--[==[ This is also a multiline comment ]==]

Page 66: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Comments

-- This is a one-line comment

--[[ This is a multiline comment ]]

--[==[ This is also a multiline comment ]==]

Page 67: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Comments

-- This is a one-line comment

--[[ This is a multiline comment ]]

--[==[ This is also a multiline comment ]==]

Page 68: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Numbers

1.0 -- double precision floating point number

1 -- integer (since Lua 5.3)

Page 69: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Numbers

1.0 -- double precision floating point number

1 -- integer (since Lua 5.3)

Page 70: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Numbers

1.0 -- double precision floating point number

1 -- integer (since Lua 5.3)

Page 71: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Comparison operators

x == y -- x is equal to y

x ~= y -- x is not equal to y

Page 72: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Nil

Nothing, the absence of any useful value

Page 73: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Booleans

true -- true

false -- false

nil -- false

'' -- true

0 -- also true

Page 74: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Functionsfunction hello(name) print('Hello, ' .. name) end

Page 75: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Functionsfunction hello(name) print('Hello, ' .. name) end

local hello = function(name) print('Hello, ' .. name) end

Page 76: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Functionsfunction hello(name) print('Hello, ' .. name) end

local hello = function(name) print('Hello, ' .. name) end

local function hello(name) print('Hello, ' .. name) end

Page 77: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Tables

• The sole data-structuring mechanism in Lua

• Represents ordinary arrays, hashes and other data structures

• Values of fields can be anything besides nil

Page 78: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Tables

-- ordinary array local array = {'foo', 'bar', 3, 7, 'baz', 9}

Page 79: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Tables

-- ordinary array local array = {'foo', 'bar', 3, 7, 'baz', 9}

-- associative array local hash = { ['foo'] = 'bar', [1] = 'one', baz = 9, }

Page 80: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Accessing table fields

local array = { foo = 'bar', [500] = 'baz' }

print(array.foo) -- bar print(array[500]) -- baz

Page 81: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Interesting facts

• Array indexing starts with 1

Page 82: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Interesting facts

• Array indexing starts with 1

• Lua implements "sparse" arrays

Page 83: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Sparse arrays

# Perl array my @values; $values[999_999] = 1; # 1M elements, a lot of RAM

-- Lua array local values = {} values[999999] = 1 -- 1 element, tiny piece of RAM

Page 84: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Array length operator: "#"

Page 85: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Array length operator: "#" (borrowed from Perl's "$#" ???)

Page 86: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Array length operator: "#"

local chars = { 'a', 'b' } print(#chars) -- 2

Page 87: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Array length operator: "#"

local chars = { 'a', 'b' } print(#chars) -- 2

chars[4] = 'd' -- chars: { 'a', 'b', nil, 'd' } print(#chars) -- Not determined: 2 or 4

Page 88: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Metatables and metamethods

Page 89: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Metatables and metamethods

local MyMetaTable = { -- ...metamethods declaration... }

local my_table = {} setmetatable( {}, MyMetaTable )

Page 90: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Metamethods• Arithmetic: __add, __sub, __mul, __div, ...

• Comparison: __eq, __lt, __le

• String: __concat

• Array: __len

• Function: __call

• Table: __index, __newindex

• Garbage collection: __gc

Page 91: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Metamethods• Arithmetic: __add, __sub, __mul, __div, ...

• Comparison: __eq, __lt, __le

• String: __concat, __tostring

• Array: __len

• Function: __call

• Table: __index, __newindex

• Garbage collection: __gc

Page 92: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Metamethods• Arithmetic: __add, __sub, __mul, __div, ...

• Comparison: __eq, __lt, __le

• String: __concat, __tostring

• Array: __len

• Function: __call

• Table: __index, __newindex

• Garbage collection: __gc

Page 93: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Metamethods• Arithmetic: __add, __sub, __mul, __div, ...

• Comparison: __eq, __lt, __le

• String: __concat, __tostring

• Array: __len

• Function: __call

• Table: __index, __newindex

• Garbage collection: __gc

Page 94: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Tables and environment

• _ENV - table with environment specific for the chunk (defaults to _G)

• _G - table with global environment

• Contains global variables and functions

• Modules are typically implemented as tables

Page 95: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua syntax difficulties

Page 96: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

No explicit ternary operator

Make it up:

result = expr and do_if_true() or do_if_false()

Page 97: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Poor regular expressions

• Can install PCRE library

• Or install and learn LPeg - Parsing Expression Grammars for Lua

• (Both need C compiler)

Page 98: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

"return" always goes last

Use:

do return end

Page 99: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

func '...' or func { ... } only

print "hi" -- OK dump { a = 1, b = 2 } -- OK

print name -- NOT OK

Page 100: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua syntax benefits

• It has a BNF

• Some constructs are optional: semicolons, parens

• Easy to learn due to its simplicity

Page 101: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Modules

Page 102: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Writing a module

Page 103: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.luaPoint = {}

function Point.new() return { x = 0, y = 0 } end

function Point.move(point, dx, dy) point.x = point.x + dx point.y = point.y + dy end

return Point

Page 104: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {}

function Point.new() return { x = 0, y = 0 } end

function Point.move(point, dx, dy) point.x = point.x + dx point.y = point.y + dy end

return Point

Page 105: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal M = {}

function M.new() return { x = 0, y = 0 } end

function M.move(point, dx, dy) point.x = point.x + dx point.y = point.y + dy end

return M

Page 106: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.luareturn {

new = function() return { x = 0, y = 0 } end,

move = function(point, dx, dy) point.x = point.x + dx point.y = point.y + dy end

}

Page 107: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Loading a module

Page 108: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

require(modname)

• Checks package.loaded table to determine if module is already loaded

• Loads the given module

• By default, uses paths from

• package.path - Lua modules

• package.cpath - compiled C modules for Lua

Page 109: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path

• Is taken from LUA_PATH_5_3, LUA_PATH, or default from luaconf.h

• Typically something like:

• /usr/share/lua/5.3/?.lua;/usr/share/lua/5.3/?/init.lua;./?.lua

Page 110: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path = '/usr/share/lua/5.3/?.lua;' .. '/usr/share/lua/5.3/?/init.lua;' .. './?.lua'

Page 111: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path = '/usr/share/lua/5.3/?.lua;' .. '/usr/share/lua/5.3/?/init.lua;' .. './?.lua'

Page 112: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path = '/usr/share/lua/5.3/?.lua;' .. '/usr/share/lua/5.3/?/init.lua;' .. './?.lua'

Page 113: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path = '/usr/share/lua/5.3/?.lua;' .. '/usr/share/lua/5.3/?/init.lua;' .. './?.lua'

Page 114: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path

package.path = './?.lua'

require('SomeModule') -- ./SomeModule.lua

require('My.Nice.Module') -- ./My/Nice/Module.lua

Page 115: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path

package.path = './?.lua'

require('SomeModule') -- ./SomeModule.lua

require('My.Nice.Module') -- ./My/Nice/Module.lua

Page 116: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

package.path

package.path = './?.lua'

require('SomeModule') -- ./SomeModule.lua

require('My.Nice.Module') -- ./My/Nice/Module.lua

Page 117: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

OOP in Lua

Page 118: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is not an OO language...

Page 119: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua is not an OO language... ...but tables are for the rescue!

Page 120: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

__index metamethod

• Happens when table[key] is queried for nonexistent key

• Value can be:

• a function

• or a table where key is looked up

Page 121: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

__index metamethodlocal MyClass = { __index = { x = 'foo', y = 10, } }

local obj = setmetatable( {}, MyClass ) print( obj.x ) -- 'foo'

Page 122: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {}

function Point.new() return { x = 0, y = 0 } end

function Point.move(point, dx, dy) point.x = point.x + dx point.y = point.y + dy end

return Point

Page 123: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {} Point.__index = Point

function Point:new() return setmetatable({ x = 0, y = 0 }, Point) end

function Point:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end

return Point

Page 124: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {} Point.__index = Point

function Point:new() return setmetatable({ x = 0, y = 0 }, Point) end

function Point:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end

return Point

Page 125: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {} Point.__index = Point

function Point:new() return setmetatable({ x = 0, y = 0 }, Point) end

function Point:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end

return Point

Page 126: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {} Point.__index = Point

function Point:new() return setmetatable({ x = 0, y = 0 }, Point) end

function Point:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end

return Point

Page 127: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Point.lualocal Point = {} Point.__index = Point

function Point:new() return setmetatable({ x = 0, y = 0 }, Point) end

function Point:move(dx, dy) self.x = self.x + dx self.y = self.y + dy end

return Point

Page 128: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

use_point.lualocal Point = require('Point')

local p1 = Point:new() print(p1.x, p1.y) -- 0, 0

p1:move(10, 20) print(p1.x, p1.y) -- 10, 20

local p2 = Point:new() print(p2.x, p2.y) -- 0, 0

Page 129: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

use_point.lualocal Point = require('Point')

local p1 = Point:new() print(p1.x, p1.y) -- 0, 0

p1:move(10, 20) print(p1.x, p1.y) -- 10, 20

local p2 = Point:new() print(p2.x, p2.y) -- 0, 0

Page 130: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

use_point.lualocal Point = require('Point')

local p1 = Point:new() print(p1.x, p1.y) -- 0, 0

p1:move(10, 20) print(p1.x, p1.y) -- 10, 20

local p2 = Point:new() print(p2.x, p2.y) -- 0, 0

Page 131: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

use_point.lualocal Point = require('Point')

local p1 = Point:new() print(p1.x, p1.y) -- 0, 0

p1:move(10, 20) print(p1.x, p1.y) -- 10, 20

local p2 = Point:new() print(p2.x, p2.y) -- 0, 0

Page 132: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

use_point.lualocal Point = require('Point')

local p1 = Point:new() print(p1.x, p1.y) -- 0, 0

p1:move(10, 20) print(p1.x, p1.y) -- 10, 20

local p2 = Point:new() print(p2.x, p2.y) -- 0, 0

Page 133: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Common OOP techniques

• Inheritance: use another class as a metatable

• Multiple inheritance: use function as the value of __index

• Private fields / methods: use local variables / functions

Page 134: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Destructors

Page 135: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

sub foo { say 'original sub ' } foo(); # original sub

{ my $token = Sub::Override->new( foo => sub { say 'overridden sub' }, ); foo(); # overridden sub }

# $token goes out of scope... foo(); # original sub

Page 136: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

sub foo { say 'original sub ' } foo(); # original sub

{ my $token = Sub::Override->new( foo => sub { say 'overridden sub' }, ); foo(); # overridden sub }

# $token goes out of scope... foo(); # original sub

Page 137: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

sub foo { say 'original sub ' } foo(); # original sub

{ my $token = Sub::Override->new( foo => sub { say 'overridden sub' }, ); foo(); # overridden sub }

# $token goes out of scope... foo(); # original sub

Page 138: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

sub foo { say 'original sub ' } foo(); # original sub

{ my $token = Sub::Override->new( foo => sub { say 'overridden sub' }, ); foo(); # overridden sub }

# $token goes out of scope... foo(); # original sub

Page 139: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

__gc metamethod

It is called before the actual garbage collection happens

Page 140: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

function foo() print('original sub') end foo() -- original sub

do local token = SubOverride:new({ foo = function() print('overridden sub') end }) foo() -- overridden sub end

foo() -- overridden sub (WTH?!)

Page 141: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

function foo() print('original sub') end foo() -- original sub

do local token = SubOverride:new({ foo = function() print('overridden sub') end }) foo() -- overridden sub end

foo() -- overridden sub (WTH?!)

Page 142: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

function foo() print('original sub') end foo() -- original sub

do local token = SubOverride:new({ foo = function() print('overridden sub') end }) foo() -- overridden sub end

foo() -- overridden sub (WTH?!)

Page 143: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

function foo() print('original sub') end foo() -- original sub

do local token = SubOverride:new({ foo = function() print('overridden sub') end }) foo() -- overridden sub end

foo() -- overridden sub (WTH?!)

Page 144: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

The execution of each finaliser may occur at any point

during the execution of the regular code

Page 145: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Destructors are complicated!

Page 146: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

OOP frameworks

Page 147: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

OOP frameworks

• lua-Coat - A port of Perl's Coat, Moose-like OOP framework

Page 148: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

OOP frameworks

• lua-Coat - A port of Perl's Coat, Moose-like OOP framework

• 30log - Single-file module, full-featured OO in 30 lines of code

Page 149: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

OOP frameworks

• lua-Coat - A port of Perl's Coat, Moose-like OOP framework

• 30log - Single-file module, full-featured OO in 30 lines of code

• MiddleClass - OO module with inheritance, mixins (roles), class variables, etc

Page 150: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

And many more

lua-users.org/wiki/ObjectOrientedProgramming

Page 151: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Standard library

Page 152: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Standard library• Basic functions

• coroutine

• package

• string

• utf8

• table

• math

• io

• os

• debug

Page 153: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Standard library in Perl: ~200 modules in v5.26.1

Page 154: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Need more modules?

Page 155: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

LuaRocks.org

Page 156: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Unofficial Lua module repository

Page 157: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Much fewer modules than on CPAN :-((

Page 158: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 159: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 160: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Google for "Lua find file"

• Links to various game engine APIs

• Suggestions to write it manually

• And finally, a link to lua-users wiki page with source code of directory iterator function!!!

Page 161: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Why wasn't it released as a Luarocks module?!

Page 162: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Other sources of reusable code• Lua users wiki: lua-users.org

• Github & friends

• "All in one" library collections:

• Independent collections: Penlight

• Product- or framework-based: OpenResty, Tarantool, Corona, Love2D, ...

Page 163: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Copy & paste is encouraged (implicitly)

Page 164: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Module names are incosistent

• luarocks install lua-TestMore <-> require 'Test.More'

• luarocks install luafilesystem <-> require 'lfs'

Page 165: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Documentation

Page 166: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

No POD (or any replacement)

Page 167: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

luarocks doc <package>• "Tries to load the documentation using a series of

heuristic"

• Looks for project homepage using rock specification

• Looks for file named like:

/ (index|readme|manual) ( [.] (html?|txt|md|textile)? ) /xi

Page 168: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Documentation is not displayed at luarocks.org

Page 169: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

You have to host docs separately

• github.com & friends

• Documentation platforms: readme.io, readthedocs.io, etc

• Maintainers' websites (often broken)

Page 170: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Unit testing

Page 171: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Place of testing in Lua infrastructure

Page 172: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Tests for Lua interpreter

• Don't run when you install it from source

• They are not even in the same repository

Page 173: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Tests during module installation

• luarocks doesn't try to run them

• You're not encouraged to write tests

Page 174: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

"Testing" section in PiL book

• Is absent

• (Also, it doesn't mention luarocks)

Page 175: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

lua-users.org/wiki/UnitTesting

Page 176: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Lua unit testing frameworks

• Busted - BDD unit testing library, produces different outputs (TAP included)

• LuaUnit (Lua 5.2 and below only)

• lua-TestMore (yes, Perl-style testing!)

Page 177: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

I wrote my own

Page 178: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

I wrote my own github.com/ichesnokov/lua-TestClass

Page 179: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

I wrote my own github.com/ichesnokov/lua-TestClass

#quickndirty #WIP #usablethough

Page 180: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Community

Page 181: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Communication methods

• lua-l mailing list - primary way of communication

• Several IRC / Telegram channels

• Local user groups / meetups

Source: lua.org/community.html

Page 182: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

User groups

• 2-3 in Europe - London, Moscow, Paris (?)

• 2 in the US

Source: lua-users.org/wiki/UserGroups

Page 183: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Conferences / meetups• Local meet-ups

• Lua devroom at FOSDEM (sometimes)

• Lua Conference - typically in Portuguese

• Lua Workshop - yearly event, typically in English

• Next one: 7-8 Sep 2018 in Kaunas, Lithuania

Page 184: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Talks at general-purpose or gamedev conferences

Page 185: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Communities around products that support Lua

Page 186: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

There are many of them!

Page 187: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Community overall: Friendly, supportive

and lots of fun

Page 188: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Conclusions

Page 189: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Do not treat Lua as a general-purpose language!

Page 190: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

"Scripting" and "embeddable" words are not just a sound!

Page 191: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Help Lua!

• Learn it

• Release a module or two (or three) to LuaRocks

• maybe port some Perl library

• Come to Lua conference/meetup, make a talk

Page 192: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Let Lua help you!

Page 193: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Let Lua help you! Use it in your project maybe?

Page 194: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Have fun!

Page 195: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

...

Page 196: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

And yeah, I created a bot!

Page 197: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

And yeah, I created a bot! It even (mostly) worked!

Page 198: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)
Page 199: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

(not really)

Page 200: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Questions?

Page 201: Lua by the eyes of a Perl developer - GitHub Pagesichesnokov.github.io/talks/tpcig2018/lua-by-the-eyes-of-a-perl... · Lua 5.x versions •Lua 5.0 (Apr 2003) •Lua 5.1 (Feb 2006)

Thank you!