[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pushcclosure / tocfunction issue
- From: "John Belmonte" <jvb@...>
- Date: Thu, 12 Oct 2000 18:22:48 +0900
I implemented the suggested lua_getcclosure (new function for 4.0b lapi.c
below). I noticed that the same function could cover both C and Lua
closures uniformly easily (in that case it would be named lua_getclosure).
I'm new to this, there may be some bugs.
-John
----
int lua_getcclosure (lua_State *L, int index) {
StkId top = L->top;
StkId o = Index(L, index);
int nelems = clvalue(o)->nupvalues;
TObject* upvalues = clvalue(o)->upvalue;
int i;
luaC_checkGC(L);
if (o >= L->top) return 0; /* index out-of-range */
LUA_ASSERT(ttype(closure) == TAG_CCLOSURE, "C closure expected");
luaD_checkstack(L, nelems);
for (i = 0; i<nelems; i++)
*top++ = upvalues[i];
L->top = top;
return nelems;
}