Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ltm.h File Reference
#include "lobject.h"

Go to the source code of this file.

Macros

#define maskflags   (~(~0u << (TM_EQ + 1)))
 
#define notm(tm)   ttisnil(tm)
 
#define gfasttm(g, et, e)
 
#define fasttm(l, et, e)   gfasttm(G(l), et, e)
 
#define ttypename(x)   luaT_typenames_[(x) + 1]
 

Enumerations

enum  TMS {
  TM_INDEX , TM_NEWINDEX , TM_GC , TM_MODE ,
  TM_LEN , TM_EQ , TM_ADD , TM_SUB ,
  TM_MUL , TM_MOD , TM_POW , TM_DIV ,
  TM_IDIV , TM_BAND , TM_BOR , TM_BXOR ,
  TM_SHL , TM_SHR , TM_UNM , TM_BNOT ,
  TM_LT , TM_LE , TM_CONCAT , TM_CALL ,
  TM_CLOSE , TM_N
}
 

Functions

LUAI_FUNC const char * luaT_objtypename (lua_State *L, const TValue *o)
 
LUAI_FUNC const TValueluaT_gettm (Table *events, TMS event, TString *ename)
 
LUAI_FUNC const TValueluaT_gettmbyobj (lua_State *L, const TValue *o, TMS event)
 
LUAI_FUNC void luaT_init (lua_State *L)
 
LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3)
 
LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, StkId p3)
 
LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
 
LUAI_FUNC void luaT_tryconcatTM (lua_State *L)
 
LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, const TValue *p2, int inv, StkId res, TMS event)
 
LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, int inv, StkId res, TMS event)
 
LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, TMS event)
 
LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, int inv, int isfloat, TMS event)
 
LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, struct CallInfo *ci, const Proto *p)
 
LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, StkId where, int wanted)
 

Macro Definition Documentation

◆ fasttm

#define fasttm ( l,
et,
e )   gfasttm(G(l), et, e)

Definition at line 67 of file lua-5.4.3/src/ltm.h.

◆ gfasttm

#define gfasttm ( g,
et,
e )
Value:
((et) == NULL ? NULL : \
((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
#define NULL
Definition gmacros.h:924
LUAI_FUNC const TValue * luaT_gettm(Table *events, TMS event, TString *ename)
static TString ** tmname

Definition at line 64 of file lua-5.4.3/src/ltm.h.

64#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
65 ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))

◆ maskflags

#define maskflags   (~(~0u << (TM_EQ + 1)))

Definition at line 54 of file lua-5.4.3/src/ltm.h.

Referenced by luaH_new().

◆ notm

#define notm ( tm)    ttisnil(tm)

◆ ttypename

#define ttypename ( x)    luaT_typenames_[(x) + 1]

Definition at line 69 of file lua-5.4.3/src/ltm.h.

Enumeration Type Documentation

◆ TMS

enum TMS
Enumerator
TM_INDEX 
TM_NEWINDEX 
TM_GC 
TM_MODE 
TM_LEN 
TM_EQ 
TM_ADD 
TM_SUB 
TM_MUL 
TM_MOD 
TM_POW 
TM_DIV 
TM_IDIV 
TM_BAND 
TM_BOR 
TM_BXOR 
TM_SHL 
TM_SHR 
TM_UNM 
TM_BNOT 
TM_LT 
TM_LE 
TM_CONCAT 
TM_CALL 
TM_CLOSE 
TM_N 

Definition at line 18 of file lua-5.4.3/src/ltm.h.

18 {
21 TM_GC,
22 TM_MODE,
23 TM_LEN,
24 TM_EQ, /* last tag method with fast access */
25 TM_ADD,
26 TM_SUB,
27 TM_MUL,
28 TM_MOD,
29 TM_POW,
30 TM_DIV,
31 TM_IDIV,
32 TM_BAND,
33 TM_BOR,
34 TM_BXOR,
35 TM_SHL,
36 TM_SHR,
37 TM_UNM,
38 TM_BNOT,
39 TM_LT,
40 TM_LE,
42 TM_CALL,
44 TM_N /* number of elements in the enum */
45} TMS;
@ TM_GC
@ TM_IDIV
@ TM_NEWINDEX
@ TM_BAND
@ TM_MODE
@ TM_MUL
@ TM_BNOT
@ TM_BXOR
@ TM_SHR
@ TM_BOR
@ TM_INDEX
@ TM_UNM
@ TM_EQ
@ TM_POW
@ TM_DIV
@ TM_LEN
@ TM_SUB
@ TM_ADD
@ TM_CALL
@ TM_SHL
@ TM_LE
@ TM_CLOSE
@ TM_CONCAT
@ TM_LT
@ TM_MOD

Function Documentation

◆ luaT_adjustvarargs()

LUAI_FUNC void luaT_adjustvarargs ( lua_State * L,
int nfixparams,
struct CallInfo * ci,
const Proto * p )

Definition at line 238 of file lua-5.4.3/src/ltm.c.

239 {
240 int i;
241 int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */
242 int nextra = actual - nfixparams; /* number of extra arguments */
243 ci->u.l.nextraargs = nextra;
244 luaD_checkstack(L, p->maxstacksize + 1);
245 /* copy function to the top of the stack */
246 setobjs2s(L, L->top++, ci->func);
247 /* move fixed parameters to the top of the stack */
248 for (i = 1; i <= nfixparams; i++) {
249 setobjs2s(L, L->top++, ci->func + i);
250 setnilvalue(s2v(ci->func + i)); /* erase original parameter (for GC) */
251 }
252 ci->func += actual + 1;
253 ci->top += actual + 1;
254 lua_assert(L->top <= ci->top && ci->top <= L->stack_last);
255}
#define luaD_checkstack(L, n)
#define cast_int(i)
#define lua_assert(c)
#define setobjs2s
#define setnilvalue(obj)
#define s2v(o)
struct CallInfo::@64::@65 l
union CallInfo::@64 u
lu_byte maxstacksize

References cast_int, CallInfo::func, CallInfo::l, lua_assert, luaD_checkstack, Proto::maxstacksize, CallInfo::nextraargs, s2v, setnilvalue, setobjs2s, lua_State::stack_last, CallInfo::top, lua_State::top, and CallInfo::u.

Referenced by luaV_execute().

◆ luaT_callorderiTM()

LUAI_FUNC int luaT_callorderiTM ( lua_State * L,
const TValue * p1,
int v2,
int inv,
int isfloat,
TMS event )

Definition at line 221 of file lua-5.4.3/src/ltm.c.

222 {
223 TValue aux; const TValue *p2;
224 if (isfloat) {
225 setfltvalue(&aux, cast_num(v2));
226 }
227 else
228 setivalue(&aux, v2);
229 if (flip) { /* arguments were exchanged? */
230 p2 = p1; p1 = &aux; /* correct them */
231 }
232 else
233 p2 = &aux;
234 return luaT_callorderTM(L, p1, p2, event);
235}
#define cast_num(i)
#define setfltvalue(obj, x)
#define setivalue(obj, x)
int luaT_callorderTM(lua_State *L, const TValue *p1, const TValue *p2, TMS event)

References cast_num, luaT_callorderTM(), setfltvalue, and setivalue.

◆ luaT_callorderTM()

LUAI_FUNC int luaT_callorderTM ( lua_State * L,
const TValue * p1,
const TValue * p2,
TMS event )

Definition at line 158 of file lua-5.3.6/src/ltm.c.

159 {
160 if (!luaT_callbinTM(L, p1, p2, L->top, event))
161 return -1; /* no metamethod */
162 else
163 return !l_isfalse(L->top);
164}
#define l_isfalse(o)
int luaT_callbinTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)

References callbinTM(), CallInfo::callstatus, lua_State::ci, CIST_LEQ, l_isfalse, luaG_ordererror(), luaT_callbinTM(), s2v, TM_LE, TM_LT, and lua_State::top.

Referenced by lessequalothers(), lessthanothers(), luaT_callorderiTM(), luaV_lessequal(), and luaV_lessthan().

◆ luaT_callTM()

LUAI_FUNC void luaT_callTM ( lua_State * L,
const TValue * f,
const TValue * p1,
const TValue * p2,
const TValue * p3 )

Definition at line 103 of file lua-5.4.3/src/ltm.c.

104 {
105 StkId func = L->top;
106 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
107 setobj2s(L, func + 1, p1); /* 1st argument */
108 setobj2s(L, func + 2, p2); /* 2nd argument */
109 setobj2s(L, func + 3, p3); /* 3rd argument */
110 L->top = func + 4;
111 /* metamethod may yield only when called from Lua code */
112 if (isLuacode(L->ci))
113 luaD_call(L, func, 0);
114 else
115 luaD_callnoyield(L, func, 0);
116}
void luaD_call(lua_State *L, StkId func, int nResults)
#define setobj2s
void luaD_callnoyield(lua_State *L, StkId func, int nResults)
#define isLuacode(ci)

References lua_State::ci, isLuacode, luaD_call(), luaD_callnoyield(), setobj2s, and lua_State::top.

◆ luaT_callTMres()

LUAI_FUNC void luaT_callTMres ( lua_State * L,
const TValue * f,
const TValue * p1,
const TValue * p2,
StkId p3 )

Definition at line 119 of file lua-5.4.3/src/ltm.c.

120 {
121 ptrdiff_t result = savestack(L, res);
122 StkId func = L->top;
123 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
124 setobj2s(L, func + 1, p1); /* 1st argument */
125 setobj2s(L, func + 2, p2); /* 2nd argument */
126 L->top += 3;
127 /* metamethod may yield only when called from Lua code */
128 if (isLuacode(L->ci))
129 luaD_call(L, func, 1);
130 else
131 luaD_callnoyield(L, func, 1);
132 res = restorestack(L, result);
133 setobjs2s(L, res, --L->top); /* move result to its place */
134}
#define savestack(L, p)
#define restorestack(L, n)

References lua_State::ci, isLuacode, luaD_call(), luaD_callnoyield(), restorestack, savestack, setobj2s, setobjs2s, and lua_State::top.

Referenced by callbinTM(), luaV_equalobj(), luaV_finishget(), and luaV_objlen().

◆ luaT_gettm()

LUAI_FUNC const TValue * luaT_gettm ( Table * events,
TMS event,
TString * ename )

Definition at line 50 of file lua-5.1.5/src/ltm.c.

50 {
51 const TValue *tm = luaH_getstr(events, ename);
52 lua_assert(event <= TM_EQ);
53 if (ttisnil(tm)) { /* no tag method? */
54 events->flags |= cast_byte(1u<<event); /* cache this fact */
55 return NULL;
56 }
57 else return tm;
58}
#define cast_byte(i)
#define ttisnil(o)
const TValue * luaH_getstr(Table *t, TString *key)
@ TM_EQ

References cast_byte, Table::flags, lua_assert, luaH_getshortstr(), luaH_getstr(), notm, NULL, TM_EQ, and ttisnil.

◆ luaT_gettmbyobj()

LUAI_FUNC const TValue * luaT_gettmbyobj ( lua_State * L,
const TValue * o,
TMS event )

Definition at line 61 of file lua-5.1.5/src/ltm.c.

61 {
62 Table *mt;
63 switch (ttype(o)) {
64 case LUA_TTABLE:
65 mt = hvalue(o)->metatable;
66 break;
67 case LUA_TUSERDATA:
68 mt = uvalue(o)->metatable;
69 break;
70 default:
71 mt = G(L)->mt[ttype(o)];
72 }
73 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
74}
#define uvalue(o)
#define hvalue(o)
#define luaO_nilobject
#define ttype(o)
#define G(L)
#define LUA_TTABLE
#define LUA_TUSERDATA
struct Table * metatable

References G, hvalue, LUA_TTABLE, LUA_TUSERDATA, luaH_getshortstr(), luaH_getstr(), luaO_nilobject, Table::metatable, tmname, ttnov, ttype, ttypenv, and uvalue.

Referenced by call_binTM(), call_binTM(), call_orderTM(), callbinTM(), callclosemethod(), checkclosemth(), GCTM(), GCTM(), GCTM(), luaD_tryfuncTM(), luaT_callbinTM(), luaV_finishget(), luaV_finishOp(), luaV_finishset(), luaV_finishset(), luaV_gettable(), luaV_objlen(), luaV_settable(), tryfuncTM(), tryfuncTM(), and tryfuncTM().

◆ luaT_getvarargs()

LUAI_FUNC void luaT_getvarargs ( lua_State * L,
struct CallInfo * ci,
StkId where,
int wanted )

Definition at line 258 of file lua-5.4.3/src/ltm.c.

258 {
259 int i;
260 int nextra = ci->u.l.nextraargs;
261 if (wanted < 0) {
262 wanted = nextra; /* get all extra arguments available */
263 checkstackGCp(L, nextra, where); /* ensure stack space */
264 L->top = where + nextra; /* next instruction will need top */
265 }
266 for (i = 0; i < wanted && i < nextra; i++)
267 setobjs2s(L, where + i, ci->func - nextra + i);
268 for (; i < wanted; i++) /* complete required results with nil */
269 setnilvalue(s2v(where + i));
270}
#define checkstackGCp(L, n, p)

References checkstackGCp, CallInfo::func, CallInfo::l, CallInfo::nextraargs, s2v, setnilvalue, setobjs2s, lua_State::top, and CallInfo::u.

Referenced by luaV_execute().

◆ luaT_init()

LUAI_FUNC void luaT_init ( lua_State * L)

Definition at line 30 of file lua-5.1.5/src/ltm.c.

30 {
31 static const char *const luaT_eventname[] = { /* ORDER TM */
32 "__index", "__newindex",
33 "__gc", "__mode", "__eq",
34 "__add", "__sub", "__mul", "__div", "__mod",
35 "__pow", "__unm", "__len", "__lt", "__le",
36 "__concat", "__call"
37 };
38 int i;
39 for (i=0; i<TM_N; i++) {
40 G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
41 luaS_fix(G(L)->tmname[i]); /* never collect these names */
42 }
43}
#define luaS_new(L, s)
#define luaS_fix(s)

References G, luaC_fix(), luaS_fix, luaS_new, obj2gco, TM_N, and tmname.

Referenced by f_luaopen(), f_luaopen(), f_luaopen(), and f_luaopen().

◆ luaT_objtypename()

LUAI_FUNC const char * luaT_objtypename ( lua_State * L,
const TValue * o )

Definition at line 90 of file lua-5.3.6/src/ltm.c.

90 {
91 Table *mt;
92 if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||
93 (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {
94 const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name"));
95 if (ttisstring(name)) /* is '__name' a string? */
96 return getstr(tsvalue(name)); /* use it as type name */
97 }
98 return ttypename(ttnov(o)); /* else use standard type name */
99}
const char * name
Definition lsqlite3.c:2154
#define tsvalue(o)
#define ttisstring(o)
#define ttistable(o)
#define getstr(ts)
#define ttypename(x)
#define ttisfulluserdata(o)
#define ttnov(o)
const TValue * luaH_getshortstr(Table *t, TString *key)

References getstr, hvalue, luaH_getshortstr(), luaS_new, name, NULL, tsvalue, ttisfulluserdata, ttisstring, ttistable, ttnov, ttype, ttypename, and uvalue.

Referenced by luaG_callerror(), luaG_forerror(), luaG_ordererror(), and luaG_typeerror().

◆ luaT_trybinassocTM()

LUAI_FUNC void luaT_trybinassocTM ( lua_State * L,
const TValue * p1,
const TValue * p2,
int inv,
StkId res,
TMS event )

Definition at line 175 of file lua-5.4.3/src/ltm.c.

176 {
177 if (flip)
178 luaT_trybinTM(L, p2, p1, res, event);
179 else
180 luaT_trybinTM(L, p1, p2, res, event);
181}
void luaT_trybinTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)

References luaT_trybinTM().

Referenced by luaT_trybiniTM(), and luaV_execute().

◆ luaT_trybiniTM()

LUAI_FUNC void luaT_trybiniTM ( lua_State * L,
const TValue * p1,
lua_Integer i2,
int inv,
StkId res,
TMS event )

Definition at line 184 of file lua-5.4.3/src/ltm.c.

185 {
186 TValue aux;
187 setivalue(&aux, i2);
188 luaT_trybinassocTM(L, p1, &aux, flip, res, event);
189}
void luaT_trybinassocTM(lua_State *L, const TValue *p1, const TValue *p2, int flip, StkId res, TMS event)

References luaT_trybinassocTM(), and setivalue.

Referenced by luaV_execute().

◆ luaT_trybinTM()

LUAI_FUNC void luaT_trybinTM ( lua_State * L,
const TValue * p1,
const TValue * p2,
StkId res,
TMS event )

Definition at line 135 of file lua-5.3.6/src/ltm.c.

136 {
137 if (!luaT_callbinTM(L, p1, p2, res, event)) {
138 switch (event) {
139 case TM_CONCAT:
140 luaG_concaterror(L, p1, p2);
141 /* call never returns, but to avoid warnings: *//* FALLTHROUGH */
142 case TM_BAND: case TM_BOR: case TM_BXOR:
143 case TM_SHL: case TM_SHR: case TM_BNOT: {
145 if (tonumber(p1, &dummy) && tonumber(p2, &dummy))
146 luaG_tointerror(L, p1, p2);
147 else
148 luaG_opinterror(L, p1, p2, "perform bitwise operation on");
149 }
150 /* calls never return, but to avoid warnings: *//* FALLTHROUGH */
151 default:
152 luaG_opinterror(L, p1, p2, "perform arithmetic on");
153 }
154 }
155}
void luaG_concaterror(lua_State *L, StkId p1, StkId p2)
@ TM_CONCAT
LUA_NUMBER lua_Number
#define tonumber(o, n)
l_noret luaG_opinterror(lua_State *L, const TValue *p1, const TValue *p2, const char *msg)
l_noret luaG_tointerror(lua_State *L, const TValue *p1, const TValue *p2)
@ TM_BAND
@ TM_BNOT
@ TM_BXOR
@ TM_SHR
@ TM_BOR
@ TM_SHL

References callbinTM(), dummy, luaG_concaterror(), luaG_opinterror(), luaG_tointerror(), luaT_callbinTM(), TM_BAND, TM_BNOT, TM_BOR, TM_BXOR, TM_CONCAT, TM_SHL, TM_SHR, tonumber, and ttisnumber.

Referenced by luaO_arith(), luaO_arith(), luaT_trybinassocTM(), luaV_concat(), luaV_execute(), and luaV_execute().

◆ luaT_tryconcatTM()

LUAI_FUNC void luaT_tryconcatTM ( lua_State * L)

Definition at line 167 of file lua-5.4.3/src/ltm.c.

167 {
168 StkId top = L->top;
169 if (l_unlikely(!callbinTM(L, s2v(top - 2), s2v(top - 1), top - 2,
170 TM_CONCAT)))
171 luaG_concaterror(L, s2v(top - 2), s2v(top - 1));
172}
static int callbinTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)

References callbinTM(), luaG_concaterror(), s2v, TM_CONCAT, and lua_State::top.

Referenced by luaV_concat().