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 945473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:45:23+00:00 2026-05-15T22:45:23+00:00

In Lua, you can create a table whose keys are themselves tables: t =

  • 0

In Lua, you can create a table whose keys are themselves tables:

t = {}
t[{1,2}] = 2

I would like to know how to do the analogous thing using the C API. That is, I am writing a C function callable from Lua, which will return a table with table keys. I tried to push a table as a key and then use lua_settable, but it seems to do nothing.

Edit: Relevant code:

lua_createtable(L, 0, n);
for(i = 0; i < n; ++i){
    // push the key table
    lua_createtable(L, 2, 0);
    for(j = 0; j < 2; ++j){
        lua_pushinteger(L, j+1);
        lua_pushinteger(L, j);
        lua_settable(L, -3);
    }
    // push the value table
    lua_createtable(L, 4, 0);
    for(j = 0; j < 4; ++j){
        lua_pushinteger(L, j+1);
        lua_pushnumber(L, j);
        lua_settable(L, -3);
    }
    lua_settable(L, -3);
}

Edit: I was being dumb; I used lua_objlen(L, -1) at the end to check on the size of the table, which returns 0 since there are no integer keyed entries. Also, in the Lua code that processed the table, I used ipairs instead of pairs. Silly mistake.

  • 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-15T22:45:24+00:00Added an answer on May 15, 2026 at 10:45 pm

    I was checking for the table entries in the wrong way. I have edited the question with the solution.

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

Sidebar

Related Questions

In lua, one can very easily create a table and add functions to it.
Say that you want to create a Lua table, and all its keys are
In Lua, you can create a table the following way : local t =
I know that you can't repeat match groups in Lua. For example, if I
I'm just starting out using Lua, and I was wondering (because I can't find
I know that Lua is gc-ed. I know that Lua can deal with c
I have a Lua table and an index function like this: curIndex = 0
In Lua the the __index metamethod can be either a function or a table
If I have some lua code like this: doSomething(function() print(Hello!) end) How can I
Can someone list the steps I would need to take to put a lua

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.