A very simple Lua interpreter + shell implementation in C++, as a
demo. It currently depends on Lua version 5.4
and GNU’s readline
library.
The interpreter loads the file located at $LUASHELL_CONFFILE
if
defined, or $XDG_CONFIG_HOME/luashell/config.lua
, if it exists, before
execution of any script or the shell’s prompt.
The interpreter globals are:
name | default value | description | types |
---|---|---|---|
CONFFILE | $XDG_CONFIG_HOME/luashell/config.lua | config file path | |
HISTFILE | $XDG_DATA_HOME/luashell/history | history file path | str, str f() |
PROMPT | >>> | prompt string | str, str f() |
BANNER | banner string | str, str f() |
Each of these globals are first fetched from the environment, where
their name is prefixed with LUASHELL_
(example:
LUASHELL_CONFFILE
). The default values are used if they are not
defined or empty.
The configuration file is loaded after fetching the environment
values, thus they can be redefined in it using the name listed in the
table above. Note redefinition of globals with an empty types
value in
the table do not matter at this stage (see the next section).
Finally, they can be redefined in the shell or the script itself, using the names in the table, but the given values won’t persist between sessions.
The types
column contains a comma-separated list of types
that the shell expects to find in the variable. If the type is of the
form returnType f(argType, argType, ...)
, the value may be a Lua
function of the described prototype (the name f
does not matter).
If no types are defined, the variable expects a string and its redefinition is only considered if it is done in the environment. The value is still accessible and modifiable from the shell/script/config file, but this won’t affect the interpreter at all.
For a list of available types (applicable to returnType
and argType
),
see the types used by Lua. Their name may be shortened in the table,
for example str
for string
. The following types are additional to this
list:
type | Lua type | description |
---|---|---|
int | number | a number that will be truncated |