MCPcopy Create free account
hub / github.com/DFHack/dfhack / checktab

Function checktab

depends/lua/src/ltablib.c:46–58  ·  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

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

Callers 1

tmoveFunction · 0.85

Calls 4

lua_typeFunction · 0.85
lua_getmetatableFunction · 0.85
checkfieldFunction · 0.85
luaL_checktypeFunction · 0.85

Tested by

no test coverage detected