Omnimaga
General Discussion => Technology and Development => Computer Projects and Ideas => Topic started by: Nick on January 05, 2012, 06:23:53 pm
-
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:
function on.create()
%varsinit
end
varsinit.lua file:
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
(http://img.removedfromgame.com/imgs/LuaCodeImpr1.gif)
(http://img.removedfromgame.com/imgs/LuaCodeImpr2.gif)
-
This like an optimizer?
Looks cool!
No download yet?
-
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
-
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/ (http://code.google.com/p/luasrcdiet/)
It's a lua script by itself. :)
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 ?
:D
-
this is great and you could also add a button to export to tns using luna...
-
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
-
That's pretty cool! Too bad there was already one... but good job anyways! :thumbsup:
-
Does changing \000 to \0 make any improvements speed-wise?
-
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
-
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 ;)
-
isn't there always a \ between two separate bytes? i've never seen any number longer than 3 digits O.o
-
No, I guess you don't understand :P
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.
-
ok, then i'll make it change \000\ into \0\, problem solved?
-
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)
-
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
-
Yes, that should do :)
-
thanks, changed it :)
-
This is a bit more trickier, but it should work too.
Escape sequences like "\012" or "\002" don't need the 0's too. But of course you must be sure they aren't followed by a normal character.
I suppose you might need some regular expressions for this.
-
hmm, that's indeed a bit tricky xp
but i'll try it
are there any other optimizations in the code itself?
what is the default setting for text-align? since that default can be removed too..
-
Don't remove it, you need it for compatibility in newer versions AFAIK.
-
UPDATE!!!
include external .lua files by using %, followed by the name of the file (without the .lua)
example main file:
function on.create()
%varsinit
end
varsinit.lua file:
menu = true
game = false
highscore = (var.recall("HS") or 0)
score = 0
results in:
function on.create()
menu = true
game = false
highscore = (var.recall("HS") or 0)
score = 0
end
-
UPDATE!!!
include external .lua files by using #, followed by the name of the file (without the .lua)
example main file:
function on.create()
#varsinit
end
What ??
#varsinit returns the number of elements in the "varsinit" table ...
You've overriden the metatables ?
-
oh, forgot about that.. thanks for reminding me Ö i feel quite ashamed right now for not having thought of it myself :-[
i changed it to %<filename>
i hope this isn't a problem?
-
You should make that it only works in the beginning of the file, since % is used for modulus and stuff.
But nice idea anyway.
-
nah, i want to make it work through the whole file, since it might be useful to make whole parts in different files, and then paste them together.
i did not only do it to include initializations, but for functions and other stuff too
so maybe §<filename> ? i guess that's not used?
and just to be clear, it only adapts those who are at the total left border of the page, it does not change the ones that are in formulas or so..
-
I don't have that wierd S-like symbol on my keyboard, and I have no clue what it means :P
Is it some foreign (to me :P) currency?
-
no, it's a paragraph sign.. well, if you don't have it, then i won't take it, maybe & or @ ?
aaargh, i really need to find a symbol for it :)
-
UPDATE!!
now it saves settings to an external file, possible settings:
- Optimize the file (get rid of comments, whitespaces etc)
- include the needed files
- save made file automatically with adaptable suffix
- suffix for the savename, changes to optimized if nothing
- copy file to clipboard, i don't really see the point of it yet, but it might be useful (?)
Possibilities for include file:
in fact, i like the second one the most, maybe that one?
the lay-out of the program itself changed too, but not that much to upload a new screenie
this is the settings pop-up screen:
-
UPDATE!!!
include external .lua files by using #, followed by the name of the file (without the .lua)
example main file:
function on.create()
#varsinit
end
What ??
#varsinit returns the number of elements in the "varsinit" table ...
You've overriden the metatables ?
Does that mean
table={1,2,3,4,5,6,7,8,9}
x=#table
And x would equal 9?
That would be useful to use :P
-
yeah, that means that :)