GLOBAL FUNCTIONS


print

Prints a value to the lua console.

@param data — The data to print to the console.

function print(data: any)
  -> nil

Example:

-- prints numbers
print(4)
print(0.42)

-- prints booleans
print(true)
print(false)

-- prints nil
print(nil)

-- prints strings
print("a string")

-- prints tables
print({
    a = {
        deeply = {
            nested = "table",
        },
    },
})

-- prints multiple strings
print("string", "another string")

stop

Stops script execution.

function stop()
  -> nil

Example:

-- runs constantly
emu.atinterval(function()
    print("Script is running!")
    -- when the S key is pressed
    if input.get().S then
        -- stop the script
        stop()
    end
end)

EMU FUNCTIONS


emu.console

This function is deprecated. See the api file for more details.

Displays the text message in the console. Similar to print, but only accepts strings or numbers. Also, emu.console does not insert a newline character. Because of this, print should be used instead.

@param message — The string to print to the console.

function emu.console(message: string|number)
  -> nil

Example:

---@diagnostic disable: deprecated

emu.console("some text\r\n")
emu.console(4)

emu.statusbar

Displays the text message in the status bar on the bottom while replacing any other text. The message will only display until the next frame.

@param message — The string to display on the status bar.

function emu.statusbar(message: string|number)
  -> nil

Example:

emu.statusbar("a cool statusbar message")

emu.atinterval(function()
    if input.get().N then
        emu.statusbar("User just pressed the N key!")
    end
end)

emu.atvi

Calls the function f every VI frame. For example, in Super Mario 64, the function will be called twice when you advance by one frame, whereas it will be called once in Ocarina of Time. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called every VI frame.

@param unregister — If true, then unregister the function f.

function emu.atvi(f: fun():nil, unregister?: boolean)
  -> nil

Example:

-- runs 60 times per second on Super Mario 64
emu.atvi(function()
    local vis = emu.framecount()
    print("VI number " .. vis)
end)

emu.atupdatescreen

Similar to emu.atvi, but for drawing commands. ONLY GDI AND GDI+ COMMANDS WILL WORK HERE. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called after every VI frame.

@param unregister — If true, then unregister the function f.

function emu.atupdatescreen(f: fun():nil, unregister?: boolean)
  -> nil

Example:

-- every screen update
emu.atupdatescreen(function()
    -- draw a 30x30 red square at (10, 10)
    wgui.fillrecta(10, 10, 30, 30, "red")
end)

emu.atdrawd2d

Similar to emu.atvi, but for all drawing commands. GDI and GDI+ commands will still work here, but it is recommended to put those in emu.atupdatescreen If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called after every VI frame.

@param unregister — If true, then unregister the function f.

function emu.atdrawd2d(f: fun():nil, unregister?: boolean)
  -> nil

emu.atinput

Calls the function f every input frame. The function f receives an argument that seems to always be 0. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function. Alias for joypad.register.

@param f — The function to be called every input frame. It receives an argument that seems to always be 0.

@param unregister — If true, then unregister the function f.

function emu.atinput(f: fun(a?: integer):nil, unregister?: boolean)
  -> nil

Example:

local counter = 0;
emu.atinput(function()
    if counter % 2 == 0 then
        joypad.set(1, {A = true})
    end
    counter = counter + 1
end)

emu.atstop

Calls the function f when the script is stopped. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when the script is stopped.

@param unregister — If true, then unregister the function f.

function emu.atstop(f: fun():nil, unregister?: boolean)
  -> nil

Example:

emu.atstop(function ()

end)

emu.atwindowmessage

Defines a handler function that is called when a window receives a message. The only message that can be recieved is WM_MOUSEWHEEL for compatability. All other functionality as been deprecated. The message data is given to the function in 4 parameters. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you] never registered the function.

@param f — The function to be called when a window message is received. a: wnd, b: msg, c: wParam, d: lParam.

@param unregister — If true, then unregister the function f.

function emu.atwindowmessage(f: fun(a: integer, b: integer, c: integer, d: integer):nil, unregister?: boolean)
  -> nil

emu.atinterval

Calls the function f constantly, even when the emulator is paused. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called constantly.

@param unregister — If true, then unregister the function f.

function emu.atinterval(f: fun():nil, unregister?: boolean)
  -> nil

emu.atplaymovie

Calls the function f when a movie is played. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when a movie is played.

@param unregister — If true, then unregister the function f.

function emu.atplaymovie(f: fun():nil, unregister?: boolean)
  -> nil

emu.atstopmovie

Calls the function f when a movie is stopped. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when a movie is stopped.

@param unregister — If true, then unregister the function f.

function emu.atstopmovie(f: fun():nil, unregister?: boolean)
  -> nil

emu.atloadstate

Calls the function f when a savestate is loaded. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when a savestate is loaded.

@param unregister — If true, then unregister the function f.

function emu.atloadstate(f: fun():nil, unregister?: boolean)
  -> nil

emu.atsavestate

Calls the function f when a savestate is saved. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when a savestate is saved.

@param unregister — If true, then unregister the function f.

function emu.atsavestate(f: fun():nil, unregister?: boolean)
  -> nil

emu.atreset

Calls the function f when the emulator is reset. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when the emulator is reset.

@param unregister — If true, then unregister the function f.

function emu.atreset(f: fun():nil, unregister?: boolean)
  -> nil

emu.atseekcompleted

Calls the function f when seek is completed. If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called when the seek is completed.

@param unregister — If true, then unregister the function f.

function emu.atseekcompleted(f: fun():nil, unregister?: boolean)
  -> nil

emu.atwarpmodifystatuschanged

If unregister is set to true, the function f will no longer be called when this event occurs, but it will error if you never registered the function.

@param f — The function to be called.

@param unregister — If true, then unregister the function f.

function emu.atwarpmodifystatuschanged(f: fun():nil, unregister?: boolean)
  -> nil

emu.framecount

Returns the number of VIs since the last movie was played. This should match the statusbar. If no movie has been played, it returns the number of VIs since the emulator was started, not reset.

@return framecount — The number of VIs since the last movie was played.

function emu.framecount()
  -> framecount: integer

emu.samplecount

Returns the number of input frames since the last movie was played. This should match the statusbar. If no movie is playing, it will return the last value when a movie was playing. If no movie has been played yet, it will return -1.

@return samplecount — The number of input frames since the last movie was played.

function emu.samplecount()
  -> samplecount: integer

emu.inputcount

Returns the number of input frames that have happened since the emulator was started. It does not reset when a movie is started. Alias for joypad.count.

@return inputcount — The number of input frames that have happened since the emulator was started.

function emu.inputcount()
  -> inputcount: integer

emu.getversion

Returns the current mupen version. If type is 0, it will return the full version name (Mupen 64 0.0.0). If type is 1, it will return only the version number (0.0.0).

@param type — Whether to get the full version (0) or the short version (1).

@return version — The Mupen version.

type:
    | 0
    | 1
function emu.getversion(type: 0|1)
  -> version: string

emu.pause

Pauses or unpauses the emulator.

@param pause — True pauses the emulator and false resumes it.

function emu.pause(pause: boolean)
  -> nil

emu.getpause

Returns true if the emulator is paused and false if it is not.

@return emu_pausedtrue if the emulator is paused and false if it is not.

function emu.getpause()
  -> emu_paused: boolean

emu.getspeed

Returns the current speed limit (not the current speed) of the emulator.

@return speed_limit — The current speed limit of the emulator.

function emu.getspeed()
  -> speed_limit: integer

emu.get_ff

Gets whether fast forward is active

function emu.get_ff()
  -> boolean

emu.set_ff

Sets whether fast forward is active

function emu.set_ff(fast_forward: boolean)

emu.speed

Sets the speed limit of the emulator.

@param speed_limit — The new speed limit of the emulator.

function emu.speed(speed_limit: integer)
  -> nil

emu.speedmode

Sets the speed mode of the emulator.

mode:
    | "normal"
    | "maximum"
function emu.speedmode(mode: "maximum"|"normal")
  -> nil

emu.getaddress

Gets the address of an internal mupen variable. For example, "rdram" is the same as mupen's ram start

address:
    | "rdram"
    | "rdram_register"
    | "MI_register"
    | "pi_register"
    | "sp_register"
    | "rsp_register"
    | "si_register"
    | "vi_register"
    | "ri_register"
    | "ai_register"
    | "dpc_register"
    | "dps_register"
    | "SP_DMEM"
    | "PIF_RAM"
function emu.getaddress(address: "MI_register"|"PIF_RAM"|"SP_DMEM"|"ai_register"|"dpc_register"...(+9))
  -> integer

emu.screenshot

Takes a screenshot and saves it to the directory dir.

@param dir — The directory to save the screenshot to.

function emu.screenshot(dir: string)
  -> nil

emu.play_sound

Played the sound file at file_path

function emu.play_sound(file_path: string)
  -> nil

emu.ismainwindowinforeground

Returns true if the main mupen window is focused and false if it is not.

function emu.ismainwindowinforeground()
  -> focused: boolean

MEMORY FUNCTIONS


memory.inttofloat

Reinterprets the bits of a 4 byte integer n as a float and returns it. This does not convert from an int to a float, but reinterprets the memory.

function memory.inttofloat(n: integer)
  -> number

memory.inttodouble

Reinterprets the bits of an 8 byte integer n as a double and returns it. This does not convert from an int to a double, but reinterprets the memory.

function memory.inttodouble(n: integer[])
  -> number

memory.floattoint

Reinterprets the bits of a float n as a 4 byte integer and returns it. This does not convert from an int to a float, but reinterprets the memory.

function memory.floattoint(n: number)
  -> integer

memory.doubletoint

Reinterprets the bits of a 8 byte integer n as a double and returns it. This does not convert from an int to a float, but reinterprets the memory.

function memory.doubletoint(n: integer[])
  -> number

memory.qwordtonumber

Takes in an 8 byte integer and returns it as a lua number. This function should only be used when reading a qword from memory.

function memory.qwordtonumber(n: integer[])
  -> number

memory.readbytesigned

Reads a signed byte from memory at address and returns it.

function memory.readbytesigned(address: integer)
  -> integer

memory.readbyte

Reads an unsigned byte from memory at address and returns it.

function memory.readbyte(address: integer)
  -> integer

memory.readwordsigned

Reads a signed word (2 bytes) from memory at address and returns it.

function memory.readwordsigned(address: integer)
  -> integer

memory.readword

Reads an unsigned word (2 bytes) from memory at address and returns it.

function memory.readword(address: integer)
  -> integer

memory.readdwordsigned

Reads a signed dword (4 bytes) from memory at address and returns it.

function memory.readdwordsigned(address: integer)
  -> integer

memory.readdword

Reads an unsigned dword (4 bytes) from memory at address and returns it.

function memory.readdword(address: integer)
  -> integer

memory.readqwordsigned

Reads a signed qword (8 bytes) from memory at address and returns it as a table of the upper and lower 4 bytes.

function memory.readqwordsigned(address: integer)
  -> integer[]

memory.readqword

Reads an unsigned qword (8 bytes) from memory at address and returns it as a table of the upper and lower 4 bytes.

function memory.readqword(address: integer)
  -> integer

memory.readfloat

Reads a float (4 bytes) from memory at address and returns it.

function memory.readfloat(address: integer)
  -> number

memory.readdouble

Reads a double (8 bytes) from memory at address and returns it.

function memory.readdouble(address: integer)
  -> number

memory.readsize

Reads size bytes from memory at address and returns them. The memory is treated as signed if size is is negative.

size:
    | 1
    | 2
    | 4
    | 8
    | -1
    | -2
    | -4
    | -8
function memory.readsize(address: integer, size: -1|-2|-4|-8|1...(+3))
  -> nil

memory.writebyte

Writes an unsigned byte to memory at address.

function memory.writebyte(address: integer, data: integer)
  -> nil

memory.writeword

Writes an unsigned word (2 bytes) to memory at address.

function memory.writeword(address: integer, data: integer)
  -> nil

memory.writedword

Writes an unsigned dword (4 bytes) to memory at address.

function memory.writedword(address: integer, data: integer)
  -> nil

memory.writeqword

Writes an unsigned qword consisting of a table with the upper and lower 4 bytes to memory at address.

function memory.writeqword(address: integer, data: integer[])
  -> nil

memory.writefloat

Writes a float to memory at address.

function memory.writefloat(address: integer, data: number)
  -> nil

memory.writedouble

Writes a double to memory at address.

function memory.writedouble(address: integer, data: number)
  -> nil

memory.writesize

Writes size bytes to memory at address. The memory is treated as signed if size is is negative.

size:
    | 1
    | 2
    | 4
    | 8
    | -1
    | -2
    | -4
    | -8
function memory.writesize(address: integer, size: -1|-2|-4|-8|1...(+3), data: integer|integer[])
  -> nil

WGUI FUNCTIONS


wgui.setbrush

Sets the current GDI brush color to color

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.setbrush(color: string|"black"|"blue"|"chartreuse"|"clear"...(+9))

wgui.setpen

GDI: Sets the current GDI pen color to color

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.setpen(color: string|"black"|"blue"|"chartreuse"|"clear"...(+9), width?: number)

wgui.setcolor

GDI: Sets the current GDI text color to color

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.setcolor(color: string|"black"|"blue"|"chartreuse"|"clear"...(+9))

wgui.setbk

GDI: Sets the current GDI background color to color

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.setbk(color: string|"black"|"blue"|"chartreuse"|"clear"...(+9))

wgui.setfont

Sets the font, font size, and font style

@param size — The size of the font. Defaults to 0 if not given

@param font — The name of the font from the operating system. Dafaults to "MS Gothic" if not given

@param style — Each character in this string sets one style of the font, applied in chronological order. b sets bold, i sets italics, u sets underline, s sets strikethrough, and a sets antialiased. Defaults to "" if not given

function wgui.setfont(size?: integer, font?: string, style?: string)

wgui.text

This function is deprecated. See the api file for more details.

GDI: Displays text in one line with the current GDI background color and GDI text color

function wgui.text(x: integer, y: integer, text: string)

wgui.drawtext

GDI: Draws text in the specified rectangle and with the specified format.

@param text — The text to be drawn.

@param rect — The rectangle in which to draw the text.

@param format — The format of the text. Applied in order stated. "l" aligns the text to the left (applied by default). "r" aligns the text to the right. "t" aligns text to the right (applied by default). "b" aligns text to the bottom. "c" horizontally aligns text. "v" vertically aligns the text. "e" adds ellipses if a line cannof fit all text. "s" forces text to be displayed on a single line.

function wgui.drawtext(text: string, rect: { l: integer, t: integer, r: integer, b: integer }|{ l: integer, t: integer, w: integer, h: integer }, format?: string)

wgui.drawtextalt

This function is deprecated. See the api file for more details.

Uses an alternate function for drawing text.

function wgui.drawtextalt(text: string, format: integer, left: integer, top: integer, right: integer, bottom: integer)

wgui.gettextextent

Gets the width and height of the given text.

function wgui.gettextextent(text: string)
  -> { width: integer, height: integer }

wgui.rect

GDI: Draws a rectangle at the specified coordinates with the current GDI background color and a border of the GDI pen color. Only use this function if you need rounded corners, otherwise, use wgui.fillrecta.

@param rounded_width — The width of the ellipse used to draw the rounded corners.

@param rounded_height — The height of the ellipse used to draw the rounded corners.

function wgui.rect(left: integer, top: integer, right: integer, bottom: integer, rounded_width?: integer, rounded_height?: integer)

wgui.fillrect

This function is deprecated. See the api file for more details.

Draws a rectangle at the specified coordinates with the specified color.

function wgui.fillrect(left: integer, top: integer, right: integer, bottom: integer, red: integer, green: integer, blue: integer)

wgui.fillrecta

GDIPlus: Draws a rectangle at the specified coordinates, size and color.

@param color — Color names are currently broken

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.fillrecta(x: integer, y: integer, w: integer, h: integer, color: string|"black"|"blue"|"chartreuse"|"clear"...(+9))

wgui.fillellipsea

GDIPlus: Draws an ellipse at the specified coordinates, size, and color

@param color — Color names are currently broken

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.fillellipsea(x: integer, y: integer, w: integer, h: integer, color: string|"black"|"blue"|"chartreuse"|"clear"...(+9))

wgui.fillpolygona

Draws a filled in polygon using the points in points

@param points — Ex: \{\{x1, y1\}, \{x2, y2\}, \{x3, y3\}\}

@param color — Color names are currently broken

--  colors can be any of these or "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBA"
color:
    | "white"
    | "black"
    | "clear"
    | "gray"
    | "red"
    | "orange"
    | "yellow"
    | "chartreuse"
    | "green"
    | "teal"
    | "cyan"
    | "blue"
    | "purple"
function wgui.fillpolygona(points: integer[][], color: string|"black"|"blue"|"chartreuse"|"clear"...(+9))

wgui.loadimage

Loads an image file from path and returns the identifier of that image

function wgui.loadimage(path: string)
  -> integer

wgui.deleteimage

Clears one of all images

@param idx — The identifier of the image to clear. If it is 0, clear all iamges

function wgui.deleteimage(idx: integer)

wgui.drawimage

Draws the image at index idx at the specified coordinates

function wgui.drawimage(idx: integer, x: integer, y: integer)

wgui.drawimage

Draws the image at index idx at the specified coordinates and scale

function wgui.drawimage(idx: integer, x: integer, y: integer, s: number)

wgui.drawimage

Draws the image at index idx at the specified coordinates and size

function wgui.drawimage(idx: integer, x: integer, y: integer, w: integer, h: integer)

wgui.drawimage

Draws the image at index idx at the specified coordinates, size, and rotation, using a part of the source image given by the src parameters

function wgui.drawimage(idx: integer, x: integer, y: integer, w: integer, h: integer, srcx: integer, srcy: integer, srcw: integer, srch: integer, rotate: number)

wgui.loadscreen

Captures the current screen and saves it as an image

@return The — identifier of the saved image

function wgui.loadscreen()
  -> The: integer

wgui.loadscreenreset

Re-initializes loadscreen

function wgui.loadscreenreset()

wgui.getimageinfo

Returns the width and height of the image at idx

function wgui.getimageinfo(idx: integer)
  -> { width: integer, height: integer }

wgui.ellipse

Draws an ellipse at the specified coordinates and size. Uses the GDI brush color for the background and a border of the GDI pen color

function wgui.ellipse(left: integer, top: integer, right: integer, bottom: integer)

wgui.polygon

Draws a polygon with the given points. Uses the GDI brush color for the background and a border of the GDI pen color

function wgui.polygon(points: integer[][])

wgui.line

Draws a line from (x1, y1) to (x2, y2)

function wgui.line(x1: integer, y1: integer, x2: integer, y2: integer)

wgui.info

Returns the current width and height of the mupen window in a table

function wgui.info()
  -> { width: integer, height: integer }

wgui.resize

Resizes the mupen window to w x h

function wgui.resize(w: integer, h: integer)

wgui.setclip

Sets a rectangle bounding box such that you cannot draw outside of it.

function wgui.setclip(x: integer, y: integer, w: integer, h: integer)

wgui.resetclip

Resets the clip

function wgui.resetclip()

D2D FUNCTIONS


d2d.create_brush

Creates a brush from a color and returns it. D2D colors range from 0 to 1

function d2d.create_brush(r: number, g: number, b: number, a: number)
  -> integer

d2d.free_brush

Frees a brush. It is a good practice to free all brushes after you are done using them

function d2d.free_brush(brush: integer)

d2d.clear

Sets clear behavior. If this function is never called, the screen will not be cleared. If it is called, the screen will be cleared with the specified color

function d2d.clear(r: number, g: number, b: number, a: number)

d2d.fill_rectangle

Draws a filled in rectangle at the specified coordinates and color.

function d2d.fill_rectangle(x1: integer, y1: integer, x2: integer, y2: integer, brush: integer)
  -> nil

d2d.draw_rectangle

Draws the border of a rectangle at the specified coordinates and color.

function d2d.draw_rectangle(x1: integer, y1: integer, x2: integer, y2: integer, thickness: number, brush: integer)
  -> nil

d2d.fill_ellipse

Draws a filled in ellipse at the specified coordinates and color.

function d2d.fill_ellipse(x: integer, y: integer, radiusX: integer, radiusY: integer, brush: integer)
  -> nil

d2d.draw_ellipse

Draws the border of an ellipse at the specified coordinates and color.

function d2d.draw_ellipse(x: integer, y: integer, radiusX: integer, radiusY: integer, thickness: number, brush: integer)
  -> nil

d2d.draw_line

Draws a line from (x1, y1) to (x2, y2) in the specified color.

function d2d.draw_line(x1: integer, y1: integer, x2: integer, y2: integer, thickness: number, brush: integer)
  -> nil

d2d.draw_text

Draws the text text at the specified coordinates, color, font, and alignment.

@param fontstyle — 0: normal, 1: bold, 2: italic, 3: bold + italic.

@param brush — pass 0 if you don't know what you're doing

fontstyle:
    | 0
    | 1
    | 2
    | 3
function d2d.draw_text(x1: integer, y1: integer, x2: integer, y2: integer, text: string, fontname: string, fontsize: number, fontweight: number, fontstyle: 0|1|2|3, horizalign: integer, vertalign: integer, options: integer, brush: integer)
  -> nil

d2d.get_text_size

Returns the width and height of the specified text.

function d2d.get_text_size(text: string, fontname: string, fontsize: number, max_width: number, max_height: number)
  -> { width: integer, height: integer }

d2d.push_clip

Specifies a rectangle to which all subsequent drawing operations are clipped. This clip is put onto a stack. It can then be popped off the stack with wgui.d2d_pop_clip.

function d2d.push_clip(x1: integer, y1: integer, x2: integer, y2: integer)
  -> nil

d2d.pop_clip

Pops the most recent clip off the clip stack.

function d2d.pop_clip()
  -> nil

d2d.fill_rounded_rectangle

Draws a filled in rounded rectangle at the specified coordinates, color and radius.

function d2d.fill_rounded_rectangle(x1: integer, y1: integer, x2: integer, y2: integer, radiusX: number, radiusY: number, brush: integer)
  -> nil

d2d.draw_rounded_rectangle

Draws the border of a rounded rectangle at the specified coordinates, color and radius.

function d2d.draw_rounded_rectangle(x1: integer, y1: integer, x2: integer, y2: integer, radiusX: number, radiusY: number, thickness: number, brush: integer)
  -> nil

d2d.load_image

Loads an image file from path which you can then access through identifier.

function d2d.load_image(path: string)
  -> integer

d2d.free_image

Frees the image at identifier.

function d2d.free_image(identifier: number)
  -> nil

d2d.draw_image

Draws an image by taking the pixels in the source rectangle of the image, and drawing them to the destination rectangle on the screen.

@param interpolation — 0: nearest neighbor, 1: linear, -1: don't use.

function d2d.draw_image(destx1: integer, desty1: integer, destx2: integer, desty2: integer, srcx1: integer, srcy1: integer, srcx2: integer, srcy2: integer, opacity: number, interpolation: integer, identifier: number)
  -> nil

d2d.get_image_info

Returns the width and height of the image at identifier.

function d2d.get_image_info(identifier: number)
  -> { width: integer, height: integer }

d2d.set_text_antialias_mode

Sets the text antialiasing mode. More info here.

mode:
    | 0
    | 1
    | 2
    | 3
    | 4294967295
function d2d.set_text_antialias_mode(mode: 0|1|2|3|4294967295)

d2d.set_antialias_mode

Sets the antialiasing mode. More info here.

mode:
    | 0
    | 1
    | 4294967295
function d2d.set_antialias_mode(mode: 0|1|4294967295)

d2d.draw_to_image

Draws to an image and returns its identifier

function d2d.draw_to_image(width: integer, height: integer, callback: fun())
  -> number

INPUT FUNCTIONS


input.get

Returns the state of all keyboard keys and the mouse position in a table. Ex: input.get() -> {xmouse=297, ymouse=120, A=true, B=true}.

function input.get()
  -> table

input.diff

Returns the differences between t1 and t2. For example, if t1 is the inputs for this frame, and t2 is the inputs for last frame, it would return which buttons were pressed this frame, not which buttons are active.

function input.diff(t1: table, t2: table)
  -> table

input.prompt

Opens a window where the user can input text. If OK is clicked, that text is returned. If Cancel is clicked or the window is closed, nil is returned.

@param title — The title of the text box. Defaults to "input:".

@param placeholder — The text box is filled with this string when it opens. Defaults to "".

function input.prompt(title?: string, placeholder?: string)
  -> string|nil

input.get_key_name_text

Gets the name of a key

function input.get_key_name_text(key: integer)
  -> string

JOYPAD FUNCTIONS


joypad.get

Gets the currently pressed game buttons and stick direction for a given port. Note that the y coordinate of the stick is the opposite of what is shown on TAS Input.

port:
    | 1
    | 2
    | 3
    | 4
function joypad.get(port: 1|2|3|4)
  -> table

joypad.set

Sets the current joypad to inputs. If you do not specify one or more inputs, they will be set to false for buttons or 0 for stick coordinates.

port:
    | 1
    | 2
    | 3
    | 4
function joypad.set(port: 1|2|3|4, inputs: table)
  -> nil

joypad.count

Returns the number of input frames that have happened since the emulator was started. It does not reset when a movie is started. Alias for emu.inputcount.

@return inputcount — The number of input frames that have happened since the emulator was started.

function joypad.count()
  -> inputcount: integer

MOVIE FUNCTIONS


movie.play

Plays a movie file located at filename. This function sets Read Only to true.

function movie.play(filename: string)
  -> nil

movie.stop

Stops the currently playing movie.

function movie.stop()
  -> nil

movie.get_filename

Returns the filename of the currently playing movie. It will error if no movie is playing.

function movie.get_filename()
  -> string

movie.get_readonly

Returns true if the currently playing movie is read only

function movie.get_readonly()
  -> boolean

movie.set_readonly

Set's the currently movie's readonly state to readonly

function movie.set_readonly(readonly: boolean)

movie.begin_seek

Begins seeking

function movie.begin_seek(str: string, pause_at_end: boolean)
  -> integer

movie.stop_seek

Stops seeking

function movie.stop_seek()

movie.is_seeking

Returns whether the emulator is currently seeking

function movie.is_seeking()
  -> boolean

movie.get_seek_completion

Gets info about the current seek

function movie.get_seek_completion()
  -> [integer, integer]

movie.begin_warp_modify

Begins a warp modify

function movie.begin_warp_modify(inputs: { [string]: boolean }[])

SAVESTATE FUNCTIONS


savestate.savefile

Saves a savestate to filename.

function savestate.savefile(filename: string)
  -> nil

savestate.loadfile

Loads a savestate from filename

function savestate.loadfile(filename: string)
  -> nil

IOHELPER FUNCTIONS


iohelper.filediag

Opens a file dialouge and returns the file path of the file chosen.

@param filter — This string acts as a filter for what files can be chosen. For example *.* selects all files, where *.txt selects only text files.

@param type — Unknown.

function iohelper.filediag(filter: string, type: integer)
  -> string

AVI FUNCTIONS


avi.startcapture

Begins an avi recording using the previously saved encoding settings. It is saved to filename.

function avi.startcapture(filename: string)
  -> nil

avi.stopcapture

Stops avi recording.

function avi.stopcapture()
  -> nil