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 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_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, TValue *p3, int hasres)
 
LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
 
LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
 
LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, TMS event)
 

Variables

LUAI_DDEC const char *const luaT_typenames_ [LUA_TOTALTAGS]
 

Macro Definition Documentation

◆ fasttm

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

Definition at line 51 of file lua-5.3.6/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 48 of file lua-5.3.6/src/ltm.h.

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

◆ ttypename

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

Definition at line 53 of file lua-5.3.6/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_N 

Definition at line 18 of file lua-5.3.6/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,
43 TM_N /* number of elements in the enum */
44} 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_CONCAT
@ TM_LT
@ TM_MOD

Function Documentation

◆ luaT_callbinTM()

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

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

125 {
126 const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
127 if (ttisnil(tm))
128 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
129 if (ttisnil(tm)) return 0;
130 luaT_callTM(L, tm, p1, p2, res, 1);
131 return 1;
132}
#define ttisnil(o)
void luaT_callTM(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)
const TValue * luaT_gettmbyobj(lua_State *L, const TValue *o, TMS event)

References luaT_callTM(), luaT_gettmbyobj(), and ttisnil.

Referenced by luaT_callorderTM(), and luaT_trybinTM().

◆ 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)

◆ luaT_callTM()

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

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

103 {
104 ptrdiff_t result = savestack(L, p3);
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 L->top += 3;
110 if (!hasres) /* no result? 'p3' is third argument */
111 setobj2s(L, L->top++, p3); /* 3rd argument */
112 /* metamethod may yield only when called from Lua code */
113 if (isLua(L->ci))
114 luaD_call(L, func, hasres);
115 else
116 luaD_callnoyield(L, func, hasres);
117 if (hasres) { /* if has result, move it to its place */
118 p3 = restorestack(L, result);
119 setobjs2s(L, p3, --L->top);
120 }
121}
void luaD_call(lua_State *L, StkId func, int nResults)
#define savestack(L, p)
#define restorestack(L, n)
#define setobj2s
#define setobjs2s
#define isLua(ci)
void luaD_callnoyield(lua_State *L, StkId func, int nResults)

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

Referenced by luaT_callbinTM(), luaV_equalobj(), luaV_finishget(), luaV_finishset(), luaV_finishset(), 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 lua_assert(c)
const TValue * luaH_getstr(Table *t, TString *key)
@ TM_EQ

◆ 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

◆ 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)

◆ 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)

◆ 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)

Variable Documentation

◆ luaT_typenames_

LUAI_DDEC const char* const luaT_typenames_[LUA_TOTALTAGS]

Definition at line 55 of file lua-5.3.6/src/ltm.h.