Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8346131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:54:43+00:00 2026-06-09T06:54:43+00:00

i have a table in lua: enUS = { LOCALE_STHOUSANDS = ,, –Thousands separator

  • 0

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",
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:54:44+00:00Added an answer on June 9, 2026 at 6:54 am

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

    You don’t.

    Lua is not C. Until the table is constructed, none of the table entries exist. Because the table itself doesn’t exist yet. Therefore, you can’t have one entry in a table constructor reference another entry in a table that doesn’t exist.

    If you want to cut down on repeated typing, then you should use local variables and do/end blocks:

    do
      local temp_thousands_separator = ","
      local temp_number_pattern = "%d+["..LOCALE_STHOUSANDS.."%d]*"
    
      enUS = {
       LOCALE_STHOUSANDS = temp_thousands_separator,  --Thousands separator e.g. comma
    
       patNumber = "%d+["..temp_thousands_separator.."%d]*", --regex to find a number
    
       ["PreScanPatterns"] = {
          ["^("..temp_number_pattern..") Armor$"] = "ARMOR",
       }
      }
    end
    

    The do/end block is there so that the temporary variables don’t exist outside of the table creation code.

    Alternatively, you can do the construction in stages:

      enUS = {}
      enUS.LOCALE_STHOUSANDS = ",",  --Thousands separator e.g. comma
    
      enUS.patNumber = "%d+["..enUS.LOCALE_STHOUSANDS.."%d]*", --regex to find a number
    
      enUS["PreScanPatterns"] = {
          ["^("..enUS.patNumber..") Armor$"] = "ARMOR",
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Lua table, t , which I iterate: for k, v in pairs(t)
So currently I have a table in Lua that contains another table (much like
Does Lua have a builtin sum() function? I can't seem to find one, and
I have a Lua table and an index function like this: curIndex = 0
I have a lua table that I use as a hashmap, ie with string
I have a key => value table I'd like to sort in Lua. The
Is it possible in lua to override access to table element? F.e. I have
I have the following lua table : t = {name=sandy, age=22, major=computerScience} I want
I have created a Lua table in C , but I'm not sure how
I have table with around 70 000 rows. There is 6000 rows that i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.