How to reference lua table member from table member?

Viewed 4642

i have a table in lua:

enUS = {
   LOCALE_STHOUSANDS = ",",  --Thousands separator e.g. comma

   patNumber = "%d+["..LOCALE_STHOUSANDS.."%d]*", --regex to find a number

   ["PreScanPatterns"] = {
      ["^("..patNumber..") Armor$"] = "ARMOR",
   }
}

So you see there is a whole chain of self-references in this table:

  • LOCAL_STHOUSANDS
    • patNumber
      • ["^("..patNumber..") Armor$"]

How can i perform self-referencing in an lua table?


What i don't want to do is have to hard-replace the values; there are hundreds of references:

enUS = {
   LOCALE_STHOUSANDS = ",",  --Thousands separator e.g. comma

   patNumber = "%d+[,%d]*", --regex to find a number

   ["PreScanPatterns"] = {
      ["^(%d+[,%d]*) Armor$"] = "ARMOR",
   }
}
2 Answers
Related