lua-users home
lua-l archive

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




On Sun, Feb 16, 2020 at 4:52 PM Pavel <temp213@gorodok.net> wrote:
Sam Putman wrote
> On Wed, Feb 12, 2020 at 4:59 AM Pavel &lt;

> temp213@

> &gt; wrote:
> I think the reason Lua doesn't work this way, is that it imposes a speed
> penalty on any nil-returning lookup, to every table so created.

Good point, G(L)->mt[LUA_TTABLE], when used as default metatable for new
tables could still be equal to NULL by default.
But at least there would be an option to set it to table library or
whatsoever when required.


`t()` is one more character than `{}` and could be defined like so:

local function t(tab) -- can be global in a long/complex program
   tab = tab or {}
   return setmetatable({}, table)
end

and you could call it with `t{}` to remind yourself what it does. 

This is what I'd do if I were planning to use such tables frequently.

cheers,
-Sam.