lua-users home
lua-l archive

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

Edgar Toernig wrote:
> Jim Pryor wrote:
>>     alpha = newobject(10,20,30)
>> [...]
>> If I had any way to intern argument lists, so that
>> a value-sequence could be collected into a single bundle that was
>> guaranteed identical to any other bundle created from the
>> same value-sequence, then I could just use a single, flat, weak cache
>> table, with those bundled sequences as keys.
> Just put them all in a string:
>     function bundle(...)
>         return table.concat({...}, "/")
>     end

Assuming they are all numbers, as your C++ code does, I would prefer to
see something that makes garbage strings over garbage tables:

function bundle(...)
   return string.format(("%f/):rep(select('#', ...)-1) .. "%f", ...);

It has the added side effect that, since strings are interned, frequent,
 identical calls would not result in an ever-increasing memory rate.

Matthew P. Del Buono