MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / checktab

Function checktab

src/Chain/libraries/glua/ltablib.cpp:45–57  ·  view source on GitHub ↗

** Check that 'arg' either is a table or can behave like one (that is, ** has a metatable with the required metamethods) */

Source from the content-addressed store, hash-verified

43** has a metatable with the required metamethods)
44*/
45static void checktab(lua_State *L, int arg, int what) {
46 if (lua_type(L, arg) != LUA_TTABLE) { /* is it not a table? */
47 int n = 1; /* number of elements to pop */
48 if (lua_getmetatable(L, arg) && /* must have metatable */
49 (!(what & TAB_R) || checkfield(L, "__index", ++n)) &&
50 (!(what & TAB_W) || checkfield(L, "__newindex", ++n)) &&
51 (!(what & TAB_L) || checkfield(L, "__len", ++n))) {
52 lua_pop(L, n); /* pop metatable and tested metamethods */
53 }
54 else
55 luaL_argerror(L, arg, "table expected"); /* force an error */
56 }
57}
58
59
60#if defined(LUA_COMPAT_MAXN)

Callers 1

tmoveFunction · 0.85

Calls 4

lua_typeFunction · 0.85
lua_getmetatableFunction · 0.85
checkfieldFunction · 0.85
luaL_argerrorFunction · 0.85

Tested by

no test coverage detected