Changes

Jump to navigation Jump to search
9,192 bytes added ,  12:43, 5 November 2019
initial page; partial save
Lua Player is an application that plays back Lua scripts on the PSP. Similar to LÖVE, Lua Player allows for development of games and apps using a simpler language than C++.

== Functions ==
=== Graphics ===

* <code>Font Font.load(filename)</code> - Loads a true type font.
* <code>Font Font.createMonoSpaced()</code> - Creates an instance of the built-in mono-spaced font.
* <code>Font Font.createProportional()</code> - Creates an instance of the built-in proportional font.
* <code>Font Font:setCharSize(number width, number height, number dpiX, number dpiY)</code> - Changes the size of the current font to the specified point size height and width (if width is 0, it will be calculated proportional to the height for every character). dpiX and dpiY is the resolution of the display (see the Freetype documentation for details).
* <code>Font Font:setPixelSizes(number width, number height)</code> - Changes the size of the current font to the specified pixel size height and width (if width is 0, it will be calculated proportional to the height for every character). (see the Freetype documentation for details).
* <code>width, height Font:getTextSize(string)</code> - Returns the width and height, which will be used, if the specified text is drawn with this font and the current font size.
* <code>Image Image.createEmpty(width, height)</code> - Creates an empty image, initially cleared. Max width and height is 512.
* <code>Image Image.load(filename)</code> - Loads an image. Currently JPEG and PNG files are supported.
* <code>Image Image.loadFromMemory(data)</code> - Loads an image from memory (data is a Lua string). Currently JPEG and PNG files are supported.
<pre>jpegFile = io.open("test.jpg", "rb")
data = jpegFile:read("*a")
jpegFile:close()
image = Image.loadFromMemory(data)</pre>
* <code>nil image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])</code> - Paints the image, which is specified as “source” to the image on which this function is called on (or to the double buffered screen, when using the “screen:blit(...)” variable, which is a special image). “sourcex” and “sourcey” is the position in the source image, from where a rectangle of the size width/height is copied.
* <code>nil image:clear([color = transparent-black])</code> - Sets all pixels of an image to the specified color.
* <code>nil image:fillRect(x, y, width, height, [color = transparent-black])</code> - Draws a filled rectangle.
* <code>nil image:drawLine(x0, y0, x1, y1, [color = black])</code> - Draws a line. TODO: Clipping needs to be enhanced.
* <code>Color image:pixel(x, y) --get</code> - Gets the color of a pixel. See for example this code to get the color of an pixel and assert the value of all color components:
<pre>image = Image.createEmpty(1, 1)
color = image:pixel(0, 0)
colors = color:colors()
assert(colors.r == 0)
assert(colors.g == 0)
assert(colors.b == 0)
assert(colors.a == 0)</pre>
* <code>nil image:pixel(x, y, Color)</code> - Sets the color of a pixel.
* <code>nil image:print(x, y, text, [color = black])</code> - Prints some text with a predefined fixed width font with 8×8 pixels per character.
* <code>nil image:fontPrint(font, x, y, text, [color = black])</code> - Prints some text with the specified true type font.
* <code>Number image:width()</code> - Returns the width of an image.
* <code>Number image:height()</code> - Returns the height of an image.
* <code>nil image:save( filename )</code> - Saves an image to memory stick. Currently JPEG and PNG files are supported.
* <code>global Image screen</code> - The special double buffered screen object, which has all methods of an image and some more, see below.
* <code>nil screen.flip() -- note the small s; this is a function of the screen</code> - Flips the offscreen and onscreen screen.
* <code>nil screen.waitVblankStart([count])</code> - Waits until vertical retrace starts.
* <code>Color Color.new(r, g, b, [a=255])</code> - Creates a new color object with the specified RGBA values.
* <code>table[r,g,b,a] color:colors()</code> - Returns the RGBA values of a color object.
* <code>Bool (Color a == Color b)</code> - Color objects are equal, if all RGBA components are equal.

=== 3D GU Mapping ===
<code>Gu.start3d()</code> saves the current GE state for the normal 2D operations. Call this function first and then draw your scene. You can use the following functions:

<code>Gu.clearColor, Gu.clearDepth, Gu.clear, Gum.matrixMode, Gum.loadIdentity, Gum.perspective, Gum.translate, Gum.rotateXYZ, Gu.texImage, Gu.texFunc, Gu.texEnvColor, Gu.texFilter, Gu.texScale, Gu.texOffset, Gu.ambientColor, Gu.enable, Gu.disable, Gu.blendFunc, Gu.light, Gu.lightAtt, Gu.lightColor, Gu.lightMode, Gu.lightSpot and Gum.drawArray</code>. See the PSPSDK for documenation about the parameters, for example pspgu.h. If there is a <code>ScePspFVector3</code>, write 3 numbers instead one parameter (this will be changed in a later version). Whereever a color is expected, use a <code>Color</code> object. For textures use an <code>Image</code> object.

<code>Gum.drawArray</code> is something special: It has just 3 parameters: "prim", "vtype" and a table. With "prim" you specify which primitive should be used, for example <code>Gu.TRIANGLES</code>. "vtype" specifies the vertex format and the transformation operation. For example "Gu.COLOR_8888|Gu.VERTEX_32BITF|Gu.TRANSFORM_3D" means, that your vertices has a color component and a 3 vertex coordinate components and is transformed before passed to the rasterizer. The table is then a list of vertex entries, where each vertex entry has the form (color, x, y, z). If you have specified <code>GU_TEXTURE_32BITF</code>, too, then one entry looks like this: <code>(textureU, textureV, color, x, y, z)</code>. The order of the entries is defined in pspgu.h: textureU, textureV, color, normalX, normalY, normalZ, vertexX, vertexY, vertexZ. Indices, weights and multiple vertices per entry (which you’ll need for the morphing feature) currently are not supported.

After drawing anything, call <code>Gu.end3d()</code>, which flushs the display buffer and draws all pending 3D graphics and restores the 2D GE state. Don’t forget to call a <code>screen:clear()</code> before fullscreen 2D operations, because otherwise the z-buffer is not cleared and the blitting functions may not work correctly. If you need to blit 2D images in 3D mode, use textures and triangles.

See the 3D Cube example in the Applications folder of the distribution of Lua Player to see how to use the 3D functions and take a look at the GU example in the PSPSDK how to use all the other functions. Most of the time you can copy and paste the examples and just remove all those C fussinesses like ".0f", semicolon, malloc etc. :-)

Note: The 3D API might change in the future.

=== Controls ===

* <code>Controls Controls.read()</code>

<pre>Bool controls:select()
Bool controls:start()
Bool controls:up()
Bool controls:right()
Bool controls:down()
Bool controls:left()
Bool controls:l()
Bool controls:r()
Bool controls:triangle()
Bool controls:circle()
Bool controls:cross()
Bool controls:square()
Bool controls:home()
Bool controls:hold()
Bool controls:note()</pre>
* <code>Number controls:analogX() -- ranges from -127 to 128</code> - Returns the current analog stick position in x direction.
* <code>Number controls:analogY() -- ranges from -127 to 128</code> - Returns the current analog stick position in y direction.
* <code>Bool (Controls a == Controls b) -- note! The analog stick is NOT considered when comparing because of analog fluctuations</code> - Compares two pad states.
* <code>Number controls:buttons() -- returns the bitmask like sceCtrlReadBufferPositive reads it</code> - Constants for binary operations on buttons() result (for example "Controls.read():buttons() & Controls.startMask > 0" is the same as "Controls.read():start()")
<pre>Number Controls.selectMask
Number Controls.startMask
Number Controls.upMask
Number Controls.rightMask
Number Controls.downMask
Number Controls.leftMask
Number Controls.ltriggerMask
Number Controls.rtriggerMask
Number Controls.triangleMask
Number Controls.circleMask
Number Controls.crossMask
Number Controls.squareMask
Number Controls.homeMask
Number Controls.holdMask
Number Controls.noteMask</pre>

=== Millisecond Timer ===
* <code>Timer Timer.new([startTime])</code> - Creates a new Timer object, sets to 0 or startTime in milliseconds, if specified BUT don’t start ticking as yet.
* <code>Number Timer:start()</code> - Starts to tick the timer (incrementing by one every millisecond), or resumes to tick after being stopped. Returns the current time() value. If the timer is running, it is the same as time().
* <code>Number Timer:time()</code> - Returns in milliseconds since the timer started/resumed.
* <code>Number Timer:stop()</code> - Stops the timer. Returns the current time(). Subsequent time() calls returns the value when stopped. If the timer is stopped, this call is the same as time().
* <code>Number Timer:reset([startTime])</code> - Resets the timer to 0 by default or startTime in milliseconds and holds the timer. Returns the time before resetted to the new value.

Navigation menu