Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1

THEMA:

Limit 200 local Variables.. 21 Jun 2019 23:18 #1

  • Thorn
  • Thorns Avatar Autor
  • Offline
  • Moderator
  • Moderator
  • Beiträge: 3398
  • Dank erhalten: 1328
I wish that the limit of 200 local variables is increased in main function. So that the lua app can do even more.

Thorn
Sorry, wegen meiner Rechtschreibung und Grammatik!!!
Links
Alle meine Apps
Wie man Lua installiert
Display App Video

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Limit 200 local Variables.. 09 Okt 2021 17:13 #2

  • davidmcq137
  • davidmcq137s Avatar
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Beiträge: 75
  • Dank erhalten: 80
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
Folgende Benutzer bedankten sich: Thorn, skyfreak

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Limit 200 local Variables.. 15 Okt 2021 23:55 #3

  • Raf
  • Rafs Avatar
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Beiträge: 133
  • Dank erhalten: 179
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
Folgende Benutzer bedankten sich: Thorn

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Limit 200 local Variables.. 16 Okt 2021 08:21 #4

  • Thorn
  • Thorns Avatar Autor
  • Offline
  • Moderator
  • Moderator
  • Beiträge: 3398
  • Dank erhalten: 1328
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!
Sorry, wegen meiner Rechtschreibung und Grammatik!!!
Links
Alle meine Apps
Wie man Lua installiert
Display App Video

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Limit 200 local Variables.. 17 Okt 2021 15:52 #5

  • davidmcq137
  • davidmcq137s Avatar
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Beiträge: 75
  • Dank erhalten: 80
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!
Folgende Benutzer bedankten sich: Thorn

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

  • Seite:
  • 1
Ladezeit der Seite: 0.220 Sekunden
Powered by Kunena Forum