Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
21 May, 2013, 17:33:41 *
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: Lua code optimizer for pc -  (Read 1878 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« on: 06 January, 2012, 01:23:53 »
0

Hi

based on Deep Thought's idea, i made a program that reduces the file size of lua with about 15% (several tests came out, average reduction..)

it does not yet change anything really coding to the code yet, but:
     - tabs are removed
     - spaces are removed where possible ( var = 5 changes into var=5 )
     - empty new lines are removed
     - \000\ changes in \0\ for images
     - removes the == true in statements (not yet ==false, that will come later)
     - changes platform.window:invalidate() into p() and adds  'function p() platform.window:invalidate() end' because this takes in less place when used more than 2 times (which prob is the case)
     - comments are removed
     - gc:setAlpha(..)'s are removed
     - include external .lua files by using %, followed by the name of the file (without the .lua)
example main file:

1
2
3
4
function on.create()
%varsinit
end
varsinit.lua file:

1
2
3
4
5
menu = true
game = false
highscore = (var.recall("HS")  or 0)
score = 0

the resulting file is saved in the same directory as the source file, but with improved added to the name, so example.lua changes into exampleimproved.lua
i tried to remove the ,"top" from drawstring, and it all worked fine, but than it seems that it is drawn on baseline, i thought top was default?

anyway, here are screenies



« Last Edit: 11 January, 2012, 22:22:13 by Nick » Logged

epic7
Chopin!
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: Today at 04:18:45
Date Registered: 22 October, 2011, 01:45:43
Location: Northeast US
Posts: 2165


Total Post Ratings: +118

View Profile
« Reply #1 on: 06 January, 2012, 01:29:24 »
0

This like an optimizer?
Looks cool!

No download yet?
Logged



Current Projects:
TitleLanguageProgressStatus
DrillMiner    C (ndless)   35%         Active
?     C (ndless)   0%        Unconfirmed

Spoiler for Programming languages I currently know:
Java (Learning in AP Comp Sci)
C (Specifically Ndless)
Unity JavaScript
LabView (For FIRST robotics)
z80 ASM (Just a little bit Tongue)
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« Reply #2 on: 06 January, 2012, 01:31:16 »
0

yeah, optimizer, that was the word i was looking for xp not yet, it's not totally finished, i would like to add the ,"top" or whatever and the ==false removed before release
Logged

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

Gender: Male
Last Login: Yesterday at 00:38:33
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1196


Total Post Ratings: +185

View Profile WWW
« Reply #3 on: 06 January, 2012, 01:36:14 »
0

Great idea, but for this kind of optimizations, people generally use LuaSrcDiet, a (well-known ?) Lua code size-reducer (extreme size decreases....)

Take a look here and try it on your code :
http://code.google.com/p/luasrcdiet/

It's a lua script by itself. Smiley
Maybe you can take it and modify it to match Nspire Lua needs ? (It messes up the ti.images !!)
And put it together with your nice graphical UI ?

Cheesy
« Last Edit: 06 January, 2012, 01:37:09 by adriweb » Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
renatose
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: Yesterday at 22:49:26
Date Registered: 17 March, 2011, 21:35:59
Location: Portugal
Posts: 201


Total Post Ratings: +3

View Profile
« Reply #4 on: 06 January, 2012, 01:37:31 »
0

this is great and you could also add a button to export to tns using luna...
Logged

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

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« Reply #5 on: 06 January, 2012, 01:37:48 »
0

thanks, didn't know that already existed Ö i'm sad now..

no, i'll have a look at it, might be very useful, since i do not bother variables yet
Logged

cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Total Post Ratings: +42

View Profile
« Reply #6 on: 06 January, 2012, 02:20:18 »
0

That's pretty cool! Too bad there was already one... but good job anyways!  Grin
Logged

hoffa
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 12:45:43
Date Registered: 28 May, 2011, 20:26:32
Posts: 302


Total Post Ratings: +115

View Profile
« Reply #7 on: 06 January, 2012, 02:59:10 »
0

Does changing \000 to \0 make any improvements speed-wise?
Logged
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« Reply #8 on: 06 January, 2012, 10:31:45 »
0

i don't really know, but it compresses the filesize a lot, since many pics have those \000

--update--
gc:setAlpha() gets removed too now
« Last Edit: 06 January, 2012, 10:32:27 by Nick » Logged

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

Gender: Male
Last Login: Today at 15:27:23
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #9 on: 06 January, 2012, 10:48:36 »
0

Changing \000 to \0 is just an improvement for the storage size. It will not change anything for drawing it.
But there can be a danger with changing it: as you know a TI.Image string contains also normal characters. Lets say you got a part that looks like this:
"\000122" (two pixels)
When you change it, this will happen:
"\0122"
Suddenly, you created a new character, "\012".
You should do some checks on the image data before changing it Wink
Logged

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

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« Reply #10 on: 06 January, 2012, 10:56:40 »
0

isn't there always a \ between two separate bytes? i've never seen any number longer than 3 digits O.o
Logged

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

Gender: Male
Last Login: Today at 15:27:23
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #11 on: 06 January, 2012, 10:59:07 »
0

No, I guess you don't understand Tongue
I'll separate the digits by space:
"\000 1 2 3"
When you change "\000" to "\0" this happens:
"\012 3"
It will think 1 and 2 are part of the escape sequence, and bad things will happen.
Logged

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

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« Reply #12 on: 06 January, 2012, 11:01:51 »
0

ok, then i'll make it change \000\ into \0\, problem solved?
Logged

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

Gender: Male
Last Login: Today at 15:27:23
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #13 on: 06 January, 2012, 11:06:48 »
0

No, let me explain the \
It is used to create escape characters.
\xxx is the same as a normal character.
For example "\065" == "A".
The three (or less) digits represent the decimal code for the character.
Most characters in a TI.Image can't be displayed, so escape characters are used.
1, 2 and 3 are real characters in my example, they don't belong to an escape sequence.
What can happen is that they do become part of an escape sequence because of the conversion (and unexpected stuff will happen)
Logged

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

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


Topic starter
Total Post Ratings: +158

View Profile WWW
« Reply #14 on: 06 January, 2012, 11:12:55 »
0

oh, now i got it.. hmm, yeah, never thought of that xs

but if i use the \000\ it will work, since then the char after it is such an escape char too, so it won't be disturbing anything, but you're right about the \000
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.249 seconds with 31 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.