= Lua =
Lua is an open source scripting language whose main purpose is being embedded in C applications. More can be learned by viewing their website at http://www.lua.org .
= Using Lua in RTEMS =
The Lua library will be included in the RTEMS distribution shortly. Until then, you can find them at http://www.coderedonly.com/GSOC/lua/index.html
= Calling Lua Functions in C =
This operates exactly as it would in the host operating system.
#include
#include
#include
//This is the reference to the lua interpreter
lua_State* L;
rtems_task Init(
rtems_task_argument ignored
)
{
L = lua_open();
luaL_openlibs(L);
//Test of basic lua functionality
lua_getglobal(L, "print");
lua_pushstring(L, "Hello, Lua!");
lua_call(L, 1, 0);
lua_close(L);
}
= Spawning a Lua Shell =
_Lua_Main(int argc, char** argv) is a standard C main function. Lua spawns a shell whenever
it is called without a script as an argument. Therefore, the end user can spawn a lua shell by modifying the
code below:
#include
#include
#include
rtems_task Init(
rtems_task_argument ignored
)
{
char** program = calloc (2, sizeof(char*));
//program[0] is the string name of the executing executable.
program[0] = "''program.exe''";
_Lua_main(1, program);
}
= Executing a Standalone Lua Script =
Since _Lua_Main(int argc, char** argv) is a standard C main function, executing lua scripts are
as simple as notifying the interpreter where the file is located.
''Note:'' This currently has only been tested with the [wiki:File_Systems#IMFS_File_System_ IMFS] in RTEMS. Technically speaking, it should work
agnostic to the underlying filesystem.
#include
#include
#include
rtems_task Init(
rtems_task_argument ignored
)
{
char** program = calloc (2, sizeof(char*));
//program[0] is the string name of the executing executable.
program[0] = "program.exe";
//program[1] is the path to the lua script to execute
program[1] = "lua_script.lua";
_Lua_main(2, program);
}