Hi,
as Tim Him proposed, A "empty" value in lua table, makes Lua have a "array" can contain any values.
But I thought more. there are something affects me a lot:
- we can not "store" lua value in C. we can get pointer of any Lua value, but we can not store it in C and get the lua value it point, currently we can do it with a table to store the map with pointer and value.
- we can not get a cheap data structure with a/some lua values. sometimes we use table, it's 24 byte without any values. we just want a non-type container, just can hold all values we want, just like a special userdata.
there is a proposal can solve all three (or more) issue: add a type only seen in C or other thing, it's just used to hold Lua values. just like the current Lua stack (internals, Roberto can implement Lua stack with this value).
we can have several APIs to maintain this data-structure, just like this:
lua_Values lua_newvalues(lua_State *L, size_t sz);
void lua_reallocvalues(lua_State *L, lua_Values *v, size_t sz); /* sz == 0 to free it */
void lua_pushvalues(lua_State *L, lua_Values *v);
void lua_valuesadd(lua_State *L, int idx, lua_Values *v);
void lua_valuesset(lua_State *L, lua_Values *v, int idx);
lua_Values has a defined length. the big difference between lua_Values and other thing is, it's just a container of some Lua value, so it can be changed: it's just a piece of memory that holds lua values, so we can grow it or shrink it.
with lua_Values, we can get a fast way to hold lua value in C program, we can implement cheap data structure that can hold all type of Lua value, and we can implement a true array userdata in C, and makes it a standard library of Lua.