lua-users home
lua-l archive

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




> 在 2022年5月18日,23:16,Mason Bogue <scythe+lua@ortsz.com> 写道:
> 
> 
> Hi,
> 
> Currently, as I understand it, the metatable of a Lua value is a Lua table with string keys "__index", "__add", "__tostring", etc. These string keys are stored in a hash table and incur a hash-table lookup whenever accessing a metatable, i.e., if I write something like
> 
> t = {}
> setmetatable(t, {__index = {a = function() return "b" end}})

In this case, __index is the only key of the table, so it’s not slower than [1] .