** Check that 'arg' has a table and set access functions in 'ta' to raw ** or non-raw according to the presence of corresponding metamethods. */
| 34 | ** or non-raw according to the presence of corresponding metamethods. |
| 35 | */ |
| 36 | static void checktab (lua_State *L, int arg, TabA *ta) { |
| 37 | ta->geti = NULL; ta->seti = NULL; |
| 38 | if (lua_getmetatable(L, arg)) { |
| 39 | lua_pushliteral(L, "__index"); /* 'index' metamethod */ |
| 40 | if (lua_rawget(L, -2) != LUA_TNIL) |
| 41 | ta->geti = lua_geti; |
| 42 | lua_pushliteral(L, "__newindex"); /* 'newindex' metamethod */ |
| 43 | if (lua_rawget(L, -3) != LUA_TNIL) |
| 44 | ta->seti = lua_seti; |
| 45 | lua_pop(L, 3); /* pop metatable plus both metamethods */ |
| 46 | } |
| 47 | if (ta->geti == NULL || ta->seti == NULL) { |
| 48 | luaL_checktype(L, arg, LUA_TTABLE); /* must be table for raw methods */ |
| 49 | if (ta->geti == NULL) ta->geti = lua_rawgeti; |
| 50 | if (ta->seti == NULL) ta->seti = lua_rawseti; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | #define aux_getn(L,n,ta) (checktab(L, n, ta), luaL_len(L, n)) |
no test coverage detected