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:
2 3 4
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 »
This like an optimizer?
Looks cool! No download yet?
Title Language Progress Status 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)
LabView (For FIRST robotics)
z80 ASM (Just a little bit
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 :
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 ?
Last Edit: 06 January, 2012, 01:37:09 by adriweb »
Does changing \000 to \0 make any improvements speed-wise?
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:
Suddenly, you created a new character, "\012".
You should do some checks on the image data before changing it
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)