Provides a Lua interpreter for RIOT. More...
Provides a Lua interpreter for RIOT.
lua_run.h contains functions that make it easy to setup the interpreter and catch errors in a safe way. The functions from Lua's auxlib can still be used but then you must supply your own allocator and panic routines, load the builtin modules, etc.
To run a chunk of code stored in an array use:
The interpreter will not use the global heap for allocations, instead the user must supply a memory buffer.
To save some memory, some builtin modules can be left out.
modmask specifies which builtins to load. Note that if a builtin is not loaded by C code, then it cannot be loaded by Lua code later.
lua_riot_do_buffer takes care of setting up the Lua state, registering a panic handler that does not crash the application, configuring an allocator, loading libraries, etc.
To run a module as a script use
lua_riot_do_module. This is roughly equivalent to executing:
While generally efficient, the Lua interpreter was not really designed for constrained devices.
A basic interpreter session typically requires about 12kB RAM. The stack but it depends on the functions used (string handling tends to use more stack). It also depends on the platform.
There is currently no easy way to determine the stack needs other than trial and error. Future versions of the package will include instrumentation to this end.
lua_loadlib.c contains two loaders, one for modules written in Lua and another one for C extensions.
An index to the modules is stored in a table (there are two, one for each kind of module). The tables are indexed by the module name and must be sorted in ascending order by this key.
The definitions for the table types are in
lua_builtin.h. The loader module containes empty tables, defined as weak symbols so they can be ovewritten by the application. The variables that must be defined are:
Currently, these must be defined manually in the application code. In the future a script will generate this tables, populating them with both RIOT modules and the user modules.
The upstream Lua code is used without with the following modifications.
Modifications that affect the API:
A version of Lua with the patches applied is available at https://github.com/riot-appstore/lua. It can be downloaded and compiled in desktop computer, and the official test suite (https://www.lua.org/tests/) can then be run.
Alternatively, the patches in this package can be directly applied to the official distribution.
The updated makefile creates two standalone executables. Tests should be run with the debug executable.
The following features are missing and will be eventually added:
|Definitions for including built-in modules. |
|Lightweight C interface to the package loader. |
|Convenience functions for running Lua code. |