Is there any way to "concatenate" variable references with strings?:
fat_greek_wedding = 0;
nationality = "greek";
"fat_" .. nationality .. "_wedding" = 1; -- fat_greek_wedding == 1
Or perhaps something like:
fat_greek_wedding = 0;
nationality = "greek";
fat_(nationality)_wedding = 1; -- fat_greek_wedding == 1
FYI I am writing code for Unified Remote, which uses Lua: https://github.com/unifiedremote/Docs
Global variables, or fields of structures - are just elements of some table, and variable's name is a text key in that table.
If that fat_greek_wedding is a global variable, you can access it like this:
fat_greek_wedding = 0;
nationality = "greek";
_G["fat_" .. nationality .. "_wedding"] = 1;
Here you explicitly access global environment, altering/creating element by the name that was constructed in run time. Effectively it is the same as running fat_greek_wedding=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With