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

  • Home
  • SEARCH
  • 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 7308885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:38:00+00:00 2026-05-28T23:38:00+00:00

I’m using Lua as a data description language for my C++ app. I have

  • 0

I’m using Lua as a data description language for my C++ app. I have a bunch of C++ classes bound to Lua using SLB 2.0. I have methods bound such as ‘SetPos’ or ‘SetName’. I specify the position or name (for example) using a table with values keyed as ‘pos’ or ‘name’. I want to be able to take the key, prepend ‘set’, and call the method, if it exists (it may not). Is that possible? If so, any suggestions?

I know I could make my bound methods lower case, but I’d rather keep them the same as the methods they’re bound to (that may be my fallback though). I could try to build the method name based on my naming standards, but case insensitivity is less error prone.

I feel there should be a tricky piece of Lua that could solve this using metatables, but I haven’t been able to work it out myself.

Any suggestions?

Thanks!

  • 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-05-28T23:38:01+00:00Added an answer on May 28, 2026 at 11:38 pm

    Case insensitivity is not really something Lua handles. All table lookups and local variable accesses are ultimately case sensitive string compares.

    The best solution would be to just accept that you’re dealing with a case sensitive system, just like C++, and deal with it.

    However, if you really want to, you can do this. The simplest way would be to put every possible case permutation of a name in your function table. So your function table would have this:

    ["setname"] = theFunction,
    ["Setname"] = theFunction,
    ["sEtname"] = theFunction,
    ["SEtname"] = theFunction,
    ...
    

    You can of course automate this with a function that takes each name in the table and replicates its data based on the case permutations.

    A more involved but easier to use mechanism would be to use the __index and __newindex metamethods along with the empty table trick.

    function CreateCaseInsensitiveTable()
      local metatbl = {}
    
      function metatbl.__index(table, key)
        if(type(key) == "string") then
          key = key:lower()
        end
    
        return rawget(table, key)
      end
    
      function metatbl.__newindex(table, key, value)
        if(type(key) == "string") then
          key = key:lower()
        end
    
        rawset(table, key, value)
      end
    
      local ret = {}
      setmetatable(ret, metatbl)
      return ret
    end
    

    Instead of creating a table with {}, you create the table with this function call. The table should otherwise function as normal (though obviously member access will be slightly slower).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.