release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Search | Go
Wiki > Main > PluginIndex > PluginLua (r6)

Lua scripting language

Introduction

This 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:
  • No floating point support.
    • The number type in Lua is usually float, however in the Rockbox implementation it is integer.
  • Non-supported libraries.
    • The coroutine, debug and math libraries are not supported.
  • Partially-supported libraries.
    • The os and package libraries are only partially supported.
  • Additional libraries.
Documentation of the API is still a work in progress, and the API itself is not finalised. For the latest information, see PluginLua?.

Note: Please note that if a script does not provide a way to exit, then the only way to exit will be to reset the player.

API

The plugin API and some Rockbox C functions are directly exposed in the rb 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()

Example

Note 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 ClipDONE, Sansa FuzeDONE, Sansa e200DONE, Sansa c200DONE, iPod 1G2GDONE, iPod 3GDONE, iPod 4GDONE, iPod ColorDONE, iPod VideoDONE, iPod MiniDONE, iPod NanoDONE, GigabeatDONE, MR-100DONE, iAudio M5DONE, iAudio X5DONE, H100DONE, H300DONE, H10DONE]
Edit | Attach | Print version | History: r9 | r7 < r6 < r5 < r4 | Backlinks | View wiki text | More topic actions...
r6 - 19 May 2010 - 01:42:27 - JustinHannigan

Parents: PluginIndex
Copyright by the contributing authors.