5

I am trying to understand how to use the TI-Nspire CAS system through Lua. I am trying to emulate the solve(x+5/3,x) functionality found in the TI-Nspire CX CAS gui.

I looked through the API Docs found here : https://education.ti.com/download/en/ed-tech/59108CCE54484B76AF68879C217D47B2/7EFB09CED41C4190AFF8F60283B6727A/TI-NspireLuaScriptingAPIReferenceGuide.pdf

I believe what I am looking for is the eval function on page 51 although I can't find much online to sample from. The examples provided are not concrete ones.

math.eval(math_expression) --apilevel = 2.0
math.eval(math_expression, [exact]) --apilevel = 1.0
local expr = "f1("..mx")"
return math.eval(expr)

Iv'e tried

require "math"
local answer
answer = math.eval("f1(x+3/4,x)")
answer = math.eval(x+3/4,x)
answer = math.eval("5+9")

I keep getting the error "cannot execute during initialization."

1) How do you fix the error

2) May I have some concrete examples of using the function

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • I think @Piglet has the answer - but when testing - use the simplest example possible. That is use `answer = math.eval("5+9")`. Also don't expect too much. The Lua API is ... well ... not exactly rich in the "working with expressions" department. – soegaard Mar 25 '19 at 13:15

2 Answers2

2

From the TI-Nspire Lua Scripting API Reference Manual 12.1 math.eval:

Warning

math.eval is not available during script initialization

To avoid this error do not call the function befor script is initialized.

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • What does it mean to initialize the script and how do you do that? –  Mar 26 '19 at 09:14
  • 1
    @MaxNova I don't know. I could not find anything in the manual. I guess you have to run some other function first. As TI-Nspire is a commercial product I suggest you ask their support for help. TI's support is usually very good. – Piglet Mar 26 '19 at 09:33
2

This works!

function on.paint(gc)
    local var1
    var1 = math.eval("nsolve(x+4=8,x)")
    gc:drawString(var1, 2, 20)
end