Created
September 13, 2026 15:28
-
-
Save holly-hacker/91fa10aee3da280d12f412ad9ffd2146 to your computer and use it in GitHub Desktop.
Haxe interop for MGBA, when compiling use `--define lua-vanilla`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mgba; | |
| import haxe.Int64; | |
| import lua.Table; | |
| /** Native mGBA scalar types. Haxe/Lua represents all 8/16/32-bit integers as | |
| * Lua numbers; these aliases preserve the API's signedness in type signatures. */ | |
| typedef U8 = UInt; | |
| typedef U16 = UInt; | |
| typedef U32 = UInt; | |
| typedef S8 = Int; | |
| typedef S16 = Int; | |
| typedef S32 = Int; | |
| typedef U64 = Int64; | |
| typedef S64 = Int64; | |
| typedef F32 = Float; | |
| /** Named callbacks currently documented by mGBA; arbitrary strings remain accepted for forward compatibility. */ | |
| enum abstract CallbackName(String) from String to String { | |
| var Alarm = "alarm"; | |
| var Crashed = "crashed"; | |
| var Frame = "frame"; | |
| var KeysRead = "keysRead"; | |
| var Reset = "reset"; | |
| var Rumble = "rumble"; | |
| var SaveDataUpdated = "savedataUpdated"; | |
| var Sleep = "sleep"; | |
| var Shutdown = "shutdown"; | |
| var Start = "start"; | |
| var Stop = "stop"; | |
| var MemoryBlocksChanged = "memoryBlocksChanged"; | |
| } | |
| /** A raw, 1-indexed Lua sequence (`list` in mGBA's documentation). */ | |
| typedef LuaList<T> = Table<Int, T>; | |
| /** A raw Lua table (`table` in mGBA's documentation). */ | |
| typedef LuaTable<K, V> = Table<K, V>; | |
| /** | |
| * Typed access to mGBA's Lua scripting globals. | |
| * | |
| * Compile this code with the Lua target. mGBA supplies the globals at run | |
| * time; this module does not load a Lua library. `LuaList` and `LuaTable` are | |
| * raw Lua tables, rather than Haxe `Array` or `Map` values. | |
| */ | |
| class MGBA { | |
| /** The scripting-aware emulator core; available after a game is loaded. */ | |
| public static inline function emu():CoreAdapter return untyped __lua__("emu"); | |
| /** The global callback manager. */ | |
| public static inline function callbacks():CallbackManager return untyped __lua__("callbacks"); | |
| /** The canvas used to display script-created layers. */ | |
| public static inline function canvas():CanvasContext return untyped __lua__("canvas"); | |
| /** The global textual console. */ | |
| public static inline function console():Console return untyped __lua__("console"); | |
| /** Current keyboard and gamepad state. */ | |
| public static inline function input():InputContext return untyped __lua__("input"); | |
| /** Persistent storage for the current script. */ | |
| public static inline function storage():StorageContext return untyped __lua__("storage"); | |
| /** Build information for the running mGBA program. */ | |
| public static inline function system():SystemInfo return untyped __lua__("system"); | |
| /** The exported constant table (`C`). */ | |
| public static inline function constants():Constants return untyped __lua__("C"); | |
| /** Paths for the currently loaded Lua script. */ | |
| public static inline function script():ScriptInfo return untyped __lua__("script"); | |
| } | |
| /** An instance of an emulator core. */ | |
| extern class Core { | |
| /** Add a single key to the currently active key list */ | |
| function addKey(key:S32):Void; | |
| /** Add a bitmask of keys to the currently active key list */ | |
| function addKeys(keys:U32):Void; | |
| /** Load the save data associated with the currently loaded ROM file */ | |
| function autoloadSave():Bool; | |
| /** Get the checksum of the loaded ROM */ | |
| function checksum(?type:S32):String; | |
| /** Remove a single key from the currently active key list */ | |
| function clearKey(key:S32):Void; | |
| /** Remove a bitmask of keys from the currently active key list */ | |
| function clearKeys(keys:U32):Void; | |
| /** Get the number of the current frame */ | |
| function currentFrame():U32; | |
| /** Get the number of cycles per frame */ | |
| function frameCycles():S32; | |
| /** Get the number of cycles per second */ | |
| function frequency():S32; | |
| /** Get internal product code for the game from the ROM header, if available */ | |
| function getGameCode():String; | |
| /** Get internal title of the game from the ROM header */ | |
| function getGameTitle():String; | |
| /** Get the active state of a given key */ | |
| function getKey(key:S32):S32; | |
| /** Get the currently active keys as a bitmask */ | |
| function getKeys():U32; | |
| /** Load a ROM file into the current state of this core */ | |
| function loadFile(path:String):Bool; | |
| /** Load save data from the given path. If the `temporary` flag is set, the given save data will not be written back to disk */ | |
| function loadSaveFile(path:String, temporary:Bool):Bool; | |
| /** Load state from a buffer. See C.SAVESTATE for possible values for `flags` */ | |
| function loadStateBuffer(buffer:String, ?flags:S32):Bool; | |
| /** Load state from the given path. See C.SAVESTATE for possible values for `flags` */ | |
| function loadStateFile(path:String, ?flags:S32):Bool; | |
| /** Load state from the slot number. See C.SAVESTATE for possible values for `flags` */ | |
| function loadStateSlot(slot:S32, ?flags:S32):Bool; | |
| /** Get which platform is being emulated. See C.PLATFORM for possible values */ | |
| function platform():S32; | |
| /** Read an 8-bit value from the given bus address */ | |
| function read8(address:U32):U32; | |
| /** Read a 16-bit value from the given bus address */ | |
| function read16(address:U32):U32; | |
| /** Read a 32-bit value from the given bus address */ | |
| function read32(address:U32):U32; | |
| /** Read byte range from the given offset */ | |
| function readRange(address:U32, length:U32):String; | |
| /** Read the value of the register with the given name */ | |
| function readRegister(regName:String):Dynamic; | |
| /** Reset the emulation. This does not invoke the **reset** callback */ | |
| function reset():Void; | |
| /** Get the size of the loaded ROM */ | |
| function romSize():S64; | |
| /** Run until the next frame */ | |
| function runFrame():Void; | |
| /** Save state and return as a buffer. See C.SAVESTATE for possible values for `flags` */ | |
| function saveStateBuffer(?flags:S32):String; | |
| /** Save state to the given path. See C.SAVESTATE for possible values for `flags` */ | |
| function saveStateFile(path:String, ?flags:S32):Bool; | |
| /** Save state to the slot number. See C.SAVESTATE for possible values for `flags` */ | |
| function saveStateSlot(slot:S32, ?flags:S32):Bool; | |
| /** Save a screenshot to a file */ | |
| function screenshot(?filename:String):Void; | |
| /** Get a screenshot in an struct::mImage */ | |
| function screenshotToImage():Image; | |
| /** Set the currently active key list */ | |
| function setKeys(keys:U32):Void; | |
| /** Run a single instruction */ | |
| function step():Void; | |
| /** Write an 8-bit value from the given bus address */ | |
| function write8(address:U32, value:U8):Void; | |
| /** Write a 16-bit value from the given bus address */ | |
| function write16(address:U32, value:U16):Void; | |
| /** Write a 32-bit value from the given bus address */ | |
| function write32(address:U32, value:U32):Void; | |
| /** Write the value of the register with the given name */ | |
| function writeRegister(regName:String, value:S32):Void; | |
| } | |
| /** A wrapper around a struct::mCore object that exposes more functionality. It can be implicity cast to a Core object, and exposes the same methods. Please see the documentation on struct::mCore for details on those methods. */ | |
| extern class CoreAdapter extends Core { | |
| var core(default, null):Core; | |
| /** A table containing a platform-specific set of struct::mScriptMemoryDomain objects */ | |
| var memory(default, null):MemoryDomains; | |
| /** Clear a breakpoint or watchpoint for a given id returned by a previous call */ | |
| function clearBreakpoint(cbid:S64):Bool; | |
| /** Get the current execution cycle */ | |
| function currentCycle():U64; | |
| /** Set a breakpoint at a given address */ | |
| function setBreakpoint(callback:Void->Void, address:U32, ?segment:S32):S64; | |
| /** Set a watchpoint in a given range of a given type. Note that the range is exclusive on the end, as though you've added the size, i.e. a 4-byte watch would specify the maximum as the minimum address + 4 */ | |
| function setRangeWatchpoint(callback:Void->Void, minAddress:U32, maxAddress:U32, type:S32, ?segment:S32):S64; | |
| /** | |
| * Sets the table of functions to be called when the game requests rotation data, for either a gyroscope or accelerometer. The following functions are supported, and if any isn't set then then default implementation for that function is called instead: | |
| * | |
| * - `sample`: Update ("sample") the values returned by the other functions. The values returned shouldn't change until the next time this is called | |
| * - `readTiltX`: Return a value between -1.0 and +1.0 representing the X (left/right axis) direction of the linear acceleration vector, as for an accelerometer. | |
| * - `readTiltY`: Return a value between -1.0 and +1.0 representing the Y (up/down axis) direction of the linear acceleration vector, as for an accelerometer. | |
| * - `readGyroZ`: Return a value between -1.0 and +1.0 representing the roll (front/back axis) value of the rotational acceleration vector, as for an gyroscope. | |
| * | |
| * Optionally, you can also set a value `context` on the table that will be passed to the callbacks. This table is copied by value, so changes made to the table after being passed to this function will not be seen unless the function is called again. Therefore, the recommended usage of the `context` field is as an index or key into a separate table. Use cases may vary. If this function is called more than once, the previous value of the table is returned. | |
| */ | |
| function setRotationCallbacks(callbacks:RotationCallbacks):RotationCallbacks; | |
| /** Set a callback that will be used to get the current value of the solar sensors between 0 (darkest) and 255 (brightest). Note that the full range of values is not used by games, and the exact range depends on the calibration done by the game itself. */ | |
| function setSolarSensorCallback(callback:Void->U8):Void; | |
| /** Set a watchpoint at a given address of a given type */ | |
| function setWatchpoint(callback:Void->Void, address:U32, type:S32, ?segment:S32):S64; | |
| } | |
| /** An object used for access directly to a memory domain, e.g. the cartridge, instead of through a whole address space, as with the functions directly on struct::mCore. */ | |
| extern class MemoryDomain { | |
| /** Get the address of the base of this memory domain */ | |
| function base():U32; | |
| /** Get the address of the end bound of this memory domain. Note that this address is not in the domain itself, and is the address of the first byte past it */ | |
| function bound():U32; | |
| /** Get a short, human-readable name for this memory domain */ | |
| function name():String; | |
| /** Read an 8-bit value from the given offset */ | |
| function read8(address:U32):U32; | |
| /** Read a 16-bit value from the given offset */ | |
| function read16(address:U32):U32; | |
| /** Read a 32-bit value from the given offset */ | |
| function read32(address:U32):U32; | |
| /** Read byte range from the given offset */ | |
| function readRange(address:U32, length:U32):String; | |
| /** Get the size of this memory domain in bytes */ | |
| function size():U32; | |
| /** Write an 8-bit value from the given offset */ | |
| function write8(address:U32, value:U8):Void; | |
| /** Write a 16-bit value from the given offset */ | |
| function write16(address:U32, value:U16):Void; | |
| /** Write a 32-bit value from the given offset */ | |
| function write32(address:U32, value:U32):Void; | |
| } | |
| /** A single, static image. */ | |
| extern class Image { | |
| /** The height of the image, in pixels */ | |
| var height(default, null):U32; | |
| /** The width of the image, in pixels */ | |
| var width(default, null):U32; | |
| /** Draw another image onto this image with alpha blending as needed, optionally specifying a coefficient for adjusting the opacity */ | |
| function drawImage(image:Image, x:U32, y:U32, ?alpha:F32):Void; | |
| /** Draw another image onto this image without any alpha blending, overwriting what was already there */ | |
| function drawImageOpaque(image:Image, x:U32, y:U32):Void; | |
| /** Get the ARGB value of the pixel at a given coordinate */ | |
| function getPixel(x:U32, y:U32):U32; | |
| /** Save the image to a file. Currently, only `PNG` format is supported */ | |
| function save(path:String, ?format:String):Bool; | |
| /** Set the ARGB value of the pixel at a given coordinate */ | |
| function setPixel(x:U32, y:U32, color:U32):Void; | |
| } | |
| /** Functions in mGBA's global `image` namespace (Lua dot calls). */ | |
| @:native("image") | |
| /** Methods for creating struct::mImage and struct::mPainter instances */ | |
| extern class ImageApi { | |
| /** Load an image from a path. Currently, only `PNG` format is supported */ | |
| static function load(path:String):Image; | |
| /** Create an image with the given dimensions. */ | |
| @:native("new") static function create(width:U32, height:U32):Image; | |
| /** Create a new painter from an existing image */ | |
| static function newPainter(image:Image):Painter; | |
| } | |
| /** A stateful object useful for performing drawing operations on an struct::mImage. */ | |
| extern class Painter { | |
| /** Draw a circle with the specified diameter with the given origin at the top-left corner of the bounding box */ | |
| function drawCircle(x:S32, y:S32, diameter:S32):Void; | |
| /** Draw a line with the specified endpoints */ | |
| function drawLine(x1:S32, y1:S32, x2:S32, y2:S32):Void; | |
| /** Draw a mask image with each color channel multiplied by the current fill color. This can be useful for displaying graphics with dynamic colors. By making a grayscale template image on a transparent background in advance, a script can set the fill color to a desired target color and use this function to draw it into a destination image. */ | |
| function drawMask(mask:Image, x:S32, y:S32):Void; | |
| /** Draw a rectangle with the specified dimensions */ | |
| function drawRectangle(x:S32, y:S32, width:S32, height:S32):Void; | |
| /** Draw text with the currently set font and fill color */ | |
| function drawText(text:String, x:S32, y:S32, ?alignment:S32):Void; | |
| /** Load a font from a given filename */ | |
| function loadFont(path:String):Void; | |
| /** Set whether or not alpha blending should be enabled when drawing */ | |
| function setBlend(enable:Bool):Void; | |
| /** Set whether or not the fill color should be applied when drawing */ | |
| function setFill(enable:Bool):Void; | |
| /** Set the fill color to be used when drawing */ | |
| function setFillColor(color:U32):Void; | |
| /** Set the font size */ | |
| function setFontSize(pt:F32):Void; | |
| /** Set the stroke color to be used when drawing */ | |
| function setStrokeColor(color:U32):Void; | |
| /** Set the stroke width to be used when drawing, or 0 to disable */ | |
| function setStrokeWidth(width:U32):Void; | |
| /** Get the bounding box size for the given string rendered in the current font. This will take into account line breaks, unlike struct::mPainter.textRunMetrics. */ | |
| function textBoxSize(text:String):Size; | |
| /** Get the struct::mTextRunMetrics for the first line of a given string rendered in the current font. If you want the bounding box for multiple lines, use struct::mPainter.textBoxSize instead. */ | |
| function textRunMetrics(text:String):TextRunMetrics; | |
| } | |
| /** A basic axis-aligned rectangle object */ | |
| extern class Rectangle { | |
| /** The x coordinate of the top-left corner */ | |
| var x:S32; | |
| /** The y coordinate of the top-left corner */ | |
| var y:S32; | |
| /** The width of the rectangle */ | |
| var width:S32; | |
| /** The height of the rectangle */ | |
| var height:S32; | |
| /** Center another rectangle inside this one */ | |
| function center(other:Rectangle):Void; | |
| /** Create a copy of this struct::mRectangle */ | |
| function copy():Rectangle; | |
| /** Find the intersection of this and another rectangle. Returns false if the rectangles don't intersect */ | |
| function intersection(other:Rectangle):Bool; | |
| /** Return the size of this struct::mRectangle as a struct::mSize object */ | |
| function size():Size; | |
| /** Find the bounding box of the union of this and another rectangle */ | |
| function union(other:Rectangle):Void; | |
| } | |
| /** A basic size (width/height) object */ | |
| extern class Size { | |
| /** The width */ | |
| var width:S32; | |
| /** The height */ | |
| var height:S32; | |
| /** Create a copy of this struct::mSize */ | |
| function copy():Size; | |
| } | |
| /** Metrics for the size of a run of text. Generally, a run will represent up to a single line of text. */ | |
| extern class TextRunMetrics { | |
| /** Get the distance from the baseline to the top of the line, in pixels */ | |
| function ascender():F32; | |
| /** Get the distance from the baseline to the bottom of the line, in pixels */ | |
| function descender():F32; | |
| /** Get the height of the run of text, in pixels */ | |
| function height():F32; | |
| /** Get the width of the run of text, in pixels */ | |
| function width():F32; | |
| } | |
| /** | |
| * A global singleton object `callbacks` used for managing callbacks. The following callbacks are defined: | |
| * | |
| * - `alarm`: An in-game alarm went off | |
| * - `crashed`: The emulation crashed | |
| * - `frame`: The emulation finished a frame | |
| * - `keysRead`: The emulation is about to read the key input | |
| * - `reset`: The emulation has been reset | |
| * - `rumble`: The state of the rumble motor was changed. This callback is passed a single argument that specifies if it was turned on (true) or off (false) | |
| * - `savedataUpdated`: The emulation has just finished modifying save data | |
| * - `sleep`: The emulation has used the sleep feature to enter a low-power mode | |
| * - `shutdown`: The emulation has been powered off | |
| * - `start`: The emulation has started | |
| * - `stop`: The emulation has voluntarily shut down | |
| * - `memoryBlocksChanged`: The list list of struct::mScriptCoreAdapter.memory domains has changed | |
| */ | |
| extern class CallbackManager { | |
| /** Callback arguments depend on `callback` (for example, `rumble` receives Bool). */ | |
| /** Add a callback of the named type. The returned id can be used to remove it later */ | |
| function add(callback:CallbackName, fn:Dynamic):U32; | |
| /** Add a one-shot callback of the named type that will be automatically removed after called. The returned id can be used to remove it early */ | |
| function oneshot(callback:CallbackName, fn:Dynamic):U32; | |
| /** Remove a callback with the previously retuned id */ | |
| function remove(cbid:U32):Void; | |
| } | |
| /** A canvas that can be used for drawing images on or around the screen. */ | |
| extern class CanvasContext { | |
| /** Get the height of the canvas */ | |
| function height():U32; | |
| /** Create a new layer of a given size. If multiple layers overlap, the most recently created one takes priority. */ | |
| function newLayer(width:S32, height:S32):CanvasLayer; | |
| /** Get the height of the emulated screen */ | |
| function screenHeight():S32; | |
| /** Get the width of the emulated screen */ | |
| function screenWidth():S32; | |
| /** Update all layers marked as having pending changes */ | |
| function update():Void; | |
| /** Get the width of the canvas */ | |
| function width():U32; | |
| } | |
| /** An individual layer of a drawable canvas. */ | |
| extern class CanvasLayer { | |
| /** The image that has the pixel contents of the image */ | |
| var image:Image; | |
| /** The current x (horizontal) position of this layer */ | |
| var x(default, null):S32; | |
| /** The current y (vertical) position of this layer */ | |
| var y(default, null):S32; | |
| /** Set the position of the layer in the canvas */ | |
| function setPosition(x:S32, y:S32):Void; | |
| /** Mark the contents of the layer as needed to be repainted */ | |
| function update():Void; | |
| } | |
| /** A global singleton object `console` that can be used for presenting textual information to the user via a console. */ | |
| extern class Console { | |
| /** Create a text buffer that can be used to display custom information */ | |
| function createBuffer(?name:String):TextBuffer; | |
| /** Print an error to the console */ | |
| function error(msg:String):Void; | |
| /** Print a log to the console */ | |
| function log(msg:String):Void; | |
| /** Print a warning to the console */ | |
| function warn(msg:String):Void; | |
| } | |
| /** An object that can be used to present texual data to the user. It is displayed monospaced, and text can be edited after sending by moving the cursor or clearing the buffer. */ | |
| extern class TextBuffer { | |
| /** Advance the cursor a number of columns */ | |
| function advance(adv:S32):Void; | |
| /** Clear the buffer */ | |
| function clear():Void; | |
| /** Get number of columns in the buffer */ | |
| function cols():U32; | |
| /** Get the current x position of the cursor */ | |
| function getX():U32; | |
| /** Get the current y position of the cursor */ | |
| function getY():U32; | |
| /** Set the position of the cursor */ | |
| function moveCursor(x:U32, y:U32):Void; | |
| /** Print a string to the buffer */ | |
| function print(text:String):Void; | |
| /** Get number of rows in the buffer */ | |
| function rows():U32; | |
| /** Set the user-visible name of this buffer */ | |
| function setName(name:String):Void; | |
| /** Set the number of rows and columns */ | |
| function setSize(cols:U32, rows:U32):Void; | |
| } | |
| extern class InputContext { | |
| /** The currently active gamepad, if any */ | |
| var activeGamepad(default, null):Null<Gamepad>; | |
| /** Sequence number of the next event to be emitted */ | |
| var seq(default, null):U64; | |
| /** Get a list of the currently active keys. The values are Unicode codepoints or special key values from C.KEY, not strings, so make sure to convert as needed */ | |
| function activeKeys():LuaList<U32>; | |
| @:overload(function(key:String):Bool {}) | |
| /** Check if a given keyboard key is currently held. The input can be either the printable character for a key, the numerical Unicode codepoint, or a special value from C.KEY */ | |
| function isKeyActive(key:U32):Bool; | |
| } | |
| extern class Gamepad { | |
| /** An indexed list of the current values of each axis */ | |
| var axes(default, null):LuaList<F32>; | |
| /** An indexed list of the current values of each button */ | |
| var buttons(default, null):LuaList<Dynamic>; | |
| /** An indexed list of the current values of POV hat */ | |
| var hats(default, null):LuaList<Dynamic>; | |
| /** The internal name of this gamepad, generally unique to the specific type of gamepad */ | |
| var internalName(default, null):String; | |
| /** The human-readable name of this gamepad */ | |
| var visibleName(default, null):String; | |
| } | |
| /** The base class for all event types. Different events have their own subclasses. */ | |
| extern class Event { | |
| /** Sequence number of this event. This value increases monotinically. */ | |
| var seq(default, null):U64; | |
| /** The type of this event. See C.EV_TYPE for a list of possible types. */ | |
| var type(default, null):S32; | |
| } | |
| /** A gamepad button event. */ | |
| extern class GamepadButtonEvent extends Event { var button(default, null):U16; var pad(default, null):U8; var state(default, null):U8; } | |
| /** A gamepad POV hat event. */ | |
| extern class GamepadHatEvent extends Event { var direction(default, null):U8; var hat(default, null):U8; var pad(default, null):U8; } | |
| /** A keyboard key event. */ | |
| extern class KeyEvent extends Event { var key(default, null):S32; var modifiers(default, null):S16; var state(default, null):U8; } | |
| /** A mouse button event. */ | |
| extern class MouseButtonEvent extends Event { var button(default, null):U8; var mouse(default, null):U8; var state(default, null):U8; } | |
| /** A mouse movement event. */ | |
| extern class MouseMoveEvent extends Event { var mouse(default, null):U8; var x(default, null):S32; var y(default, null):S32; } | |
| /** A mouse-wheel event. `x` and `y` are horizontal and vertical scroll amounts. */ | |
| extern class MouseWheelEvent extends Event { var mouse(default, null):U8; var x(default, null):S32; var y(default, null):S32; } | |
| /** Singleton persistent storage for the current script. */ | |
| extern class StorageContext { | |
| /** Flush all buckets to disk manually. */ | |
| function flushAll():Void; | |
| /** Get or create a named bucket. Names allow letters, digits, underscores, and periods. */ | |
| function getBucket(key:String):StorageBucket; | |
| } | |
| /** A persistent bucket whose user-defined fields can hold primitive values, lists, and tables. */ | |
| @:dynamic extern class StorageBucket { | |
| /** Enable or disable automatic flushing. Re-enable it or call `flush` after an atomic update. */ | |
| function enableAutoFlush(enable:Bool):Void; | |
| /** Flush this bucket to disk manually. */ | |
| function flush():Bool; | |
| /** Reload this bucket's state from disk. */ | |
| function reload():Bool; | |
| } | |
| /** Functions in mGBA's global `util` namespace (Lua dot calls). */ | |
| @:native("util") | |
| /** Basic utility library */ | |
| extern class Util { | |
| /** Expand a bitmask into a list of bit indices */ | |
| static function expandBitmask(mask:U64):LuaList<U32>; | |
| /** Compile a list of bit indices into a bitmask */ | |
| static function makeBitmask(bits:LuaList<U32>):U64; | |
| /** Create a new mRectangle */ | |
| static function newRectangle(x:S32, y:S32, width:S32, height:S32):Rectangle; | |
| /** Create a new mSize */ | |
| static function newSize(width:S32, height:S32):Size; | |
| } | |
| typedef SystemInfo = { var branch:String; var commit:String; var program:String; var revision:S32; var version:String; } | |
| typedef ScriptInfo = { var dir:String; var path:String; } | |
| typedef RotationCallbacks = { @:optional var sample:Void->Void; @:optional var readTiltX:Void->F32; @:optional var readTiltY:Void->F32; @:optional var readGyroZ:Void->F32; @:optional var context:Dynamic; } | |
| typedef MemoryDomains = { | |
| @:optional var bios:MemoryDomain; @:optional var wram:MemoryDomain; @:optional var iwram:MemoryDomain; | |
| @:optional var io:MemoryDomain; @:optional var palette:MemoryDomain; @:optional var vram:MemoryDomain; | |
| @:optional var oam:MemoryDomain; @:optional var cart0:MemoryDomain; @:optional var cart1:MemoryDomain; | |
| @:optional var cart2:MemoryDomain; @:optional var sram:MemoryDomain; @:optional var hram:MemoryDomain; | |
| } | |
| /** Values in the mGBA global `C` table. */ | |
| typedef Constants = { | |
| var ALIGN:AlignConstants; var CHECKSUM:ChecksumConstants; var EV_TYPE:EventTypeConstants; | |
| var GBA_KEY:GbaKeyConstants; var GB_KEY:GbKeyConstants; var INPUT_DIR:InputDirectionConstants; | |
| var INPUT_STATE:InputStateConstants; var KEY:KeyConstants; var KMOD:KeyModifierConstants; | |
| var MOUSE_BUTTON:MouseButtonConstants; var PLATFORM:PlatformConstants; var SAVESTATE:SavestateConstants; | |
| var SOCKERR:SocketErrorConstants; var WATCHPOINT_TYPE:WatchpointConstants; | |
| } | |
| typedef AlignConstants = { var LEFT:Int; var HCENTER:Int; var RIGHT:Int; var TOP:Int; var VCENTER:Int; var BOTTOM:Int; var BASELINE:Int; } | |
| typedef ChecksumConstants = { var CRC32:Int; var MD5:Int; var SHA1:Int; } | |
| typedef EventTypeConstants = { var NONE:Int; var KEY:Int; var MOUSE_BUTTON:Int; var MOUSE_MOVE:Int; var MOUSE_WHEEL:Int; var GAMEPAD_BUTTON:Int; var TRIGGER:Int; } | |
| typedef GbaKeyConstants = { var A:Int; var B:Int; var SELECT:Int; var START:Int; var RIGHT:Int; var LEFT:Int; var UP:Int; var DOWN:Int; var R:Int; var L:Int; } | |
| typedef GbKeyConstants = { var A:Int; var B:Int; var SELECT:Int; var START:Int; var RIGHT:Int; var LEFT:Int; var UP:Int; var DOWN:Int; } | |
| typedef InputDirectionConstants = { var NONE:Int; var NORTH:Int; var UP:Int; var EAST:Int; var RIGHT:Int; var NORTHEAST:Int; var DOWN:Int; var SOUTH:Int; var SOUTHEAST:Int; var LEFT:Int; var WEST:Int; var NORTHWEST:Int; var SOUTHWEST:Int; } | |
| typedef InputStateConstants = { var UP:Int; var DOWN:Int; var HELD:Int; } | |
| typedef KeyModifierConstants = { var NONE:Int; var LSHIFT:Int; var RSHIFT:Int; var SHIFT:Int; var LCONTROL:Int; var RCONTROL:Int; var CONTROL:Int; var LALT:Int; var RALT:Int; var ALT:Int; var LSUPER:Int; var RSUPER:Int; var SUPER:Int; var CAPS_LOCK:Int; var NUM_LOCK:Int; var SCROLL_LOCK:Int; } | |
| typedef MouseButtonConstants = { var PRIMARY:Int; var SECONDARY:Int; var MIDDLE:Int; } | |
| typedef PlatformConstants = { var NONE:Int; var GBA:Int; var GB:Int; } | |
| typedef SavestateConstants = { var SCREENSHOT:Int; var SAVEDATA:Int; var CHEATS:Int; var RTC:Int; var METADATA:Int; var ALL:Int; } | |
| typedef SocketErrorConstants = { var UNKNOWN_ERROR:Int; var OK:Int; var AGAIN:Int; var ADDRESS_IN_USE:Int; var CONNECTION_REFUSED:Int; var DENIED:Int; var FAILED:Int; var NETWORK_UNREACHABLE:Int; var NOT_FOUND:Int; var NO_DATA:Int; var OUT_OF_MEMORY:Int; var TIMEOUT:Int; var UNSUPPORTED:Int; } | |
| typedef WatchpointConstants = { var WRITE:Int; var READ:Int; var RW:Int; var WRITE_CHANGE:Int; } | |
| /** Keyboard constants, including all F1–F24 and keypad values. */ | |
| typedef KeyConstants = { | |
| var NONE:Int; var BACKSPACE:Int; var TAB:Int; var ENTER:Int; var ESCAPE:Int; var DELETE:Int; | |
| var F1:Int; var F2:Int; var F3:Int; var F4:Int; var F5:Int; var F6:Int; var F7:Int; var F8:Int; var F9:Int; var F10:Int; var F11:Int; var F12:Int; var F13:Int; var F14:Int; var F15:Int; var F16:Int; var F17:Int; var F18:Int; var F19:Int; var F20:Int; var F21:Int; var F22:Int; var F23:Int; var F24:Int; | |
| var UP:Int; var RIGHT:Int; var DOWN:Int; var LEFT:Int; var PAGE_UP:Int; var PAGE_DOWN:Int; var HOME:Int; var END:Int; var INSERT:Int; var BREAK:Int; var CLEAR:Int; var PRINT_SCREEN:Int; var SYSRQ:Int; var MENU:Int; var HELP:Int; | |
| var LSHIFT:Int; var RSHIFT:Int; var SHIFT:Int; var LCONTROL:Int; var RCONTROL:Int; var CONTROL:Int; var LALT:Int; var RALT:Int; var ALT:Int; var LSUPER:Int; var RSUPER:Int; var SUPER:Int; var CAPS_LOCK:Int; var NUM_LOCK:Int; var SCROLL_LOCK:Int; | |
| var KP_0:Int; var KP_1:Int; var KP_2:Int; var KP_3:Int; var KP_4:Int; var KP_5:Int; var KP_6:Int; var KP_7:Int; var KP_8:Int; var KP_9:Int; var KP_PLUS:Int; var KP_MINUS:Int; var KP_MULTIPLY:Int; var KP_DIVIDE:Int; var KP_COMMA:Int; var KP_POINT:Int; var KP_ENTER:Int; | |
| } | |
| @:native("socket") | |
| /** A basic TCP socket library */ | |
| extern class SocketApi { | |
| static var ERRORS(default, null):Dynamic; | |
| /** Create and bind a new socket to a specific interface and port. Use `nil` for `address` to bind to all interfaces */ | |
| static function bind(address:Null<String>, port:U16):Socket; | |
| /** | |
| * Create and return a new TCP socket with a connection to the specified address and port. | |
| * | |
| * **Caution:** This is a blocking call. The emulator will not respond until the connection either succeeds or fails | |
| */ | |
| static function connect(address:String, port:U16):Socket; | |
| /** Create a new TCP socket, for use with either lua::struct::socket.bind or lua::struct::socket.connect later */ | |
| static function tcp():Socket; | |
| } | |
| /** An instance of a TCP socket. Most of these functions will return two values if an error occurs; the first value is `nil` and the second value is an error string from socket.ERRORS */ | |
| extern class Socket { | |
| /** Creates a new socket for an incoming connection from a listening server socket */ | |
| function accept():Null<Socket>; | |
| /** | |
| * Add a callback for a named event. The returned id can be used to remove it later. Events get checked once per frame but can be checked manually using lua::struct::socket.poll. The following callbacks are defined: | |
| * | |
| * - **received**: New data has been received and can be read | |
| * - **error**: An error has occurred on the socket | |
| */ | |
| function add(event:SocketEventName, callback:Dynamic):S64; | |
| /** Bind the socket to a specific interface and port. Use `nil` for `address` to bind to all interfaces */ | |
| function bind(address:Null<String>, port:U16):S32; | |
| /** | |
| * Opens a TCP connection to the specified address and port. | |
| * | |
| * **Caution:** This is a blocking call. The emulator will not respond until the connection either succeeds or fails | |
| */ | |
| function connect(address:String, port:U16):S32; | |
| /** Check if a socket has data ready to receive, and return true if so */ | |
| function hasdata():Bool; | |
| /** Begins listening for incoming connections. The socket must have first been bound with the lua::struct::socket.bind function */ | |
| function listen(?backlog:S32):S32; | |
| /** Manually check for events on this socket and dispatch associated callbacks */ | |
| function poll():Void; | |
| /** Read up to `maxBytes` bytes from the socket and return them. If the socket has been disconnected or an error occurs, it will return `nil, error` instead */ | |
| function receive(maxBytes:S64):Null<String>; | |
| /** Remove a callback with the previously returned id */ | |
| function remove(cbid:S64):Void; | |
| /** Writes a string to the socket. If `i` and `j` are provided, they have the same semantics as the parameters to `string.sub` to write a substring. Returns the last index written */ | |
| function send(data:String, ?i:S64, ?j:S64):S32; | |
| } | |
| enum abstract SocketEventName(String) from String to String { | |
| var Received = "received"; | |
| var Error = "error"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment