lua-users home
lua-l archive

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



On 01/08/14 04:13 PM, Coda Highland wrote:
On Fri, Aug 1, 2014 at 12:08 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
If there is no API function for this, then there is no call for having
it in Lua.

What would such an API function do? Traverse the whole table and
set every value to nil, in order to adjust the reference count. It's not
obvious that the performance enhancement relative to

for k in pairs(tbl) do tbl[k]=nil end

is worth yet another library function in a language that can't even carry
the baggage of cosh, sinh and tanh.
Is that the only way to achieve it? Is there not a way to simply
disown the contents of the table and leave it for GC? I mean, even if
it's "create new empty table, swap internal data pointers, let new
table go unreferenced" that would be faster than a loop -- and it
would be something that couldn't be achieved by Lua code.

/s/ Adam

You mean something like:
setmetatable(t,{__mode="kv"}) collectgarbage() setmetatable(t,nil) for k in pairs(tbl) do tbl[k]=nil end