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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:36:31+00:00 2026-05-27T12:36:31+00:00

After years of java, javascript, python, I am not only forget C++, but also

  • 0

After years of java, javascript, python, I am not only forget C++, but also confuse that syntax.

http://heavycoder.com/tutorials/lua_embed.php

static const luaL_reg lualibs[] =
{
        { "base",       luaopen_base },
        { NULL,         NULL }
};

lualibs init with a 2D array? luaL_reg is a type, but obviously is not a array,

const luaL_reg *lib;

for (lib = lualibs; lib->func != NULL; lib++)
{
    lib->func(l);
    lua_settop(l, 0);
}
  • 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-27T12:36:31+00:00Added an answer on May 27, 2026 at 12:36 pm

    luaL_reg probably looks something as the below.

    typedef struct luaL_reg_t {
      char const * const name;
      void(*func)(< type_of_<l> >);
    } luaL_reg;
    

    The members of an object can be set using {} as in the below example, which will set the member name to point towards the location of "hello world" and func to have the adress of my_function.

    luaL_reg obj = {"hello world", my_function};
    

    The syntax shown in the previous snippet can also be used when initializing members of an array. In the below snippet a array of const luaL_reg instances is set to contain two objects, the first one having name = "base" and func set to luaopen_base.

    To make things clear; the below is not a 2D array, but an array of const luaL_reg initialized using {} to set the members of each instance.

    static const luaL_reg lualibs[] =
    {
      { "base",       luaopen_base },
      { NULL,         NULL }
    };
    

    The last element is used to simplify iterating our array, setting both members to NULL makes it easy to see when we have reached the last element.

    The loop in the upcoming snippet takes advantage of this. As long as the member func isn’t equal to NULL we haven’t gotten to the end of our array.

    for (lib = lualibs; lib->func != NULL; lib++) {
      lib->func(l);
      lua_settop(l, 0);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After five years of professional Java (and to a lesser extent, Python) programming and
After years of ASP.NET development I'm actually quite surprised that I can't seem to
I'm considering spending time learning and using LINQ to SQL but after years of
After some years of experience in the field, it seems to me that the
Using Getting back up to speed on Java after 8-10 years as a starting
I'm about to jump into Java development again after a number of years. The
after some years in Java and C# now I'm back to C++. Of course
I'm new to Java after working for a few years in PHP and I'm
I'm an experienced Java programmer that for the last two years have programmed for
After three years on a RESTful Java/ExtJS application, I have taken over development of

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.