Limit 200 local Variables..

  • Thorn
  • Thorn's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 3464
  • Thank you received: 1485

TPL_KUNENA_MESSAGE_CREATED Limit 200 local Variables..

21 Jun 2019 21:18
#1
I wish that the limit of 200 local variables is increased in main function. So that the lua app can do even more.

Thorn
!! Bitte alle meine Apps vom Sender Löschen!

Sorry, wegen meiner Rechtschreibung und Grammatik!!!

Lg Thorn

Please Log in or Create an account to join the conversation.

  • davidmcq137
  • davidmcq137's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 79
  • Thank you received: 87

TPL_KUNENA_MESSAGE_REPLIED_NEW Limit 200 local Variables..

09 Oct 2021 15:13
#2
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
The following user(s) said Thank You: Thorn, skyfreak

Please Log in or Create an account to join the conversation.

  • Raf
  • Raf's Avatar
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 141
  • Thank you received: 192

TPL_KUNENA_MESSAGE_REPLIED_NEW Limit 200 local Variables..

15 Oct 2021 21:55
#3
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
The following user(s) said Thank You: Thorn

Please Log in or Create an account to join the conversation.

  • Thorn
  • Thorn's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 3464
  • Thank you received: 1485

TPL_KUNENA_MESSAGE_REPLIED_NEW Limit 200 local Variables..

16 Oct 2021 06:21
#4
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

Please Log in or Create an account to join the conversation.

  • davidmcq137
  • davidmcq137's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 79
  • Thank you received: 87

TPL_KUNENA_MESSAGE_REPLIED_NEW Limit 200 local Variables..

17 Oct 2021 13:52
#5
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!
The following user(s) said Thank You: Thorn

Please Log in or Create an account to join the conversation.

Time to create page: 0.325 seconds
Powered by Kunena Forum