Omnimaga
Calculator Community => TI Calculators => Lua => Topic started by: blauemauritius on April 16, 2013, 02:48:34 pm
-
Hello,
i have one question regarding the function loadstring. How could i use the function to load a file from the MyLib folder on my TI-nspire?
Thank you very much for your help.
-
Like this :)
myVar = math.eval("externalDocumentInMyLib\\thePublicVariableYouWant")
More advanced use :
https://github.com/adriweb/EEPro-for-Nspire/blob/master/EEPro.big.lua#L1519
But there, I'm actually calling a function and taking its return value :P
-
Thank you. That´s what i was looking for.
Which kind of variables can i use? Can I use lists?
Which format should have the file?
-
You can use any type you want as long as it's lua compatible (through the math.eval)
It has to be a math variable inside a normal .tns document you created as usual.
-
Thank you very much. Do you have an example? I have read the Code in your file, but i don't understand thim?
I couldn't image how does it work.
For example i have the file test.txt in the folder Mylib. In the file i have the variable Zahl=1234.
What are the steps what i have to do?
I would be grateful, if you can help me.
Thank you very much.
-
If you want to do like Make3D (http://levak.free.fr/ftp/nspire/Make3D/Makefile.sh) - that is, loading the entire source code from MyLib - you can use loadstring(var.restore("my_file\\my_var"))()
In my_var of the TI-Nspire document my_file.tns, you have a string (be careful on its size tho, there is a limit, like 16K chars or so) contaning your source code.
For example :
In my_file.tns (normal document, inside MyLib - don't forget to refresh libraries)
my_var := "function on.pain(gc) gc:drawString('Hello world', 0, 0, 'top') end"
In my_example.tns (Lua document)
function on.restore()
_, err = pcall(function() loadstring(var.recall("my_file\\my_var"))() end)
print err
end
This should display "Hello world" (haven't tested yet but you should understand the logic)
-
Thank you very much. This helps me. Do you know if i can use ".txt" or ".lua" files too?
-
Do you know if i can use ".txt" or ".lua" files too?
No, you can't read file, basically. This is why such "hacks" have been introduced.
-
Thank you very much. Have a nice evening!