Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ltm.c File Reference
#include "lprefix.h"
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"

Go to the source code of this file.

Macros

#define ltm_c
 
#define LUA_CORE
 

Functions

void luaT_init (lua_State *L)
 
const TValueluaT_gettm (Table *events, TMS event, TString *ename)
 
const TValueluaT_gettmbyobj (lua_State *L, const TValue *o, TMS event)
 
const char * luaT_objtypename (lua_State *L, const TValue *o)
 
void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)
 
int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
 
void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
 
int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, TMS event)
 

Variables

static const char udatatypename [] = "userdata"
 
LUAI_DDEF const char *const luaT_typenames_ [LUA_TOTALTAGS]
 

Macro Definition Documentation

◆ ltm_c

#define ltm_c

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

◆ LUA_CORE

#define LUA_CORE

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

Function Documentation

◆ luaT_callbinTM()

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

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 l_isfalse, luaT_callbinTM(), and lua_State::top.

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

◆ luaT_callTM()

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

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

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

59 {
60 const TValue *tm = luaH_getshortstr(events, ename);
61 lua_assert(event <= TM_EQ);
62 if (ttisnil(tm)) { /* no tag method? */
63 events->flags |= cast_byte(1u<<event); /* cache this fact */
64 return NULL;
65 }
66 else return tm;
67}
#define NULL
Definition gmacros.h:924
#define cast_byte(i)
#define lua_assert(c)
@ TM_EQ
const TValue * luaH_getshortstr(Table *t, TString *key)

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

◆ luaT_gettmbyobj()

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

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

70 {
71 Table *mt;
72 switch (ttnov(o)) {
73 case LUA_TTABLE:
74 mt = hvalue(o)->metatable;
75 break;
76 case LUA_TUSERDATA:
77 mt = uvalue(o)->metatable;
78 break;
79 default:
80 mt = G(L)->mt[ttnov(o)];
81 }
82 return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);
83}
#define uvalue(o)
#define hvalue(o)
#define luaO_nilobject
#define G(L)
#define LUA_TTABLE
#define LUA_TUSERDATA
#define ttnov(o)
static TString ** tmname
struct Table * metatable

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

Referenced by luaT_callbinTM().

◆ luaT_init()

void luaT_init ( lua_State * L)

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

37 {
38 static const char *const luaT_eventname[] = { /* ORDER TM */
39 "__index", "__newindex",
40 "__gc", "__mode", "__len", "__eq",
41 "__add", "__sub", "__mul", "__mod", "__pow",
42 "__div", "__idiv",
43 "__band", "__bor", "__bxor", "__shl", "__shr",
44 "__unm", "__bnot", "__lt", "__le",
45 "__concat", "__call"
46 };
47 int i;
48 for (i=0; i<TM_N; i++) {
49 G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
50 luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */
51 }
52}
#define obj2gco(v)
#define luaS_new(L, s)
void luaC_fix(lua_State *L, GCObject *o)

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

◆ luaT_objtypename()

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)

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

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

◆ luaT_trybinTM()

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 dummy, luaG_concaterror(), luaG_opinterror(), luaG_tointerror(), luaT_callbinTM(), TM_BAND, TM_BNOT, TM_BOR, TM_BXOR, TM_CONCAT, TM_SHL, TM_SHR, and tonumber.

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

Variable Documentation

◆ luaT_typenames_

LUAI_DDEF const char* const luaT_typenames_[LUA_TOTALTAGS]
Initial value:
= {
"no value",
"nil", "boolean", udatatypename, "number",
"string", "table", "function", udatatypename, "thread",
"proto"
}
static const char udatatypename[]

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

29 {
30 "no value",
31 "nil", "boolean", udatatypename, "number",
32 "string", "table", "function", udatatypename, "thread",
33 "proto" /* this last case is used for tests only */
34};

◆ udatatypename

const char udatatypename[] = "userdata"
static

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