Changes

Jump to navigation Jump to search

Overview of the API

448 bytes added, 00:53, 31 May 2011
no edit summary
Line 5: Line 5:  
( This has been taken from [http://www.wowwiki.com/Lua_functions a WoWWiki page] - See the full, official documentation [http://www.lua.org/manual/5.1/manual.html here] )
 
( This has been taken from [http://www.wowwiki.com/Lua_functions a WoWWiki page] - See the full, official documentation [http://www.lua.org/manual/5.1/manual.html here] )
   −
*'''_G''' - Global Variable - A global variable (not a function) that holds the global environment (that is, _G._G = _G). Lua itself does not use this variable; changing its value does not affect any environment, nor vice-versa. (Use setfenv to change environments.)  - taken from Lua docs
+
*'''[[_G]]''' - Global Variable - A global variable (not a function) that holds the global environment (that is, _G._G = _G). Lua itself does not use this variable; changing its value does not affect any environment, nor vice-versa. (Use setfenv to change environments.)  - taken from Lua docs
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.
+
*'''[[assert]]'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.
+
*'''[[getfenv]]'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.
+
*'''[[getmetatable]]'''(obj, mtable) - Returns the metatable of the given table or userdata object.
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.
+
*'''[[next]]'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.
+
*'''[[newproxy]]'''(boolean or proxy) - Creates a userdata with a sharable metatable.
*'''print''' - print (···) - Receives any number of arguments, and prints their values to stdout, using the tostring function to convert them to strings. print is not intended for formatted output, but only as a quick way to show a value, typically for debugging. For formatted output, use string.format.  - taken from Lua Docs
+
*'''[[print]]''' - print (···) - Receives any number of arguments, and prints their values to stdout, using the tostring function to convert them to strings. print is not intended for formatted output, but only as a quick way to show a value, typically for debugging. For formatted output, use string.format.  - taken from Lua Docs
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.
+
*'''[[select]]'''(index, list) - Returns the number of items in list or the value of the item in list at index.
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.
+
*'''[[setfenv]]'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.
+
*'''[[setmetatable]]'''(obj, mtable) - Sets the metatable of the given table or userdata object.
*'''tostring''' - tostring (e) - Receives an argument of any type and converts it to a string in a reasonable format. For complete control of how numbers are converted, use string.format. If the metatable of e has a "__tostring" field, then tostring calls the corresponding value with e as argument, and uses the result of the call as its result. - taken from Lua Docs.
+
*'''[[tostring]]''' - tostring (e) - Receives an argument of any type and converts it to a string in a reasonable format. For complete control of how numbers are converted, use string.format. If the metatable of e has a "__tostring" field, then tostring calls the corresponding value with e as argument, and uses the result of the call as its result. - taken from Lua Docs.
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".
+
*'''[[type]]'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.
+
*'''[[unpack]]'''(table[, start][, end]) - Returns the contents of its argument as separate values.
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.
+
*'''[[xpcall]]'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.
    
==Concepts and Basics==
 
==Concepts and Basics==
Line 96: Line 96:  
The maximum screen resolution available to Lua programs is 318 by 212 pixels.
 
The maximum screen resolution available to Lua programs is 318 by 212 pixels.
   −
*'''begin''' -
+
*'''[[begin]]''' -
*'''clipRect''' -
+
*'''[[clipRect]]''' -
*'''drawArc'''(x, y, width, height, start angle, finish angle) Note, to draw a circle, use drawArc(x - diameter/2, y - diameter/2, diameter,diameter,0,360) where x and y are the coordinates of the middle.
+
*'''[[drawArc]]'''(x, y, width, height, start angle, finish angle) Note, to draw a circle, use drawArc(x - diameter/2, y - diameter/2, diameter,diameter,0,360) where x and y are the coordinates of the middle.
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.
+
*'''[[drawImage]]'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)
+
*'''[[drawLine]]'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)
*'''drawPolyLine'''(int list1 [,int list2, .., int listN]) Draws a shape from a list contaning successively the x and y coordinates of each point the line have to draw.
+
*'''[[drawPolyLine]]'''(int list1 [,int list2, .., int listN]) Draws a shape from a list contaning successively the x and y coordinates of each point the line have to draw.
 
For example
 
For example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
Line 111: Line 111:  
</syntaxhighlight>
 
</syntaxhighlight>
 
do the same. If there are multiple argument (which can be 4 elements list to represent lines), each list has to contain an even number of element.
 
do the same. If there are multiple argument (which can be 4 elements list to represent lines), each list has to contain an even number of element.
*'''drawRect'''(x, y, xwidth, yheight) Draws a rectangle at (x,y) with the “x” side being “xwidth” long and the “y” side being “yheight” long
+
*'''[[drawRect]]'''(x, y, xwidth, yheight) Draws a rectangle at (x,y) with the “x” side being “xwidth” long and the “y” side being “yheight” long
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”.  
+
*'''[[drawString]]'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”.  
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc
+
*'''[[fillArc]]'''(x, y, width, height, start angle, finish angle) see drawArc
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine
+
*'''[[fillPolygon]]'''(int list1 [,int list2, .., int listN]) see drawPolyLine
*'''fillRect'''(x, y, width, height) see drawRect
+
*'''[[fillRect]]'''(x, y, width, height) see drawRect
*'''finish''' -
+
*'''[[finish]]''' -
*'''getStringHeight'''(string)
+
*'''[[getStringHeight]]'''(string)
*'''getStringWidth'''(string)
+
*'''[[getStringWidth]]'''(string)
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.
+
*'''[[isColorDisplay]]''' Bool (Read-only) Returns 1 if color, 0 if not.
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.
+
*'''[[setAlpha]]'''(int) - where the argument is an int between 0 and 255. Sets the transparency.
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.
+
*'''[[setColorRGB]]'''(red, green, blue) RGB values are integers, from 0 to 255.
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)
+
*'''[[setFont]]'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}
+
*'''[[setPen]]'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}
    
==platform==
 
==platform==
 
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"
 
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.
+
*'''[[apilevel()]]''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.
*'''window'''
+
*'''[[window]]'''
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''
+
: *'''[[width()]]''' - Returns the width of the window. Ex : ''platform.window:height()''
: *'''height()''' - Returns the height of the window
+
: *'''[[height()]]''' - Returns the height of the window
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')
+
: *'''[[invalidate()]]''' - Repaints the window (it calls '''on.paint(gc)''')
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not
+
*'''[[ isDeviceModeRendering()]]''' Returns true or false whether the unit is "rendering" or not
*'''gc''' - Other way to call '''gc'''. Use it like that : '''platform.gc():setAlpha(...)''' for example. This is useful when you're in a function outside '''on.paint(gc)''' (but this function has to be called within on.paint(gc).
+
*'''[[gc]]''' - Other way to call '''gc'''. Use it like that : '''platform.gc():setAlpha(...)''' for example. This is useful when you're in a function outside '''on.paint(gc)''' (but this function has to be called within on.paint(gc).
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.
+
*'''[[isColorDisplay()]]''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.
    
==cursor==
 
==cursor==
*'''hide'''() - hides the cursor (mouse pointer)
+
*'''[[hide]]'''() - hides the cursor (mouse pointer)
*'''set'''(string) - string can be one of those : (interrogation, crosshair, text, pointer, link select, diag resize, wait busy, hollow pointer, rotation, pencil, zoom box, arrow, zoom out, dotted arrow, clear, animate, excel plus, mod label, writing, unavailable, resize row, resize column, drag grab, hand open, hand close, hand pointer, zoom in, dilation, translation).
+
*'''[[set]]'''(string) - string can be one of those : (interrogation, crosshair, text, pointer, link select, diag resize, wait busy, hollow pointer, rotation, pencil, zoom box, arrow, zoom out, dotted arrow, clear, animate, excel plus, mod label, writing, unavailable, resize row, resize column, drag grab, hand open, hand close, hand pointer, zoom in, dilation, translation).
*'''show'''() - Shows the cursor on screen
+
*'''[[show]]'''() - Shows the cursor on screen
    
==document==
 
==document==
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.
+
*'''[[markChanged]]'''() - Flag the document as "changed" so the user has to save it after using it.
    
==clipboard==
 
==clipboard==
*'''addText'''()
+
*'''[[addText]]'''()
*'''getText'''()
+
*'''[[getText]]'''()
    
==locale==
 
==locale==
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).
+
*'''[[name]]'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).
    
==image==
 
==image==
*'''__gc'''() - Do not use ! Causes crash : ''(Invalid memory access of location 0x0 eip=0x465cc7ac / Bus error)'' but thats probably just when calling in TI's emulator.
+
*'''[[__gc]]'''() - Do not use ! Causes crash : ''(Invalid memory access of location 0x0 eip=0x465cc7ac / Bus error)'' but thats probably just when calling in TI's emulator.
*'''copy'''(image, width, height) - returns a new Image which has a new scale. Width is the final width, Heigth, the final height of the image.
+
*'''[[copy]]'''(image, width, height) - returns a new Image which has a new scale. Width is the final width, Heigth, the final height of the image.
 
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))
 
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))
*'''height'''(image) - returns the height of the image given in parameter
+
*'''[[height]]'''(image) - returns the height of the image given in parameter
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt>
+
*'''[[new]]'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt>
*'''width'''(image) - returns the width of the image given in parameter
+
*'''[[width]]'''(image) - returns the width of the image given in parameter
    
==timer==
 
==timer==
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)
+
*'''[[getMilliSecCounter]]'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)
*'''start'''(int) - Starts a timer with 1 second.
+
*'''[[start]]'''(int) - Starts a timer with 1 second.
*'''stop'''() - Stops a timer
+
*'''[[stop]]'''() - Stops a timer
    
==toolpalette==
 
==toolpalette==
*'''enable'''(string)
+
*'''[[enable]]'''(string)
*'''enableCopy'''()
+
*'''[[enableCopy]]'''()
*'''enableCut'''()
+
*'''[[enableCut]]'''()
*'''enablePaste'''()
+
*'''[[enablePaste]]'''()
*'''register'''(table)
+
*'''[[register]]'''(table)
    
==var==
 
==var==
*'''list'''() - returns a list of all the variables in the entire Activity
+
*'''[[list]]'''() - returns a list of all the variables in the entire Activity
*'''monitor'''() - ?
+
*'''[[monitor]]'''() - ?
*'''recall'''(string) - returns the variable value which name is given in parameter
+
*'''[[recall]]'''(string) - returns the variable value which name is given in parameter
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter
+
*'''[[recallstr]]'''(string) - returns the variable value converted to string which name is given in parameter
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value
+
*'''[[store]]'''(string, value) - store in the variable, which name is given in parameter, the value
*'''unmonitor'''() - ?
+
*'''[[unmonitor]]'''() - ?
    
==Events==
 
==Events==
   −
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)
+
*'''[[on.paint]]'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)
*'''on.resize'''() is called when the window is rezised
+
*'''[[on.resize]]'''() is called when the window is rezised
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation :  
+
*'''[[on.timer]]'''() is called when the timer has been finished. Here an example of using timer to play an animation :  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
  x = 1
 
  x = 1
Line 207: Line 207:  
</syntaxhighlight>
 
</syntaxhighlight>
 
----
 
----
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)
+
*'''[[on.arrowKey]]'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed
+
*'''[[on.arrowLeft]]'''() is called when the '''left''' arrow is pressed
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed
+
*'''[[on.arrowRight]]'''() is called when the '''right''' arrow is pressed
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed
+
*'''[[on.arrowUp]]'''() is called when the up '''arrow''' is pressed
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed
+
*'''[[on.arrowDown]]'''() is called when the '''down''' arrow is pressed
 
----
 
----
*'''on.up'''() -- probably for the touchpad up motion
+
*'''[[on.up]]'''() -- probably for the touchpad up motion
*'''on.down'''() -- probably for the touchpad down motion
+
*'''[[on.down]]'''() -- probably for the touchpad down motion
 
----
 
----
*'''on.enterKey'''() is called when the '''enter''' key is pressed.
+
*'''[[on.enterKey]]'''() is called when the '''enter''' key is pressed.
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.
+
*'''[[on.escapeKey]]'''() is called when the '''escape''' key is pressed.
*'''on.tabKey'''() is called when the '''tab''' key is pressed.
+
*'''[[on.tabKey]]'''() is called when the '''tab''' key is pressed.
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.
+
*'''[[on.deleteKey]]'''() is called when the '''delete''' key is pressed.
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.
+
*'''[[on.backspaceKey]]'''() is called when the '''clear''' key is pressed.
*'''on.returnKey'''() is called when the '''return''' key is pressed.
+
*'''[[on.returnKey]]'''() is called when the '''return''' key is pressed.
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.
+
*'''[[on.contextMenu]]'''() is called when the combo-key '''Ctrl Menu''' is pressed.
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.
+
*'''[[on.backtabKey]]'''() is called when the combo-key '''Maj Tab''' is pressed.
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.
+
*'''[[on.clearKey]]'''() is called when the combo-key '''Ctrl Clear''' is pressed.
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.
+
*'''[[on.help]]'''() is called when the combo-key '''Ctrl H''' is pressed.
   −
*'''on.charIn'''(string) is called when the Nspire detects a non arrow key being pressed. ch is the character it detect. If you want to auto start an event in the file linked to key r(like a reset) put on.charIn(“r”) where you want. This Lua program lets you display the value of a valid non arrow key :
+
*'''[[on.charIn]]'''(string) is called when the Nspire detects a non arrow key being pressed. ch is the character it detect. If you want to auto start an event in the file linked to key r(like a reset) put on.charIn(“r”) where you want. This Lua program lets you display the value of a valid non arrow key :
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
  c = ""
 
  c = ""
Line 240: Line 240:  
</syntaxhighlight>
 
</syntaxhighlight>
 
----
 
----
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)
+
*'''[[on.blink]]'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)
 
----
 
----
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)
+
*'''[[on.deactivate]]'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)
+
*'''[[on.activate]]'''() ? is called when the focus is on the page (like launching the document, changing page etc...)
 
----
 
----
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.
+
*'''[[on.mouseDown]]'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.
*'''on.mouseUp'''() is called when we release the left mouse button.  
+
*'''[[on.mouseUp]]'''() is called when we release the left mouse button.  
*'''on.mouseMove'''() is called when the mouse moves
+
*'''[[on.mouseMove]]'''() is called when the mouse moves
*'''on.grabDown'''() ? (software only ?)
+
*'''[[on.grabDown]]'''() ? (software only ?)
*'''on.grabMove'''() ? (software only ?)
+
*'''[[on.grabMove]]'''() ? (software only ?)
*'''on.grabUp'''() ? (software only ?)
+
*'''[[on.grabUp]]'''() ? (software only ?)
*'''on.rightMouseDown'''() ? (software only ?)
+
*'''[[on.rightMouseDown]]'''() ? (software only ?)
*'''on.rightMouseUp'''() ? (software only ?)
+
*'''[[on.rightMouseUp]]'''() ? (software only ?)
 
----
 
----
*'''on.cutEnabled'''() ? (software only ?)
+
*'''[[on.cutEnabled]]'''() ? (software only ?)
*'''on.copyEnabled'''() ? (software only ?)
+
*'''[[on.copyEnabled]]'''() ? (software only ?)
*'''on.pasteEnabled'''() ? (software only ?)
+
*'''[[on.pasteEnabled]]'''() ? (software only ?)
*'''on.cut'''() ? (software only ?)
+
*'''[[on.cut]]'''() ? (software only ?)
*'''on.copy'''() ? (software only ?)
+
*'''[[on.copy]]'''() ? (software only ?)
*'''on.paste'''() ? (software only ?)
+
*'''[[on.paste]]'''() ? (software only ?)
 
----
 
----
    
==D2Editor==
 
==D2Editor==
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)
+
*'''[[newRichText]]'''() creates a new RichText object (default values : x, y, width, height = 0)
*'''resize'''(width, height)  
+
*'''[[resize]]'''(width, height)  
*'''move'''(x, y)
+
*'''[[move]]'''(x, y)
*'''setText'''(string)
+
*'''[[setText]]'''(string)
*'''getText'''() returns the RichText value
+
*'''[[getText]]'''() returns the RichText value
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.
+
*'''[[setReadOnly]]'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.
*'''setFormattedText'''() - ?
+
*'''[[setFormattedText]]'''() - ?
 
Example of a valid function using the D2Editor
 
Example of a valid function using the D2Editor
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">

Navigation menu