LuaDEV R0

The most performant Lua interpreter for making games for the PlayStation Portableā„¢


Introductory Note

First and foremost, I'd like to clarify I did not develop LuaDEV R0. It was developed and maintained by DeViaNTe until 2011.

I was not around at the time but from what I can gather, the original documentation was written in Spanish and loosely translated to English shortly after, being released as a bunch of individual text files. Sadly the documentation was never complete so there's a lot of missing functions and a lot of relevant information is scattered around old forums. This repository shall serve to gather the most up-to-date version of LuaDEV R0's EBOOT.PBP and documentation by cross-referencing a bunch of old links so you don't have to.

The original Spanish documentation is also available here, so you can always refer back to it if you have any questions or need more information about certain functions, even though it's quite unfinished. All this is still a work in progress but I'll try provide some instructions on setting up the environment and a few demos/examples so you have everything you need to get started programming games for the PSP using Lua with LuaDEV R0.

I'm just a beginner myself so feel free to submit corrections to this repository if you feel any is due.

Before Moving On

Why getting into PSP homebrew in 2020?

Well, why not? Making games is cool, but making games for older consoles is cooler. But I guess since you're already here, I assume you're already sold on the idea of developing for this amazing console!

Why use Lua?

If you want to get into homebrew development for the PSP I'd say you have two options:

  1. Using PSPSDK and develop in C;
  2. Picking one of the many Lua interpreters available for the PSP and use Lua.

Obviously using one over the other has its own advantages and trade-offs.

The gist of it as I see it is this: if you know what you're doing, using C obviously provides better control over the hardware and much better performance but its development process is slower and it has a steeper learning curve. On the other hand, Lua is easier to get into than C, the environment is easier to setup and you can have a demo running in 10 minutes. But to get all that, you're trading off the control over the hardware you might want or need and the speed of execution, because unlike C, Lua is interpreted, not compiled.

In short, using Lua abstracts a lot of the hardware part which allows you to focus on actually designing and making games more easily and faster.

Why use LuaDEV R0?

Over the years, there's been a bunch of Lua interpreters for the PSP, among the most known are Lua Player (which was later ported to the Playstation 2 as well), Phoenix Game Engine (aka PGELua), ONELua (multiplatform - PSP and PSVita - and the only one being maintained to this day) and LuaDEV R0.

I personally picked LuaDEV R0 because it has a reputation for being the most performant handling graphics, even when compared against PGELua (up until the release of LuaDEV R0, the fastest available Lua interpreter for the PSP).

What can you do with LuaDEV R0?

LuaDEV R0 is fit for small 2D/3D games, but it can also be used for general software. I'll try to provide some demos of my own as well as other developers' demos so you can see what has been done so far.

This game is probably the most impressive example made with LuaDEV R0. It was developed by the original LuaDEV creator and is included in the examples folder, so you can look at the complete code and see how things are done.

Note that anything you program will only run on emulators or modded consoles, as this is not an official SDK.

In This Repo

This repository contains several things that might be useful for you.

  1. A more comprehensive documentation in English as well as the Spanish original
  2. The last verion of the actual interpreter in .PBP format that's readable by the PSP (EBOOT.PBP)
  3. A set of tools that may help:
    1. ttf2pgf to convert fonts from .TTF to .PGF (the format used by LuaDEV R0)
    2. PBPUnpacker that allows you to customize your EBOOT.PBP (change the ICON0, PIC0, etc)

Folder Structure

  • /docs - contains this and original documentation both in HTML format
  • /examples - contains some examples and demos
  • /projects - folder for your own projects
  • /tools - toolset described above
  • EBOOT.PBP - The interpreter

Note: The examples provided with the old documentation for coroutines.lua (1), savedata.lua (2) and strings.lua (3) were broken. I fixed them and they are available in the projects folder.

  1. The coroutines.lua script was being halted midway, because it was trying to print nil values and throwing an error afterwards while trying to call the routine after it got killed. Just implemented xpcall to handle the exception.
  2. The savedata.lua script was trying to call the implode method on a table instead of a string;
  3. The strings.lua was breaking while calling the gsub method in one of the examples;

Getting Started

You don't need much to get the development environment up and running. You basically need:

  1. Some programming knowledge, preferably in Lua;
  2. This repository;
  3. An emulator to run your games on;
  4. (Optional) A modded PSP if you'd like to play your games on original hardware.

Kickstart Guide

0. Install the emulator (PPSSPP if you followed the link above) and have it open and ready.

1. Clone this repository:

                                    git clone https://github.com/jcnmsg/luadev-r0-psp.git
                                

2. Make a folder for your new project in ./luadev-r0-psp/projects/:

                                    mkdir ./luadev-r0-psp/projects/hello-world-test
                                

3. Copy the EBOOT.PBP file to your new project folder:

                                    cp ./luadev-r0-psp/EBOOT.PBP ./luadev-r0-psp/projects/hello-world-test/
                                

4. Create a file called script.lua in the project folder. This will be the entrypoint of our game:

                                    blue = color.new(0,0,255) 
                                    white = color.new(255, 255, 255)
                                    black = color.new(0, 0, 0)

                                    screen.print(10, 10, "Hello world!" , 0.6, blue, blue)
                                    screen.print(10, 26, "This is my first program and it runs on the PSP!" , 0.4, white, black)

                                    screen.flip()

                                    while true do
                                        screen.waitvblankstart()
                                    end
                                

5. On your emulator go to File > Load and load the EBOOT.PBP in your project folder. You should see the result:

hello world example

If you make changes to your code, you can hit CTRL+B to refresh your emulator and the program will restart. And you're basically good to go!

6. (Optional) To run this on your actual PSP (assuming it's modded), simply connect it via USB and drag the entire project folder into usb:/PSP/GAME/ or usb:/PSP/GAME150/ depending on your CFW version. Here's the example running on mine with slightly adjusted text sizes:

hello world example

How does this work?

Lua is an interpreted language. The EBOOT.PBP file contains the LuaDEV R0 interpreter, all you have to do is provide the script for it to read. Sadly we do not have access to the actual interpreter code, only snippets that DeViAnTe posted throughout the years on psp.scenebeta.com.

Demos and examples

This repository contains some demos and examples you can check. Right now, here's what's available to you:

  1. Hello World (shown in "Getting Started")
  2. INI - Using configuration files
  3. Using Lua courotines
  4. Save/Load data example
  5. String manipulation examples
  6. GDP - 3D game made by the original developer
  7. Chipmunk - Demo of the 2D physics engine (WIP)
  8. Simple top down y-sort example
  9. HTTP example (PR#6)

To run these examples simply copy the EBOOT.PBP into the folder of the example and run it on your emulator (the GDP example has its own EBOOT.PBP file because it contains game images and whatnot).

Hopefully this list will grow soon as I intend to provide some more demos but feel free to submit your own if you want.

Update log

Since there's so many things undocumented, here's the progress that has been made (starting 30/12/2020):

                                                22/06/2021: Added HTTP example and fixed http.get return values (PR#6)
                                                01/01/2021: Documented video and UMD modules;
                                                01/01/2021: Documented more of the Chipmunk API and updated the example to show gravity (WIP);
                                                31/12/2020: Started working on documenting Chipmunk physics engine and a new example for it (WIP) 
                                                31/12/2020: Added the complete WLAN function set to the documentation.
                                                30/12/2020: Added HTTP post method to the documentation.
                                            

Documentation

Use of this documentation

From this point onwards, most of the text will be by the original developer and has been translated from Spanish. It might contain notes and snippets from the already existing English translation and other useful links as well as "random" stuff that I've collected and cross-referenced. To avoid clutter, each module has extra info that you can check in the old documentation via the "More info" link available for each section.

There will be some repeated functions in this manual. This implies that a function can be used in different ways, with different arguments, and obtaining different results. All these cases will be separately documented.

In addition, in this manual, the following typology will be used:
type_of_result module.function ( type argument, type argument)

There are also modules that use "variables", which are named numeric constants, to use them they don't need the parentheses. For example: math.pi or math.g

Object Oriented Programming:

While Lua is not an object-oriented language, it offers a nice way to look like it.
It offers us the possibility of using the colon ":" instead of a period when calling functions. The use of the colon implies that as the first argument it will pass the object before the colon, and the rest of the arguments as normal.
Attention : But this does not work for all functions, only for objects of the same type!

Examples:
We create an image:

myimage = image.create(10,10);
We apply image.blit() to that same image by calling it like this:
myimage:blit(0,0); 
If we look at the documentation, we will see that image.blit() has one image as the first parameter, followed by two coordinates. So it accepts as the first argument an object returned by its same module.

More examples:
file = io.open("test.txt"); 
data = file:read("* a");
file:close(); 
We can check that io.read() and io.close() accept a "file" type argument as the first argument, the same one returned by io.open, from the same module.

If it is still not clear to you, you can see it in the examples attached to this manual. Either way can always use the traditional way of calling functions.

Brief documentation of data types

Data types in Lua:
  • - nil (empty, null)
  • - boolean (boolean, true or false)
  • - number (number, integer, decimal or hexadecimal)
  • - string (array of chars, text)
  • - function (function)
  • - table (table)
  • - thread (coroutine, process)
  • - file (file decrypter, returned by the io module)
  • - userdata (objects returned by LuaDEV)
  • - chunk (chunk of code, returned by certain functions)
Data types in LuaDEV:
  • - int (type number, but always integer, not decimal)
  • - font (userdata returned by the font module)
  • - image (userdata returned by the image module)
  • - sound (userdata returned by the sound module)
  • - model (userdata returned by the model module)
  • - timer (userdata returned by the timer module)
  • - body (userdata returned by the chipmunk module)
  • - space (userdata returned by the chipmunk module)
  • - video (userdata returned by the video module)

Reference map

This is a comprehensive set of functions that you can look up if you want to see if a function is available to you or not.

The first list contains all LuaDEV R0's undocumented functions (video, chipmunk 2d, etc) while the second list contains THE COMPLETE SET of the functions available to you if you're using the EBOOT.PBP file in this repository, including general Lua funcions like assert, pcall and xpcall. The objective is to have all of these documented in the future.

In that regard, whatever is highlighted in the first list, means it has been documented in the meantime and is available for you to check below. Hopefully we'll get rid of the first list as soon as possible.

You can also refer back to the original Lua manual. It uses version 5.1.

                                    chipmunk
                                        body
                                            mass
                                            new
                                            position
                                        cursor
                                            grab
                                            move
                                            new
                                            release
                                        init
                                        moment
                                            box
                                            circle
                                            polygon
                                            segment
                                        shape
                                            elasticity
                                            friction
                                            getbody
                                            newcircle
                                            newpoly
                                            newsegment
                                        space
                                            addbody
                                            addshape
                                            addstaticshape
                                            damping
                                            free
                                            gravity
                                            idlespeedthreshold
                                            iterations
                                            new
                                            pointqueryfirst
                                            pointqueryfirst_body
                                            resizeactivehash
                                            resizestatichash
                                            sleeptimethreshold
                                            staticbody
                                            step
                                            wiredraw
                                    debugmode
                                    debugprint
                                    debugset
                                    dump
                                    error
                                    fx
                                        add
                                        alpha
                                        color
                                        default
                                        none
                                        rgba
                                        sub
                                    gcinfo
                                    getfenv
                                    getfullmodulefunction
                                    getmetatable
                                    iif
                                    image
                                        chipload
                                        fastblit
                                        fxadd
                                        fxsub
                                        fxtint
                                        gearload
                                        logoload
                                        luaload
                                        zblit
                                    include
                                    ipairs
                                    lightstation
                                    load
                                    loadfile
                                    loadstring
                                    math
                                        bbox
                                        clamp
                                        inrect
                                        int
                                        poly
                                            rotate
                                            testlist
                                            testxy
                                        round
                                        vector
                                            cartesian
                                            magnitude
                                            polar
                                    model
                                        alpha
                                        buffer
                                        lshf
                                        mat
                                        stat
                                    module
                                    newproxy
                                    next
                                    debug
                                        debug
                                        getfenv
                                        gethook
                                        getinfo
                                        getlocal
                                        getmetatable
                                        getregistry
                                        getupvalue
                                        setfenv
                                        sethook
                                        setlocal
                                        setmetatable
                                        setupvalue
                                        traceback
                                    particles
                                        blit
                                        count
                                        enabled
                                        free
                                        init
                                        intensity
                                        limit
                                        new
                                        rand
                                        start
                                        stop
                                    socket
                                        connect
                                        free
                                        isconnected
                                        localport
                                        packetslost
                                        peerport
                                        recv
                                        send
                                        udp
                                    table
                                        foreach
                                        foreachi
                                        getn
                                        setn
                                        sort
                                    umd
                                        present
                                    video
                                        free
                                        info
                                        load
                                    wlan
                                        connected
                                        getconfigs
                                        init
                                        ip
                                        mac
                                        scan
                                        status
                                        statustext
                                        strength
                                        term
                                    world
                                        ambient
                                        envmapcolor
                                        envmapfx
                                        fog
                                        lightambient
                                        lightattenuation
                                        lightcomponent
                                        lightdiffuse
                                        lightdirection
                                        lightenabled
                                        lightposition
                                        lights
                                        lightspecular
                                        lightspotlight
                                        lighttype
                                        lookat
                                        ortho
                                        perspective
                                        shademodel
                                        specular
                                        update
                                
                                    _G
                                    _VERSION
                                    assert
                                    batt
                                        charging
                                        chargingstatus
                                        exists
                                        islow
                                        percent
                                        temp
                                        time
                                        volt
                                    cam
                                        blit
                                        direction
                                        hmirrored
                                        off
                                        on
                                        start
                                        state
                                        status
                                        toimage
                                        vmirrored
                                    chipmunk
                                        body
                                            mass
                                            new
                                            position
                                        cursor
                                            grab
                                            move
                                            new
                                            release
                                        init
                                        moment
                                            box
                                            circle
                                            polygon
                                            segment
                                        shape
                                            elasticity
                                            friction
                                            getbody
                                            newcircle
                                            newpoly
                                            newsegment
                                        space
                                            addbody
                                            addshape
                                            addstaticshape
                                            damping
                                            free
                                            gravity
                                            idlespeedthreshold
                                            iterations
                                            new
                                            pointqueryfirst
                                            pointqueryfirst_body
                                            resizeactivehash
                                            resizestatichash
                                            sleeptimethreshold
                                            staticbody
                                            step
                                            wiredraw
                                    collectgarbage
                                    color
                                        A
                                        B
                                        G
                                        R
                                        add
                                        blend
                                        goto
                                        mix
                                        new
                                        random
                                        sub
                                    controls
                                        analogtodigital
                                        analogx
                                        analogy
                                        circle
                                        cross
                                        down
                                        hold
                                        home
                                        homepopup
                                        l
                                        left
                                        note
                                        press
                                        r
                                        read
                                        release
                                        right
                                        select
                                        square
                                        start
                                        triangle
                                        up
                                        waitforkey
                                        wlan
                                    coroutine
                                        create
                                        resume
                                        running
                                        status
                                        wrap
                                        yield
                                    debugmode
                                    debugprint
                                    debugset
                                    dofile
                                    draw
                                        fillpoly
                                        fillrect
                                        gradline
                                        gradrect
                                        line
                                        pbar
                                        poly
                                        rect
                                    dump
                                    error
                                    files
                                        cdir
                                        copy
                                        decrypt
                                        encrypt
                                        exists
                                        ext
                                        freespace
                                        list
                                        listdirs
                                        listfiles
                                        mkdir
                                        nofile
                                        nopath
                                        remove
                                        rename
                                        size
                                        sizeformat
                                        totalspace
                                    font
                                        free
                                        load
                                    fx
                                        add
                                        alpha
                                        color
                                        default
                                        none
                                        rgba
                                        sub
                                    gcinfo
                                    getfenv
                                    getfullmodulefunction
                                    getmetatable
                                    hprm
                                        back
                                        forward
                                        headphones
                                        hold
                                        microphone
                                        playpause
                                        press
                                        read
                                        release
                                        remote
                                        voldown
                                        volup
                                    http
                                        get
                                        post
                                    iif
                                    image
                                        blend
                                        blit
                                        blitsprite
                                        center
                                        chipload
                                        clear
                                        create
                                        factorscale
                                        fastblit
                                        free
                                        fxadd
                                        fxsub
                                        fxtint
                                        gearload
                                        height
                                        load
                                        loadfrommemory
                                        loadsprite
                                        logoload
                                        luaload
                                        mirrorh
                                        mirrorv
                                        pixel
                                        print
                                        realheight
                                        realwidth
                                        reset
                                        resize
                                        rotate
                                        save
                                        setframe
                                        width
                                        zblit
                                    include
                                    ini
                                        free
                                        get
                                        load
                                        read
                                        save
                                        write
                                    io
                                        close
                                        flush
                                        input
                                        lines
                                        open
                                        output
                                        popen
                                        read
                                        stderr
                                        stdin
                                        stdout
                                        tmpfile
                                        type
                                        write
                                    ipairs
                                    lightstation
                                    load
                                    loadfile
                                    loadstring
                                    math
                                        abs
                                        acos
                                        asin
                                        atan
                                        atan2
                                        bbox
                                        ceil
                                        clamp
                                        cos
                                        cosh
                                        deg
                                        e
                                        exp
                                        floor
                                        fmod
                                        frexp
                                        g
                                        huge
                                        inrect
                                        int
                                        isqrt
                                        ldexp
                                        log
                                        log10
                                        log2
                                        max
                                        min
                                        modf
                                        pi
                                        poly
                                            rotate
                                            testlist
                                            testxy
                                        pow
                                        rad
                                        random
                                        randomseed
                                        round
                                        sin
                                        sincos
                                        sinh
                                        sqrt
                                        tan
                                        tanh
                                        vector
                                            cartesian
                                            magnitude
                                            polar
                                    model
                                        alpha
                                        blit
                                        buffer
                                        free
                                        load
                                        lshf
                                        mat
                                        position
                                        rotation
                                        scale
                                        stat
                                    module
                                    newproxy
                                    next
                                    os
                                        autofps
                                        buildnumber
                                        chipmunksplash
                                        clock
                                        cpu
                                        date
                                        difftime
                                        execute
                                        exit
                                        getenv
                                        getfreememory
                                        getinitmemory
                                        kernel
                                        language
                                        launchfile
                                        luadevsplash
                                        luasplash
                                        md5
                                        message
                                        nick
                                        osk
                                        quit
                                        remove
                                        rename
                                        runeboot
                                        runiso
                                        setlocale
                                        sha1
                                        sleep
                                        startPSX
                                        time
                                        tmpname
                                    package
                                        config
                                        cpath
                                        loaded
                                            _G
                                            batt
                                            cam
                                            chipmunk
                                            color
                                            controls
                                            coroutine
                                            debug
                                                debug
                                                getfenv
                                                gethook
                                                getinfo
                                                getlocal
                                                getmetatable
                                                getregistry
                                                getupvalue
                                                setfenv
                                                sethook
                                                setlocal
                                                setmetatable
                                                setupvalue
                                                traceback
                                            draw
                                            files
                                            font
                                            fx
                                            hprm
                                            http
                                            image
                                            ini
                                            io
                                            math
                                            model
                                            os
                                            package
                                            particles
                                                blit
                                                count
                                                enabled
                                                free
                                                init
                                                intensity
                                                limit
                                                new
                                                rand
                                                start
                                                stop
                                            pbp
                                                checksfo
                                                geticon0
                                                getpic1
                                                getsfo
                                            power
                                                idle
                                                idledisable
                                                idleenable
                                                lock
                                                plugged
                                                standby
                                                suspend
                                                tick
                                                tick_all
                                                tick_display
                                                tick_suspend
                                                unlock
                                            savedata
                                                autoload
                                                autosave
                                                delete
                                                load
                                                save
                                            screen
                                                bilinear
                                                blendmode
                                                brightness
                                                buffertoimage
                                                clear
                                                cleardepth
                                                clip
                                                depthtest
                                                disable
                                                dithering
                                                enable
                                                flip
                                                fps
                                                frameskip
                                                print
                                                sync
                                                textwidth
                                                toimage
                                                waitvblank
                                                waitvblankstart
                                            socket
                                                connect
                                                free
                                                isconnected
                                                localport
                                                packetslost
                                                peerport
                                                recv
                                                send
                                                udp
                                            sound
                                                blit
                                                cover
                                                divider
                                                duration
                                                fastload
                                                fft
                                                fmt
                                                free
                                                id3
                                                load
                                                loop
                                                pause
                                                percent
                                                play
                                                playing
                                                position
                                                samples
                                                size
                                                stop
                                                vis
                                                volume
                                            string
                                                byte
                                                char
                                                dump
                                                ed
                                                explode
                                                find
                                                format
                                                gettok
                                                gfind
                                                gmatch
                                                gsub
                                                implode
                                                join
                                                len
                                                levenhstein
                                                lower
                                                match
                                                numtok
                                                rep
                                                reverse
                                                split
                                                splitinlines
                                                sub
                                                substrcount
                                                upper
                                            table
                                                concat
                                                foreach
                                                foreachi
                                                getn
                                                insert
                                                maxn
                                                remove
                                                setn
                                                sort
                                            threadman
                                                exists
                                                list
                                                loaderpriority
                                            timer
                                                free
                                                new
                                                reset
                                                start
                                                stop
                                                time
                                            umd
                                                present
                                            usb
                                                off
                                                on
                                                state
                                                status
                                            video
                                                free
                                                info
                                                load
                                            wlan
                                                connected
                                                getconfigs
                                                init
                                                ip
                                                mac
                                                scan
                                                status
                                                statustext
                                                strength
                                                term
                                            world
                                                ambient
                                                envmapcolor
                                                envmapfx
                                                fog
                                                lightambient
                                                lightattenuation
                                                lightcomponent
                                                lightdiffuse
                                                lightdirection
                                                lightenabled
                                                lightposition
                                                lights
                                                lightspecular
                                                lightspotlight
                                                lighttype
                                                lookat
                                                ortho
                                                perspective
                                                shademodel
                                                specular
                                                update
                                            zip
                                                extract
                                                list
                                        loaders
                                            1
                                            2
                                            3
                                            4
                                        loadlib
                                        path
                                        preload
                                        seeall
                                    pairs
                                    particles
                                    pbp
                                    pcall
                                    power
                                    print
                                    rawequal
                                    rawget
                                    rawset
                                    require
                                    savedata
                                    screen
                                    select
                                    setfenv
                                    setmetatable
                                    socket
                                    sound
                                    string
                                    table
                                    threadman
                                    timer
                                    tonumber
                                    tostring
                                    type
                                    umd
                                    unpack
                                    usb
                                    video
                                    wlan
                                    world
                                    xpcall
                                    zip
                                

Basic functions

Detailed description

Basic functions that don't belong in any existing module. More info here.

Functions
nil assert (chunk v, string message)
 Activates an error message when its argument is false.
nil collectgarbage (string option, int length)
 Garbage collector.
... dofile (string archive)
 Executes a file as a Lua file.
nil error (string message, int level)
 Throws a Lua error.
chunk loadstring (string code, string number)
 Similar to load, but obtains a chunk of the specified string.

Battery module

Detailed description

All battery-related functions are incorporated in this module. More info here.

Functions
boolean batt.exists ()
 Battery connected (inside the PSP).
boolean batt.charging ()
 Battery is charging.
number batt.chargingstatus ()
 Battery charging state.
boolean batt.islow ()
 Low battery.
number batt.percent ()
 Battery percentage left.
number batt.time (void)
 Battery speculated duration.
number batt.temp (void)
 Battery temperature.
number batt.volt ()
 Battery voltage.

Camera module

Detailed description

This module incorporates all the functions related to the camera of the PSP (Go! CAM). More info here.

Functions
nil cam.on ()
 Activate the camera driver.
nil cam.off ()
 Deactivat the camera driver.
boolean cam.status ()
 Status of the camera driver.
table cam.state ()
 Status of the connection with the camera.
nil cam.start ()
 Start capturing video from the camera.
boolean cam.vmirrored ()
 Vertical flip.
boolean cam.hmirrored ()
 Horizontal flip.
int cam.direction ()
 Camera direction.
image cam.toimage ()
 Get a copy of the current image on the camera.
nil cam.blit (int x, int y)
 Displays the current image that the camera sees on the screen.

Color module

Detailed description

This module incorporates all the functions related to colors. More info here.

Functions
color color.new (int R, int G, int B, int A)
 Create a new color from the R(ed), G(reen), B(lue) values provided.
color color.blend (color c1, color c2)
 Get the mix of two colors.
color color.mix (color c1, color c2, int p1, int p2)
 Get the mix of two colors, using percentages.
color color.add (color c1, color c2)
 Get the sum of the provided colors.
color color.sub (color c1, color c2)
 Subtraction of the provided colors
int color.R (color c1)
 Get the value of red in a color.
int color.G (color c1)
 Get the value of green in a color.
int color.B (color c1)
 Get the value of blue in a color.
int color.A (color c1)
 Get the value of the alpha (transparency) in a color.

Controller module

Detailed description

All the functions related to the controls are incorporated in this module. In LuaDEV, it is not necessary to save variables with the current and previous controls, as it is already done internally. To check if the buttons are pressed at the moment, use controls.xxxx(), if you want to check if they were just pressed, controls.press("xxxx"), and to check if were just released - controls.release("xxxx" ). Only one controls.read() will be used in each loop. More info here.

Functions
nil controls.read ()
 Reads the controls.
boolean controls.up ()
 D-PAD Up.
boolean controls.down ()
 D-PAD Down.
boolean controls.right ()
 D-PAD Right.
boolean controls.left ()
 D-PAD Left.
boolean controls.l ()
 L1 Button.
boolean controls.r ()
 R1 Button.
boolean controls.triangle ()
 Triangle Button.
boolean controls.circle ()
 Circle Button.
boolean controls.cross ()
 Cross Button.
boolean controls.square ()
 Square Button.
boolean controls.home ()
 Home Button.
boolean controls.hold ()
 Hold. (Blocks the controls).
boolean controls.start ()
 Start Button.
boolean controls.select ()
 Select Button.
boolean controls.wlan ()
 WLAN Switch.
number controls.analogx ()
 Analog joystick, X axis.
number controls.analogy ()
 Analog joystick, Y axis.
boolean controls.press (string key)
 Button recently clicked.
boolean controls.release (string key)
 Button recently released.
number controls.waitforkey ()
 Wait for any button to be pressed.
nil controls.homepopup (int active)
 Enable / disable the Home message (Quit the game).
nil controls.analogtodigital (int distance)
 Convert analog joystick to digital.

Coroutines module

Detailed description

Coroutines can be somewhat complex, possibly requiring practice and understanding of the language to a great extent. More info here.

Functions
thread coroutine.create (function f)
 Create a new coroutine.
...args coroutine.resume (thread coroutine, ...args)
 Resumes or starts executing a coroutine.
thread coroutine.running ()
 Returns the coroutine being executed.
string coroutine.status (thread coroutine)
 Get the state of a coroutine.
function coroutine.wrap (function f)
 Creates a new coroutine, converted to a function.
...args coroutine.yield (...args)
 Suspends the execution of a coroutine.

Draw module

Detailed description

Functions to draw simple shapes and lines. More info here.

Functions
nil draw.line (int x1, int y1, int x2, int y2, color col)
 Draw a line from (x1,y1) to (x2,y2).
nil draw.gradline (int x1, int y1, int x2, int y2, color c1, color c2)
 Draw a line from (x1,y1) to (x2,y2) with a gradiente.
nil draw.rect (int x, int y, int w, int h, color col)
 Draw an empty rectangle (border only).
nil draw.fillrect (int x, int y, int w, int h, color col)
 Draw a rectangle.
nil draw.gradrect (int x, int y, int w, int h, color c1, color c2, color c3, color c4)
 Draw a rectangle with gradient background.
nil draw.pbar (int x, int y, int w, int h, color border, color fill, int value, int max)
 Draw a simple progress bar.

Files module

Detailed description

This module incorporates all the functions related to file management. Normally, you can only work within the directory where the EBOOT.PBP file is located (your workspace). Outside of this directory, it will require the consent of the user to be able to modify files. (Accessing in read-only mode does not require permission). More info here.

Functions
nil files.cdir (string path)
 Change the current working directory to the specified one.
string files.cdir ()
 Returns the current working directory.
table files.list (string path)
 List a directory.
table files.listfiles (string path)
 List a directory, but only show files.
table files.listdirs (string path)
 List a directory, but only show other directories.
nil files.mkdir (string path)
 Create a directory.
nil files.remove (string path)
 Delete a file or directory.
nil files.remove (string path, boolean recursive)
 Delete a file or directory.
nil files.copy (string source, string dest)
 Copy a file or directory.
nil files.copy (string source, string dest, boolean recursive)
 Copy a file or directory. Recursively.
nil files.copy (string source, string dest, boolean recursive, boolean overwrite)
 Copy a file or directory. Recursive.
nil files.rename (string name, string newname)
 Rename a file or directory.
boolean files.exists (string path)
 Check if file/directory exists.
string files.nopath (string path)
 Remove the directory to a path (?).
string files.nofile (string path)
 Remove the file to a path (?)..
string files.ext (string path)
 Returns the extension in lowercase.
number files.size (string path)
 Returns the size of a file in bytes.
string files.sizeformat (number bytes)
 Formats a file size.
int files.freespace ()
 Empty space on the memory stick.
int files.totalspace ()
 Total space of the memory stick.

Fonts module

Detailed description

Only supports PGF fonts. Use the converter in the tools folder to convert TTS to PGF. More info here.

Functions
font font.load (string path)
 Loads a font in PGF format.
nil font.free (font f)
 Frees a font from memory.

HPRM module

Detailed description

All the functions related to the audio remote (HPRM) are incorporated in this module. The buttons part of the HPRM is very similar to controls. More info here.

Functions
boolean hprm.headphones ()
 Headphones connected.
boolean hprm.microphone ()
 Microphone connected.
boolean hprm.remote ()
 Remote connected.
nil hprm.read ()
 Reads the controls.
boolean hprm.playpause ()
 Play / Pause Button.
boolean hprm.forward ()
 Forward Button.
boolean hprm.back ()
 Back Button.
boolean hprm.hold ()
 Hold Switch.
boolean hprm.press (string key)
 Recently pressed button.
boolean hprm.release (string key)
 Recenty released button.

HTTP module

Detailed description

In this module all the functions related to HTTP requests are incorporated. More info here.

Functions
boolean,string http.get (string url, int size)
 Executes a GET request, returns a string.
nil http.get (string url, string file)
 Executes a GET request, saves it to a file.
string http.post (string url, string data, int size)
 Make a POST request. Return to string.
nil http.post (string url, string data, string file)
 Make a POST request. Save to a file.

Image module

Detailed description

All images are loaded and managed using this module. Supported formats are: JPG, PNG and GIF. More info here.

Functions
image image.load (string filename)
 Load an image.
image image.loadsprite (string filename, int width, int height)
 Load an image (tilesheet), and divide it into sprites.
image image.loadfrommemory (string data, string filetype)
 Load an image from memory.
image image.create (int width, int height, color col)
 Create a new image.
nil image.clear (image img, color col)
 Clear an image (fills the image with a color).
nil image.blit (image img, number x, number y)
 Displays the complete image on the screen..
nil image.blit (image img, number x, number y, number ximage, number yimage, number width, number height)
 Displays part of an image on screen.
nil image.blitsprite (image img, number x, number y, int frame, int alpha)
 Display a spirte on screen.
nil image.setframe (image img, int frame)
 Choose the frame in a sprite.
nil image.blend (image img, number x, number y, int alpha)
 Same as basic blit, but with transparency.
nil image.fxadd (image img, number x, number y, int alpha)
 Same as basic blit, but with a sum color effect.
nil image.fxsub (image img, number x, number y, int alpha)
 Same as basic blit, but with a subtraction color effect.
nil image.fxtint (image img, number x, number y, color col)
 Same as basic blit, but with a tint color effect.
nil image.resize (image img, int width, int height)
 Scale an image.
nil image.rotate (image img, number angle)
 Rotate an image based on its own center point.
nil image.rotate (image img, number x, number y, number angle)
 Rotate an image based on a defined point.
nil image.factorscale (image img, number factor)
 Scales an image, proportional to a rescaling factor.
nil image.pixel (image img, number x, number y, color col)
 Change the color of a pixel in an image.
color image.pixel (image img, number x, number y)
 Returns the color of a pixel in an image.
nil image.save (image img, string path)
 Saves an image object to PNG.
number image.width (image img)
 Width of an image.
number image.height (image img)
 Height of an image.
nil image.center (image img, number x, number y)
 Specifies the center of an image.
nil image.reset (image img)
 Reset modified properties. (Scale, Rotation...).
nil image.free (image img)
 Free an image object.

INI module

Detailed description

This module incorporates all the functions related to configuration files (.INI). More info here.

Functions
string ini.read (string path, string section, string key, string default)
 Reads an entry in a .ini file.
string ini.read (string path, string key, string default)
 Reads an entry in a .ini file (without section).
nil ini.write (string path, string section, string key, string data)
 Writes data to a .ini file.
nil ini.write (string path, string key, string data)
 Writes data to a .ini (without section).

I/O module

Detailed description

File manager. More info here.

Functions
file io.open (string path, string mode)
 Open a file in any mode.
file io.open (string path)
 Open a file in reading mode.
nil io.close (file fd)
 Close a file.
string io.read (file fd, string format)
 Read data from a file.
string io.read (file fd)
 Read a line from a file.
function io.lines (string path)
 Iterate line by line in a file.
nil io.write (file fd, ...args)
 Write data to a file.
nil io.flush (file fd)
 Save the written data to a file.
nil io.seek (file fd, string where)
 Sets or returns the current position of the cursor in a file.
nil io.seek (file fd, string where, int offset)
 Move the cursor position in a file.
nil io.setvbuf (file fd, string mode)
 Sets how the data will be written to a file.

Math module

Detailed description

Well... math. More info here.

Functions
integer math.round (number x)
 Round decimal number to integer.
int math.ceil (number x)
 Round up (ceil).
int math.floor (number x)
 Round down (floor).
number math.max (number...args)
 Get the biggest number.
number math.min (number...args)
 Get the smallest number.
number math.random ()
 Random number between 0 and 1. (with decimals).
int math.random (int m)
 Random number between 1 and m. (integer).
int math.random (int m, int n)
 Random number between m and n. (entero).
nil math.randomseed (number x)
 Change the seed from the pseudorandom number generator.
number math.abs (number x)
 Absolute value.
number math.pow (number x, number y)
 Squared.
number math.sqrt (number x)
 Square root.
number math.log (number x)
 Natural logarithm.
number math.log10 (number x)
 Decimal lograrithm.
number math.exp (number x)
 Euler's constant raised to x.
number math.modf (number x)
 Separate into integer and fractional.
number math.fmod (number x, number y)
 Remainder of a division.
number math.frexp (number x)
 x = m*(2^e)
number math.ldexp (number m, int e)
 m*(2^e)
number math.deg (number x)
 Convert radian angle to degree.
number math.rad (number x)
 Convert degree angle to radians.
number math.cos (number x)
 Cosine.
number math.acos (number x)
 Arccosine.
number math.cosh (number x)
 Hyperbolic Cosine.
number math.sin (number x)
 Sine.
number math.asin (number x)
 Arcsine.
number math.sinh (number x)
 Hyperbolic sine.
number math.tan (number x)
 Tangent.
number math.atan (number x)
 Arctangent.
number math.atan2 (number y, number x)
 Arctangent.
number math.tanh (number x)
 Hyperbolic tangent.
number math.vector.polar (number x, number y)
 Get polar vector between x and y.
nil math.poly.testxy ()
 No description.
nil math.poly.testlist ()
 No description.
number tonumber (string s)
 Convert a string to a number.
Variables
const number math.huge = HUGE_VAL
 The biggest number.
const number math.pi = 3.14159
 The value of pi.
const number math.e = 2.71828
 The value of e (Euler's Constant).
const number math.g = 9.81
 Gravity acceleration (m/s2).

Operating system module

Detailed description

OS related functions. More info here.

Functions
number os.clock ()
 Time since LuaDEV has initiated in seconds.
number os.time ()
 Actual time in seconds (since 1990).
number os.time (table date)
 Time in seconds since the specified date.
string os.date ()
 Date and Time.
string os.date (string format)
 Formatted Date and Time.
table os.date (string format)
 Date and Time in table format.
string os.date (string format, number time)
 Format specified time (not the actual time).
table os.date (string format, number time)
 Format specified time in a table (not the actual time).
number os.difftime (number time2, number time1)
 Difference between two times.
string os.tmpfile ()
 Temporal archive.
nil os.remove (string path)
 Direct access to files.remove() . Deletes a file/directory.
nil os.rename (string origen, string destino)
 Direct access to files.rename() . Changes name of file/directory.
nil os.getenv (any var)
 Get value of any environment variable.
nil os.quit ()
 Exit to XMB.
nil os.exit ()
 Direct access to os.quit().
int os.cpu ()
 Current CPU speed.
nil os.cpu (int speed)
 Change current CPU speed.
nil os.autofps ()
 Deactivate auto-adjustment of the CPU speed.
nil os.autofps (int fps)
 Activate auto-adjustment of the CPU speed, to maintain a constant framerate.
number os.runeboot (string path)
 Launch another EBOOT.PBP. (In HBL this function returns -1).
number os.runiso (string path)
 Launch an ISO or CSO. (In HBL this function returns -1).
number os.startPSX (string path)
 Launch a PSX game. (In HBL this function returns -1).
number os.getinitmemory ()
 Get total RAM. (Calculated when LuaDEV initiates).
number os.getfreememory ()
 Get total available RAM.
string os.md5 (string data)
 Get the data MD5.
string os.sha1 (string data)
 Get the data SHA1.
string os.nick ()
 OS Username.
string os.language ()
 OS Language.
nil os.message (string text)
 Shows a message on screen. Only option is "Accept".
number os.message (string text, int mode)
 Shows a message on screen. Options of yes and no.
number os.message (string text, int mode, image logo)
 Shows a message on screen. Options of yes and no. With a logo.
number os.message (string text, int mode, function bottom, function top)
 Advanced version of a message.
string os.osk (string desc, string init, int maxsize, int lines, int mode)
 Original keyboard on screen.
nil os.sleep (int time)
 Sleep for specified time in seconds.
nil os.luadevsplash ()
 Show LuaDEV splash screen.
nil os.luasplash ()
 Show Lua splash screen.
Variables
const boolean os.hbl
 Indicates if running in HBL (Half Byte Loader). Eg: if os.hbl then ... end.

Power module

Detailed description

This module incorporates all the functions related to the power supply system. More info here.

Functions
boolean power.plugged ()
 Power plug connected.
nil power.lock ()
 Lock the power switch.
nil power.unlock ()
 Unlock the power switch.
nil power.standby ()
 Change PSP to stand-by mode.
nil power.suspend ()
 Change PSP to suspension mode.
nil power.tick ()
 Prevents PSP from entering stand-by mode.
nil power.tick (int modo)
 Prevents PSP from entering specified mode.
Variables
const number power.tick.all
 Constants to use along with power.tick().
const number power.tick.display
 Constants to use along with power.tick().
const number power.tick.suspend
 Constants to use along with power.tick().

Screen module

Detailed description

This module incorporates all the functions related to the screen. More info here.

Functions
nil screen.flip ()
 Refresh the screen showing the changes. Changes made to the draw buffer will be displayed on the current screen, and the draw buffer will be completely clean (black) again.
nil screen.clear (color col)
 Clear the screen.
nil screen.clip (int x, int y, int w, int h)
 Limits the drawing area.
nil screen.clip ()
 Removes the drawing area limitation set previously.
nil screen.print (number x, number y, string text)
 Print text on screen. (White, regular size, default font).
nil screen.print (font font, number x, number y, string text)
 Print text on screen. (White, regular size, specified font).
nil screen.print (number x, number y, string text, color col)
 Print text on screen. (Color, regular size, default font).
nil screen.print (font font, number x, number y, string text, color col)
 Print text on screen. (Color, regular size, specified font).
nil screen.print (number x, number y, string text, number size, color letters, color shadow)
 Print text on screen with color and shadow, dynamic size, and default font.
nil screen.print (font font, number x, number y, string text, number size, color letters, color shadow)
 Print text on screen with color and shadow, dynamic size, and specified font.
nil screen.print (number x, number y, string text, number size, color letters, color shadow, string align)
 Print text on screen with color and shadow, dynamic size, aligned, and default font.
nil screen.print (font font, number x, number y, string text, number size, color letters, color shadow, string align)
 Print text on screen with color and shadow, dynamic size, aligned, specified font.
nil screen.print (number x, number y, string text, number size, color letters, color shadow, string align, int width)
 Print text on screen with color and shadow, dynamic size, aligned, with set width, default font.
nil screen.print (font font, number x, number y, string text, number size, color letters, color shadow, string align, int width)
 Print text on screen with color and shadow, dynamic size, aligned, with set width, sprecified font.
number screen.print (number x, number y, string text, number size, color letters, color shadow, string scroll, int width)
 Text with automatic scrolling, default font.
number screen.print (font font, number x, number y, string text, number size, color letters, color shadow, string scroll, int width)
 Text with automatic scrolling, specified font.
number screen.textwidth (string text, number size)
 Calculate width of the specified text with the default font.
number screen.textwidth (font font, string text, number size)
 Calculate width of the specified text with a specified font.
imagen screen.toimage ()
 Take a print screen.
imagen screen.buffertoimage ()
 Take a print screen. (The buffer).
nil screen.waitvblank ()
 Wait until the vertical refresh is done.
nil screen.waitvblankstart ()
 Wait until the vertical refresh starts.
nil screen.enable ()
 Turn on the screen.

Exceptions:
En In HBL this function doesn't do anything.

nil screen.disable ()
 Turn off the screen.

Exceptions:
En In HBL this function doesn't do anything.

number screen.brightness ()
 Get screen brightness.

Exceptions:
En In HBL this function returns -1.

nil screen.brightness (int brightness)
 Set screen brightness.
nil screen.sync ()
 Synchronize internal GU list.
nil screen.frameskip (int frames)
 Activate frameskip.
nil screen.frameskip ()
 Deactivate frameskip.
nil screen.dithering (int active)
 Enable / disable anti-aliasing.
nil screen.bilinear (int active)
 Activates / deactivates the bilinear filter.
nil screen.fps ()
 Current framerate.

Sound module

Detailed description

Sounds will be loaded and managed using this module. Supported formats: MP3, AT3, BGM, WAV. The are exceptions for HBL, more info here.

Functions
sound sound.load (string filename)
 Load a sound (MP3, AT3, BGM or WAV).
nil sound.play (sound object)
 Play a sound object through the default audio channel.
nil sound.play (sound object, int channel)
 Play a sound object.
nil sound.pause (sound object, int mode)
 Pause a sound object.
number sound.volume (sound object)
 Get the volume of a sound.
nil sound.volume (sound object, int volumen)
 Set the volume of a sound.
nil sound.volume (sound object, int volumenL, int volumenR)
 Set the volume of a sound, separated by channels.
nil sound.stop (sound object)
 Stop a sound object.
nil sound.free (sound object)
 Frees a sound object.
boolean sound.playing (sound object)
 Checks if a sound object is playing or not.
nil sound.loop ()
 Stops a sound in loop mode.
nil sound.loop (string path)
 Plays a sound in loop mode.
table sound.id3 (string path)
 ID3 information (MP3 only).
imagen sound.cover (string path)
 ID3 cover (MP3 only).
number sound.position (sound object)
 Sound position. (MP3 only).
number sound.duration (sound object)
 Sound duration. (MP3 only).
number sound.percent (sound object)
 Returns the played percentage of a sound.
nil sound.percent (sound object, number percent)
 Set the played percentage of a sound (Change the position).
table sound.vis (sound object)
 Internal interface to the display.
table sound.fft (sound object)
 Internal interface to the FFT (Fast Fourier Transform).
table sound.blit (sound object, string type, number x, number y, number w, number h, color base)
 Draw a waveform or spectrometer (Winamp-like bars).
table sound.blit (sound object, string type, number x, number y, number w, number h, color up, color down, color max)
 Draw a spectrometer, but with gradients.
table sound.blit (sound object, string type, number x, number y, number w, number h, color bg_up, color bg_down, color bar_up, color bar_down, color max, number space)
 Draw a ber spectrometer. (Winamp-like style).

String module

Detailed description

String handling functions. More info here.

Functions
...args string_byte (string str)
 Convert an ASCII character to its numeric value. (Example: A = 65).
...args string_byte (string str, int i)
 Convert an ASCII character to its numeric value. (Example: A = 65).
...args string_byte (string str, int i, int j)
 Convert an ASCII character to its numeric value. (Example: A = 65).
string string_char (int ...args)
 Does the exact contrary of string.byte(). Accepts integers >= 0.
...args string_find (string str, string pattern)
 Find in a string by pattern.
...args string_find (string str, string pattern, int i)
 Find in a string by pattern, starting at the specified index.
...args string_find (string str, string pattern, int i, boolean plano)
 Find in a string by plain text, starting at the specified index.

Table module

Detailed description

Table management. More info here.

Functions

Multithread module

Detailed description

Process management. More info here.

Functions
table list ()
 List current threads.

Timer module

Detailed description

This module incorporates all the functions related to the timers. More info here.

Functions
timer new (int c)
 Create a new timer.

USB module

Detailed description

This module incorporates all the functions related to the USB connection. More info here.

Functions
nil usb.on ()
 Activate the USB driver.
nil usb.off ()
 Deactivate the USB driver.
boolean usb.status ()
 Get the status of the USB driver.
table usb.state ()
 Get the state of the USB connection.


WLAN module

Detailed description

More info here and in ./docs/original/english/wlan.txt.

Functions
boolean wlan.connected ()
 Detects wether we're connected to a network or not.
table wlan.getconfigs ()
 Returns a table with the configured connections, which contains the name and ssid for each network.
int wlan.init ()
 Connect to WLAN, returns 1 if connection is successful, other valus if it isn't.
int wlan.init (int config)
 Connect to WLAN by config number.
string wlan.ip ()
 Returns the IP you were assigned.
string wlan.mac ()
 Returns your MAC address.
table wlan.scan ()
 Get active connections.
int wlan.status ()
 Get the network status: 0: Offline, 1: Scanning, 2: Connecting, 3: Obtaning IP address, 4: Connected, 5: Authorizing, 6: Key exchange.
string wlan.statustext ()
 Get the network status (same as above) but in string format.
int wlan.strength ()
 Get the strengh of the signal (0-100).

Chipmunk 2D module

Detailed description

2D physics engine. A lot of this was cross-referenced with the official Chipmunk2D API so it might be flimsy since it's still a work in progress. More info here and here.

Functions
nil chipmunk.init ()
 Starts the physics engine, must be called before any other Chipmunk function.
body chipmunk.body.new (number mass, number moment)
 Create a new body.
number chipmunk.body.mass (body b)
 Get the mass of a body.
nil chipmunk.body.position (body b, number vx, number vy)
 Set the position of a body.
number chipmunk.body.position (body b)
 Get the position of a body.
space chipmunk.space.new ()
 Create a new space.
nil chipmunk.space.addbody (space s, body b)
 Add an existing body to a space.
number chipmunk.space.gravity (space s)
 Get the gravity vector for a given space.
nil chipmunk.space.gravity (space s, number vx, number vy)
 Set the gravity vector for a given space.
number chipmunk.space.damping (space s)
 Get damping for a given space.
nil chipmunk.space.damping (space s, number d, boolean update)
 Set damping for a given space.
number chipmunk.space.idlespeedthreshold (space s)
 Get idle speed threshold for a given space.
nil chipmunk.space.idlespeedthreshold (space s, number spt)
 Set idle speed threshold for a given space.
nil chipmunk.space.step (space s, number step)
 Run physics simulation for a specified time in seconds (eg. 1/60).
nil chipmunk.space.free (space s)
 Free a space from memory.

Video module

Detailed description

Video module functions. Mostly useless because there's no playback functions implemented, but you can still load a video (in AVI format) into memory.

Functions
video video.load (string path)
 Load a video into memory.
nil video.info (video v)
 Get video info (function exists but doesn't appear to work).
nil video.free (video v)
 Free a video from memory.

UMD module

Detailed description

UMD related functions.

Functions
boolean umd.present ()
 Check if a UMD is inserted on the PSP.