Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
24 May, 2013, 18:18:05 *
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]   Go Down
  Print  
Author Topic: Lua and 3.2 -  (Read 806 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 14:19:08
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Topic starter
Total Post Ratings: +180

View Profile WWW
« on: 07 June, 2012, 09:15:24 »
0

So, the new TI-Nspire OS 3.2 is out. What does that mean for Lua developers ?
Well, a lot ! There are some important changes that you all should know about, in order to make your applications works perfectly on 3.2.
TI has done a great job keeping compatibility, but there are some tiny stuff that might cause certain programs not to run (properly).


Compatibility mode
Let me first begin with the compatibility mode. TI has 2 "apiLevel's" in 3.2. apiLevel 1.0 provides backwards compatibility for <3.2 OS's by keeping the old API structure.
All documents created for 3.1 and previous will run in that apiLevel by default. This is because some changes in the XML structure of the document. So most programs and games should run fine by default.
Then there is apiLevel 2.0. This apiLevel has some big changes to the API structure, so you will have to update some of your code in order to have some of they new 3.2 stuff. However, it is currently not possible to create apiLevel 2.0 documents with Luna due to changes in the XML structure. I have given the details of the changes to ExtendeD so he will probably update Luna soon.

For the best support and guarantee that you are using the correct apiLevel, you should add the following to the top of new Lua documents you create:

1
2
3
4
5
6
platform.apilevel = '1.0'

or

platform.apilevel = '2.0'


Please note that using apiLevel 2.0 with the current Luna will result in an error. (I have a little customized version myself, but I'm not going to release it because it's Linux only, and I'm sure ExtendeD will update Luna soon.)


Events
*on.create is removed in apiLevel 2.0 and replaced with on.construction. This event handler is guaranteed to run before all others.
* on.getFocus is called when the script receives user input focus.
* on.loseFocus is called when the script loses user input focus.
* on.getSymbolList is called when the script app symbol list is being serialized to the clipboard.

Graphical operations
* Most graphical operations are now anti-aliased. This makes that applications look more pretty Smiley
* gc:setColorRGB now supports one number as input (as well as the old style). For example, you can do gc:setColorRGB(0xFF00CC) or gc:setColorRGB(0)
* You can not use coordinates for drawing to the screen above/under (-) 32 000. Normally this shouldn't affect anyone, but because of this Cubefield refuses to run.

* In apiLevel 2.0 platform.gc() is removed and replaced with platform.withGC(). An example of it:

1
2
3
4
5
6
7
8
9

function getStringWidth(str, gc)
  return gc:getStringWidth(str)
end

function on.construction()
  local strw = platform.withGC(getStringWidth, "The game")
end

So what it does it call the function you give as first argument and pass a dummy GC to it as last argument.

D2Editor
D2Editor is greatly improved, and it finally useful Smiley


require
There are three modules that you can 'require': physics, color, and strict.
The physics module is the chipmunk physics engine.
color is just a table containing colors. color.red (or color["red"]) will return the color code for red.
I have no idea what strict is or does Tongue

Usage: require 'modulename'


Physics
Maybe the best part of it of. OS 3.2 now includes the Open Source Chipmunk physics engine, and you can use it right from Lua!
This will allow some great games and applications Smiley
However it's is far to complex to detail in this post, so I will probably write a tutorial about it soon Smiley


Image
Normally 3.2 would have many updates to the image, but sadly enough they did not make 3.2 and are pushed for the next OS.
However, there is one function that made it, and that is image.rotate. This allows you to rotate images in anyway.
But beware, it is not the fastest function out there.

Math
math.eval has got some friends: math.evalStr, math.getEvalSettings and  math.setEvalSettings.

Platform
I already mentioned platform.withGC, but there are still two other newcomers:
* platform.registerErrorHandler, this allows you to take actions when an error occurs in your document. Pretty nice Smiley
* platform.window:setFocus, regain focus in your script.
* platform.hw(), returns a number corresponding to the device the scripts is running on.

Variable
* var.recallAt, fetch data from a certain spot in a list or matrix
* var.makeNumericList, create a list in the symbol table. The create list will work much more efficient with other var functions.

Toolpalette
In apiLevel 2.0 the names of toolpalette items may be changed dynamically while the program is running. Calling toolpalette.register(nil) deactivates the toolpalette.

Well, that's about it. I'm sure there are some stuff I forgot, but you can find them all in the API documentation here http://education.ti.com/downloads/guidebooks/ti-nspire/3.2/TI-Nspire_Scripting_API_Reference_Guide/TI-Nspire_Scripting_API_Reference_Guide_EN.pdf .
Good luck and may the coding force be with you!

Links:
Wiki version of this post with more details
« Last Edit: 08 June, 2012, 12:42:22 by jimbauwens » Logged

Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Today at 14:17:04
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #1 on: 07 June, 2012, 09:27:28 »
0

Wow, thanks for that jim

now i have some questions for you:
    1) can you declare classes in on.construnction, or do you still have to put before this? because with on.create, you had to place them before the on.create
    2) is it plaform.apilevel = '1.0' at the top, or really both of them with an 'or' in between?
    3) how are error's formatted when you use the errorhandler? i mean, how can one use them?
    4) is gc:setAlpha() working?

that's about it Smiley

now i'm waiting for the tutorial xp
Logged

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

Gender: Male
Last Login: Today at 14:19:08
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Topic starter
Total Post Ratings: +180

View Profile WWW
« Reply #2 on: 07 June, 2012, 09:34:14 »
0

1) Do you mean objects ? (obj1 = TheGame() )
Normally yes, as this will run before all other events and they will be declared when other evens run.
2) It's on of the two, no or in between Smiley
3) I haven't tried to use this function yet. As soon as the new documentation is out I'll link it here so you can have a peek in it Tongue
4) TI removed it several build versions ago, where we warned several people that it would go away. It might return in the future, but I can not guarantee that..
It's also worth noting that TI never mentioned this function, as it still had some bugs.

The tutorial should not take too long ..
Logged

adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 12:02:44
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1197


Total Post Ratings: +185

View Profile WWW
« Reply #3 on: 07 June, 2012, 11:47:25 »
0

Here's the Wiki version of it, with more details and links etc.:

http://wiki.inspired-lua.org/Changes_in_OS_3.2

Can you put that too on the post, jim ? Tongue
« Last Edit: 07 June, 2012, 11:56:24 by adriweb » Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 14:19:08
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Topic starter
Total Post Ratings: +180

View Profile WWW
« Reply #4 on: 08 June, 2012, 12:42:51 »
0

Added a link to the API doc Smiley
Logged

Levak
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 15:10:44
Date Registered: 04 April, 2010, 23:42:49
Location: France
Posts: 843


Total Post Ratings: +148

View Profile WWW
« Reply #5 on: 08 June, 2012, 15:46:28 »
0

Important notice : on.construction() hasn't the same goal as on.create().

Indeed, on.construction() is executed just after the de-serialization of the XML contrary to on.create where platform, math, table etc .. lib were loaded.
I made all my best in order to have on.create back in 3.2 but TI didn't wanted to listen to the problems I showed.
I explained that on.construction has no more interest but didn't replied ...
« Last Edit: 08 June, 2012, 15:47:16 by Levak » Logged

Human always wants to survive and that's why he will fall one day.
My website - TI-Planet - iNspired-Lua
adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 12:02:44
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1197


Total Post Ratings: +185

View Profile WWW
« Reply #6 on: 08 June, 2012, 15:52:59 »
0

Hmm, I thought there would be some loaded libs already when on.construction gets fired, but if it's not the case, then I don't really see the point of having that event since init stuff can be put outside of any functions at the end of the programs for example and it would behave the same way ... ?
Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
Art_of_camelot
The matrix has you.. ಠ_ಠ
Support Staff
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Last Login: Today at 14:25:22
Date Registered: 30 August, 2008, 04:55:55
Location: Dr. Light's Laboratory
Posts: 4405


Total Post Ratings: +152

View Profile WWW
« Reply #7 on: 08 June, 2012, 16:51:28 »
0

Nice list Jim. I'm not much of an Nspire guy, but I can appreciate your dedication. =)
Logged

Projects:
TBA! Coming to an 83+ near you!

NerdTests.com says I'm a Cool Nerd King.  Click here to take the Nerd Test, get nerdy images and jokes, and write on the nerd forum!


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

Gender: Male
Last Login: Today at 14:19:08
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Topic starter
Total Post Ratings: +180

View Profile WWW
« Reply #8 on: 08 June, 2012, 22:34:27 »
0

Levak, the platform, math, etc libs do get loaded before on.construction runs. However, the display window isn't initialized yet, so platform.window:height() and platform.window:height() return 0.
It would be a good idea to put this code in on.resize.
on.construction is still good for var, document, math, local and other stuff.

Art_of_camelot: Thank you Smiley
Also, maybe this topic could be pinned ? I think it's pretty useful for people Smiley

Edit: yay, it is pinned !
« Last Edit: 08 June, 2012, 22:52:56 by jimbauwens » Logged

Pages: [1]   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.313 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.