diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-07 14:26:48 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-07 14:26:48 -0200 |
commit | 26679b1a48de4f7cfcde985764cb31c78ece4fc3 (patch) | |
tree | df30c6972204791dd6a792dd36c1dd132bc5dbf4 /ldo.c | |
parent | e04c2b9aa817ed59b4e05025e0d33bfb3bba8f59 (diff) | |
download | lua-26679b1a48de4f7cfcde985764cb31c78ece4fc3.tar.gz lua-26679b1a48de4f7cfcde985764cb31c78ece4fc3.tar.bz2 lua-26679b1a48de4f7cfcde985764cb31c78ece4fc3.zip |
back to upavalues as extra arguments for C closures; this way it's
trivial to make currying.
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.19 1997/12/23 12:50:49 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.20 1997/12/26 18:38:16 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -157,6 +157,21 @@ static StkId callC (lua_CFunction f, StkId base) | |||
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) | ||
161 | { | ||
162 | TObject *pbase; | ||
163 | int nup = cl->nelems; /* number of upvalues */ | ||
164 | luaD_checkstack(nup); | ||
165 | pbase = L->stack.stack+base; /* care: previous call may change this */ | ||
166 | /* open space for upvalues as extra arguments */ | ||
167 | luaO_memup(pbase+nup, pbase, (L->stack.top-pbase)*sizeof(TObject)); | ||
168 | /* copy upvalues into stack */ | ||
169 | memcpy(pbase, cl->consts+1, nup*sizeof(TObject)); | ||
170 | L->stack.top += nup; | ||
171 | return callC(f, base); | ||
172 | } | ||
173 | |||
174 | |||
160 | void luaD_callTM (TObject *f, int nParams, int nResults) | 175 | void luaD_callTM (TObject *f, int nParams, int nResults) |
161 | { | 176 | { |
162 | luaD_openstack(nParams); | 177 | luaD_openstack(nParams); |
@@ -190,7 +205,7 @@ void luaD_call (StkId base, int nResults) | |||
190 | TObject *proto = &(c->consts[0]); | 205 | TObject *proto = &(c->consts[0]); |
191 | ttype(func) = LUA_T_CLMARK; | 206 | ttype(func) = LUA_T_CLMARK; |
192 | firstResult = (ttype(proto) == LUA_T_CPROTO) ? | 207 | firstResult = (ttype(proto) == LUA_T_CPROTO) ? |
193 | callC(fvalue(proto), base) : | 208 | callCclosure(c, fvalue(proto), base) : |
194 | luaV_execute(c, tfvalue(proto), base); | 209 | luaV_execute(c, tfvalue(proto), base); |
195 | break; | 210 | break; |
196 | } | 211 | } |