Difference between revisions of "LuaZM Reference"

From WikiPrizm
Jump to navigationJump to search
Line 10: Line 10:
  
 
Run a Lua script. With no arguments, run will launch a file browser ''(not yet implemented)''. With arguments, it will run the specified plain-text or compressed Lua program from Flash memory.
 
Run a Lua script. With no arguments, run will launch a file browser ''(not yet implemented)''. With arguments, it will run the specified plain-text or compressed Lua program from Flash memory.
 +
 +
=== about() ===
 +
  
 
== ZMG Library ==
 
== ZMG Library ==
Line 21: Line 24:
 
=== zmg.copySprite() ===
 
=== zmg.copySprite() ===
 
  zmg.copysprite(x,y,width,height,data)
 
  zmg.copysprite(x,y,width,height,data)
Copies the sprite to the VRAM buffer, overwriting any existing contents. '''Does''' perform clipping.
+
Copies the sprite to the VRAM buffer, overwriting any existing contents. Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping.
  
 
''x'': (number) x-coordinate of left edge of sprite<br />
 
''x'': (number) x-coordinate of left edge of sprite<br />
Line 33: Line 36:
 
=== zmg.drawLine() ===
 
=== zmg.drawLine() ===
 
  zmg.drawLine(x1, y1, x2, y2, color)
 
  zmg.drawLine(x1, y1, x2, y2, color)
Draws a line of color color from (x1, y1) to (x2, y2). Both points must be on-screen.
+
Draws a line of color color from (x1, y1) to (x2, y2). Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping.
  
 
''x1'': (number) x-coordinate of first point<br />
 
''x1'': (number) x-coordinate of first point<br />
Line 47: Line 50:
 
=== zmg.drawRectFill() ===
 
=== zmg.drawRectFill() ===
 
  zmg.drawRectFill(x,y,width,height,color)
 
  zmg.drawRectFill(x,y,width,height,color)
Draw a rectangular fill of width width and height height starting from top-left pixel coordinate (x,y). Performs clipping to keep rectangle on-screen, but will throw an error for negative coordinates or dimensions.
+
Draw a rectangular fill of width width and height height starting from top-left pixel coordinate (x,y). Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping. Width and height must be positive.
 
''x'': (number) x-coordinate of top-left corner<br />
 
''x'': (number) x-coordinate of top-left corner<br />
 
''y'': (number) y-coordinate of top-left corner<br />
 
''y'': (number) y-coordinate of top-left corner<br />
Line 60: Line 63:
 
=== zmg.drawCircle() ===
 
=== zmg.drawCircle() ===
 
  zmg.drawCircle(x,y,radius,color)
 
  zmg.drawCircle(x,y,radius,color)
Draws an unfilled circle centered at (x,y) with radius radius and line color color.
+
Draws an unfilled circle centered at (x,y) with radius radius and line color color.  Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping.
  
 
''x'': (number) x-coordinate of center of circle. Must be onscreen.<br />
 
''x'': (number) x-coordinate of center of circle. Must be onscreen.<br />
Line 66: Line 69:
 
''radius'': (number) radius of circle. May put some portions of circle offscreen.<br />
 
''radius'': (number) radius of circle. May put some portions of circle offscreen.<br />
 
''color'': (number) A color, such as 0xF500. Not a string. Planned: zmg.nametocolor("red") function.
 
''color'': (number) A color, such as 0xF500. Not a string. Planned: zmg.nametocolor("red") function.
 +
 +
=== zmg.clipRect() ===
 +
zmg.clipRect(x0,y0,width,height)
 +
Set the clipping rectangle for drawing operations, which defaults to precisely matching the full LCD. Affects drawCircle, drawRectFill, drawRect, drawPoint, drawLine, copySprite, and copySpriteMask.
 +
 +
''x0'': (number) x-coordinate of top-left of clipping rectangle. Must be on-screen.<br />
 +
''y0'': (number) y-coordinate of top-left of clipping rectangle. Must be on-screen.<br />
 +
''width'': (number) width of clipping rectangle. Must be positive.<br />
 +
''height'': (number) height of clipping rectangle. Must be positive.
  
 
=== zmg.keyMenu() ===
 
=== zmg.keyMenu() ===

Revision as of 17:47, 26 August 2012

LuaZM for the Prizm is under active development, but does not yet have a released beta. Stay tuned.

Base Library

The base Lua library has been expanded with a few Prizm-specific functions to make life easier.

run()

run()
run("file.lua")
run("compressed.lc")

Run a Lua script. With no arguments, run will launch a file browser (not yet implemented). With arguments, it will run the specified plain-text or compressed Lua program from Flash memory.

about()

ZMG Library

All functions in the ZMG ("PriZM Graphics) library are invoked with zmg.function(arguments,...). The functions with filled-in details and arguments have been implemented, but most are untested. Functions without details are unimplemented. They are as follows:

zmg.clear()

zmg.clear()

Clears the VRAM buffer. No arguments, no return value.

zmg.copySprite()

zmg.copysprite(x,y,width,height,data)

Copies the sprite to the VRAM buffer, overwriting any existing contents. Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping.

x: (number) x-coordinate of left edge of sprite
y: (number) y-coordinate of top edge of sprite
width: (number) width of sprite in pixels
height: (number) height of sprite in pixels
data: (string) hex for sprite. 4 hex characters per pixel, 5-6-5 color

zmg.copySpriteMask()

zmg.drawLine()

zmg.drawLine(x1, y1, x2, y2, color)

Draws a line of color color from (x1, y1) to (x2, y2). Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping.

x1: (number) x-coordinate of first point
y1: (number) y-coordinate of first point
x2: (number) x-coordinate of second point
y2: (number) y-coordinate of second point
color: (number) 16-bit color code. See drawcircle() for details.

zmg.drawPoint()

zmg.drawRect()

zmg.drawRectFill()

zmg.drawRectFill(x,y,width,height,color)

Draw a rectangular fill of width width and height height starting from top-left pixel coordinate (x,y). Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping. Width and height must be positive. x: (number) x-coordinate of top-left corner
y: (number) y-coordinate of top-left corner
width: (number) width of fill
height: (number) height of fill
color: (number) 16-bit color code. See drawcircle() for details.

zmg.fastCopy()

zmg.fastCopy()

Copy the VRAM to the LCD. Takes no arguments, has no return value.

zmg.drawCircle()

zmg.drawCircle(x,y,radius,color)

Draws an unfilled circle centered at (x,y) with radius radius and line color color. Clips to the current clipping rectangle; if clipRect has not been called, the edges of the screen are used for clipping.

x: (number) x-coordinate of center of circle. Must be onscreen.
y: (number) y-coordinate of center of circle. Must be onscreen.
radius: (number) radius of circle. May put some portions of circle offscreen.
color: (number) A color, such as 0xF500. Not a string. Planned: zmg.nametocolor("red") function.

zmg.clipRect()

zmg.clipRect(x0,y0,width,height)

Set the clipping rectangle for drawing operations, which defaults to precisely matching the full LCD. Affects drawCircle, drawRectFill, drawRect, drawPoint, drawLine, copySprite, and copySpriteMask.

x0: (number) x-coordinate of top-left of clipping rectangle. Must be on-screen.
y0: (number) y-coordinate of top-left of clipping rectangle. Must be on-screen.
width: (number) width of clipping rectangle. Must be positive.
height: (number) height of clipping rectangle. Must be positive.

zmg.keyMenu()

zmg.fastKeyMenu()

Get a keypress, and handle the [MENU] key if pressed. This is blocking, meaning that it will not return until a key is pressed, and will therefore not return zero. Takes no arguments, returns a number. The [ON] key will cause the Lua interpreter to abort.

zmg.keyMenuFast()

zmg.fastKeyMenu()

Get a keypress, and handle the [MENU] key if pressed. This is non-blocking, and returns zero if no key is pressed. Takes no arguments, returns a number.

zmg.keyFastest()

zmg.keyFastest(key)

Checks whether key is currently released, pressed, or held. Returns 0 if it is released, 1 if pressed momentarily, and 2 if held down (ie, is currently pressed and was pressed during the last call to this function).

zmg.time()

zmg.time()

Get the current Unix epoch time (that is, the number of seconds since 00:00:00 1/1/1970). Uses the Prizm's internal clock, and returns an integer counting the number of seconds since the beginning of the epoch.

zmg.ticks()

zmg.ticks()

Returns the current value of the Prizm's 64Hz clock, which increments every 1/64th of a second. May recycle unexpectedly; good for making games run at a consistent speed regardless of user input.