Cours the Novelties of Lua, tutoriel & guide de travaux pratiques en pdf.
a myriad of small improvements
light C functions
emergency garbage collection
ephemeron tables
bitlib
yieldable pcall/metamethods
generational collector
goto statement
new ENV scheme
Light C Functions
C functions without upvalues are stored as simple values, without memory allocation
Light C Functions
only possible due to change in environments new internal type
-concept of type variant
-opens the door for other variants (e.g., non-collectable strings) implemented as a single pointer to function eliminate the need for lua_cpcall saves a few bytes of memory standard libraries create almost 200 light functions portable way to represent other C functions in Lua
-C standard allows conversions between dierent types of C functions
Emergency Garbage Collection
when memory allocation fails, collector does a complete collection cycle and then tries again seems obvious, but implementation is tricky Lua allocates memory in lots of places everything must be properly anchored before any allocation nalizers (__gc metamethods) postponed during emergency collection
Ephemeron Tables
break cycles in weak tables where values refer to their keys
typical example:
local mem = setmetatable({}, {__mode = "k"}) function newKfunc (o) local f = mem[o] if not f then f = function () return o end mem[o] = f end return f end
despite weak keys, entries may never be removed from mem.
-each key has a reference to it in its value
-values are not (and cannot be) weak ephemeron table: value is only alive when its key is alive implementation has a quadratic worst case
-but only for weird scenarios
bitlib
library with bitwise operations a most-wanted feature in Lua
far from straightforward
-main problem: numbers in Lua are double
-in particular, -1 is dierent from 0x some dierences from older libraries
-signed unsigned results
-over ows in shift/rotate
-negative shifts future problem: 64-bit operations
Yieldable pcall/metamethods
programs in Lua 5.2 can yield inside a pcall, a metamethod, or a for iterator another most-wanted feature planned to be the main change for Lua 5.2 basic idea from Mike Pall
-long-jump over C functions and call them again when resuming
-lua_pcall lua_pcallk allows function to signalize whether it can yield at each point change from original implementation: resume calls a continuation function
-instead of the same function that was interrupted
-continuation passed as argument to lua_pcallk metamethods resume through extra code to complete execution of interrupted opcodes
……..
Document The Novelties of Lua 5.2 (209 KO) (Cours PDF)