Bueno compañeros. La verdad es que llevo bastante sin postear ningun tutorial, así que, para que no os desanimeis, aquí os dejo esta listita de las funciones de LUA, que poco a poco iré traduciendo a castellano y comentandolas mediante ejemplos.
Si teneis alguna duda, hacedmela saber
[QUOTE]
Graphics
Font Font.load(filename)Loads a true type font.
--------------------------------------------------------------------------------
Font Font.createMonoSpaced()Creates an instance of the built-in mono-spaced font.
--------------------------------------------------------------------------------
Font Font.createProportional()Creates an instance of the built-in proportional font.
--------------------------------------------------------------------------------
Font Font:setCharSize(number width, number height, number dpiX, number dpiY)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).
--------------------------------------------------------------------------------
Font Font:setPixelSizes(number width, number height)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).
--------------------------------------------------------------------------------
width, height Font:getTextSize(string)Returns the width and height, which will be used, if the specified text is drawn with this font and the current font size.
--------------------------------------------------------------------------------
Image Image.createEmpty(width, height)Creates an empty image, initially cleared. Max width and height is 512.
--------------------------------------------------------------------------------
Image Image.load( filename )Loads an image. Currently JPEG and PNG files are supported.
--------------------------------------------------------------------------------
nil image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])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.
--------------------------------------------------------------------------------
nil image:clear([color = transparent-black])Sets all pixels of an image to the specified color.
--------------------------------------------------------------------------------
nil image:fillRect(x, y, width, height, [color = transparent-black])Draws a filled rectangle.
--------------------------------------------------------------------------------
nil image:drawLine(x0, y0, x1, y1, [color = black])Draws a line. TODO: Clipping needs to be enhanced.
--------------------------------------------------------------------------------
Color image:pixel(x, y) --getGets 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:
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)
--------------------------------------------------------------------------------
nil image:pixel(x, y, Color) --setSets the color of a pixel.
--------------------------------------------------------------------------------
nil image:print(x, y, text, [color = black])Prints some text with a predefined fixed width font with 8×8 pixels per character.
--------------------------------------------------------------------------------
nil image:fontPrint(font, x, y, text, [color = black])Prints some text with the specified true type font.
--------------------------------------------------------------------------------
Number image:width()Returns the width of an image.
--------------------------------------------------------------------------------
Number image:height()Returns the height of an image.
--------------------------------------------------------------------------------
nil Image:save( filename )Saves an image to memory stick. Currently JPEG and PNG files are supported.
--------------------------------------------------------------------------------
global Image screenThe special double buffered screen object, which has all methods of an image and some more, see below.
--------------------------------------------------------------------------------
nil screen.flip() -- note the small s; this is a function of the screenFlips the offscreen and onscreen screen.
--------------------------------------------------------------------------------
nil screen.waitVblankStart([count])Waits until vertical retrace starts.
--------------------------------------------------------------------------------
Color Color.new(r, g, b, [a=255])Creates a new color object with the specified RGBA values.
--------------------------------------------------------------------------------
table[r,g,b,a] color:colors()Returns the RGBA values of a color object.
--------------------------------------------------------------------------------
Bool (Color a == Color b)Color objects are equal, iff all RGBA components are equal.
--------------------------------------------------------------------------------
3D GU mapping
Note: The 3D API might change in future.
Gu.start3d() 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:
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. See the PSPSDK for documenation about the parameters, for example the pspgu.h. If there is a ScePspFVector3, write 3 numbers instead one parameter (this will be changed in a later version). Whereever a color is expected, use a Color object. For textures use an Image object.
Gum.drawArray is something special: It has just 3 parameters: “prim”, “vtype” and a table. With “prim” you specify which primitive should be used, for example Gu.TRIANGLES. “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 GU_TEXTURE_32BITF, too, then one entry looks like this: (textureU, textureV, color, x, y, z). 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 Gu.end3d(), which flushs the display buffer and draws all pending 3D graphics and restores the 2D GE state. Don’t forget to call a screen:clear() 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.
--------------------------------------------------------------------------------
Controls
Controls Controls.read()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()
--------------------------------------------------------------------------------
Number controls:analogX() -- ranges from -127 to 128.Returns the current analog stick position in x direction.
--------------------------------------------------------------------------------
Number controls:analogY() -- sameReturns the current analog stick position in y direction.
--------------------------------------------------------------------------------
Bool (Controls a == Controls b) -- note! The analog stick is NOT considered when comparing because of analog fluctuations.Compares two pad states.
--------------------------------------------------------------------------------
Number controls:buttons() -- returns the bitmask like sceCtrlReadBufferPositive reads itConstants for binary operations on buttons() result (for example “Controls.read():buttons() & Controls.startMask > 0” is the same as “Controls.read():start()”)
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
--------------------------------------------------------------------------------
Millisecond Timer
Timer Timer.new([startTime])Creates a new Timer object, sets to 0 or startTime in milliseconds, if specified BUT don’t start ticking as yet.
--------------------------------------------------------------------------------
Number Timer:start()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().
--------------------------------------------------------------------------------
Number Timer:time()Returns in milliseconds since the timer started/resumed.
--------------------------------------------------------------------------------
Number Timer:stop()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().
--------------------------------------------------------------------------------
Number Timer:reset([startTime])Resets the timer to 0 by default or startTime in milliseconds and holds the timer. Returns the time before resetted to the new value.
--------------------------------------------------------------------------------
System
String System.currentDirectory() -- getGets the current working directory.
--------------------------------------------------------------------------------
String System.currentDirectory( path ) -- set, returns old path.Sets the current working directory.
--------------------------------------------------------------------------------
table System.listDirectory( [path] )Lists the contents of the current working directory or the specified path. The result is a table of tables, where each table-entry has the string entry “name”, the number entry “size” and the boolean entry “directory”, which is set to true, when the current entry is a directory. See for example this code to print all files in the current working directory:
files = System.listDirectory()
for index, file in files do
print(file.name)
end
--------------------------------------------------------------------------------
nil System.createDirectory(path)Creates a new directory. The path is relative to the current directory, if not absolute.
--------------------------------------------------------------------------------
nil System.removeDirectory(path)Deletes a directory. The path is relative to the current directory, if not absolute.
--------------------------------------------------------------------------------
nil System.removeFile(path)Deletes a file. The path is relative to the current directory, if not absolute.
--------------------------------------------------------------------------------
nil System.usbDiskModeActivate()Activates the USB mode. Attention: When writing from USB to the memory stick, you must not write from within your Lua script to the memory stick, until you disable USB, otherwise the filesystem of your memory stick gets corrupted and you have to reformat your memmory stick.
--------------------------------------------------------------------------------
nil System.usbDiskModeDeactivate()Deactivates the USB mode.
--------------------------------------------------------------------------------
Battery functions:
Bool System.powerIsPowerOnline()
--------------------------------------------------------------------------------
Bool System.powerIsBatteryExist()
--------------------------------------------------------------------------------
Bool System.powerIsBatteryCharging()
--------------------------------------------------------------------------------
Number System.powerGetBatteryChargingStatus()
--------------------------------------------------------------------------------
Bool System.powerIsLowBattery()
--------------------------------------------------------------------------------
Number System.powerGetBatteryLifePercent()
--------------------------------------------------------------------------------
Number System.powerGetBatteryLifeTime()
--------------------------------------------------------------------------------
Number System.powerGetBatteryTemp()
--------------------------------------------------------------------------------
Number System.powerGetBatteryVolt()
--------------------------------------------------------------------------------
Number System.powerTick()When called, it resets the internal power off counter, which prevents auto power off.
--------------------------------------------------------------------------------
String System.md5sum(String)Calculates the md5sum of a string. For example print(System.md5sum(io.input(”EBOOT.PBP”):read(”*a”))) prints the same digest as “md5sum EBOOT.PBP” on Unix.
--------------------------------------------------------------------------------
Serial input/output functions:
nil System.sioInit(baudrate)Opens the SIO device and sets the baud rate. This needs some seconds to power up the UART.
--------------------------------------------------------------------------------
System.sioWrite(string)Writes the string to the SIO
--------------------------------------------------------------------------------