** Check that 'arg' either is a table or can behave like one (that is, ** has a metatable with the required metamethods) */
| 44 | ** has a metatable with the required metamethods) |
| 45 | */ |
| 46 | static 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) |
no test coverage detected