-
Notifications
You must be signed in to change notification settings - Fork 6
Lua
This page will present the functions that can be used in a Lua script. For further information on Lua 5.3, please refer to the official manual.
-
[]
(brackets) around a parameter means that the parameter is optional. The default value is given after the?
(question mark); -
table
is a Lua table.
The operations to manipulate bits are officially supported in Lua 5.3. Therefore, the bit
namespace is not implemented. Please, see the official manual on this chapter.
-
emu.frameadvance()
Asks the emulator to emulate one frame.
-
emu.pause()
Asks the emulator to pause.
-
emu.unpause()
Asks the emulator to resume.
-
emu.resume()
Same as emu.unpause.
-
int emu.framecount()
Returns the current frame number.
-
emu.registerbefore(function)
Register a Lua function to be executed at the beginning of a frame.
-
emu.registerafter(function)
Register a Lua function to be executed at the end of a frame. Please note that, in this emulator, it works as emu.registerbefore.
-
emu.registerexit(function)
Register a Lua function to be executed at the end of the script (when the lua engine closes).
The following functions operate on the PS2 memory. They work as the Memory tab in the Debug window.
The available cpu are r3000
and r5900
. I (DocSkellington) don't know the differences.
Please note that there is no memory search in PCSX2 v1.4.0 and I will not implement it.
-
int emu.readXXX(int address, string cpu)
Reads the value at the given address of the given cpu and returns it.
The following functions are available:
- readbyte
- readbytesigned
- readword
- readwordsigned
- readdword
- readdwordsigned
-
** emu.writeXXX(int address, int val, string cpu)
Writes
val
at the given address in the given cpu.- writebyte
- writedword
Inputs are handled in this order:
- From keyboard or pad.
- From KeyMovie
- From Lua scripts
Accepted ports are 0
(Player 1) and 1
(Player 2).
A Key is described as:
Type | Key(s) | Values |
---|---|---|
Normal Key | up, right, left, down, select, start, x, circle, triangle, square, l1, l2, l3, r1, r2, r3 | Booleans: whether the key is pressed (true) or not (false). False is not pushed when writing to a port. |
Analog Key | l_updown | Returns the information of the left analog stick as a numerical value from 0 to 255. 0 is the maximum up, 127 is the neutral 0, 255 is the maximum moving down. |
Analog Key | l_leftright | Returns the information of the left analog stick as a numerical value from 0 to 255. 0 is the maximum left, 127 is the neutral 0, 255 is the maximum movement to the right. |
Analog Key | r_updown | Returns the information of the right analog stick as a numerical value from 0 to 255. 0 is the maximum up, 127 is the neutral 0, 255 is the maximum moving down. |
Analog Key | r_leftright | Returns the information of the right analog stick as a numerical value from 0 to 255. 0 is the maximum left, 127 is the neutral 0, 255 is the maximum movement to the right. |
-
table joypad.get(int port)
Returns the key information entered in the latest frame from the given port.
-
joypad.set(int port, table key)
Sets the input information of the next frame.
-
savestate.saveslot(int slotnum)
Saves the current state of the emulation in the given slot (0 to 9).
-
sasvestate.loadslot(int slotnum)
Loads the state in the given slot (0 to 9).
-
string movie.mode()
If a movie is open, returns the current state of that movie ("record" or "playback"). Otherwise, returns nil.
-
int movie.length()
If a movie is open, returns the maximum number of frames of that movie. Otherwise, returns nil.
-
string movie.author()
If a movie is open, returns the author of that movie. Otherwise, returns nil.
-
string movie.getauthor()
Same as movie.author.
-
string movie.name()
If a movie is open, returns the name of the file of that movie. Otherwise, returns nil.
-
string movie.getname()
Same as movie.name.
-
string movie.cdrom()
If a movie is open, returns the cd information of that movie. Otherwise, returns nil.
-
string movie.getcdrom()
Same as movie.cdrom.
-
int movie.rerecordcount()
If a movie is open, returns the number of re-records of that movie. Otherwise, returns nil.
-
movie.stop()
Stops and closes the current movie (if one is opened).
-
movie.close()
Same as movie.stop.
In the following functions, Color
is a structure describing a color. The value(s) passed from Lua must be:
- a string (see wxWidgets documentation for accepted colors), or
- 3 integers describing red, green and blue values (opacity is, by default, 255), or
- 4 integers describing red, green, blue and alpha (opacity) values.
If you describe two consecutive colors with integers, the first one must have an explicit alpha value (otherwise, the script will not execute). See gui.lua
file in the lua
folder (next to the executable).
Some descriptions come from the Bizhawk Lua documentation.
-
gui.text(int x, int y, string text, [Color foreground ? black], [Color background ? transparent], [int charSize ? 12], [string fontFamily ? "default"], [string fontStyle ? "normal"], [string fontWeight ? "normal"])
-
gui.drawText(...)
Displays the text at the given coordinates.
fontFamily
,fontStyle
andfontWeight
are not case-sensitive.Values accepted for fontFamily are (descriptions come from the wxWidgets documentation):
-
default
: Chooses a default font. -
decorative
: A decorative font. -
roman
: A formal, serif font. -
script
: A handwriting font. -
swiss
: A sans-serif font. -
modern
: A fixed pitch font. -
teletype
: A teletype (i.e. monospaced) font.
Values accepted for fontStyle are (descriptions come from the wxWidgets documentation):
-
normal
: The font is drawn without slant. -
italic
: The font is slanted in an italic style. -
slant
: The font is slanted, but in a roman style.
Values accepted for fontWeight are (descriptions come from the wxWidgets documentation):
-
normal
: Normal font. -
light
: Light font. -
bold
: Bold font.
-
-
gui.box(int x1, int y1, int x2, int y2, [Color line ? black], [Color background ? transparent])
-
gui.drawBox(...)
Draws a rectangle on screen from x1/y1 to x2/y2. Same as rectangle/drawRectangle except it receives two points intead of a point and width/height.
-
gui.rectangle(int x, int y, int width, int height, [Color line ? black], [Color background ? transparent])
-
gui.drawRectangle(...)
Draws a rectangle at the given coordinate and the given width and height. Line is the color of the box. Background is the optional fill color.
-
gui.line(int x1, int y1, int x2, int y2, [Color line ? black])
-
gui.drawLine(...)
Draws a line from the first coordinate pair to the 2nd. Color is optional (if not specified it will be drawn black).
-
gui.pixel(int x, int y, [Color color ? black])
-
gui.drawPixel(...)
-
gui.setPixel(...)
-
gui.writePixel(...)
Draws a single pixel at the given coordinates in the given color. Color is optional (if not specified it will be drawn black).
-
gui.ellipse(int x, int y, int width, int height, [Color line ? black], [Color background ? transparent])
-
gui.drawEllipse(...)
Draws an ellipse at the given coordinates and the given width and height. Line is the color of the ellipse. Background is the optional fill color.
-
gui.circle(int x, int y, int radius, [Color line ? black], [Color background ? transparent])
-
gui.drawCircle(...)
Draws a circle at the given coordinates and the given radius. Line is the color of the ellipse. Background is the optional fill color.
- lua.close() Closes the lua script.
- print(string text) Displays the text in the Console.