π
<-

LuaTerm v2.0 - An interactive Lua prompt for your TI-Nspire

Pour TI-Nspire OS 3.0 ou ultérieur.

LuaTerm v2.0 - An interactive Lua prompt for your TI-Nspire

Unread postby jimbauwens » 10 Sep 2013, 13:54

Hi all,

As some of you might remember, in the very beginning of the TI-Nspire Lua era I released LuaTerm. It was the very first tool that allowed you to enter and run Lua code directly on your calculator.

Now more than two years later (yes, it has been that long) I am proud to announce a new release of LuaTerm!
So what's new ?
  • OOP design
  • Monospace font using a custom font routine
  • Multi-line syntax
  • Cursor support so you can easily edit your command
  • Built using a special session engine that allows cooperative multitasking
  • New build system

The session engine is the biggest change to LuaTerm. This engine is not only useful for LuaTerm, but other projects can take advantage of it as well.

Image

Image

LuaTerm functions and Session API
Code: Select all
------------------------------
-- LuaTerm spefic functions --
------------------------------

print(...)      : print to the console
clear()         : clear the console
sleep(n)        : sleep n seconds. Please note that this lets the execSession sleep, so if you want to sleep another session use yourSession:sleep(n)
readLine([str]) : reads console input. Please note, that just as sleep this is linked to the session execSession, don't use it in other sessions. If str is specified, it will be preinserted in the input stream.

gcct()          : List all (registered) sessions
browse([tbl])   : Browse the global enviroment. If tbl is specified, browse that instead.

getConsole() : returns the Console object
getSession() : returns the execSession Session object


The following documentation is not needed to use LuaTerm; it just describes the internal classes used by LuaTerm.
But you can also use them from within the console.

--------------
-- Sessions --
--------------

There are two sessions used by default:
luaTermSession and execSession.

luaTermSession implements the entire input handling and terminal functionality.
After the user enters a command, it will dynamically generate the execSession, suspend itself, pass control to execSession.
After execSession is completed, it will resume luaTermSession and pass the results to it.

-------------------
-- Console class --
-------------------

Console()                     : create a new Console object

.cursorX                      : cursor column
.cursorY                      : cursor row
.cursorVisisble               : boolean, show/hide the cursor
.height                       : height (in px) of the console
.width                        : width (in px) of the console
.rows                         : amount of rows
.cols                         : amount of collumns
.linesMoved                   : how many lines the console shifted during its lifecycle
.lineBuffer                   : table representing the console buffer

:fit([w], [h])                : resize the console. If parameters ommited it will use the display size
:draw(gc)                     : draw the console to the specified graphical context
:moveUp()                     : shift the console buffer one line. Internally used by :write
:write(str, [ignoreCursor])   : write str to the console (at the location of the cursor). If ignoreCursor is specied and true, the cursor position will not be updated after writing.
:print(...)                   : print the arguments to the console plus a new line
:clear()                      : clear the console
:read(session)                : reads one character. You need to supply a session; and you may only call it from within that session. (otherwise the world can collapse)
:readLine(session, [str])     : reads a line. You can prefill the line with str. Same session restrictions as read
:dataIn(str)                  : used to send data to the console. This data will eventually be parsed by read[Line]
:cursorBack()                 : move the cursor back
:cursorForward()              : move the cursor forward

-----------------------------------------
--           Session class             --
-- implements cooperative multitasking --
-----------------------------------------

Session(console, func, [callback], [commandTable])
                              : create a new Session from func with console as console. If specified, callback will get called when the Session object ends. The thread state and result will be passed as argument to the function. commandTable is used to define functions that can be called using :sendCommand to the Session object.
               
Session.addSession(session)    : register a Session object
Session.removeSession(session) : unregister a Session object
Session.updateSessions()       : 'tick' all registered Session objects
Session.getSessions()          : return the registered Session object table. Warning: this is a reference! Don't mess with it.

.thread                        : the coroutine behind everything
.console                       : the sessions Console object
.callback                      : the callback function
.commandTable                  : the commandTable
.started                       : true if the Session object has been started
.suspended                     : true if the Session object has been suspended
.nextTick                      : time when the Session may resume its thread

:checkSession(state, ...)      : internally used the check the thread state
:start([run])                  : start the session. If run is specified and true, the session will wait until the next global tick to start the thread
:suspend()                     : suspend the session
:interrupt()                   : interrupt the session
:triggerResume()               : session will resume on next tick
:sleep(n)                      : let the session sleep for n seconds
:tick([forcetick])             : tick the session. If forcetick is true, it will tick regardless if the session is suspended or nextTick isn't due yet
:sendCommand(command, ...)     : call command out of commandTable and pass the arguments. Warning, this is not thread safe!

-- Aliases to the console functions
:print(...)
:write(str)
:read()
:readLine(str)


I have attached the latest build to this post (LuaTerm v2.0beta). I would really appreciate if people could test it and report any bugs they can find :)
Please note that I haven't tried it on 3.1, although it *should* work as I've implemented some compatibility options.
You do not have the required permissions to view the files attached to this post.
User avatar
jimbauwensProgrammeur
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 30.5%
 
Posts: 54
Joined: 13 May 2011, 00:00
Location: Belgium
Gender: Male
Calculator(s):
MyCalcs profile
Class: Computer Science @ VUB University Brussels

Re: LuaTerm v2.0 - An interactive Lua prompt for your TI-Nsp

Unread postby AnToX98 » 10 Sep 2013, 16:28

That is awesome stuff ! Thank you jims !
User avatar
AnToX98Premium
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 75.5%
 
Posts: 1022
Images: 15
Joined: 19 May 2013, 16:54
Location: Paris, France
Gender: Male
Calculator(s):
MyCalcs profile
Class: 1ere S

Re: LuaTerm v2.0 - An interactive Lua prompt for your TI-Nsp

Unread postby Lionel Debroux » 10 Sep 2013, 18:26

Pretty good :)
Membre de la TI-Chess Team.
Co-mainteneur de GCC4TI (documentation en ligne de GCC4TI), TIEmu et TILP.
User avatar
Lionel DebrouxSuper Modo
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 11.4%
 
Posts: 6873
Joined: 23 Dec 2009, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Class: -
GitHub: debrouxl


Return to Nspire-Lua

Who is online

Users browsing this forum: No registered users and 4 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1109 utilisateurs:
>1095 invités
>7 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)