https://wiki.inspired-lua.org/api.php?action=feedcontributions&user=Levak&feedformat=atomInspired-Lua Wiki - User contributions [en]2024-03-29T07:56:11ZUser contributionsMediaWiki 1.33.0https://wiki.inspired-lua.org/index.php?title=gc:setPen&diff=1096gc:setPen2013-07-29T02:00:20Z<p>Levak: /* Syntax */</p>
<hr />
<div><br />
'''setPen''' is a function that is part of [[:Category:gc|gc]].<br />
<br />
Sets the pen for drawing lines and borders.<br />
<br />
<br /> {{Since|3.0}}<br />
<br />
==Syntax==<br />
gc:'''setPen'''([thickness[, style]])<br />
<br />
If the thickness is not specified, it defaults to ”thin.”, and if the style is not specified, it defaults to ”smooth.” <br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
| <u><center>thickness</center></u> || string || Optional. Can be "thin", "medium" or "thick" <br />
|-<br />
| <u><center>style</center></u> || string || Optional. Can be "smooth", "dotted", "dashed" <br />
|-<br />
|}<br />
<br />
== Example == <br />
<syntaxhighlight>gc:setPen("thick","dotted")</syntaxhighlight><br />
<br />
<br /><br />
[[Category:gc]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=on.varChange&diff=949on.varChange2013-05-20T00:46:21Z<p>Levak: /* Example */ Fixed link adding /index.php</p>
<hr />
<div>This event gets fired when a [[var.monitor|monitored variable]] gets changed.<br /><br />
It has an argument it creates by itself (like 'gc' with on.paint), which is ''varlist'', being a list of variable names whose values were changed.<br /><br />
This handler must return a value to indicate if it accepts the new value(s) or vetoes the change. <br />
<br />
==Syntax==<br />
<br />
on.'''varChange'''(''varlist'')<br />
<br /><br />
<br />
==Return values==<br />
Valid return values are:<br />
* 0 Success. The script application accepts the change.<br />
* -1 Veto range. The new value is unsatisfactory because it is outside the acceptable range, i.e. too low or too high.<br />
* -2 Veto type. The new value is unsatisfactory because its type cannot be used by the script application.<br />
* -3 Veto existence. Another application deleted the variable and this application <br />
<br />
==Example== <br />
<br />
This example is about Highscore Saving.<br /><br />
More details here : http://www.inspired-lua.org/index.php/2011/08/save-a-high-score-without-cheating-possibility/<br />
<br />
<source lang="lua"><br />
<br />
function on.create()<br />
if not var.recall("highscore") then<br />
highscore = 0<br />
var.store("highscore", highscore)<br />
end<br />
var.monitor("highscore")<br />
end<br />
<br />
function on.varChange(varlist)<br />
for k, v in pairs(varlist) do<br />
if k == "highscore" then<br />
if var.recall(k) ~= highscore then<br />
return 1 -- it is an external change, block modifications<br />
else<br />
return 0 -- it is an internal change, allow modifications<br />
end<br />
end<br />
end<br />
return 0 -- allow modifications of other monitored variables if any<br />
end<br />
</source><br />
<br />
[[Category:Events]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=class&diff=635class2012-03-14T22:58:51Z<p>Levak: </p>
<hr />
<div>A complete tutorial about classes is written here: http://www.inspired-lua.org/2011/05/5-object-classes/<br />
<br />
Here's how the class() function is defined, in the API :<br />
<br />
<source lang="lua"><br />
class = function(prototype)<br />
local derived={}<br />
if prototype then<br />
function derived.__index(t,key)<br />
return rawget(derived,key) or prototype[key]<br />
end<br />
else<br />
function derived.__index(t,key)<br />
return rawget(derived,key)<br />
end<br />
end<br />
function derived.__call(proto,...)<br />
local instance={}<br />
setmetatable(instance,proto)<br />
local init=instance.init<br />
if init then<br />
init(instance,...)<br />
end<br />
return instance<br />
end<br />
setmetatable(derived,derived)<br />
return derived<br />
end<br />
<br />
</source></div>Levakhttps://wiki.inspired-lua.org/index.php?title=gc:drawString&diff=531gc:drawString2011-08-06T22:09:12Z<p>Levak: </p>
<hr />
<div>'''drawString ''' is a function that is part of [[:Category:gc|gc]] (Graphics Context). <br />
<br />
This function is used to display text, numbers etc. on the screen at specified coordinates.<br />
<br />
<br />
Returns an integer corresponding to the width of the displayed string.<br />
<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
gc:'''drawString'''(string, x, y [,position]) <br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
| <u><center>string</center></u> || string || The text to display<br />
|-<br />
| <u><center>x</center></u> || number || the ''x'' coordinate of the beginning of the string. Relative to ''position''.<br />
|-<br />
| <u><center>y</center></u> || number || the ''y'' coordinate of the beginning of the string. Relative to ''position''.<br />
|-<br />
| <u><center>position</center></u> || string || the string’s anchor point. It can either be "baseline", “bottom”, “middle”, or “top”.<br />
|}<br />
== Example ==<br />
<syntaxhighlight>gc:drawString("Hello World", 0, 0, "top")</syntaxhighlight><br />
will display&nbsp;&nbsp;&nbsp; Hello World &nbsp;&nbsp;&nbsp; at the top-left part of the screen.<br />
<br />
<br /><br /><br />
[[Category:gc]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=gc:drawString&diff=530gc:drawString2011-08-06T22:08:27Z<p>Levak: </p>
<hr />
<div>'''drawString ''' is a function that is part of [[:Category:gc|gc]] (Graphics Context). <br />
<br />
This function is used to display text, numbers etc. on the screen at specified coordinates.<br />
<br />
Returns an integer corresponding to the width of the displayed string.<br />
<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
gc:'''drawString'''(string, x, y [,position]) <br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
| <u><center>string</center></u> || string || The text to display<br />
|-<br />
| <u><center>x</center></u> || number || the ''x'' coordinate of the beginning of the string. Relative to ''position''.<br />
|-<br />
| <u><center>y</center></u> || number || the ''y'' coordinate of the beginning of the string. Relative to ''position''.<br />
|-<br />
| <u><center>position</center></u> || string || the string’s anchor point. It can either be "baseline", “bottom”, “middle”, or “top”.<br />
|}<br />
== Example ==<br />
<syntaxhighlight>gc:drawString("Hello World", 0, 0, "top")</syntaxhighlight><br />
will display&nbsp;&nbsp;&nbsp; Hello World &nbsp;&nbsp;&nbsp; at the top-left part of the screen.<br />
<br />
<br /><br /><br />
[[Category:gc]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=timer.start&diff=489timer.start2011-06-22T16:24:32Z<p>Levak: /* Syntax */</p>
<hr />
<div>timer.'''start''' is a function that is part of the [[:Category:timer|timer]] functions.<br />
<br />
Starts the timer with the given period in seconds.<br /><br />
If the timer is already running when this routine is called, the timer is reset to the new period.<br />
<br />
This function fires the [[on.timer]]() event.<br />
<br />
<br /><br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
timer.'''start'''(period)<br /><br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
| <u><center>period</center></u> || number || the time period in seconds for the timer to start. Must be > 0.01<br />
|-<br />
|}<br />
<br />
== Example ==<br />
<source>timer.start(0.5)</source><br />
<br />
== See also ==<br />
*[[timer.stop]]<br />
*[[on.timer]]<br />
<br />
<br /><br />
[[Category:timer]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=on.paint&diff=487on.paint2011-06-17T13:31:42Z<p>Levak: </p>
<hr />
<div>The function '''on.paint'''(''[[:Category:gc|gc]]'') is called when the script's window needs to be painted.<br /><br />
''[[:Category:gc|'gc']]'' is the Graphics Context, passed by default to the function.<br />
<br />
This function can be fired by the [[platform.window:invalidate]] function.<br />
<br />
== Example ==<br />
<br />
Below is an example of a program that uses on.paint(gc) to draw a line to the screen:<br />
<source lang="lua"><br />
function on.paint(gc) --Define a function for the event with the default argument<br />
gc:drawLine(5,5,200,1) --Draw a line on the screen<br />
end<br />
</source><br />
[[Category:Events]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Category:gc&diff=456Category:gc2011-06-02T22:59:10Z<p>Levak: </p>
<hr />
<div>== Quick Overview==<br />
*'''[[gc:begin]]''' -<br />
*'''[[gc:clipRect]]'''(?, x, y, width, height) -<br />
*'''[[gc:drawArc]]'''(x, y, width, height, start angle, finish angle).<br />
*'''[[gc:drawImage]]'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''[[gc:drawLine]]'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''[[gc: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.<br />
*'''[[gc: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<br />
*'''[[gc:drawString]]'''(string, x, y, position) position is the string’s anchor point and can be "baseline", “bottom”, “middle”, or “top”. <br />
*'''[[gc:fillArc]]'''(x, y, width, height, start angle, finish angle) see [[gc:drawArc]]<br />
*'''[[gc:fillPolygon]]'''(int list1 [,int list2, .., int listN]) see [[gc:drawPolyLine]]<br />
*'''[[gc:fillRect]]'''(x, y, width, height) see [[gc:drawRect]]<br />
*'''[[gc:finish]]''' -<br />
*'''[[gc:getStringHeight]]'''(string) - Returns the string's height.<br />
*'''[[gc:getStringWidth]]'''(string) - Returns the string's width<br />
*'''[[gc:isColorDisplay]]''' Bool (Read-only) Returns 1 if the device has a color display, 0 if not.<br />
*'''[[gc:setAlpha]]'''(alpha) - where alpha is an integer between 0 and 255. Sets the transparency.<br />
*'''[[gc:setColorRGB]]'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''[[gc:setFont]]'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''[[gc:setPen]]'''(thickness, smoothness) : thickness {“thin”, “medium”, "thick"}, smoothness {“smooth”, "dotted", "dashed"}<br />
<br></div>Levakhttps://wiki.inspired-lua.org/index.php?title=var.monitor&diff=351var.monitor2011-05-27T23:58:40Z<p>Levak: Created page with "Category:var"</p>
<hr />
<div>[[Category:var]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=on.varChange&diff=350on.varChange2011-05-27T23:56:12Z<p>Levak: Created page with " Category:Events"</p>
<hr />
<div><br />
<br />
[[Category:Events]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Category:Events&diff=349Category:Events2011-05-27T23:54:29Z<p>Levak: /* Quick Overview */</p>
<hr />
<div>==Quick Overview==<br />
*'''[[on.paint]]''' is called when the GUI is painted. [[:Category:gc|'gc' is the Graphics Context]] <br />
*'''[[on.resize]]''' is called when the window is rezised<br />
<br />
<br> <br />
<br />
*'''[[on.timer]]''' is called at each timer ticks. See [[:Category:timer|timer]].<br />
<br />
<br> <br />
<br />
*'''[[on.arrowKey]]''' is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down) <br />
*'''[[on.arrowLeft]]''' is called when the '''left''' arrow is pressed <br />
*'''[[on.arrowRight]]''' is called when the '''right''' arrow is pressed <br />
*'''[[on.arrowUp]]''' is called when the up '''arrow''' is pressed <br />
*'''[[on.arrowDown]]''' is called when the '''down''' arrow is pressed <br />
*'''[[on.up]]''' -- probably for the touchpad up motion <br />
*'''[[on.down]]''' -- probably for the touchpad down motion<br />
<br />
<br> <br />
<br />
*'''[[on.enterKey]]''' is called when the '''enter''' key is pressed. <br />
*'''[[on.escapeKey]]''' is called when the '''escape''' key is pressed. <br />
*'''[[on.tabKey]]''' is called when the '''tab''' key is pressed. <br />
*'''[[on.deleteKey]]''' is called when the '''delete''' key is pressed. <br />
*'''[[on.backspaceKey]]''' is called when the '''clear''' key is pressed. <br />
*'''[[on.returnKey]]''' is called when the '''return''' key is pressed. <br />
*'''[[on.contextMenu]]''' is called when the combo-key '''Ctrl Menu''' is pressed. <br />
*'''[[on.backtabKey]]''' is called when the combo-key '''Maj Tab''' is pressed. <br />
*'''[[on.clearKey]]''' is called when the combo-key '''Ctrl Clear''' is pressed. <br />
*'''[[on.help]]''' is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
<br> <br />
<br />
*'''[[on.charIn]]''' is called when the Nspire detects a non arrow key being pressed.<br />
<br />
<br> <br />
<br />
*'''[[on.blink]]''' called when the focus is lost on the page (like launching the document, changing page etc...) <br />
*'''[[on.create]]''' called when the script gets created. <br />
*'''[[on.deactivate]]''' called when the focus is lost on the page (like launching the document, changing page etc...) <br />
*'''[[on.activate]]''' called when the focus is on the page (like launching the document, changing page etc...) <br />
*'''[[on.destroy]]''' is called when the document is about to get closed (or cut)<br />
<br />
<br> <br />
<br />
*'''[[on.mouseDown]]''' is called when we press the left mouse button. X and Y are the pressed point coordinates. <br />
*'''[[on.mouseUp]]''' is called when we release the left mouse button. <br />
*'''[[on.mouseMove]]''' is called when the mouse moves <br />
*'''[[on.grabDown]]''' <br />
*'''[[on.grabMove]]'''<br />
*'''[[on.grabUp]]''' <br />
*'''[[on.rightMouseDown]]''' <br />
*'''[[on.rightMouseUp]]'''<br />
<br />
<br> <br />
<br />
*'''[[on.varChange]]'''<br />
<br />
<br> <br />
<br />
*'''[[on.cutEnabled]]''' <br />
*'''[[on.copyEnabled]]''' <br />
*'''[[on.pasteEnabled]]'''<br />
*'''[[on.cut]]''' <br />
*'''[[on.copy]]'''<br />
*'''[[on.paste]]'''<br />
<br> <br></div>Levakhttps://wiki.inspired-lua.org/index.php?title=Category:Events&diff=348Category:Events2011-05-27T23:54:10Z<p>Levak: /* Quick Overview */</p>
<hr />
<div>==Quick Overview==<br />
*'''[[on.paint]]''' is called when the GUI is painted. [[:Category:gc|'gc' is the Graphics Context]] <br />
*'''[[on.resize]]''' is called when the window is rezised<br />
<br />
<br> <br />
<br />
*'''[[on.timer]]''' is called at each timer ticks. See [[:Category:timer|timer]].<br />
<br />
<br> <br />
<br />
*'''[[on.arrowKey]]''' is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down) <br />
*'''[[on.arrowLeft]]''' is called when the '''left''' arrow is pressed <br />
*'''[[on.arrowRight]]''' is called when the '''right''' arrow is pressed <br />
*'''[[on.arrowUp]]''' is called when the up '''arrow''' is pressed <br />
*'''[[on.arrowDown]]''' is called when the '''down''' arrow is pressed <br />
*'''[[on.up]]''' -- probably for the touchpad up motion <br />
*'''[[on.down]]''' -- probably for the touchpad down motion<br />
<br />
<br> <br />
<br />
*'''[[on.enterKey]]''' is called when the '''enter''' key is pressed. <br />
*'''[[on.escapeKey]]''' is called when the '''escape''' key is pressed. <br />
*'''[[on.tabKey]]''' is called when the '''tab''' key is pressed. <br />
*'''[[on.deleteKey]]''' is called when the '''delete''' key is pressed. <br />
*'''[[on.backspaceKey]]''' is called when the '''clear''' key is pressed. <br />
*'''[[on.returnKey]]''' is called when the '''return''' key is pressed. <br />
*'''[[on.contextMenu]]''' is called when the combo-key '''Ctrl Menu''' is pressed. <br />
*'''[[on.backtabKey]]''' is called when the combo-key '''Maj Tab''' is pressed. <br />
*'''[[on.clearKey]]''' is called when the combo-key '''Ctrl Clear''' is pressed. <br />
*'''[[on.help]]''' is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
<br> <br />
<br />
*'''[[on.charIn]]''' is called when the Nspire detects a non arrow key being pressed.<br />
<br />
<br> <br />
<br />
*'''[[on.blink]]''' called when the focus is lost on the page (like launching the document, changing page etc...) <br />
*'''[[on.create]]''' called when the script gets created. <br />
*'''[[on.deactivate]]''' called when the focus is lost on the page (like launching the document, changing page etc...) <br />
*'''[[on.activate]]''' called when the focus is on the page (like launching the document, changing page etc...) <br />
*'''[[on.destroy]]''' is called when the document is about to get closed (or cut)<br />
<br />
<br> <br />
<br />
*'''[[on.mouseDown]]''' is called when we press the left mouse button. X and Y are the pressed point coordinates. <br />
*'''[[on.mouseUp]]''' is called when we release the left mouse button. <br />
*'''[[on.mouseMove]]''' is called when the mouse moves <br />
*'''[[on.grabDown]]''' <br />
*'''[[on.grabMove]]'''<br />
*'''[[on.grabUp]]''' <br />
*'''[[on.rightMouseDown]]''' <br />
*'''[[on.rightMouseUp]]'''<br />
<br />
<br> <br />
<br />
<br />
*'''[[on.varChange]]'''<br />
<br />
<br> <br />
<br />
<br />
*'''[[on.cutEnabled]]''' <br />
*'''[[on.copyEnabled]]''' <br />
*'''[[on.pasteEnabled]]'''<br />
*'''[[on.cut]]''' <br />
*'''[[on.copy]]'''<br />
*'''[[on.paste]]'''<br />
<br> <br></div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:width&diff=347platform.window:width2011-05-26T15:34:59Z<p>Levak: /* Syntax */</p>
<hr />
<div>'''platform.window.width''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
Returns the width in pixel of the current display window.<br />
== Syntax ==<br />
'''platform.window.width'''()<br /><br />
(No arguments)<br />
<br />
== Example ==<br />
<syntaxhighlight>ww = platform.window.width()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:width&diff=346platform.window:width2011-05-26T15:34:42Z<p>Levak: /* Syntax */</p>
<hr />
<div>'''platform.window.width''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
Returns the width in pixel of the current display window.<br />
== Syntax ==<br />
'''platform.window.width'''()<br />
<br />
<br /><br />
(No arguments)<br />
<br />
== Example ==<br />
<syntaxhighlight>ww = platform.window.width()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:height&diff=345platform.window:height2011-05-26T15:34:35Z<p>Levak: /* Syntax */</p>
<hr />
<div>'''platform.window.height''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
Returns the height in pixel of the current display window.<br />
== Syntax ==<br />
'''platform.window.height'''()<br /><br />
(No arguments)<br />
<br />
== Example ==<br />
<syntaxhighlight>wh = platform.window.height()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:height&diff=344platform.window:height2011-05-26T15:34:06Z<p>Levak: /* Syntax */</p>
<hr />
<div>'''platform.window.height''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
Returns the height in pixel of the current display window.<br />
== Syntax ==<br />
'''platform.window.height'''()<br />
(No arguments)<br />
<br />
== Example ==<br />
<syntaxhighlight>wh = platform.window.height()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:width&diff=343platform.window:width2011-05-26T15:31:40Z<p>Levak: </p>
<hr />
<div>'''platform.window.width''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
Returns the width in pixel of the current display window.<br />
== Syntax ==<br />
'''platform.window.width'''() <br />
<br />
== Example ==<br />
<syntaxhighlight>ww = platform.window.width()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:height&diff=342platform.window:height2011-05-26T15:31:28Z<p>Levak: </p>
<hr />
<div>'''platform.window.height''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
Returns the height in pixel of the current display window.<br />
== Syntax ==<br />
'''platform.window.height'''() <br />
<br />
== Example ==<br />
<syntaxhighlight>wh = platform.window.height()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:height&diff=341platform.window:height2011-05-26T15:30:57Z<p>Levak: /* Example */</p>
<hr />
<div>'''platform.window.height''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
'''platform.window.height'''() <br />
<br />
== Example ==<br />
<syntaxhighlight>wh = platform.window.height()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:width&diff=340platform.window:width2011-05-26T15:30:45Z<p>Levak: Created page with "'''platform.window.width''' is a function that is part of platform.window. {{Since|3.0}} == Syntax == '''platform.window.width'''() == Example ..."</p>
<hr />
<div>'''platform.window.width''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
'''platform.window.width'''() <br />
<br />
== Example ==<br />
<syntaxhighlight>ww = platform.window.width()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=platform.window:height&diff=339platform.window:height2011-05-26T15:30:24Z<p>Levak: Created page with "'''platform.window.height''' is a function that is part of platform.window. {{Since|3.0}} == Syntax == '''platform.window.height'''() == Exampl..."</p>
<hr />
<div>'''platform.window.height''' is a function that is part of [[:Category:platform.window|platform.window]].<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
'''platform.window.height'''() <br />
<br />
== Example ==<br />
<syntaxhighlight>ww = platform.window.height()</syntaxhighlight><br />
<br />
<br /><br /><br />
<br />
[[Category:platform.window]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=image.new&diff=338image.new2011-05-26T15:26:31Z<p>Levak: /* Example */</p>
<hr />
<div>image.'''new''' is a function that is part of [[:Category:image|image]].<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
image.'''new'''(image) <br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
| <u>image</u> || string || The compressed/encrypted string containing the image header + data (see [[TI.Image]])<br />
|-<br />
|}<br />
<br />
== Example ==<br />
<syntaxhighlight>image.new("\002\000\000\000\002\000\000\000\000\000\000\000\004\000\000\000\016\000\001\000\255\255\255\255\255\255\255\255")</syntaxhighlight><br />
<br />
== See also ==<br />
*[[TI.Image]]<br />
*[[:Category:image|image functions]]<br />
*[[image.copy]]<br />
<br />
<br /><br /><br />
<br />
[[Category:image]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=image.copy&diff=337image.copy2011-05-26T15:24:56Z<p>Levak: /* Example */</p>
<hr />
<div>__NOTOC__<br />
image.'''copy''' is a function that is part of [[:Category:image|image]].<br />
<br />
<br />
The function returns a copy of the input image scaled to fit the specified pixel width and height. <br /><br />
The width and height default to the size of the input image.<br /><br />
The routine raises an error if the new width or height are less than or equal to 0 or greater than 25000.<br /><br />
This routine raises an error if there is insufficient memory to create the new image.<br />
<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
image.'''copy'''(image, width, height) <br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
<br />
| <u>image</u> || [[TI.Image]] || The original image.<br />
|-<br />
| <u>width</u> || number || The width of the new image<br />
|-<br />
| <u>height</u> || number || The height of the new image<br />
|}<br />
<br />
== Example ==<br />
<syntaxhighlight>newImage = image.copy(oldImage, 10, 15)</syntaxhighlight><br />
<br />
== Good to know ==<br />
<br />
To make a relative scale, use <syntaxhighlight>image.copy(image, scaleX * image.width(image), scaleY * image.height(image))</syntaxhighlight><br />
<br />
== See also ==<br />
*[[TI.Image]]<br />
*[[:Category:image|image functions]]<br />
*[[image.new]]<br />
<br />
<br /><br /><br />
<br />
[[Category:image]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=gc:drawImage&diff=207gc:drawImage2011-05-24T19:12:37Z<p>Levak: Created page with "'''drawImage''' is a function that is part of gc. {{Since|3.0}} == Syntax == gc:'''drawImage'''(image, x, y) {| class="wikitable" |- ! Parameter !! Type !! D..."</p>
<hr />
<div>'''drawImage''' is a function that is part of [[:Category:gc|gc]].<br />
<br />
{{Since|3.0}}<br />
<br />
== Syntax ==<br />
gc:'''drawImage'''(image, x, y)<br />
<br />
{| class="wikitable"<br />
|-<br />
! Parameter !! Type !! Description<br />
|-<br />
| <u>image</u> || [[TI.Image]] || The image to display<br />
|-<br />
| <u>x</u> || number || the x coordinate of the upper-left corner of the image<br />
|-<br />
| <u>y</u> || number || the y coordinate of the upper-left corner of the image<br />
|}<br />
<br />
== Example ==<br />
<syntaxhighlight><br />
imgSRC = "\002\000\000\000\002\000\000\000\000\000\000\000\004\000\000\000\016\000\001\000\255\255\255\255\255\255\255\255"<br />
img = image.new(imgSRC)<br />
drawImage(img, 0, 0)<br />
</syntaxhighlight><br />
<br />
== See also ==<br />
*[[TI.Image]]<br />
<br />
<br /><br /><br />
<br />
[[Category:gc]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Overview_of_the_API&diff=52Overview of the API2011-05-20T20:22:40Z<p>Levak: /* D2Editor */</p>
<hr />
<div>[[Image: See-the-link-here |thumb||right| [http://i.imgur.com/LTznh.jpg The Hexadecimal view of all the api functions, readable in an extraded phoenix.raw file]]]<br />
<br />
The TI-Nspire allows, since OS v3.0, programming with the Lua language through a hidden application "TI.ScriptApp".<br />
<br />
This page describes how to setup a Lua development environment and documents the currently known Lua functions for the Nspire, and a brief description of how to use the functions.<br />
<br />
Note: Neither the ''io'' nor ''os'' libraries are present for the TI-Nspire, which seems to be running a light version of Lua 5.1.4.<br />
<br />
Here's a dump of a lot of functions available in the API : [http://adriweb.free.fr/upload/ti/dump.html Link to the dump].<br />
<br />
==Prerequisites==<br />
<br />
Lua is only supported starting from OS v3.0.1. Creating Lua scripts is currently not officially supported by TI, you need one of the following third-party tools to convert Lua scripts to TI-Nspire documents:<br />
*[http://www.ticalc.org/archives/files/fileinfo/437/43704.html LUAtoTNS.sh] (bash script, works on Linux, Mac OS and Unix, or Windows + Cygwin or Windows + MSYS).<br />
*[http://www.mirari.fr/KbOD maketns.py] (Python script, cross-platform)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=651 lua2ti] (Windows + .NET Framework v4.0)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=652 lua2ti_linux] (Linux (No longer requires Mono, it is now a native Linux binary!))<br />
You may also want to install Lua [http://www.lua.org/download.html on your computer]: <tt>luac -p</tt> can be used to check the syntax of your script before running it on a TI-Nspire or an emulator.<br />
<br />
==Standard Library==<br />
<br />
( 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] )<br />
<br />
*'''_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<br />
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.<br />
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.<br />
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.<br />
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.<br />
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.<br />
*'''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<br />
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.<br />
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.<br />
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.<br />
*'''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.<br />
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".<br />
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.<br />
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.<br />
<br />
==Concepts and Basics==<br />
<br />
This part will explain you how the Lua actually works inside the OS and help you to figure out what you're doing when you write a script for the TI-Nspire. Before reading this, you have to know all about the Lua basics.<br />
<br />
The Lua is an interpreted script language which means that it isn't as fast as ASM/C programs, but is still better than the TI-BASIC.<br />
One good thing is that this language is in a complete harmony with the OS with basic events and a powerfull graphic context.<br />
First, we have to understand how this works. Basicly the script is launched before the executive engine. This means that we can neither evaluate expressions nor use some of the standard API (like platform, var) until the engine is launched. Here is a call summary :<br />
<br />
*Launch string library<br />
*Launch math library<br />
* ...<br />
*Open and launch User's Lua script<br />
*...<br />
*Launch var API (store, recall, ...)<br />
*Launch platform API (window, gc, ...)<br />
*...<br />
*Link events (pseudo code)<br />
<syntaxhighlight lang="lua"><br />
while(Exit)<br />
------- Some OS routines here<br />
<br />
---- Begin of Event link<br />
buffer:captureDataFromKeyPad() -- (N) some underground routines to catch events<br />
if buffer.charInput ~= "" then -- (N)<br />
on.charIn(buffer.charInput)<br />
buffer.charInput= "" -- (N)<br />
end<br />
if buffer.arrowKey ~= "" then -- (N)<br />
on.arrowKey(buffer.arrowKey)<br />
buffer.arrowKey = "" -- (N)<br />
end<br />
----- etc ... <br />
if platform.window.isInvalidate then <br />
platform.gc():purge() -- (N) Empty buffer before starting to draw<br />
on.paint(platform.gc()) -- save all the things we have to draw<br />
platform:paint() -- (N) draw all those things<br />
platform.window.isInvalidate = false -- say that the window has been drawn<br />
end<br />
----- End of Event link<br />
end<br />
</syntaxhighlight><br />
<br />
''Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.''<br />
<br />
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.<br />
<br />
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).<br />
<syntaxhighlight lang="lua"><br />
function on.paint(gc)<br />
if message then<br />
gc:setFont("sansserif", "r", 10) -- initialize font drawing<br />
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates<br />
message = nil -- erase the message<br />
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen<br />
end<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate()<br />
end<br />
<br />
function on.charIn(ch)<br />
message = "Hello World !" -- store a message<br />
platform.window:invalidate() -- force display<br />
end<br />
</syntaxhighlight><br />
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that ? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again ? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.<br />
<br />
==gc (as in Graphics Context)==<br />
<br />
Note: You need to add “gc:” before each of these commands in order to use them. ex. '''gc:setAlpha(...)'''.<br />
You can also call gc like this : '''platform.gc():setAlpha(...)'''. Then you can use the gc library in a function where gc is not passed as an argument. but this function *has* to be called within '''on.paint(gc)'''<br />
<br />
The maximum screen resolution available to Lua programs is 318 by 212 pixels.<br />
<br />
*'''begin''' -<br />
*'''clipRect''' -<br />
*'''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.<br />
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''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.<br />
For example<br />
<syntaxhighlight lang="lua"><br />
drawPolyLine({0,0, 0,100, 100,100, 100,0, 0,0})<br />
</syntaxhighlight><br />
and<br />
<syntaxhighlight lang="lua"><br />
drawRect(0,0,100,100)<br />
</syntaxhighlight><br />
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.<br />
*'''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<br />
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”. <br />
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc<br />
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine<br />
*'''fillRect'''(x, y, width, height) see drawRect<br />
*'''finish''' -<br />
*'''getStringHeight'''(string)<br />
*'''getStringWidth'''(string)<br />
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.<br />
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.<br />
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}<br />
<br />
==platform==<br />
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"<br />
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.<br />
*'''window'''<br />
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''<br />
: *'''height()''' - Returns the height of the window<br />
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')<br />
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not<br />
*'''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).<br />
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.<br />
<br />
==cursor==<br />
*'''hide'''() - hides the cursor (mouse pointer)<br />
*'''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).<br />
*'''show'''() - Shows the cursor on screen<br />
<br />
==document==<br />
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.<br />
<br />
==clipboard==<br />
*'''addText'''()<br />
*'''getText'''()<br />
<br />
==locale==<br />
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).<br />
<br />
==image==<br />
*'''__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.<br />
*'''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.<br />
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))<br />
*'''height'''(image) - returns the height of the image given in parameter<br />
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt><br />
*'''width'''(image) - returns the width of the image given in parameter<br />
<br />
==timer==<br />
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)<br />
*'''start'''(int) - Starts a timer with 1 second.<br />
*'''stop'''() - Stops a timer<br />
<br />
==toolpalette==<br />
*'''enable'''(string)<br />
*'''enableCopy'''()<br />
*'''enableCut'''()<br />
*'''enablePaste'''()<br />
*'''register'''(table)<br />
<br />
==var==<br />
*'''list'''() - returns a list of all the variables in the entire Activity<br />
*'''monitor'''() - ?<br />
*'''recall'''(string) - returns the variable value which name is given in parameter<br />
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter<br />
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value<br />
*'''unmonitor'''() - ?<br />
<br />
==Events==<br />
<br />
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)<br />
*'''on.resize'''() is called when the window is rezised<br />
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation : <br />
<syntaxhighlight lang="lua"><br />
x = 1<br />
animating = false<br />
function on.paint(gc)<br />
gc:setFont("sansserif", "r", 10)<br />
gc:drawString(tostring(x), 0, 0, "top")<br />
if animating then<br />
x = x + 1<br />
timer.start(0.5)<br />
end<br />
end<br />
<br />
function on.charIn(ch)<br />
animating = not animating -- switch state<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)<br />
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed<br />
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed<br />
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed<br />
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed<br />
----<br />
*'''on.up'''() -- probably for the touchpad up motion<br />
*'''on.down'''() -- probably for the touchpad down motion<br />
----<br />
*'''on.enterKey'''() is called when the '''enter''' key is pressed.<br />
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.<br />
*'''on.tabKey'''() is called when the '''tab''' key is pressed.<br />
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.<br />
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.<br />
*'''on.returnKey'''() is called when the '''return''' key is pressed.<br />
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.<br />
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.<br />
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.<br />
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
*'''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 :<br />
<syntaxhighlight lang="lua"><br />
c = ""<br />
function on.charIn(ch)<br />
c = ch<br />
platform.window:invalidate() -- we force the screen draw<br />
end<br />
function on.paint(gc)<br />
gc:setFont(“sansserif”, "r", 10)<br />
gc:drawString(c, 0, 0, "top")<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.<br />
*'''on.mouseUp'''() is called when we release the left mouse button. <br />
*'''on.mouseMove'''() is called when the mouse moves<br />
*'''on.grabDown'''() ? (software only ?)<br />
*'''on.grabMove'''() ? (software only ?)<br />
*'''on.grabUp'''() ? (software only ?)<br />
*'''on.rightMouseDown'''() ? (software only ?)<br />
*'''on.rightMouseUp'''() ? (software only ?)<br />
----<br />
*'''on.cutEnabled'''() ? (software only ?)<br />
*'''on.copyEnabled'''() ? (software only ?)<br />
*'''on.pasteEnabled'''() ? (software only ?)<br />
*'''on.cut'''() ? (software only ?)<br />
*'''on.copy'''() ? (software only ?)<br />
*'''on.paste'''() ? (software only ?)<br />
----<br />
<br />
==D2Editor==<br />
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)<br />
*'''resize'''(width, height) <br />
*'''move'''(x, y)<br />
*'''setText'''(string)<br />
*'''getText'''() returns the RichText value<br />
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.<br />
*'''setFormattedText'''() - ?<br />
Example of a valid function using the D2Editor<br />
<syntaxhighlight lang="lua"><br />
function createRichTextBox<br />
box = D2Editor.newRichText()<br />
box:move(50, 50)<br />
box:resize(50, 50)<br />
box:setText("Hello World !")<br />
end<br />
</syntaxhighlight><br />
<br />
==External Links==<br />
An interesting page about LUA code optimization, that can be really useful, especially for calculators : [http://trac.caspring.org/wiki/LuaPerformance Lua Performance]<br />
<br />
==Online Demo==<br />
[[Document Player]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Overview_of_the_API&diff=51Overview of the API2011-05-20T20:22:12Z<p>Levak: /* Events */</p>
<hr />
<div>[[Image: See-the-link-here |thumb||right| [http://i.imgur.com/LTznh.jpg The Hexadecimal view of all the api functions, readable in an extraded phoenix.raw file]]]<br />
<br />
The TI-Nspire allows, since OS v3.0, programming with the Lua language through a hidden application "TI.ScriptApp".<br />
<br />
This page describes how to setup a Lua development environment and documents the currently known Lua functions for the Nspire, and a brief description of how to use the functions.<br />
<br />
Note: Neither the ''io'' nor ''os'' libraries are present for the TI-Nspire, which seems to be running a light version of Lua 5.1.4.<br />
<br />
Here's a dump of a lot of functions available in the API : [http://adriweb.free.fr/upload/ti/dump.html Link to the dump].<br />
<br />
==Prerequisites==<br />
<br />
Lua is only supported starting from OS v3.0.1. Creating Lua scripts is currently not officially supported by TI, you need one of the following third-party tools to convert Lua scripts to TI-Nspire documents:<br />
*[http://www.ticalc.org/archives/files/fileinfo/437/43704.html LUAtoTNS.sh] (bash script, works on Linux, Mac OS and Unix, or Windows + Cygwin or Windows + MSYS).<br />
*[http://www.mirari.fr/KbOD maketns.py] (Python script, cross-platform)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=651 lua2ti] (Windows + .NET Framework v4.0)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=652 lua2ti_linux] (Linux (No longer requires Mono, it is now a native Linux binary!))<br />
You may also want to install Lua [http://www.lua.org/download.html on your computer]: <tt>luac -p</tt> can be used to check the syntax of your script before running it on a TI-Nspire or an emulator.<br />
<br />
==Standard Library==<br />
<br />
( 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] )<br />
<br />
*'''_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<br />
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.<br />
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.<br />
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.<br />
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.<br />
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.<br />
*'''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<br />
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.<br />
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.<br />
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.<br />
*'''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.<br />
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".<br />
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.<br />
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.<br />
<br />
==Concepts and Basics==<br />
<br />
This part will explain you how the Lua actually works inside the OS and help you to figure out what you're doing when you write a script for the TI-Nspire. Before reading this, you have to know all about the Lua basics.<br />
<br />
The Lua is an interpreted script language which means that it isn't as fast as ASM/C programs, but is still better than the TI-BASIC.<br />
One good thing is that this language is in a complete harmony with the OS with basic events and a powerfull graphic context.<br />
First, we have to understand how this works. Basicly the script is launched before the executive engine. This means that we can neither evaluate expressions nor use some of the standard API (like platform, var) until the engine is launched. Here is a call summary :<br />
<br />
*Launch string library<br />
*Launch math library<br />
* ...<br />
*Open and launch User's Lua script<br />
*...<br />
*Launch var API (store, recall, ...)<br />
*Launch platform API (window, gc, ...)<br />
*...<br />
*Link events (pseudo code)<br />
<syntaxhighlight lang="lua"><br />
while(Exit)<br />
------- Some OS routines here<br />
<br />
---- Begin of Event link<br />
buffer:captureDataFromKeyPad() -- (N) some underground routines to catch events<br />
if buffer.charInput ~= "" then -- (N)<br />
on.charIn(buffer.charInput)<br />
buffer.charInput= "" -- (N)<br />
end<br />
if buffer.arrowKey ~= "" then -- (N)<br />
on.arrowKey(buffer.arrowKey)<br />
buffer.arrowKey = "" -- (N)<br />
end<br />
----- etc ... <br />
if platform.window.isInvalidate then <br />
platform.gc():purge() -- (N) Empty buffer before starting to draw<br />
on.paint(platform.gc()) -- save all the things we have to draw<br />
platform:paint() -- (N) draw all those things<br />
platform.window.isInvalidate = false -- say that the window has been drawn<br />
end<br />
----- End of Event link<br />
end<br />
</syntaxhighlight><br />
<br />
''Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.''<br />
<br />
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.<br />
<br />
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).<br />
<syntaxhighlight lang="lua"><br />
function on.paint(gc)<br />
if message then<br />
gc:setFont("sansserif", "r", 10) -- initialize font drawing<br />
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates<br />
message = nil -- erase the message<br />
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen<br />
end<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate()<br />
end<br />
<br />
function on.charIn(ch)<br />
message = "Hello World !" -- store a message<br />
platform.window:invalidate() -- force display<br />
end<br />
</syntaxhighlight><br />
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that ? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again ? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.<br />
<br />
==gc (as in Graphics Context)==<br />
<br />
Note: You need to add “gc:” before each of these commands in order to use them. ex. '''gc:setAlpha(...)'''.<br />
You can also call gc like this : '''platform.gc():setAlpha(...)'''. Then you can use the gc library in a function where gc is not passed as an argument. but this function *has* to be called within '''on.paint(gc)'''<br />
<br />
The maximum screen resolution available to Lua programs is 318 by 212 pixels.<br />
<br />
*'''begin''' -<br />
*'''clipRect''' -<br />
*'''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.<br />
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''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.<br />
For example<br />
<syntaxhighlight lang="lua"><br />
drawPolyLine({0,0, 0,100, 100,100, 100,0, 0,0})<br />
</syntaxhighlight><br />
and<br />
<syntaxhighlight lang="lua"><br />
drawRect(0,0,100,100)<br />
</syntaxhighlight><br />
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.<br />
*'''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<br />
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”. <br />
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc<br />
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine<br />
*'''fillRect'''(x, y, width, height) see drawRect<br />
*'''finish''' -<br />
*'''getStringHeight'''(string)<br />
*'''getStringWidth'''(string)<br />
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.<br />
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.<br />
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}<br />
<br />
==platform==<br />
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"<br />
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.<br />
*'''window'''<br />
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''<br />
: *'''height()''' - Returns the height of the window<br />
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')<br />
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not<br />
*'''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).<br />
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.<br />
<br />
==cursor==<br />
*'''hide'''() - hides the cursor (mouse pointer)<br />
*'''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).<br />
*'''show'''() - Shows the cursor on screen<br />
<br />
==document==<br />
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.<br />
<br />
==clipboard==<br />
*'''addText'''()<br />
*'''getText'''()<br />
<br />
==locale==<br />
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).<br />
<br />
==image==<br />
*'''__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.<br />
*'''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.<br />
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))<br />
*'''height'''(image) - returns the height of the image given in parameter<br />
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt><br />
*'''width'''(image) - returns the width of the image given in parameter<br />
<br />
==timer==<br />
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)<br />
*'''start'''(int) - Starts a timer with 1 second.<br />
*'''stop'''() - Stops a timer<br />
<br />
==toolpalette==<br />
*'''enable'''(string)<br />
*'''enableCopy'''()<br />
*'''enableCut'''()<br />
*'''enablePaste'''()<br />
*'''register'''(table)<br />
<br />
==var==<br />
*'''list'''() - returns a list of all the variables in the entire Activity<br />
*'''monitor'''() - ?<br />
*'''recall'''(string) - returns the variable value which name is given in parameter<br />
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter<br />
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value<br />
*'''unmonitor'''() - ?<br />
<br />
==Events==<br />
<br />
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)<br />
*'''on.resize'''() is called when the window is rezised<br />
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation : <br />
<syntaxhighlight lang="lua"><br />
x = 1<br />
animating = false<br />
function on.paint(gc)<br />
gc:setFont("sansserif", "r", 10)<br />
gc:drawString(tostring(x), 0, 0, "top")<br />
if animating then<br />
x = x + 1<br />
timer.start(0.5)<br />
end<br />
end<br />
<br />
function on.charIn(ch)<br />
animating = not animating -- switch state<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)<br />
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed<br />
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed<br />
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed<br />
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed<br />
----<br />
*'''on.up'''() -- probably for the touchpad up motion<br />
*'''on.down'''() -- probably for the touchpad down motion<br />
----<br />
*'''on.enterKey'''() is called when the '''enter''' key is pressed.<br />
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.<br />
*'''on.tabKey'''() is called when the '''tab''' key is pressed.<br />
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.<br />
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.<br />
*'''on.returnKey'''() is called when the '''return''' key is pressed.<br />
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.<br />
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.<br />
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.<br />
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
*'''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 :<br />
<syntaxhighlight lang="lua"><br />
c = ""<br />
function on.charIn(ch)<br />
c = ch<br />
platform.window:invalidate() -- we force the screen draw<br />
end<br />
function on.paint(gc)<br />
gc:setFont(“sansserif”, "r", 10)<br />
gc:drawString(c, 0, 0, "top")<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.<br />
*'''on.mouseUp'''() is called when we release the left mouse button. <br />
*'''on.mouseMove'''() is called when the mouse moves<br />
*'''on.grabDown'''() ? (software only ?)<br />
*'''on.grabMove'''() ? (software only ?)<br />
*'''on.grabUp'''() ? (software only ?)<br />
*'''on.rightMouseDown'''() ? (software only ?)<br />
*'''on.rightMouseUp'''() ? (software only ?)<br />
----<br />
*'''on.cutEnabled'''() ? (software only ?)<br />
*'''on.copyEnabled'''() ? (software only ?)<br />
*'''on.pasteEnabled'''() ? (software only ?)<br />
*'''on.cut'''() ? (software only ?)<br />
*'''on.copy'''() ? (software only ?)<br />
*'''on.paste'''() ? (software only ?)<br />
----<br />
<br />
==D2Editor==<br />
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)<br />
*'''resize'''(width, height) <br />
*'''move'''(x, y)<br />
*'''setText'''(string)<br />
*'''getText'''() returns the RichText value<br />
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.<br />
*'''setFormattedText'''() - ?<br />
Example of a valid function using the D2Editor<br />
function createRichTextBox<br />
box = D2Editor.newRichText()<br />
box:move(50, 50)<br />
box:resize(50, 50)<br />
box:setText("Hello World !")<br />
end<br />
<br />
==External Links==<br />
An interesting page about LUA code optimization, that can be really useful, especially for calculators : [http://trac.caspring.org/wiki/LuaPerformance Lua Performance]<br />
<br />
==Online Demo==<br />
[[Document Player]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Overview_of_the_API&diff=50Overview of the API2011-05-20T20:21:36Z<p>Levak: /* Events */</p>
<hr />
<div>[[Image: See-the-link-here |thumb||right| [http://i.imgur.com/LTznh.jpg The Hexadecimal view of all the api functions, readable in an extraded phoenix.raw file]]]<br />
<br />
The TI-Nspire allows, since OS v3.0, programming with the Lua language through a hidden application "TI.ScriptApp".<br />
<br />
This page describes how to setup a Lua development environment and documents the currently known Lua functions for the Nspire, and a brief description of how to use the functions.<br />
<br />
Note: Neither the ''io'' nor ''os'' libraries are present for the TI-Nspire, which seems to be running a light version of Lua 5.1.4.<br />
<br />
Here's a dump of a lot of functions available in the API : [http://adriweb.free.fr/upload/ti/dump.html Link to the dump].<br />
<br />
==Prerequisites==<br />
<br />
Lua is only supported starting from OS v3.0.1. Creating Lua scripts is currently not officially supported by TI, you need one of the following third-party tools to convert Lua scripts to TI-Nspire documents:<br />
*[http://www.ticalc.org/archives/files/fileinfo/437/43704.html LUAtoTNS.sh] (bash script, works on Linux, Mac OS and Unix, or Windows + Cygwin or Windows + MSYS).<br />
*[http://www.mirari.fr/KbOD maketns.py] (Python script, cross-platform)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=651 lua2ti] (Windows + .NET Framework v4.0)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=652 lua2ti_linux] (Linux (No longer requires Mono, it is now a native Linux binary!))<br />
You may also want to install Lua [http://www.lua.org/download.html on your computer]: <tt>luac -p</tt> can be used to check the syntax of your script before running it on a TI-Nspire or an emulator.<br />
<br />
==Standard Library==<br />
<br />
( 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] )<br />
<br />
*'''_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<br />
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.<br />
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.<br />
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.<br />
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.<br />
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.<br />
*'''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<br />
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.<br />
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.<br />
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.<br />
*'''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.<br />
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".<br />
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.<br />
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.<br />
<br />
==Concepts and Basics==<br />
<br />
This part will explain you how the Lua actually works inside the OS and help you to figure out what you're doing when you write a script for the TI-Nspire. Before reading this, you have to know all about the Lua basics.<br />
<br />
The Lua is an interpreted script language which means that it isn't as fast as ASM/C programs, but is still better than the TI-BASIC.<br />
One good thing is that this language is in a complete harmony with the OS with basic events and a powerfull graphic context.<br />
First, we have to understand how this works. Basicly the script is launched before the executive engine. This means that we can neither evaluate expressions nor use some of the standard API (like platform, var) until the engine is launched. Here is a call summary :<br />
<br />
*Launch string library<br />
*Launch math library<br />
* ...<br />
*Open and launch User's Lua script<br />
*...<br />
*Launch var API (store, recall, ...)<br />
*Launch platform API (window, gc, ...)<br />
*...<br />
*Link events (pseudo code)<br />
<syntaxhighlight lang="lua"><br />
while(Exit)<br />
------- Some OS routines here<br />
<br />
---- Begin of Event link<br />
buffer:captureDataFromKeyPad() -- (N) some underground routines to catch events<br />
if buffer.charInput ~= "" then -- (N)<br />
on.charIn(buffer.charInput)<br />
buffer.charInput= "" -- (N)<br />
end<br />
if buffer.arrowKey ~= "" then -- (N)<br />
on.arrowKey(buffer.arrowKey)<br />
buffer.arrowKey = "" -- (N)<br />
end<br />
----- etc ... <br />
if platform.window.isInvalidate then <br />
platform.gc():purge() -- (N) Empty buffer before starting to draw<br />
on.paint(platform.gc()) -- save all the things we have to draw<br />
platform:paint() -- (N) draw all those things<br />
platform.window.isInvalidate = false -- say that the window has been drawn<br />
end<br />
----- End of Event link<br />
end<br />
</syntaxhighlight><br />
<br />
''Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.''<br />
<br />
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.<br />
<br />
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).<br />
<syntaxhighlight lang="lua"><br />
function on.paint(gc)<br />
if message then<br />
gc:setFont("sansserif", "r", 10) -- initialize font drawing<br />
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates<br />
message = nil -- erase the message<br />
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen<br />
end<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate()<br />
end<br />
<br />
function on.charIn(ch)<br />
message = "Hello World !" -- store a message<br />
platform.window:invalidate() -- force display<br />
end<br />
</syntaxhighlight><br />
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that ? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again ? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.<br />
<br />
==gc (as in Graphics Context)==<br />
<br />
Note: You need to add “gc:” before each of these commands in order to use them. ex. '''gc:setAlpha(...)'''.<br />
You can also call gc like this : '''platform.gc():setAlpha(...)'''. Then you can use the gc library in a function where gc is not passed as an argument. but this function *has* to be called within '''on.paint(gc)'''<br />
<br />
The maximum screen resolution available to Lua programs is 318 by 212 pixels.<br />
<br />
*'''begin''' -<br />
*'''clipRect''' -<br />
*'''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.<br />
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''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.<br />
For example<br />
<syntaxhighlight lang="lua"><br />
drawPolyLine({0,0, 0,100, 100,100, 100,0, 0,0})<br />
</syntaxhighlight><br />
and<br />
<syntaxhighlight lang="lua"><br />
drawRect(0,0,100,100)<br />
</syntaxhighlight><br />
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.<br />
*'''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<br />
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”. <br />
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc<br />
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine<br />
*'''fillRect'''(x, y, width, height) see drawRect<br />
*'''finish''' -<br />
*'''getStringHeight'''(string)<br />
*'''getStringWidth'''(string)<br />
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.<br />
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.<br />
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}<br />
<br />
==platform==<br />
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"<br />
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.<br />
*'''window'''<br />
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''<br />
: *'''height()''' - Returns the height of the window<br />
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')<br />
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not<br />
*'''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).<br />
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.<br />
<br />
==cursor==<br />
*'''hide'''() - hides the cursor (mouse pointer)<br />
*'''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).<br />
*'''show'''() - Shows the cursor on screen<br />
<br />
==document==<br />
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.<br />
<br />
==clipboard==<br />
*'''addText'''()<br />
*'''getText'''()<br />
<br />
==locale==<br />
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).<br />
<br />
==image==<br />
*'''__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.<br />
*'''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.<br />
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))<br />
*'''height'''(image) - returns the height of the image given in parameter<br />
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt><br />
*'''width'''(image) - returns the width of the image given in parameter<br />
<br />
==timer==<br />
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)<br />
*'''start'''(int) - Starts a timer with 1 second.<br />
*'''stop'''() - Stops a timer<br />
<br />
==toolpalette==<br />
*'''enable'''(string)<br />
*'''enableCopy'''()<br />
*'''enableCut'''()<br />
*'''enablePaste'''()<br />
*'''register'''(table)<br />
<br />
==var==<br />
*'''list'''() - returns a list of all the variables in the entire Activity<br />
*'''monitor'''() - ?<br />
*'''recall'''(string) - returns the variable value which name is given in parameter<br />
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter<br />
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value<br />
*'''unmonitor'''() - ?<br />
<br />
==Events==<br />
<br />
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)<br />
*'''on.resize'''() is called when the window is rezised<br />
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation : <br />
<syntaxhighlight lang="lua"><br />
x = 1<br />
animating = false<br />
function on.paint(gc)<br />
gc:setFont("sansserif", "r", 10)<br />
gc:drawString(tostring(x), 0, 0, "top")<br />
if animating then<br />
x = x + 1<br />
timer.start(0.5)<br />
end<br />
end<br />
<br />
function on.charIn(ch)<br />
animating = not animating -- switch state<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)<br />
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed<br />
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed<br />
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed<br />
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed<br />
----<br />
*'''on.up'''() -- probably for the touchpad up motion<br />
*'''on.down'''() -- probably for the touchpad down motion<br />
----<br />
*'''on.enterKey'''() is called when the '''enter''' key is pressed.<br />
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.<br />
*'''on.tabKey'''() is called when the '''tab''' key is pressed.<br />
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.<br />
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.<br />
*'''on.returnKey'''() is called when the '''return''' key is pressed.<br />
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.<br />
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.<br />
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.<br />
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
*'''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 :<br />
<syntaxhighlight lang="lua"><br />
c = “”<br />
function on.charIn(ch)<br />
c = ch<br />
platform.window:invalidate() -- we force the screen draw<br />
end<br />
function on.paint(gc)<br />
gc:setFont(“sansserif”, “r”, 10)<br />
gc:drawString(c, 0, 0, “top”)<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.<br />
*'''on.mouseUp'''() is called when we release the left mouse button. <br />
*'''on.mouseMove'''() is called when the mouse moves<br />
*'''on.grabDown'''() ? (software only ?)<br />
*'''on.grabMove'''() ? (software only ?)<br />
*'''on.grabUp'''() ? (software only ?)<br />
*'''on.rightMouseDown'''() ? (software only ?)<br />
*'''on.rightMouseUp'''() ? (software only ?)<br />
----<br />
*'''on.cutEnabled'''() ? (software only ?)<br />
*'''on.copyEnabled'''() ? (software only ?)<br />
*'''on.pasteEnabled'''() ? (software only ?)<br />
*'''on.cut'''() ? (software only ?)<br />
*'''on.copy'''() ? (software only ?)<br />
*'''on.paste'''() ? (software only ?)<br />
----<br />
<br />
==D2Editor==<br />
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)<br />
*'''resize'''(width, height) <br />
*'''move'''(x, y)<br />
*'''setText'''(string)<br />
*'''getText'''() returns the RichText value<br />
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.<br />
*'''setFormattedText'''() - ?<br />
Example of a valid function using the D2Editor<br />
function createRichTextBox<br />
box = D2Editor.newRichText()<br />
box:move(50, 50)<br />
box:resize(50, 50)<br />
box:setText("Hello World !")<br />
end<br />
<br />
==External Links==<br />
An interesting page about LUA code optimization, that can be really useful, especially for calculators : [http://trac.caspring.org/wiki/LuaPerformance Lua Performance]<br />
<br />
==Online Demo==<br />
[[Document Player]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Overview_of_the_API&diff=49Overview of the API2011-05-20T20:21:14Z<p>Levak: /* Events */</p>
<hr />
<div>[[Image: See-the-link-here |thumb||right| [http://i.imgur.com/LTznh.jpg The Hexadecimal view of all the api functions, readable in an extraded phoenix.raw file]]]<br />
<br />
The TI-Nspire allows, since OS v3.0, programming with the Lua language through a hidden application "TI.ScriptApp".<br />
<br />
This page describes how to setup a Lua development environment and documents the currently known Lua functions for the Nspire, and a brief description of how to use the functions.<br />
<br />
Note: Neither the ''io'' nor ''os'' libraries are present for the TI-Nspire, which seems to be running a light version of Lua 5.1.4.<br />
<br />
Here's a dump of a lot of functions available in the API : [http://adriweb.free.fr/upload/ti/dump.html Link to the dump].<br />
<br />
==Prerequisites==<br />
<br />
Lua is only supported starting from OS v3.0.1. Creating Lua scripts is currently not officially supported by TI, you need one of the following third-party tools to convert Lua scripts to TI-Nspire documents:<br />
*[http://www.ticalc.org/archives/files/fileinfo/437/43704.html LUAtoTNS.sh] (bash script, works on Linux, Mac OS and Unix, or Windows + Cygwin or Windows + MSYS).<br />
*[http://www.mirari.fr/KbOD maketns.py] (Python script, cross-platform)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=651 lua2ti] (Windows + .NET Framework v4.0)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=652 lua2ti_linux] (Linux (No longer requires Mono, it is now a native Linux binary!))<br />
You may also want to install Lua [http://www.lua.org/download.html on your computer]: <tt>luac -p</tt> can be used to check the syntax of your script before running it on a TI-Nspire or an emulator.<br />
<br />
==Standard Library==<br />
<br />
( 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] )<br />
<br />
*'''_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<br />
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.<br />
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.<br />
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.<br />
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.<br />
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.<br />
*'''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<br />
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.<br />
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.<br />
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.<br />
*'''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.<br />
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".<br />
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.<br />
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.<br />
<br />
==Concepts and Basics==<br />
<br />
This part will explain you how the Lua actually works inside the OS and help you to figure out what you're doing when you write a script for the TI-Nspire. Before reading this, you have to know all about the Lua basics.<br />
<br />
The Lua is an interpreted script language which means that it isn't as fast as ASM/C programs, but is still better than the TI-BASIC.<br />
One good thing is that this language is in a complete harmony with the OS with basic events and a powerfull graphic context.<br />
First, we have to understand how this works. Basicly the script is launched before the executive engine. This means that we can neither evaluate expressions nor use some of the standard API (like platform, var) until the engine is launched. Here is a call summary :<br />
<br />
*Launch string library<br />
*Launch math library<br />
* ...<br />
*Open and launch User's Lua script<br />
*...<br />
*Launch var API (store, recall, ...)<br />
*Launch platform API (window, gc, ...)<br />
*...<br />
*Link events (pseudo code)<br />
<syntaxhighlight lang="lua"><br />
while(Exit)<br />
------- Some OS routines here<br />
<br />
---- Begin of Event link<br />
buffer:captureDataFromKeyPad() -- (N) some underground routines to catch events<br />
if buffer.charInput ~= "" then -- (N)<br />
on.charIn(buffer.charInput)<br />
buffer.charInput= "" -- (N)<br />
end<br />
if buffer.arrowKey ~= "" then -- (N)<br />
on.arrowKey(buffer.arrowKey)<br />
buffer.arrowKey = "" -- (N)<br />
end<br />
----- etc ... <br />
if platform.window.isInvalidate then <br />
platform.gc():purge() -- (N) Empty buffer before starting to draw<br />
on.paint(platform.gc()) -- save all the things we have to draw<br />
platform:paint() -- (N) draw all those things<br />
platform.window.isInvalidate = false -- say that the window has been drawn<br />
end<br />
----- End of Event link<br />
end<br />
</syntaxhighlight><br />
<br />
''Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.''<br />
<br />
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.<br />
<br />
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).<br />
<syntaxhighlight lang="lua"><br />
function on.paint(gc)<br />
if message then<br />
gc:setFont("sansserif", "r", 10) -- initialize font drawing<br />
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates<br />
message = nil -- erase the message<br />
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen<br />
end<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate()<br />
end<br />
<br />
function on.charIn(ch)<br />
message = "Hello World !" -- store a message<br />
platform.window:invalidate() -- force display<br />
end<br />
</syntaxhighlight><br />
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that ? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again ? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.<br />
<br />
==gc (as in Graphics Context)==<br />
<br />
Note: You need to add “gc:” before each of these commands in order to use them. ex. '''gc:setAlpha(...)'''.<br />
You can also call gc like this : '''platform.gc():setAlpha(...)'''. Then you can use the gc library in a function where gc is not passed as an argument. but this function *has* to be called within '''on.paint(gc)'''<br />
<br />
The maximum screen resolution available to Lua programs is 318 by 212 pixels.<br />
<br />
*'''begin''' -<br />
*'''clipRect''' -<br />
*'''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.<br />
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''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.<br />
For example<br />
<syntaxhighlight lang="lua"><br />
drawPolyLine({0,0, 0,100, 100,100, 100,0, 0,0})<br />
</syntaxhighlight><br />
and<br />
<syntaxhighlight lang="lua"><br />
drawRect(0,0,100,100)<br />
</syntaxhighlight><br />
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.<br />
*'''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<br />
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”. <br />
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc<br />
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine<br />
*'''fillRect'''(x, y, width, height) see drawRect<br />
*'''finish''' -<br />
*'''getStringHeight'''(string)<br />
*'''getStringWidth'''(string)<br />
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.<br />
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.<br />
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}<br />
<br />
==platform==<br />
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"<br />
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.<br />
*'''window'''<br />
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''<br />
: *'''height()''' - Returns the height of the window<br />
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')<br />
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not<br />
*'''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).<br />
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.<br />
<br />
==cursor==<br />
*'''hide'''() - hides the cursor (mouse pointer)<br />
*'''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).<br />
*'''show'''() - Shows the cursor on screen<br />
<br />
==document==<br />
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.<br />
<br />
==clipboard==<br />
*'''addText'''()<br />
*'''getText'''()<br />
<br />
==locale==<br />
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).<br />
<br />
==image==<br />
*'''__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.<br />
*'''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.<br />
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))<br />
*'''height'''(image) - returns the height of the image given in parameter<br />
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt><br />
*'''width'''(image) - returns the width of the image given in parameter<br />
<br />
==timer==<br />
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)<br />
*'''start'''(int) - Starts a timer with 1 second.<br />
*'''stop'''() - Stops a timer<br />
<br />
==toolpalette==<br />
*'''enable'''(string)<br />
*'''enableCopy'''()<br />
*'''enableCut'''()<br />
*'''enablePaste'''()<br />
*'''register'''(table)<br />
<br />
==var==<br />
*'''list'''() - returns a list of all the variables in the entire Activity<br />
*'''monitor'''() - ?<br />
*'''recall'''(string) - returns the variable value which name is given in parameter<br />
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter<br />
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value<br />
*'''unmonitor'''() - ?<br />
<br />
==Events==<br />
<br />
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)<br />
*'''on.resize'''() is called when the window is rezised<br />
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation : <br />
<syntaxhighlight lang="lua"><br />
x = 1<br />
animating = false<br />
function on.paint(gc)<br />
gc:setFont("sansserif", "r", 10)<br />
gc:drawString(tostring(x), 0, 0, "top")<br />
if animating then<br />
x = x + 1<br />
timer.start(0.5)<br />
end<br />
end<br />
<br />
function on.charIn(ch)<br />
animating = not animating -- switch state<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
</syntaxhighlight><br />
----<br />
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)<br />
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed<br />
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed<br />
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed<br />
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed<br />
----<br />
*'''on.up'''() -- probably for the touchpad up motion<br />
*'''on.down'''() -- probably for the touchpad down motion<br />
----<br />
*'''on.enterKey'''() is called when the '''enter''' key is pressed.<br />
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.<br />
*'''on.tabKey'''() is called when the '''tab''' key is pressed.<br />
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.<br />
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.<br />
*'''on.returnKey'''() is called when the '''return''' key is pressed.<br />
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.<br />
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.<br />
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.<br />
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
*'''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 :<br />
<br />
c = “”<br />
function on.charIn(ch)<br />
c = ch<br />
platform.window:invalidate() -- we force the screen draw<br />
end<br />
function on.paint(gc)<br />
gc:setFont(“sansserif”, “r”, 10)<br />
gc:drawString(c, 0, 0, “top”)<br />
end<br />
<br />
----<br />
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.<br />
*'''on.mouseUp'''() is called when we release the left mouse button. <br />
*'''on.mouseMove'''() is called when the mouse moves<br />
*'''on.grabDown'''() ? (software only ?)<br />
*'''on.grabMove'''() ? (software only ?)<br />
*'''on.grabUp'''() ? (software only ?)<br />
*'''on.rightMouseDown'''() ? (software only ?)<br />
*'''on.rightMouseUp'''() ? (software only ?)<br />
----<br />
*'''on.cutEnabled'''() ? (software only ?)<br />
*'''on.copyEnabled'''() ? (software only ?)<br />
*'''on.pasteEnabled'''() ? (software only ?)<br />
*'''on.cut'''() ? (software only ?)<br />
*'''on.copy'''() ? (software only ?)<br />
*'''on.paste'''() ? (software only ?)<br />
----<br />
<br />
==D2Editor==<br />
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)<br />
*'''resize'''(width, height) <br />
*'''move'''(x, y)<br />
*'''setText'''(string)<br />
*'''getText'''() returns the RichText value<br />
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.<br />
*'''setFormattedText'''() - ?<br />
Example of a valid function using the D2Editor<br />
function createRichTextBox<br />
box = D2Editor.newRichText()<br />
box:move(50, 50)<br />
box:resize(50, 50)<br />
box:setText("Hello World !")<br />
end<br />
<br />
==External Links==<br />
An interesting page about LUA code optimization, that can be really useful, especially for calculators : [http://trac.caspring.org/wiki/LuaPerformance Lua Performance]<br />
<br />
==Online Demo==<br />
[[Document Player]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Overview_of_the_API&diff=48Overview of the API2011-05-20T20:20:22Z<p>Levak: /* gc (as in Graphics Context) */</p>
<hr />
<div>[[Image: See-the-link-here |thumb||right| [http://i.imgur.com/LTznh.jpg The Hexadecimal view of all the api functions, readable in an extraded phoenix.raw file]]]<br />
<br />
The TI-Nspire allows, since OS v3.0, programming with the Lua language through a hidden application "TI.ScriptApp".<br />
<br />
This page describes how to setup a Lua development environment and documents the currently known Lua functions for the Nspire, and a brief description of how to use the functions.<br />
<br />
Note: Neither the ''io'' nor ''os'' libraries are present for the TI-Nspire, which seems to be running a light version of Lua 5.1.4.<br />
<br />
Here's a dump of a lot of functions available in the API : [http://adriweb.free.fr/upload/ti/dump.html Link to the dump].<br />
<br />
==Prerequisites==<br />
<br />
Lua is only supported starting from OS v3.0.1. Creating Lua scripts is currently not officially supported by TI, you need one of the following third-party tools to convert Lua scripts to TI-Nspire documents:<br />
*[http://www.ticalc.org/archives/files/fileinfo/437/43704.html LUAtoTNS.sh] (bash script, works on Linux, Mac OS and Unix, or Windows + Cygwin or Windows + MSYS).<br />
*[http://www.mirari.fr/KbOD maketns.py] (Python script, cross-platform)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=651 lua2ti] (Windows + .NET Framework v4.0)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=652 lua2ti_linux] (Linux (No longer requires Mono, it is now a native Linux binary!))<br />
You may also want to install Lua [http://www.lua.org/download.html on your computer]: <tt>luac -p</tt> can be used to check the syntax of your script before running it on a TI-Nspire or an emulator.<br />
<br />
==Standard Library==<br />
<br />
( 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] )<br />
<br />
*'''_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<br />
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.<br />
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.<br />
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.<br />
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.<br />
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.<br />
*'''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<br />
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.<br />
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.<br />
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.<br />
*'''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.<br />
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".<br />
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.<br />
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.<br />
<br />
==Concepts and Basics==<br />
<br />
This part will explain you how the Lua actually works inside the OS and help you to figure out what you're doing when you write a script for the TI-Nspire. Before reading this, you have to know all about the Lua basics.<br />
<br />
The Lua is an interpreted script language which means that it isn't as fast as ASM/C programs, but is still better than the TI-BASIC.<br />
One good thing is that this language is in a complete harmony with the OS with basic events and a powerfull graphic context.<br />
First, we have to understand how this works. Basicly the script is launched before the executive engine. This means that we can neither evaluate expressions nor use some of the standard API (like platform, var) until the engine is launched. Here is a call summary :<br />
<br />
*Launch string library<br />
*Launch math library<br />
* ...<br />
*Open and launch User's Lua script<br />
*...<br />
*Launch var API (store, recall, ...)<br />
*Launch platform API (window, gc, ...)<br />
*...<br />
*Link events (pseudo code)<br />
<syntaxhighlight lang="lua"><br />
while(Exit)<br />
------- Some OS routines here<br />
<br />
---- Begin of Event link<br />
buffer:captureDataFromKeyPad() -- (N) some underground routines to catch events<br />
if buffer.charInput ~= "" then -- (N)<br />
on.charIn(buffer.charInput)<br />
buffer.charInput= "" -- (N)<br />
end<br />
if buffer.arrowKey ~= "" then -- (N)<br />
on.arrowKey(buffer.arrowKey)<br />
buffer.arrowKey = "" -- (N)<br />
end<br />
----- etc ... <br />
if platform.window.isInvalidate then <br />
platform.gc():purge() -- (N) Empty buffer before starting to draw<br />
on.paint(platform.gc()) -- save all the things we have to draw<br />
platform:paint() -- (N) draw all those things<br />
platform.window.isInvalidate = false -- say that the window has been drawn<br />
end<br />
----- End of Event link<br />
end<br />
</syntaxhighlight><br />
<br />
''Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.''<br />
<br />
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.<br />
<br />
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).<br />
<syntaxhighlight lang="lua"><br />
function on.paint(gc)<br />
if message then<br />
gc:setFont("sansserif", "r", 10) -- initialize font drawing<br />
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates<br />
message = nil -- erase the message<br />
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen<br />
end<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate()<br />
end<br />
<br />
function on.charIn(ch)<br />
message = "Hello World !" -- store a message<br />
platform.window:invalidate() -- force display<br />
end<br />
</syntaxhighlight><br />
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that ? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again ? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.<br />
<br />
==gc (as in Graphics Context)==<br />
<br />
Note: You need to add “gc:” before each of these commands in order to use them. ex. '''gc:setAlpha(...)'''.<br />
You can also call gc like this : '''platform.gc():setAlpha(...)'''. Then you can use the gc library in a function where gc is not passed as an argument. but this function *has* to be called within '''on.paint(gc)'''<br />
<br />
The maximum screen resolution available to Lua programs is 318 by 212 pixels.<br />
<br />
*'''begin''' -<br />
*'''clipRect''' -<br />
*'''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.<br />
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''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.<br />
For example<br />
<syntaxhighlight lang="lua"><br />
drawPolyLine({0,0, 0,100, 100,100, 100,0, 0,0})<br />
</syntaxhighlight><br />
and<br />
<syntaxhighlight lang="lua"><br />
drawRect(0,0,100,100)<br />
</syntaxhighlight><br />
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.<br />
*'''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<br />
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”. <br />
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc<br />
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine<br />
*'''fillRect'''(x, y, width, height) see drawRect<br />
*'''finish''' -<br />
*'''getStringHeight'''(string)<br />
*'''getStringWidth'''(string)<br />
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.<br />
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.<br />
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}<br />
<br />
==platform==<br />
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"<br />
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.<br />
*'''window'''<br />
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''<br />
: *'''height()''' - Returns the height of the window<br />
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')<br />
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not<br />
*'''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).<br />
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.<br />
<br />
==cursor==<br />
*'''hide'''() - hides the cursor (mouse pointer)<br />
*'''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).<br />
*'''show'''() - Shows the cursor on screen<br />
<br />
==document==<br />
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.<br />
<br />
==clipboard==<br />
*'''addText'''()<br />
*'''getText'''()<br />
<br />
==locale==<br />
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).<br />
<br />
==image==<br />
*'''__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.<br />
*'''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.<br />
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))<br />
*'''height'''(image) - returns the height of the image given in parameter<br />
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt><br />
*'''width'''(image) - returns the width of the image given in parameter<br />
<br />
==timer==<br />
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)<br />
*'''start'''(int) - Starts a timer with 1 second.<br />
*'''stop'''() - Stops a timer<br />
<br />
==toolpalette==<br />
*'''enable'''(string)<br />
*'''enableCopy'''()<br />
*'''enableCut'''()<br />
*'''enablePaste'''()<br />
*'''register'''(table)<br />
<br />
==var==<br />
*'''list'''() - returns a list of all the variables in the entire Activity<br />
*'''monitor'''() - ?<br />
*'''recall'''(string) - returns the variable value which name is given in parameter<br />
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter<br />
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value<br />
*'''unmonitor'''() - ?<br />
<br />
==Events==<br />
<br />
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)<br />
*'''on.resize'''() is called when the window is rezised<br />
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation : <br />
x = 1<br />
animating = false<br />
function on.paint(gc)<br />
gc:setFont("sansserif", "r", 10)<br />
gc:drawString(tostring(x), 0, 0, "top")<br />
if animating then<br />
x = x + 1<br />
timer.start(0.5)<br />
end<br />
end<br />
<br />
function on.charIn(ch)<br />
animating = not animating -- switch state<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
----<br />
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)<br />
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed<br />
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed<br />
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed<br />
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed<br />
----<br />
*'''on.up'''() -- probably for the touchpad up motion<br />
*'''on.down'''() -- probably for the touchpad down motion<br />
----<br />
*'''on.enterKey'''() is called when the '''enter''' key is pressed.<br />
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.<br />
*'''on.tabKey'''() is called when the '''tab''' key is pressed.<br />
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.<br />
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.<br />
*'''on.returnKey'''() is called when the '''return''' key is pressed.<br />
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.<br />
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.<br />
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.<br />
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
*'''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 :<br />
<br />
c = “”<br />
function on.charIn(ch)<br />
c = ch<br />
platform.window:invalidate() -- we force the screen draw<br />
end<br />
function on.paint(gc)<br />
gc:setFont(“sansserif”, “r”, 10)<br />
gc:drawString(c, 0, 0, “top”)<br />
end<br />
<br />
----<br />
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.<br />
*'''on.mouseUp'''() is called when we release the left mouse button. <br />
*'''on.mouseMove'''() is called when the mouse moves<br />
*'''on.grabDown'''() ? (software only ?)<br />
*'''on.grabMove'''() ? (software only ?)<br />
*'''on.grabUp'''() ? (software only ?)<br />
*'''on.rightMouseDown'''() ? (software only ?)<br />
*'''on.rightMouseUp'''() ? (software only ?)<br />
----<br />
*'''on.cutEnabled'''() ? (software only ?)<br />
*'''on.copyEnabled'''() ? (software only ?)<br />
*'''on.pasteEnabled'''() ? (software only ?)<br />
*'''on.cut'''() ? (software only ?)<br />
*'''on.copy'''() ? (software only ?)<br />
*'''on.paste'''() ? (software only ?)<br />
----<br />
<br />
==D2Editor==<br />
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)<br />
*'''resize'''(width, height) <br />
*'''move'''(x, y)<br />
*'''setText'''(string)<br />
*'''getText'''() returns the RichText value<br />
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.<br />
*'''setFormattedText'''() - ?<br />
Example of a valid function using the D2Editor<br />
function createRichTextBox<br />
box = D2Editor.newRichText()<br />
box:move(50, 50)<br />
box:resize(50, 50)<br />
box:setText("Hello World !")<br />
end<br />
<br />
==External Links==<br />
An interesting page about LUA code optimization, that can be really useful, especially for calculators : [http://trac.caspring.org/wiki/LuaPerformance Lua Performance]<br />
<br />
==Online Demo==<br />
[[Document Player]]</div>Levakhttps://wiki.inspired-lua.org/index.php?title=Overview_of_the_API&diff=47Overview of the API2011-05-20T20:09:07Z<p>Levak: /* Concepts and Basics */</p>
<hr />
<div>[[Image: See-the-link-here |thumb||right| [http://i.imgur.com/LTznh.jpg The Hexadecimal view of all the api functions, readable in an extraded phoenix.raw file]]]<br />
<br />
The TI-Nspire allows, since OS v3.0, programming with the Lua language through a hidden application "TI.ScriptApp".<br />
<br />
This page describes how to setup a Lua development environment and documents the currently known Lua functions for the Nspire, and a brief description of how to use the functions.<br />
<br />
Note: Neither the ''io'' nor ''os'' libraries are present for the TI-Nspire, which seems to be running a light version of Lua 5.1.4.<br />
<br />
Here's a dump of a lot of functions available in the API : [http://adriweb.free.fr/upload/ti/dump.html Link to the dump].<br />
<br />
==Prerequisites==<br />
<br />
Lua is only supported starting from OS v3.0.1. Creating Lua scripts is currently not officially supported by TI, you need one of the following third-party tools to convert Lua scripts to TI-Nspire documents:<br />
*[http://www.ticalc.org/archives/files/fileinfo/437/43704.html LUAtoTNS.sh] (bash script, works on Linux, Mac OS and Unix, or Windows + Cygwin or Windows + MSYS).<br />
*[http://www.mirari.fr/KbOD maketns.py] (Python script, cross-platform)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=651 lua2ti] (Windows + .NET Framework v4.0)<br />
*[http://www.omnimaga.org/index.php?action=downloads;sa=view;down=652 lua2ti_linux] (Linux (No longer requires Mono, it is now a native Linux binary!))<br />
You may also want to install Lua [http://www.lua.org/download.html on your computer]: <tt>luac -p</tt> can be used to check the syntax of your script before running it on a TI-Nspire or an emulator.<br />
<br />
==Standard Library==<br />
<br />
( 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] )<br />
<br />
*'''_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<br />
*'''assert'''(value[, errormsg]) - asserts a value evaluates to true. If it is, returns value, otherwise causes a Lua error to be thrown.<br />
*'''getfenv'''(function or integer) - Returns the table representing the stack frame of the given function or stack level.<br />
*'''getmetatable'''(obj, mtable) - Returns the metatable of the given table or userdata object.<br />
*'''next'''(table, index) - Returns the next key, value pair of the table, allowing you to walk over the table.<br />
*'''newproxy'''(boolean or proxy) - Creates a userdata with a sharable metatable.<br />
*'''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<br />
*'''select'''(index, list) - Returns the number of items in list or the value of the item in list at index.<br />
*'''setfenv'''(function or integer, table) - Sets the table representing the stack frame of the given function or stack level.<br />
*'''setmetatable'''(obj, mtable) - Sets the metatable of the given table or userdata object.<br />
*'''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.<br />
*'''type'''(var) - Returns the type of variable as a string, "number", "string", "table", "function" or "userdata".<br />
*'''unpack'''(table[, start][, end]) - Returns the contents of its argument as separate values.<br />
*'''xpcall'''(func, err) - Returns a boolean indicating successful execution of func and calls err on failure, additionally returning func's or err's results.<br />
<br />
==Concepts and Basics==<br />
<br />
This part will explain you how the Lua actually works inside the OS and help you to figure out what you're doing when you write a script for the TI-Nspire. Before reading this, you have to know all about the Lua basics.<br />
<br />
The Lua is an interpreted script language which means that it isn't as fast as ASM/C programs, but is still better than the TI-BASIC.<br />
One good thing is that this language is in a complete harmony with the OS with basic events and a powerfull graphic context.<br />
First, we have to understand how this works. Basicly the script is launched before the executive engine. This means that we can neither evaluate expressions nor use some of the standard API (like platform, var) until the engine is launched. Here is a call summary :<br />
<br />
*Launch string library<br />
*Launch math library<br />
* ...<br />
*Open and launch User's Lua script<br />
*...<br />
*Launch var API (store, recall, ...)<br />
*Launch platform API (window, gc, ...)<br />
*...<br />
*Link events (pseudo code)<br />
<syntaxhighlight lang="lua"><br />
while(Exit)<br />
------- Some OS routines here<br />
<br />
---- Begin of Event link<br />
buffer:captureDataFromKeyPad() -- (N) some underground routines to catch events<br />
if buffer.charInput ~= "" then -- (N)<br />
on.charIn(buffer.charInput)<br />
buffer.charInput= "" -- (N)<br />
end<br />
if buffer.arrowKey ~= "" then -- (N)<br />
on.arrowKey(buffer.arrowKey)<br />
buffer.arrowKey = "" -- (N)<br />
end<br />
----- etc ... <br />
if platform.window.isInvalidate then <br />
platform.gc():purge() -- (N) Empty buffer before starting to draw<br />
on.paint(platform.gc()) -- save all the things we have to draw<br />
platform:paint() -- (N) draw all those things<br />
platform.window.isInvalidate = false -- say that the window has been drawn<br />
end<br />
----- End of Event link<br />
end<br />
</syntaxhighlight><br />
<br />
''Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.''<br />
<br />
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.<br />
<br />
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).<br />
<syntaxhighlight lang="lua"><br />
function on.paint(gc)<br />
if message then<br />
gc:setFont("sansserif", "r", 10) -- initialize font drawing<br />
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates<br />
message = nil -- erase the message<br />
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen<br />
end<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate()<br />
end<br />
<br />
function on.charIn(ch)<br />
message = "Hello World !" -- store a message<br />
platform.window:invalidate() -- force display<br />
end<br />
</syntaxhighlight><br />
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that ? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again ? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.<br />
<br />
==gc (as in Graphics Context)==<br />
<br />
Note: You need to add “gc:” before each of these commands in order to use them. ex. '''gc:setAlpha(...)'''.<br />
You can also call gc like this : '''platform.gc():setAlpha(...)'''. Then you can use the gc library in a function where gc is not passed as an argument. but this function *has* to be called within '''on.paint(gc)'''<br />
<br />
The maximum screen resolution available to Lua programs is 318 by 212 pixels.<br />
<br />
*'''begin''' -<br />
*'''clipRect''' -<br />
*'''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.<br />
*'''drawImage'''(image,x,y) First argument in format “[[TI.Image]]”, x and y the coords.<br />
*'''drawLine'''(xstart, ystart, xend, yend) Draws a line starting at the point (xstart,ystart) and ending at the point (xend, yend)<br />
*'''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.<br />
For example<br />
drawPolyLine({0,0, 0,100, 100,100, 100,0, 0,0})<br />
and<br />
drawRect(0,0,100,100)<br />
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.<br />
*'''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<br />
*'''drawString'''(string, x, y, PositionString) PositionString is the string’s anchor point and can be “bottom”, “middle”, or “top”. <br />
*'''fillArc'''(x, y, width, height, start angle, finish angle) see drawArc<br />
*'''fillPolygon'''(int list1 [,int list2, .., int listN]) see drawPolyLine<br />
*'''fillRect'''(x, y, width, height) see drawRect<br />
*'''finish''' -<br />
*'''getStringHeight'''(string)<br />
*'''getStringWidth'''(string)<br />
*'''isColorDisplay''' Bool (Read-only) Returns 1 if color, 0 if not.<br />
*'''setAlpha'''(int) - where the argument is an int between 0 and 255. Sets the transparency.<br />
*'''setColorRGB'''(red, green, blue) RGB values are integers, from 0 to 255.<br />
*'''setFont'''(font, type, size), with font : {“sansserif”, "serif", ..}, type {“b”, “r”, “i”}, size(int)<br />
*'''setPen'''(size, smooth) size {“thin”, “medium”, "thick"}, smooth {“smooth”, "dotted", "dashed"}<br />
<br />
==platform==<br />
These are mainly read-only. These work by writing "'''platform.'''" in front of them. Example : "'''platform.window:invalidate()'''"<br />
*'''apilevel()''' : Returns the version of the API. Currently (OS 3.0.1) returns 1.0.0.<br />
*'''window'''<br />
: *'''width()''' - Returns the width of the window. Ex : ''platform.window:height()''<br />
: *'''height()''' - Returns the height of the window<br />
: *'''invalidate()''' - Repaints the window (it calls '''on.paint(gc)''')<br />
*''' isDeviceModeRendering()''' Returns true or false whether the unit is "rendering" or not<br />
*'''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).<br />
*'''isColorDisplay()''' Returns ''true'' if the unit the code is being run on has a color display (-> Nspire CX), and ''false'' otherwise.<br />
<br />
==cursor==<br />
*'''hide'''() - hides the cursor (mouse pointer)<br />
*'''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).<br />
*'''show'''() - Shows the cursor on screen<br />
<br />
==document==<br />
*'''markChanged'''() - Flag the document as "changed" so the user has to save it after using it.<br />
<br />
==clipboard==<br />
*'''addText'''()<br />
*'''getText'''()<br />
<br />
==locale==<br />
*'''name'''() - Returns the current language the calculator is set in, formatted as ISO-639 (i.e : "fr", "en", "it" ...).<br />
<br />
==image==<br />
*'''__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.<br />
*'''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.<br />
To make a relative scale, use '''image.copy'''(image, scaleX * '''image.width'''(image), scaleY * '''image.height'''(image))<br />
*'''height'''(image) - returns the height of the image given in parameter<br />
*'''new'''(string) - Creates a new image from the string given in parameter (see TI.Image). Call it with <tt>img = image.new("...")</tt><br />
*'''width'''(image) - returns the width of the image given in parameter<br />
<br />
==timer==<br />
*'''getMilliSecCounter'''() - Returns the amount of milliseconds elapsed since last calculator reboot. (in TI's Computer software, returns an absolute negative time)<br />
*'''start'''(int) - Starts a timer with 1 second.<br />
*'''stop'''() - Stops a timer<br />
<br />
==toolpalette==<br />
*'''enable'''(string)<br />
*'''enableCopy'''()<br />
*'''enableCut'''()<br />
*'''enablePaste'''()<br />
*'''register'''(table)<br />
<br />
==var==<br />
*'''list'''() - returns a list of all the variables in the entire Activity<br />
*'''monitor'''() - ?<br />
*'''recall'''(string) - returns the variable value which name is given in parameter<br />
*'''recallstr'''(string) - returns the variable value converted to string which name is given in parameter<br />
*'''store'''(string, value) - store in the variable, which name is given in parameter, the value<br />
*'''unmonitor'''() - ?<br />
<br />
==Events==<br />
<br />
*'''on.paint'''(gc) is called when the GUI is painted. 'gc' is the Graphics Context (see above)<br />
*'''on.resize'''() is called when the window is rezised<br />
*'''on.timer'''() is called when the timer has been finished. Here an example of using timer to play an animation : <br />
x = 1<br />
animating = false<br />
function on.paint(gc)<br />
gc:setFont("sansserif", "r", 10)<br />
gc:drawString(tostring(x), 0, 0, "top")<br />
if animating then<br />
x = x + 1<br />
timer.start(0.5)<br />
end<br />
end<br />
<br />
function on.charIn(ch)<br />
animating = not animating -- switch state<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
function on.timer()<br />
timer.stop()<br />
platform.window:invalidate() -- recall graph engine<br />
end<br />
<br />
----<br />
*'''on.arrowKey'''(key) is called when an '''arrow key''' from the clickPad/TouchPad is pressed (right, left, up, down)<br />
*'''on.arrowLeft'''() is called when the '''left''' arrow is pressed<br />
*'''on.arrowRight'''() is called when the '''right''' arrow is pressed<br />
*'''on.arrowUp'''() is called when the up '''arrow''' is pressed<br />
*'''on.arrowDown'''() is called when the '''down''' arrow is pressed<br />
----<br />
*'''on.up'''() -- probably for the touchpad up motion<br />
*'''on.down'''() -- probably for the touchpad down motion<br />
----<br />
*'''on.enterKey'''() is called when the '''enter''' key is pressed.<br />
*'''on.escapeKey'''() is called when the '''escape''' key is pressed.<br />
*'''on.tabKey'''() is called when the '''tab''' key is pressed.<br />
*'''on.deleteKey'''() is called when the '''delete''' key is pressed.<br />
*'''on.backspaceKey'''() is called when the '''clear''' key is pressed.<br />
*'''on.returnKey'''() is called when the '''return''' key is pressed.<br />
*'''on.contextMenu'''() is called when the combo-key '''Ctrl Menu''' is pressed.<br />
*'''on.backtabKey'''() is called when the combo-key '''Maj Tab''' is pressed.<br />
*'''on.clearKey'''() is called when the combo-key '''Ctrl Clear''' is pressed.<br />
*'''on.help'''() is called when the combo-key '''Ctrl H''' is pressed.<br />
<br />
*'''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 :<br />
<br />
c = “”<br />
function on.charIn(ch)<br />
c = ch<br />
platform.window:invalidate() -- we force the screen draw<br />
end<br />
function on.paint(gc)<br />
gc:setFont(“sansserif”, “r”, 10)<br />
gc:drawString(c, 0, 0, “top”)<br />
end<br />
<br />
----<br />
*'''on.blink'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.deactivate'''() ? is called when the focus is lost on the page (like launching the document, changing page etc...)<br />
*'''on.activate'''() ? is called when the focus is on the page (like launching the document, changing page etc...)<br />
----<br />
*'''on.mouseDown'''(x, y) is called when we press the left mouse button. X and Y are the pressed point coordinates.<br />
*'''on.mouseUp'''() is called when we release the left mouse button. <br />
*'''on.mouseMove'''() is called when the mouse moves<br />
*'''on.grabDown'''() ? (software only ?)<br />
*'''on.grabMove'''() ? (software only ?)<br />
*'''on.grabUp'''() ? (software only ?)<br />
*'''on.rightMouseDown'''() ? (software only ?)<br />
*'''on.rightMouseUp'''() ? (software only ?)<br />
----<br />
*'''on.cutEnabled'''() ? (software only ?)<br />
*'''on.copyEnabled'''() ? (software only ?)<br />
*'''on.pasteEnabled'''() ? (software only ?)<br />
*'''on.cut'''() ? (software only ?)<br />
*'''on.copy'''() ? (software only ?)<br />
*'''on.paste'''() ? (software only ?)<br />
----<br />
<br />
==D2Editor==<br />
*'''newRichText'''() creates a new RichText object (default values : x, y, width, height = 0)<br />
*'''resize'''(width, height) <br />
*'''move'''(x, y)<br />
*'''setText'''(string)<br />
*'''getText'''() returns the RichText value<br />
*'''setReadOnly'''(bool) bool : true/false : If true, the content becomes read-only, i.e. non-editable.<br />
*'''setFormattedText'''() - ?<br />
Example of a valid function using the D2Editor<br />
function createRichTextBox<br />
box = D2Editor.newRichText()<br />
box:move(50, 50)<br />
box:resize(50, 50)<br />
box:setText("Hello World !")<br />
end<br />
<br />
==External Links==<br />
An interesting page about LUA code optimization, that can be really useful, especially for calculators : [http://trac.caspring.org/wiki/LuaPerformance Lua Performance]<br />
<br />
==Online Demo==<br />
[[Document Player]]</div>Levak