| 962 | |
| 963 | |
| 964 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 965 | TValue *obj; |
| 966 | Table *mt; |
| 967 | lua_lock(L); |
| 968 | api_checkpop(L, 1); |
| 969 | obj = index2value(L, objindex); |
| 970 | if (ttisnil(s2v(L->top.p - 1))) |
| 971 | mt = NULL; |
| 972 | else { |
| 973 | api_check(L, ttistable(s2v(L->top.p - 1)), "table expected"); |
| 974 | mt = hvalue(s2v(L->top.p - 1)); |
| 975 | } |
| 976 | switch (ttype(obj)) { |
| 977 | case LUA_TTABLE: { |
| 978 | hvalue(obj)->metatable = mt; |
| 979 | if (mt) { |
| 980 | luaC_objbarrier(L, gcvalue(obj), mt); |
| 981 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 982 | } |
| 983 | break; |
| 984 | } |
| 985 | case LUA_TUSERDATA: { |
| 986 | uvalue(obj)->metatable = mt; |
| 987 | if (mt) { |
| 988 | luaC_objbarrier(L, uvalue(obj), mt); |
| 989 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 990 | } |
| 991 | break; |
| 992 | } |
| 993 | default: { |
| 994 | G(L)->mt[ttype(obj)] = mt; |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | L->top.p--; |
| 999 | lua_unlock(L); |
| 1000 | return 1; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { |
no test coverage detected