Last active
September 1, 2022 22:37
-
-
Save tbrunz/9a1b278b7b2ec0b2af83148cda33a65c to your computer and use it in GitHub Desktop.
What makes Lua a cool programming language?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What makes Lua a cool programming language? | |
* You can mix imperative, OOP, or functional programming styles. | |
* Can execute as a file, interactively in a REPL[1], or be embedded. | |
* Highly portable, extensible, and has an excellent C API[2]. | |
* Compact and headless; you add packages to extend capabilities. | |
* Supports packages and modules[3]; package manager is 'LuaRocks'. | |
* Dynamic typing[4] & dynamic structures; easily polymorphic. | |
* Lua has only 8 data types[5]; all are first-class values. | |
* Strings are 8-bit clean, conv to/from byte arrays, support unicode. | |
* Strings have pattern-matching with captures (very regex-like). | |
* Multiple return values! Allows constructs such as x,y = y,x. | |
* Variadic parameters/return values, easily defaulted & looped over. | |
* Tables! Can be created as maps, arrays[6], or both simultaneously. | |
* Metatables! Can define default values & behaviors for tables[7]. | |
* Lua OOP is prototype-based; syntactic sugar includes 'self'. | |
* Reflective global environment; can be manipulated at run-time. | |
* All functions are unnamed full lexical closures (lambdas). | |
* Loops can be controlled via user-defined iterator functions. | |
* Proper tail call elimination; allows deep recursion. | |
* Coroutines (co-operative multitasking); can be used for iterators. | |
* Automatic memory management (GC), 'weak' tables, finalizers. | |
* Block comments can encapsulate code that includes comments. | |
* You can have apps in other languages call out to Lua code. | |
* You can have Lua apps call out to code in other languages. | |
* 'luajit' (based on Lua 5.1) is 10x faster than the interpreter. | |
[1] REPL = "Read, Evaluate, Print, Loop" (a fancy acronym alternative to 'CLI'). | |
[2] Lua's C API is based on a stack used to exchange parameters & return values. | |
[3] Packages were introduced to Lua in version 5.1 (the current version is 5.4). | |
[4] Variables aren't typed; variable values are. The 'type()' function will | |
reflect the type of an expression or the value that a variable holds. | |
[5] Lua's built-in data types are nil, boolean, number, string, table, function, | |
thread, userdata. All numbers in Lua are IEEE-754 doubles, which can hold | |
exact integers up to 2^53. (There is a library for I32 bit manipulation.) | |
[6] Arrays in Lua (as with Julia, R, Smalltalk, Fortran, et al) are 1-based. | |
Tables allow construction of matrices, linked lists, sets & bags, etc. | |
[7] Metatables unlock all sorts of capabilities, such as table typing, defaulted | |
field values, read-only tables, reference logging/tracing, type-specific | |
methods, single- and multiple-inheritance, etc. Each data type can have a | |
metatable; a metatable for 'string' is pre-defined. Individual tables and | |
userdata items can have their own metatables. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment