lua-users home
lua-l archive

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


2007/5/28, Sam Roberts <sroberts@bycast.com>:
On Mon, May 28, 2007 at 08:12:58PM -0400, Tim Hunter wrote:
I think Jerome's right the the fenv is more suited. I forgot there isn't
a one-shot for sharing the same upvalue among multiple c functions. I
was thinking of luaL_openlib(), but it requires the seed to be in a
table to be shared.

[...]

You have to do more like
lua_pushtable(L)
lua_pushinteger(L, DEF_SEEED)
lua_setfield(L, -2, "seed");
lua_pushvalue(L, -1);
lua_pushcclosure(L, seedfn, 1);
lua_pushvalue(L, -1);
lua_pushcclosure(L, randfn, 1);

That's exactly what I meant. You can share the upvalue only if it is
of a type handled by reference in Lua. That is not the case for
numbers, so you have to wrap it in a table, or eventually a full
userdata to gain some speed.