

Moreover, as a Lua developer, I have no need to speculate about what a table looks like on the inside. I was about to describe the logic LuaJIT is guided by when new elements are inserted, but this a rather sophisticated algorithm. Both are represented by continuous storage areas. */Ī table has two parts: array and hashmap. Uint32_t hmask /* Hash part mask (size of hash part - 1). Uint32_t asize /* Size of array part (keys ). Scientifically speaking, a table is an associative array. Values of any type can be used as keys (except for nil). A table can be used both as a data array (if the keys are integer-valued) and as a key-value repository. Tables in Lua are the only composite data type designed to suit any purpose. There is another good presentation about tables in PUC-Rio implementation, if you’re interested. Our version is a bit patched as compared to the authentic LuaJIT, but the differences don’t impact tables. In this article, I’m going to discuss mostly LuaJIT 2.1.0, which is used in Tarantool.

Lua has several implementations and several versions.

LUA TABLE INSERT PROFESSIONAL
Lua is my primary professional programming language, and if one wants to write good code, one needs at least to peek behind the curtain. In this article, I’m going to tell you about the internals of Lua tables and special considerations for their use. I don’t know about you, but I really like to get inside all sorts of systems.
