Lua
From RTEMSWiki
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 .
Contents |
Using Lua in RTEMS
For now, you can find the lua rtems files at http://gwu.webhop.net/~cssmith/GSOC/index.html
Calling Lua Functions in C
This operates exactly as it would in the host operating system.
#include <rtems/lua.h>
#include <rtems/lualib.h>
#include <rtems/lauxlib.h>
//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 <rtems/lua.h>
#include <rtems/lualib.h>
#include <rtems/lauxlib.h>
rtems_task Init(
rtems_task_argument ignored
)
{
_Lua_spawn_shell();
}
Spawning a RTEMS Shell
This creates a lua shell that allows for the execution of RTEMS commands.
#include <rtems/lua.h>
#include <rtems/lualib.h>
#include <rtems/lauxlib.h>
rtems_task Init(
rtems_task_argument ignored
)
{
_Lua_spawn_RTEMS_shell();
}
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 IMFS in RTEMS. Technically speaking, it should work agnostic to the underlying filesystem.
#include <rtems/lua.h>
#include <rtems/lualib.h>
#include <rtems/lauxlib.h>
rtems_task Init(
rtems_task_argument ignored
)
{
char** program_args = NULL;
/*
Setup arguments for the lua script, if any
*/
_Lua_run_script("path-to-program.lua", num_arguments, program_args);
}