Skip to content
tiffany352 edited this page Nov 4, 2012 · 6 revisions

Convention

Each table in the API consists of:

  • A create method, which will create a new version of that object.
  • Objects are tables that have __index set to the table of that type.
  • The table contains a function called getType() which returns the name of the type as a string.
  • The table contains a function called isA() which will return true if the object is or inherets directly or indirectly from the given string type name.
  • The table's __call is set to create

Any additions to the table are noted in the documentation for that type.

API

Script

Table name: script

  • script:fromSource(source) - Loads a script from the provided source string.
  • script:fromFile(file) - Loads a script from the provided file name.
  • script:run() - Runs a script in its own Lua state.

Vector2

Table name: vector2

  • Metamethods in each instance: __tostring, __add, __sub, __mul, __div, __index, __newindex.
  • Values in each instance: x, y, len, normal.
  • vector2:dot(vec) - Computes the dot product of the two supplied vectors.

Vector3

Table name: vector3

  • Same as Vector2, but has additional members:
  • Values in each instance: z.
  • vector3:cross(vec) - Computes the cross product of the two supplied vectors.

Vector4

Table name: vector4

  • Same as Vector3, but has additional members:
  • Values in each instance: w.

Quaternion

Table name: quaternion

  • Metamethods in each instance: __index, __newindex, __mul.
  • Values in each instance: x, y, z, w.
  • quaternion:fromAxisAngle(vec, a) or quaternion:fromAxisAngles(x, y, z, a) - Creates a new quaternion from an axis to rotate around (normal represented by vec) and an angle to rotate by (a).
  • quaternion:fromYPR(y, p, r) - Creates a new quaternion using Yaw, Pitch, and Roll values.

Positionable

Table name: positionable

  • Metamethods in each instance: __index, __newindex.
  • Values in each instance: position, rotation, size, velocity, parent.

World

Table name: world

  • Values in each instance: camera.

Event

Table name: event

  • event.register(id, fun) - Registers fun as a callback for event IDs of id. The callback is called with an argument of type event.
  • event:push() - Pushes an event to be handled.
  • event:timer(interval) - Pushes an event that will be handled every interval microseconds.
  • event:getData() - Tries to convert the internal data parameter into something Lua can handle.
  • keyup, keydown, mouseup, mousedown: Returns the SDL keycode for the key/button cast to a double.
  • mousemove: Returns the x, y of the mouse movement.
  • mousewheel: Returns the y, x of the mouse scroll.
  • tick, startup, shutdown: Returns nil.
  • event:getId() - Returns the event id cast to a double.
  • event:getIdName() - Returns a string representation of the event ID.

Input

Table name: input

  • Does not have instances, therefore create, isA, and getType do not apply.
  • input.keyDown(key) - Returns a boolean of whether or not the given key is being pressed.
  • input.mouseDown(button) - Returns a boolean of whether or not the given mouse button is being pressed.
  • input.grabMouse(toggle) - Sets the mouse grab of the window depending on the passed boolean.

Drawable

Table name: drawable

  • Does not have a function to create it. It is an abstract 'class'.
  • Values in each instance: type (An integer used internally), positionable.

Terrain

Table name: terrain

  • "inherits" Drawable.
  • Values in each instance: data (a TerrainData).

TerrainData

Table name: terraindata

  • Values in each instance: width, height.
  • terraindata:getPoint(x, y, z) - Takes 3 coordinates and performs an action meaningful to the specific type of terrain it represents, returning a number.
  • terraindata:getNormal(x, y, z) - Takes 3 coordinates and performs an action meaningful to the specific type of terrain it represents, returning a Vector3.
  • terraindata:heightmap(w, h, t) - Takes a table with w*h numbers in it and creates a heightmap of the specified size, filling an existing terraindata.

Shape

Table name: shape

  • "inherits" Drawable.
  • Values in each instance: type (string).

Examples

Simple Script Usage

local s = script();
s:fromFile("test.lua");
s:run();
Clone this wiki locally