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

The Archive Base Latest Questions

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

I’m trying to write some c++ classes for interfacing with LUA and I am

  • 0

I’m trying to write some c++ classes for interfacing with LUA and I am confused about the following:

In the following example: Wherigo.ZCommand returns a “Command” objects, also zcharacterFisherman.Commands is an array of Command objects:

With the following LUA code, I understand it and it works by properly (luaL_getn returns 3 in the zcharacterFisherman.Commands c++ set newindex function):

zcharacterFisherman.Commands = {
  Wherigo.ZCommand{a="Talk", b=false, d=true, c="Nothing available"},
  Wherigo.ZCommand{a="Talk", b=false, d=true, c="Nothing available"},
  Wherigo.ZCommand{a="Talk", b=false, d=true, c="Nothing available"},
}

But when the array is defined with the following LUA code with a slightly different syntax luaL_getn returns 0.

zcharacterFisherman.Commands = {
  Talk = Wherigo.ZCommand{a="Talk", b=false, d=true, c="Nothing available"},
  Talk2 = Wherigo.ZCommand{a="Talk", b=false, d=true, c="Nothing available"},
  Talk3 = Wherigo.ZCommand{a="Talk", b=false, d=true, c="Nothing available"},
}

All objects are defined in c++ and the c++ objects hold all the object members so I am trying to just connect LUA to those c++ objects. Is this enough or do I need to post some of my code??

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

    luaL_getn is for getting the highest numeric element of an array in Lua. An array is a table with only integer indices. When you define a table in Lua (the first example) without explicitly setting indices, you will get an array with elements 1, 2, and 3. Naturally, luaL_getn returns a 3 here. luaL_getn is NOT defined to return the number of elements in the table, it is defined to return the highest numeric index in the table (see http://www.lua.org/manual/5.1/manual.html#pdf-table.maxn)

    The second example is NOT using numeric indices, and this table is not a Lua array — it is more like a hash table. Since luaL_getn only works on true arrays, you wouldn’t expect it to work here.

    Unfortunately, there is no simple way to get the number of elements in a table (lua_objlen solves a related problem, but does not fix this one). The only way to do it is to either:

    1. Always use array notation. Don’t ever use anything else as the keys in your table. You will get a lot of speed-ups this way.
    2. Iterate through your table and count the number of elements when you wish to know the table’s size. The language does not provide a one-line method for getting the size of a full table, since general tables are implemented using hashes and do not track their element count.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 143k
  • Answers 143k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Beans defined inside other beans are, by definition, "inner" beans.… May 12, 2026 at 8:23 am
  • Editorial Team
    Editorial Team added an answer sometimes complex types are not de-serialised properly. Are you calling… May 12, 2026 at 8:23 am
  • Editorial Team
    Editorial Team added an answer There are these cases: Something can go wrong and you… May 12, 2026 at 8:23 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.