|
|
|
Lua scripting languageIntroductionThis plugin is an interpreter for the Lua language. To quote from the Lua website ( http://www.lua.org), Lua is a “powerful, fast, lightweight, embeddable scripting language”. Select a .lua file in the File Browser to run it. For more information on programming in Lua, please see http://www.lua.org/manual/5.1/ and http://www.lua.org/pil/. There are a few exceptions/additions to the Lua support in Rockbox:
APIThe plugin API and some Rockbox C functions are directly exposed in therb table. Have a look at the source code for more info (like plugin.h and others).
To generate a /rb.txt file containing the keys of the rb object, you can run this code:
rb_obj = {}
for k, v in pairs(rb) do
local the_type = type(v)..'s'
if not rb_obj[the_type] then
rb_obj[the_type] = {}
end
table.insert(rb_obj[the_type], k)
end
local list = {}
for rb_type, rb_table in pairs(rb_obj) do
table.insert(list, string.format('* %s *', rb_type))
table.sort(rb_table)
for _, v in ipairs(rb_table) do
table.insert(list, v)
end
-- jump a line
table.insert(list, '')
end
local file = io.open('/rb.txt', "w+")
file:write(table.concat(list, '\n'))
file:close()
ExampleNote that the following example may not be up to date with the current version of the Lua plugin.
function sayhello(seconds)
local message = string.format("Hello from LUA for %d seconds", 5)
rb.splash(seconds, message)
end
-- Drawn an X on the screen
rb.lcd_clear_display()
rb.lcd_drawline(0, 0, rb.LCD_WIDTH, rb.LCD_HEIGHT)
rb.lcd_drawline(rb.LCD_WIDTH, 0, 0, rb.LCD_HEIGHT)
rb.lcd_update()
local seconds = 5
rb.sleep(5 * rb.HZ)
sayhello(seconds)
There's also a helloworld example script in SVN, see apps/plugins/helloworld.lua
CategoryPlugin: Lua interpreter [Sansa Clip r6 - 19 May 2010 - 01:42:27 - JustinHannigan
Copyright © by the contributing authors.
|