Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lfunc.c File Reference
#include "lprefix.h"
#include <stddef.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"

Go to the source code of this file.

Macros

#define lfunc_c
 
#define LUA_CORE
 
#define MAXDELTA    ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1)
 

Functions

CClosureluaF_newCclosure (lua_State *L, int nupvals)
 
LClosureluaF_newLclosure (lua_State *L, int nupvals)
 
void luaF_initupvals (lua_State *L, LClosure *cl)
 
static UpValnewupval (lua_State *L, int tbc, StkId level, UpVal **prev)
 
UpValluaF_findupval (lua_State *L, StkId level)
 
static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy)
 
static void checkclosemth (lua_State *L, StkId level)
 
static void prepcallclosemth (lua_State *L, StkId level, int status, int yy)
 
void luaF_newtbcupval (lua_State *L, StkId level)
 
void luaF_unlinkupval (UpVal *uv)
 
void luaF_closeupval (lua_State *L, StkId level)
 
static void poptbclist (lua_State *L)
 
void luaF_close (lua_State *L, StkId level, int status, int yy)
 
ProtoluaF_newproto (lua_State *L)
 
void luaF_freeproto (lua_State *L, Proto *f)
 
const char * luaF_getlocalname (const Proto *f, int local_number, int pc)
 

Macro Definition Documentation

◆ lfunc_c

#define lfunc_c

Definition at line 7 of file lua-5.4.3/src/lfunc.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.4.3/src/lfunc.c.

◆ MAXDELTA

#define MAXDELTA    ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1)

Definition at line 162 of file lua-5.4.3/src/lfunc.c.

162#define MAXDELTA \
163 ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1)

Referenced by luaF_newtbcupval(), and poptbclist().

Function Documentation

◆ callclosemethod()

static void callclosemethod ( lua_State * L,
TValue * obj,
TValue * err,
int yy )
static

Definition at line 108 of file lua-5.4.3/src/lfunc.c.

108 {
109 StkId top = L->top;
110 const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);
111 setobj2s(L, top, tm); /* will call metamethod... */
112 setobj2s(L, top + 1, obj); /* with 'self' as the 1st argument */
113 setobj2s(L, top + 2, err); /* and error msg. as 2nd argument */
114 L->top = top + 3; /* add function and arguments */
115 if (yy)
116 luaD_call(L, top, 0);
117 else
118 luaD_callnoyield(L, top, 0);
119}
void luaD_call(lua_State *L, StkId func, int nResults)
#define setobj2s
const TValue * luaT_gettmbyobj(lua_State *L, const TValue *o, TMS event)
void luaD_callnoyield(lua_State *L, StkId func, int nResults)
@ TM_CLOSE

References luaD_call(), luaD_callnoyield(), luaT_gettmbyobj(), setobj2s, TM_CLOSE, and lua_State::top.

Referenced by prepcallclosemth().

◆ checkclosemth()

static void checkclosemth ( lua_State * L,
StkId level )
static

Definition at line 126 of file lua-5.4.3/src/lfunc.c.

126 {
127 const TValue *tm = luaT_gettmbyobj(L, s2v(level), TM_CLOSE);
128 if (ttisnil(tm)) { /* no metamethod? */
129 int idx = cast_int(level - L->ci->func); /* variable index */
130 const char *vname = luaG_findlocal(L, L->ci, idx, NULL);
131 if (vname == NULL) vname = "?";
132 luaG_runerror(L, "variable '%s' got a non-closable value", vname);
133 }
134}
#define NULL
Definition gmacros.h:924
void luaG_runerror(lua_State *L, const char *fmt,...)
#define cast_int(i)
#define ttisnil(o)
const char * luaG_findlocal(lua_State *L, CallInfo *ci, int n, StkId *pos)
#define s2v(o)

References cast_int, lua_State::ci, CallInfo::func, luaG_findlocal(), luaG_runerror(), luaT_gettmbyobj(), NULL, s2v, TM_CLOSE, and ttisnil.

Referenced by luaF_newtbcupval().

◆ luaF_close()

void luaF_close ( lua_State * L,
StkId level,
int status,
int yy )

Definition at line 228 of file lua-5.4.3/src/lfunc.c.

228 {
229 ptrdiff_t levelrel = savestack(L, level);
230 luaF_closeupval(L, level); /* first, close the upvalues */
231 while (L->tbclist >= level) { /* traverse tbc's down to that level */
232 StkId tbc = L->tbclist; /* get variable index */
233 poptbclist(L); /* remove it from list */
234 prepcallclosemth(L, tbc, status, yy); /* close variable */
235 level = restorestack(L, levelrel);
236 }
237}
#define savestack(L, p)
#define restorestack(L, n)
static void poptbclist(lua_State *L)
static void prepcallclosemth(lua_State *L, StkId level, int status, int yy)
void luaF_closeupval(lua_State *L, StkId level)

References luaF_closeupval(), poptbclist(), prepcallclosemth(), restorestack, savestack, and lua_State::tbclist.

◆ luaF_closeupval()

void luaF_closeupval ( lua_State * L,
StkId level )

Definition at line 194 of file lua-5.4.3/src/lfunc.c.

194 {
195 UpVal *uv;
196 StkId upl; /* stack index pointed by 'uv' */
197 while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) {
198 TValue *slot = &uv->u.value; /* new position for value */
199 lua_assert(uplevel(uv) < L->top);
200 luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */
201 setobj(L, slot, uv->v); /* move value to upvalue slot */
202 uv->v = slot; /* now current value lives here */
203 if (!iswhite(uv)) { /* neither white nor dead? */
204 nw2black(uv); /* closed upvalues cannot be gray */
205 luaC_barrier(L, uv, slot);
206 }
207 }
208}
#define luaC_barrier(L, p, v)
#define iswhite(x)
#define lua_assert(c)
#define setobj(L, obj1, obj2)
void luaF_unlinkupval(UpVal *uv)
#define uplevel(up)
#define nw2black(x)
union UpVal::@48 u
GCObject * openupval

References iswhite, lua_assert, luaC_barrier, luaF_unlinkupval(), NULL, nw2black, lua_State::openupval, setobj, lua_State::top, UpVal::u, uplevel, UpVal::v, and UpVal::value.

Referenced by luaE_freethread(), luaF_close(), and luaV_execute().

◆ luaF_findupval()

UpVal * luaF_findupval ( lua_State * L,
StkId level )

Definition at line 88 of file lua-5.4.3/src/lfunc.c.

88 {
89 UpVal **pp = &L->openupval;
90 UpVal *p;
92 while ((p = *pp) != NULL && uplevel(p) >= level) { /* search for it */
93 lua_assert(!isdead(G(L), p));
94 if (uplevel(p) == level) /* corresponding upvalue? */
95 return p; /* return it */
96 pp = &p->u.open.next;
97 }
98 /* not found: create a new upvalue after 'pp' */
99 return newupval(L, 0, level, pp);
100}
#define isdead(g, v)
#define G(L)
#define isintwups(L)
static UpVal * newupval(lua_State *L, int tbc, StkId level, UpVal **prev)
struct UpVal::@68::@69 open
struct UpVal * next

References G, isdead, isintwups, lua_assert, newupval(), UpVal::next, NULL, UpVal::open, lua_State::openupval, UpVal::u, and uplevel.

◆ luaF_freeproto()

void luaF_freeproto ( lua_State * L,
Proto * f )

Definition at line 267 of file lua-5.4.3/src/lfunc.c.

267 {
268 luaM_freearray(L, f->code, f->sizecode);
269 luaM_freearray(L, f->p, f->sizep);
270 luaM_freearray(L, f->k, f->sizek);
275 luaM_free(L, f);
276}
#define luaM_freearray(L, b, n, t)
#define luaM_free(L, b)
AbsLineInfo * abslineinfo
Instruction * code
struct LocVar * locvars
struct Proto ** p
TString ** upvalues

References Proto::abslineinfo, Proto::code, Proto::k, Proto::lineinfo, Proto::locvars, luaM_free, luaM_freearray, Proto::p, Proto::sizeabslineinfo, Proto::sizecode, Proto::sizek, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizep, Proto::sizeupvalues, and Proto::upvalues.

◆ luaF_getlocalname()

const char * luaF_getlocalname ( const Proto * f,
int local_number,
int pc )

Definition at line 283 of file lua-5.4.3/src/lfunc.c.

283 {
284 int i;
285 for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
286 if (pc < f->locvars[i].endpc) { /* is variable active? */
287 local_number--;
288 if (local_number == 0)
289 return getstr(f->locvars[i].varname);
290 }
291 }
292 return NULL; /* not found */
293}
#define getstr(ts)
TString * varname

References getstr, Proto::locvars, NULL, Proto::sizelocvars, LocVar::startpc, and LocVar::varname.

◆ luaF_initupvals()

void luaF_initupvals ( lua_State * L,
LClosure * cl )

Definition at line 48 of file lua-5.4.3/src/lfunc.c.

48 {
49 int i;
50 for (i = 0; i < cl->nupvalues; i++) {
51 GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));
52 UpVal *uv = gco2upv(o);
53 uv->v = &uv->u.value; /* make it closed */
54 setnilvalue(uv->v);
55 cl->upvals[i] = uv;
56 luaC_objbarrier(L, cl, uv);
57 }
58}
#define luaC_objbarrier(L, p, o)
#define setnilvalue(obj)
GCObject * luaC_newobj(lua_State *L, int tt, size_t sz, GCObject **list, int offset)
#define LUA_VUPVAL
#define gco2upv(o)

References gco2upv, LUA_VUPVAL, luaC_newobj(), luaC_objbarrier, setnilvalue, UpVal::u, LClosure::upvals, UpVal::v, and UpVal::value.

◆ luaF_newCclosure()

CClosure * luaF_newCclosure ( lua_State * L,
int nupvals )

Definition at line 27 of file lua-5.4.3/src/lfunc.c.

27 {
28 GCObject *o = luaC_newobj(L, LUA_VCCL, sizeCclosure(nupvals));
29 CClosure *c = gco2ccl(o);
30 c->nupvalues = cast_byte(nupvals);
31 return c;
32}
#define sizeCclosure(n)
#define cast_byte(i)
#define gco2ccl(o)
#define LUA_VCCL

References cast_byte, gco2ccl, LUA_VCCL, luaC_newobj(), and sizeCclosure.

◆ luaF_newLclosure()

LClosure * luaF_newLclosure ( lua_State * L,
int nupvals )

Definition at line 35 of file lua-5.4.3/src/lfunc.c.

35 {
36 GCObject *o = luaC_newobj(L, LUA_VLCL, sizeLclosure(nupvals));
37 LClosure *c = gco2lcl(o);
38 c->p = NULL;
39 c->nupvalues = cast_byte(nupvals);
40 while (nupvals--) c->upvals[nupvals] = NULL;
41 return c;
42}
#define sizeLclosure(n)
#define gco2lcl(o)
#define LUA_VLCL
struct Proto * p

References cast_byte, gco2lcl, LUA_VLCL, luaC_newobj(), NULL, LClosure::p, sizeLclosure, and LClosure::upvals.

◆ luaF_newproto()

Proto * luaF_newproto ( lua_State * L)

Definition at line 240 of file lua-5.4.3/src/lfunc.c.

240 {
241 GCObject *o = luaC_newobj(L, LUA_VPROTO, sizeof(Proto));
242 Proto *f = gco2p(o);
243 f->k = NULL;
244 f->sizek = 0;
245 f->p = NULL;
246 f->sizep = 0;
247 f->code = NULL;
248 f->sizecode = 0;
249 f->lineinfo = NULL;
250 f->sizelineinfo = 0;
251 f->abslineinfo = NULL;
252 f->sizeabslineinfo = 0;
253 f->upvalues = NULL;
254 f->sizeupvalues = 0;
255 f->numparams = 0;
256 f->is_vararg = 0;
257 f->maxstacksize = 0;
258 f->locvars = NULL;
259 f->sizelocvars = 0;
260 f->linedefined = 0;
261 f->lastlinedefined = 0;
262 f->source = NULL;
263 return f;
264}
#define gco2p(o)
#define LUA_VPROTO
lu_byte maxstacksize
TString * source

References Proto::abslineinfo, Proto::code, gco2p, Proto::is_vararg, Proto::k, Proto::lastlinedefined, Proto::linedefined, Proto::lineinfo, Proto::locvars, LUA_VPROTO, luaC_newobj(), Proto::maxstacksize, NULL, Proto::numparams, Proto::p, Proto::sizeabslineinfo, Proto::sizecode, Proto::sizek, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizep, Proto::sizeupvalues, Proto::source, and Proto::upvalues.

◆ luaF_newtbcupval()

void luaF_newtbcupval ( lua_State * L,
StkId level )

Definition at line 169 of file lua-5.4.3/src/lfunc.c.

169 {
170 lua_assert(level > L->tbclist);
171 if (l_isfalse(s2v(level)))
172 return; /* false doesn't need to be closed */
173 checkclosemth(L, level); /* value must have a close method */
174 while (cast_uint(level - L->tbclist) > MAXDELTA) {
175 L->tbclist += MAXDELTA; /* create a dummy node at maximum delta */
176 L->tbclist->tbclist.delta = 0;
177 }
178 level->tbclist.delta = cast(unsigned short, level - L->tbclist);
179 L->tbclist = level;
180}
#define cast(t, exp)
#define l_isfalse(o)
#define MAXDELTA
static void checkclosemth(lua_State *L, StkId level)
#define cast_uint(i)

References cast, cast_uint, checkclosemth(), l_isfalse, lua_assert, MAXDELTA, s2v, and lua_State::tbclist.

Referenced by lua_toclose(), and luaV_execute().

◆ luaF_unlinkupval()

void luaF_unlinkupval ( UpVal * uv)

Definition at line 183 of file lua-5.4.3/src/lfunc.c.

183 {
184 lua_assert(upisopen(uv));
185 *uv->u.open.previous = uv->u.open.next;
186 if (uv->u.open.next)
187 uv->u.open.next->u.open.previous = uv->u.open.previous;
188}
#define upisopen(up)
struct UpVal ** previous

References lua_assert, UpVal::next, UpVal::open, UpVal::previous, UpVal::u, and upisopen.

Referenced by freeupval(), and luaF_closeupval().

◆ newupval()

static UpVal * newupval ( lua_State * L,
int tbc,
StkId level,
UpVal ** prev )
static

Definition at line 65 of file lua-5.4.3/src/lfunc.c.

65 {
66 GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));
67 UpVal *uv = gco2upv(o);
68 UpVal *next = *prev;
69 uv->v = s2v(level); /* current value lives in the stack */
70 uv->tbc = tbc;
71 uv->u.open.next = next; /* link it to list of open upvalues */
72 uv->u.open.previous = prev;
73 if (next)
74 next->u.open.previous = &uv->u.open.next;
75 *prev = uv;
76 if (!isintwups(L)) { /* thread not in list of threads with upvalues? */
77 L->twups = G(L)->twups; /* link it to the list */
78 G(L)->twups = L;
79 }
80 return uv;
81}
#define next(ls)
struct lua_State * twups

References G, gco2upv, isintwups, LUA_VUPVAL, luaC_newobj(), next, UpVal::next, UpVal::open, UpVal::previous, s2v, UpVal::tbc, lua_State::twups, UpVal::u, and UpVal::v.

Referenced by luaF_findupval().

◆ poptbclist()

static void poptbclist ( lua_State * L)
static

Definition at line 214 of file lua-5.4.3/src/lfunc.c.

214 {
215 StkId tbc = L->tbclist;
216 lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */
217 tbc -= tbc->tbclist.delta;
218 while (tbc > L->stack && tbc->tbclist.delta == 0)
219 tbc -= MAXDELTA; /* remove dummy nodes */
220 L->tbclist = tbc;
221}

References lua_assert, MAXDELTA, lua_State::stack, and lua_State::tbclist.

Referenced by luaF_close().

◆ prepcallclosemth()

static void prepcallclosemth ( lua_State * L,
StkId level,
int status,
int yy )
static

Definition at line 144 of file lua-5.4.3/src/lfunc.c.

144 {
145 TValue *uv = s2v(level); /* value being closed */
146 TValue *errobj;
147 if (status == CLOSEKTOP)
148 errobj = &G(L)->nilvalue; /* error object is nil */
149 else { /* 'luaD_seterrorobj' will set top to level + 2 */
150 errobj = s2v(level + 1); /* error object goes after 'uv' */
151 luaD_seterrorobj(L, status, level + 1); /* set error object */
152 }
153 callclosemethod(L, uv, errobj, yy);
154}
void luaD_seterrorobj(lua_State *L, int errcode, StkId oldtop)
static void callclosemethod(lua_State *L, TValue *obj, TValue *err, int yy)
#define CLOSEKTOP

References callclosemethod(), CLOSEKTOP, G, luaD_seterrorobj(), and s2v.

Referenced by luaF_close().