Lua and user defined functions

217 views
Skip to first unread message

Bert Wikkerink

unread,
Mar 11, 2012, 10:53:19 AM3/11/12
to tins...@googlegroups.com
Hi,

I was in Chicago too and had a great time!
Learned a lot about lua and other things, but ...

Is there a way to call a user defined function (created in TI-Nspire) in a lua script?

Bert Wikkerink


--
Dit bericht is gescanned op virussen en andere gevaarlijke
inhoud door MailScanner en lijkt schoon te zijn.

Adriweb

unread,
Mar 11, 2012, 11:38:36 AM3/11/12
to tins...@googlegroups.com
Hi !

What you are looking for is the math.eval() function

On OS < 3.2, it's just math.eval("your math expression here") and it will return a string with the result.
On OS >= 3.2, this commands still exists but will return a number with the result. To have a string, just do math.evalStr("expression")

For your example, just type your basic's function name etc...

You can find some more info here : http://wiki.inspired-lua.org/math.eval

And probably some tutorials about it on inspired-lua.org or Steve Arnold's website here (http://www.compasstech.com.au/TNS_Authoring/Scripting/script_tut16.html).

What the official doc says about it (3.1) : 

math.eval(math_expression)
This function sends an expression or command to the Nspire math server for evaluation.
The input expression must be a string that the Nspire math server can interpret and
evaluate.

If the math server successfully evaluates the expression, it returns the numerical results.
The eval function returns no result if the math server does not return a calculated result
or if the calculated result cannot be represented as a fundamental Lua data type.

If the math server cannot evaluate the expression because of a syntax, simplification, or
semantic error, eval returns two results: nil and an error number.
 

Have fun !

Adriweb

unread,
Mar 11, 2012, 11:44:41 AM3/11/12
to tins...@googlegroups.com
Also, just a little addition : 

on < 3.2, math.eval() returns directly the right type of variable (number if the result if number, 1d table if list, etc.)
On 3.2 with platform.apilevel = "1.0", it forces the output type as string...

Andy Kemp

unread,
Mar 11, 2012, 1:40:07 PM3/11/12
to tins...@googlegroups.com
It's also worth noting that you can use the math.eval() function to make use of any of the built-in routines on the Nspire including the CAS engine if you are using a CAS device...

--
To post to this group, send email to tins...@googlegroups.com
To unsubscribe send email to tinspire+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com.au/group/tinspire?hl=en-GB?hl=en-GB
The tns documents shared by group members are archived at
https://sites.google.com/site/tinspiregroup/classroom-news/welcome-abouttime

Levak

unread,
Mar 11, 2012, 2:21:20 PM3/11/12
to tins...@googlegroups.com
Note that you can't use programs (Prgm:EndPrgm) or built-in graphical routines (Text, Request ...) with math.eval()


On Sunday, 11 March 2012 19:40:07 UTC+2, Andy Kemp wrote:
It's also worth noting that you can use the math.eval() function to make use of any of the built-in routines on the Nspire including the CAS engine if you are using a CAS device...

On Sun, Mar 11, 2012 at 3:44 PM, Adriweb <bertran...@gmail.com> wrote:
Also, just a little addition : 

on < 3.2, math.eval() returns directly the right type of variable (number if the result if number, 1d table if list, etc.)
On 3.2 with platform.apilevel = "1.0", it forces the output type as string...

--
To post to this group, send email to tins...@googlegroups.com
To unsubscribe send email to tinspire+unsubscribe@googlegroups.com

Eric Findlay

unread,
Mar 11, 2012, 8:48:20 PM3/11/12
to tins...@googlegroups.com
Hmm...yet another great reason to design function properly instead of relying on input boxes.  ;)

  --Eric
To unsubscribe send email to tinspire+u...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages