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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:58:07+00:00 2026-05-26T19:58:07+00:00

I want to pass a list containing numbers from Lua to C and access

  • 0

I want to pass a list containing numbers from Lua to C and access it in C. How can I do it?

Suppose I have the following Table:

x = {1, 2, 3, 9, 5, 6}

I want to send it to C and store this table in array in C.

I sent it using:

quicksort(x)

where quicksort is the function I have defined in C.

How can I access the x in C?

  • 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-26T19:58:07+00:00Added an answer on May 26, 2026 at 7:58 pm

    The table you pass to the function will be on the function’s stack. You can index it by using lua_getfield or lua_gettable.

    Traversing the table with lua_next, you can populate your array in C if you need to; although, for an array, simply iterating from 1 to #t should suffice.

    Some example utility code (untested):

    int* checkarray_double(lua_State *L, int narg, int *len_out) {
        luaL_checktype(L, narg, LUA_TTABLE);
    
        int len = lua_objlen(L, narg);
        *len_out = len;
        double *buff = (double*)malloc(len*sizeof(double));
    
        for(int i = 0; i < len; i++) {
            lua_pushinteger(L, i+1);
            lua_gettable(L, -2);
            if(lua_isnumber(L, -1)) {
                buff[i] = lua_tonumber(L, -1);
            } else {
                lua_pushfstring(L,
                    strcat(
                        strcat(
                            "invalid entry #%d in array argument #%d (expected number, got ",
                            luaL_typename(L, -1)
                        ),
                        ")"
                    ),
                    i, narg
                );
                lua_error(L);
            }
            lua_pop(L, 1);
        }
    
        return buff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a list array from the View to the controller on
I want to pass a custom made vector object containing data from background service
I have controller which gets list of keys and i want to pass them
I want to pass a list of alarm names from COM to VBScript used
I want to pass list of entitiy objects from Client to WCF Service, but
I have a list that contains arguments I want to pass to a function.
I want to pass an int list (List) as a declarative property to a
In my viewmodel, I have a list (ObservableCollection) containing items. In the view, this
I want to pass a List into a method, but I only want it
Essentially, I have a very large List containing in turn relatively large Dictionaries. So

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.