These are my notes following my own review of the lua53 commit diff file:
-
The type
LUA_TTABLEnow has subtypesLUA_TTBLRAMandLUA_TTBLROF, with handling of these subtypes following the model adopted for strings being split into short and long subtypes. In general the variant coding for table subtypes is managed as low as possible in theltable.croutine. The newROTableis a cut down version ofTablewhich only includes the fields used in ROTables. -
The
getXXX(o)access macros replace(o)->XXXfield accesses for lu_byte fields in records that could be in constant (flash-based) memory. -
Functional support for dynamically loaded libraries removed from
lauxlib.c,ldo.c, andloadlib.c. -
On firmware builds all ROM modules and base functions are in the ROTable
ROM. The metatable of_Gis_Gand both__indexandROMpoint to this ROTable. Onluac.crossbuildsROMonly contains the ROM modules, with its meta__indexpointing to a separatebaselibROTable. This gives the fastest runtime performance in the case of firmware builds, butluac.crossbuilds can now be linked using standard linker defaults without any GCC, MSVC, etc. botches. In both cases all ROM tables and base functions are resolved through the global environment,_G. -
The new 5.3 string cache is replaced by a unified keycache which is used for both string and ROTable entry caching. The hash algo is now prime multiplier based to allow the use of a 2^n
KEYCACHE_Nnumber of rows. This avoid the need for an expensive modulus call during cache lookup. -
LCDstyle compressed line info is implemented as standard throughlcode.candldebug.c. -
The
mathlibrary is now pretty complete. -
ldblib.cnow contains a pretty completedebugimplementation (lessdebug.debugfor firmware builds as this would require take-over of stdin). -
Error reporting is not directed to
stderr, but instead the error string is posted as an upval to the C closure error reporter helper. This then calls the Lua error reporter as a separate task. -
lapi.candlauxlib.cimplement the API and interface changes listed below. -
lobject.cincludes a fast implementation ofluaO_ceillog2()using anasm("nsau %0, %1;")instruction which is a lot faster and avoids the need for a byte lookup table. -
The
lstate.cseed aglo is fixed rather than using randomisation. -
lua.cis a complete reimplementation more closely following the current NodeMCU 5.1lua.cimplementation. This is as a result of architectural drivers arising from its context and being initiated within the startup sequence of the IoT embedded runtime.- Processing is based on a single threaded event loop model. The Lua interactive mode processes input lines from a stdin pipe. This must be handled on a line by line basis, and other Lua tasks can interleave any multiline processing, so the standard doREPL approach doesn't work.
- Most OS services and environment processing are supported so much of the standard functionality is irrelevant and is stripped out for simplicity.
stderrandstdoutredirection aren't offered as an SDK service, so this is handled in the baselib print function and errors are sent to print.
-
luaconf.hhas been reworked to reflect the IoT implementation. -
locales support has been removed from
lvm.c. Ditto caching of last closure in Proto records. -
ltest.chas its Memcontrol structure extended to include a double linked list. This allows me to set H/W watchpoints on dangling blocks in host gdb to work out what blocks aren't being GCed. -
The test suite has disabled tests which aren't appropriate (e.g. dynamic loading). Even so I need to do a second pass to make sure that I haven't disabled valid, but failing tests.
-
lua_gc has an extra parameter option
LUA_GCSETMEMLIMITto set the ECG memory limit. -
lua_pushrotable,
void lua_pushrotable(lua_State *L, const ROTable *p)can be used to push a ROtable onto the Lua Stack. -
lua_createrotable,
void lua_createrotable(lua_State *L, ROTable *t, const ROTable_entry *e, ROTable *mt)is used the create a ROTable header for the specifiedROTable_entryvector. This is only required for linker-marshalled entry vectors as the ROTable is normally generated by theLROTmacro declarations. -
lua_getstate,
lua_State *lua_getstate(void). Returns the L0 state. Used in C modules CBs to call the Lua VM. -
lua_getcache,
KeyCache *lua_getcache(int cacheline)used internally to access the string and table key cache. -
lua_getstrings,
int lua_getstrings(lua_State *L, int opt)returns a table of strings in the specified string table (0 = RAM, 1 = LFS ROM) -
lua_freeheap,
int lua_freeheap(void)returns the amount of free heap. -
luaL_rometatable,
int luaL_rometatable(lua_State *L, const char* tname, const ROTable *p)shorthand forlua_pushrotable()andluaL_newmetatable(); used to associate a ROTable metatable with the entrytnamein the Lua registry. -
luaL_pcallx,
int luaL_pcallx(lua_State *L, int narg, int nres). This is designed as a plug-in replacement forlua_call(L, n, m)used to call Lua CBs in the module event routines. Unlikelua_call(), this does a protected call and returns a call status. In the case of the called routine throwing an error, instead of the VM panicing and restarting, the error handler collects a full traceback and posts a separate task with this error string as an upval. The error reporter then calls the users reporter function, which can then print or log the error, and continue or restart as required. -
luaL_posttask,
int luaL_posttask(lua_State* L, int prio)Post the task popped from the stack at the specified priority.
The build will compile in the Lua Test suite if LUA_ENABLE_TEST and LUA_USE_HOST are defined -- that is for test luac.cross builds only.
-
lgc.cto honour thelua_gc()optionLUA_GCSETMEMLIMIT -
Replace all
lua_call()uses in theapp/modulesfiles with theluaL_pcallx()variant. -
Support loading both standard (format=0) and NodeMCU (format=10) dump formats. Also use the head to determin the int and float sizes.
-
LFS implementation
-
Write up a howto on using the
LROTmacros.
debug.getstrings()raises aE:M 32784 not enough memoryerror.