[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Could metatables easily be faster?
- From: 云风 <cloudwu@...>
- Date: Fri, 20 May 2022 07:12:13 +0800
> 在 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] .