Omnimaga
Calculator Community => TI Calculators => Lua => Topic started by: ExtendeD on June 25, 2011, 05:56:31 am
-
It appears that during its function cleanup of the TI-Nspire implementation, TI fortunately kept the standard Lua function loadstring() that allows dynamic loading of Lua code snippets.
Here is a quick and dirty example of a command prompt to execute Lua on-liners:
function on.create()
editor = D2Editor.newRichText()
editor:move(0,150)
editor:resize(250,50)
end
function on.charIn(char)
editor:setText(editor:getText() .. char)
end
function on.enterKey()
local chunk, errc = loadstring(editor:getText())
if (not chunk) then
print(errc)
else
local status, err = pcall(chunk)
if (not status) then
print(err)
end
end
editor:setText("")
end
function on.backspaceKey()
editor:setText(editor:getText():sub(1, editor:getText():len() - 1))
end
Now imagine this combined with calls to var.store() and var.recall(), and you have a on-calc Lua code compiler :)
Unfortunately I have too many simultaneous projects to invest more on this, but I'm sure some of you will be able to build interesting tools from this.
-
This seems just like Jim Bauwen's Lua Console. Yours reads lines like his, but his also reads files, as you suggested in the end.
Not sure if yours has any improvement, but it's funny because both of you got to the same conclusion.
However, I hope TI doesn't remove those functions, a dynamic interpreter is very cool :) Nice job ExtendeD!
-
jimbauwens, ephan pointed me to this (http://ourl.ca/11333/215527). Does the console really read files, bypassing TI's filters?
-
If they take it away though, would it really be that hard to make your own loadstring() function? It doesnt seems as though it would.
-
If it has to compile the code, then yes it'll be hard.
But this has some interesting possibilities. Self modifying code!
-
ExtendeD, it allows loading variables in the current document, or variables in libraries (not in the local document).
In case you want to try my lua console, you can find the current version here: http://bwns.be/jim/term.lua . It has basic history support and runs everything in a coroutine, which makes that I can have functions such as pause. I have added these functions: print, pause, sleep, readinp, load and save. load("varname") will load and execute the content of varname. save("data","varname") will save data in varname. I'm currently planning an oncalc Lua programmer that utilizes some of these functions.
-
Nice :)
-
When Ndless 3 comes, I think a C Text Editor that zipped TNSs like Lua>TNS Converters do won't be too hard, right?
-
Well, no.
A C text editor that reads and writes plain text documents (which cannot be opened with the built-in document viewer/editor) is significantly easier than a C text editor that reads and writes normal TNS documents that are made up by using TIXC (TI XML Compression, proprietary and patented) and currently unspecified data structures, Zlib and OpenSSL-based triple DES ECB ;)
The method used by the third-party Lua->TNS converters wouldn't help - for a start, it doesn't work on OS 3.0.2 anyway.
-
Here is a first shot at an on-calc Lua editor, oclua.
The standard Notes editor is used to type in Lua code, then the code just needs to be pasted to be run.
The file is built for OS 3.0.1, it needs to be rebuilt with TI's official tools for OS 3.0.2 compatibility (or sent to an OS 3.0.1 then exported).
(sorry for the lines on the screenshot, it may be because I'm using an unregistered version of Camtasia Studio)
-
Great, congratulations once again :)
-
Thats looks pretty good! I didn't think of using copy/paste for that.
Good work!
-
Wow, this looks very useful!
If you would like, I will try to post an encrypted version of this later today! :)
-
I've resaved the oclua.tns file with the 3.0.1 software.
http://ti.bank.free.fr/index.php?mod=archives&ac=voir&id=3606
So now, everybody with an OS/software 3.0.1, 3.0.2 or above should be able to use Oclua directly. :)
-
Do you have any idea how much I love you guys?
Great job!
-
I love you.
This was the only which lacked to the TI-Nspire
-
Darn this is epic ExtendeD. A lot of people liked to program on-calc when they did 83+ stuff. I bet this will be appreciated by many Nspire owners too. O.O
-
I hope if ndless 3 comes out we can have a robust editor with a compiler.
-
with a compiler.
A what ? for Lua ?
-
Even if it's not a compiler, it looks like one...
How should we call that ? an "encryptor" ?
-
Even if it's not a compiler, it looks like one...
How should we call that ? an "encryptor" ?
Well .. a shell ?
-
I think he means that if Ndless 3 comes it'd be good to have an on-calc text editor with a LUA>TNS Converter. Keep it simple :)
-
I was talking of the tool which produces TNS files from LUA code.
I don't really know what a shell is, but I think it's something different. (The interpretor is a shell, isn't it ?)
-
I think he means that if Ndless 3 comes it'd be good to have an on-calc text editor with a LUA>TNS Converter. Keep it simple :)
^this
-
Huge up, sorry :/
I'm having trouble with OCLua : why can't I use a for loop which runs more than 128 times ?
This code brings the calc into an infinite loop :for i = 0, 128 do
end
And this works fine :for i = 0, 127 do
end
-
I haven't tried your code, but I assume you put that in on.paint .
Probably what is happening is that on.paint get's called again (sometimes it does this when execution time is a bit too long), causing it too loop constantly.
But that's just a theory.
-
Huge up, sorry :/
I'm having trouble with OCLua : why can't I use a for loop which runs more than 128 times ?
This code brings the calc into an infinite loop :for i = 0, 128 do
end
And this works fine :for i = 0, 127 do
end
Could you post more of the code ?
Also, I'm not sure about Jim's theory - well I haven't found myself in such case before. but maybe with timers and stuff it may happen... weird though...
-
Here is the code which doesn't work for me.
In fact, once I try the code I just posted, it works ??? but just try the one I joined (it's the page 3).
Also, do you know a way to get text from a *.tns ?
-
Copying and pasting some text might work, as would accessing TI-BASIC variables... but without external help, TI's proprietary Lua, which does not have io.* and os.* functions (i.e., among other limitations and incompatibilities with standard Lua, no external file access) cannot get text from a .tns.
-
Copying and pasting some text might work, as would accessing TI-BASIC variables... but without external help, TI's proprietary Lua, which does not have io.* and os.* functions (i.e., among other limitations and incompatibilities with standard Lua, no external file access) cannot get text from a .tns.
I believe he's talking about the OcLua's text in page 2 which is a Notes page. So not-related with TI's Nspire-Lua. But still, it's a closed format.
The "only" easy way is to open it with the computer software. Then copy/paste it wherever you want it.
Anyway, about your script : no problems for me for any of your codes...
(Also, remember to put the least possible code (only the final graphics/screen drawing -related things) in the paint method since it's going to get called quite often and you don't want it to slow the rest :)