[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Self-deleting weak tables?
- From: Edgar Toernig <froese@...>
- Date: Sat, 31 Oct 2009 20:03:14 +0100
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
and if profiling shows that it's too slow or generates too much
garbage (the {...} table), write a C function that puts the
binary representation into a string:
int bundle(lua_State *L)
{
lua_Number buf[32]; // assume no padding
int i, n;
n = lua_gettop(L);
if (n > 32)
luaL_error(L, "sorry pal, too many arguments");
for (i = 0; i < n; ++i)
buf[i] = luaL_checknumber(L, i+1);
lua_pushlstring(L, (char*)buf, n * sizeof(*buf));
return 1;
}
Ciao, ET.