_G for local variables
After searching and trying almost an hour to find a way to access local variables with dynamic names (and facepalming when the most simple solution sprang to my mind...), I'm still wondering: is there a way, analogue to _G for global variables, to access local variables?
lua Code:
|
Hmm, correct me if I'm wrong but couldn't you just imitate the _G with a local version, since as far as I understand, _G is just a table.
So: lua Code:
Not as neat assignment though... |
I think what you're trying to say, is there a different way of getting the global variable without using this?
Lua Code:
In the usage you're describing, no. |
Offtopic, what's the tag for showing lua-code like that? With syntax highlighting and all.
|
Quote:
It's the same as 'code', but instead of 'code' it's 'lua'. ^ WRONG use '[' highlight=lua ']' closed with '[' /highlight ']'. |
As for a true Lua global, there's no way to define or read dynamic locals. However as you've demonstrated, you may define a single local table that holds additional data as key/value pairs. I would advise against this unless absolutely necessary as table entries consume more resources than locals themselves. I follow the simple rule, tables are only for list/structure data, everything else is to stay in locals.
|
Quote:
Quote:
Quote:
|
Quote:
|
If you need such a construct for local variables, you're probably structuring your code incorrectly; scoping is a logical tool, not something to be avoided.
|
local addonName, _L = ...
Could then use _L table for local addon storage, accessible across files, but shouldn't be used for standard data access like OnUpdate loop constantly accessing the table _L.data={} at certain index would take more resources than having a local data = ... where the data is directly stored in the variable local to that file. Table within table is slower than just one table. Anyway, probably not useful info. |
Quote:
lua Code:
Quote:
|
Quote:
lua Code:
|
All times are GMT -6. The time now is 10:52 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI