Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
23 May, 2013, 09:38:58 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: Loading Lua code dynamically for fun and profit (on-calc Lua editor) -  (Read 2584 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 10:41:34
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Topic starter
Total Post Ratings: +151

View Profile
« on: 25 June, 2011, 11:56:31 »
0

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 Smiley
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.

* luaconsole.tns (0.94 KB - downloaded 87 times.)
« Last Edit: 03 July, 2011, 09:13:33 by ExtendeD » Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Munchor
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: 21 May, 2013, 17:58:01
Date Registered: 16 October, 2010, 15:39:13
Location: Position
Posts: 6209


Total Post Ratings: +174

View Profile
« Reply #1 on: 25 June, 2011, 12:05:52 »
0

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 Smiley Nice job ExtendeD!
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 10:41:34
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Topic starter
Total Post Ratings: +151

View Profile
« Reply #2 on: 25 June, 2011, 12:09:56 »
0

jimbauwens, ephan pointed me to this. Does the console really read files, bypassing TI's filters?
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Ashbad
Guest
« Reply #3 on: 25 June, 2011, 13:37:25 »
0

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.
« Last Edit: 25 June, 2011, 13:37:51 by Ashbad » Logged
t0xic_kitt3n
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: 13 May, 2013, 01:56:35
Date Registered: 16 June, 2010, 20:46:00
Location: w,x,y,z
Posts: 1583


Total Post Ratings: +32

View Profile
« Reply #4 on: 25 June, 2011, 14:00:38 »
0

If it has to compile the code, then yes it'll be hard.
But this has some interesting possibilities. Self modifying code!
Logged




██████  ██  ██  ███████           ████    ██    ██   ██ ███████
█ ██ █  ██  ██   ██   █          ██  ██  ████   ███ ███  ██   █
  ██    ██  ██   ██             ██   ██ ██  ██  ███████  ██    
  ██    ██  ██   ██  █         ██       ██  ██  ███████  ██  █
  ██    ██████   █████         ██       ██  ██  ██ █ ██  █████ 
  ██    ██  ██   ██  █         ██   ███ ██████  ██   ██  ██  █
  ██    ██  ██   ██             ██   ██ ██  ██  ██   ██  ██    
  ██    ██  ██   ██   █          ██  ██ ██  ██  ██   ██  ██   █
 ████   ██  ██  ███████           █████ ██  ██  ██   ██ ███████

Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 22:51:04
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #5 on: 25 June, 2011, 16:53:15 »
0

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.
Logged

ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 10:41:34
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Topic starter
Total Post Ratings: +151

View Profile
« Reply #6 on: 26 June, 2011, 09:02:44 »
0

Nice Smiley
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Munchor
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: 21 May, 2013, 17:58:01
Date Registered: 16 October, 2010, 15:39:13
Location: Position
Posts: 6209


Total Post Ratings: +174

View Profile
« Reply #7 on: 26 June, 2011, 12:25:40 »
0

When Ndless 3 comes, I think a C Text Editor that zipped TNSs like Lua>TNS Converters do won't be too hard, right?
Logged
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 08:01:47
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1854

Total Post Ratings: +208

View Profile WWW
« Reply #8 on: 26 June, 2011, 13:37:15 »
0

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 Wink

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.
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 10:41:34
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Topic starter
Total Post Ratings: +151

View Profile
« Reply #9 on: 03 July, 2011, 10:04:16 »
+1

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)


* oclua.gif (70.32 KB, 324x243 - viewed 17217 times.)
* oclua.lua (1.51 KB - downloaded 64 times.)
* oclua.tns (1.36 KB - downloaded 53 times.)
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 08:01:47
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1854

Total Post Ratings: +208

View Profile WWW
« Reply #10 on: 03 July, 2011, 10:13:34 »
0

Great, congratulations once again Smiley
« Last Edit: 03 July, 2011, 10:14:16 by Lionel Debroux » Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 22:51:04
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #11 on: 03 July, 2011, 10:14:05 »
0

Thats looks pretty good! I didn't think of using copy/paste for that.
Good work!
Logged

apcalc
The Game
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 16:59:33
Date Registered: 20 March, 2010, 16:31:47
Location: 2003 UB313
Posts: 1393


Total Post Ratings: +118

View Profile
« Reply #12 on: 03 July, 2011, 14:49:43 »
0

Wow, this looks very useful!

If you would like, I will try to post an encrypted version of this later today! Smiley
Logged


critor
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 08:33:26
Date Registered: 14 July, 2009, 23:57:37
Location: Aix-Marseille, France
Posts: 1723


Total Post Ratings: +369

View Profile WWW
« Reply #13 on: 03 July, 2011, 18:53:34 »
0

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. Smiley
Logged

TI-Planet co-admin.
pianoman
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 20 October, 2011, 04:23:28
Date Registered: 21 May, 2011, 19:13:57
Location: You can know that my current velocity is about 0 m/s.
Posts: 427


Total Post Ratings: +24

View Profile
« Reply #14 on: 03 July, 2011, 18:55:15 »
0

Do you have any idea how much I love you guys?
Great job!
Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.277 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.