Limit 200 local Variables..
- Thorn
- Offline Autor
- Platinum Mitglied
- Beiträge: 3460
- Dank erhalten: 1462
I wish that the limit of 200 local variables is increased in main function. So that the lua app can do even more.
Thorn
Thorn
!! Bitte alle meine Apps vom Sender Löschen!
Sorry, wegen meiner Rechtschreibung und Grammatik!!!
Lg Thorn
Sorry, wegen meiner Rechtschreibung und Grammatik!!!
Lg Thorn
von Thorn
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- davidmcq137
- Offline
- Senior Mitglied
- Beiträge: 75
- Dank erhalten: 82
Hi Thorn,
First I think all your lua apps are great!
I have run into this limit too, and have done what I am sure most lua developers do .. group variables together by common function and then make them part of a table, for example gpsSettings.zoomlevel, gpsSettings.screenSize, gpsSettings.color
instead of 3 variables this becomes one.
I have found that while this started as a workaround, it actually makes the code more readable and better self-documenting .. and with some thought on variable groupings is really much better and the 200 limit never becomes a problem again.
For me it tends to come up only at the top level of the code, where the locals are really "global" to the app .. I've never seen this limit hit in a local function inside the app.
My current strategy is to put most of the top level variables under tables like this, and only to reserve a small number of locals not under a table for things where access time/speed would be critical, since the table access will be a little slower.
The only other thought is that the local functions declared in the app are themselves local top-level variables .. so cutting down on similarly named functions e.g.
setColorMap() ... setColorTriangle() .. setColorNoFly() ... setColorRunway becomes
setColor("Map"), setColor("Triangle"), setColor("NoFly"), setColor("Runway") saves multiple top level local variables (the function names) and in my opinion is clearer to read and better structured anyway.
So maybe the genius of Roberto and the lua team is that the 200 variables limit helps us code better!
Dave
First I think all your lua apps are great!
I have run into this limit too, and have done what I am sure most lua developers do .. group variables together by common function and then make them part of a table, for example gpsSettings.zoomlevel, gpsSettings.screenSize, gpsSettings.color
instead of 3 variables this becomes one.
I have found that while this started as a workaround, it actually makes the code more readable and better self-documenting .. and with some thought on variable groupings is really much better and the 200 limit never becomes a problem again.
For me it tends to come up only at the top level of the code, where the locals are really "global" to the app .. I've never seen this limit hit in a local function inside the app.
My current strategy is to put most of the top level variables under tables like this, and only to reserve a small number of locals not under a table for things where access time/speed would be critical, since the table access will be a little slower.
The only other thought is that the local functions declared in the app are themselves local top-level variables .. so cutting down on similarly named functions e.g.
setColorMap() ... setColorTriangle() .. setColorNoFly() ... setColorRunway becomes
setColor("Map"), setColor("Triangle"), setColor("NoFly"), setColor("Runway") saves multiple top level local variables (the function names) and in my opinion is clearer to read and better structured anyway.
So maybe the genius of Roberto and the lua team is that the 200 variables limit helps us code better!
Dave
von davidmcq137
Folgende Benutzer bedankten sich: Thorn, skyfreak
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- Raf
- Offline
- Premium Mitglied
- Beiträge: 137
- Dank erhalten: 184
200 local variables should be enough for everybody Another solution could be to use global variables, but it's not nice - and global variables are shared between apps.
Voltario T30, Touch Switch, MicroVario, AMS, SE6
von Raf
Folgende Benutzer bedankten sich: Thorn
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- Thorn
- Offline Autor
- Platinum Mitglied
- Beiträge: 3460
- Dank erhalten: 1462
So with me the 200 local were not enough then had to do it differently which was absolutely no problem. Did not know before that you can limit something like that!
!! Bitte alle meine Apps vom Sender Löschen!
Sorry, wegen meiner Rechtschreibung und Grammatik!!!
Lg Thorn
Sorry, wegen meiner Rechtschreibung und Grammatik!!!
Lg Thorn
von Thorn
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- davidmcq137
- Offline
- Senior Mitglied
- Beiträge: 75
- Dank erhalten: 82
I am with Thorn on this one! If you are writing few hundred line lua apps, then sure 200 is fine. But my maps app is 4300 lines of code... you need some sort of strategy to manage the variables. Lua's 200 limit is based on performance of the lua VM, and the techniques I listed for using tables will be slower due to additional steps to reference the table .. hence my advice to save some of the 200 that are in scope for the entire app (these would be declared "local" at the top level .. but would be available to the entire app so kind of a "local global") for things that really need speed of access and I think this becomes a solved problem. I agree that in the Jeti system "real" globals should be rarely used. I've done it a few times for app to app communication.
And of course remember Bill Gates once said: "640K ought to be enough for anyone".
I have been totally impressed with how large apps can get and still perform well on the Jeti TX!
And of course remember Bill Gates once said: "640K ought to be enough for anyone".
I have been totally impressed with how large apps can get and still perform well on the Jeti TX!
von davidmcq137
Folgende Benutzer bedankten sich: Thorn
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
Ladezeit der Seite: 0.969 Sekunden