lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> On 14 April 2015 at 18:37, Konstantin Osipov <> wrote:
> Since there is no easy way to distinguish between a Lua map and an
> array

This question arises on this list from time to time. It would be great to know if the array is really an array.

I have used this code to detect arrays:

But when I look lobject.h, I can see:

typedef struct Table {
  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */
  lu_byte lsizenode;  /* log2 of size of 'node' array */
  unsigned int sizearray;  /* size of 'array' array */
  TValue *array;  /* array part */
  Node *node;
  Node *lastfree;  /* any free position is before this position */
  struct Table *metatable;
  GCObject *gclist;
} Table;

So internally Lua seems make distinction between array parts and nodes. I'm not sure though if I have understood this even the slightest, so please correct me. The thing that I don't understand is that why this cannot be made available to Lua side as well?