| 931 | |
| 932 | |
| 933 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 934 | TValue *obj; |
| 935 | Table *mt; |
| 936 | lua_lock(L); |
| 937 | api_checknelems(L, 1); |
| 938 | obj = index2value(L, objindex); |
| 939 | if (ttisnil(s2v(L->top.p - 1))) |
| 940 | mt = NULL; |
| 941 | else { |
| 942 | api_check(L, ttistable(s2v(L->top.p - 1)), "table expected"); |
| 943 | mt = hvalue(s2v(L->top.p - 1)); |
| 944 | } |
| 945 | switch (ttype(obj)) { |
| 946 | case LUA_TTABLE: { |
| 947 | hvalue(obj)->metatable = mt; |
| 948 | if (mt) { |
| 949 | luaC_objbarrier(L, gcvalue(obj), mt); |
| 950 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 951 | } |
| 952 | break; |
| 953 | } |
| 954 | case LUA_TUSERDATA: { |
| 955 | uvalue(obj)->metatable = mt; |
| 956 | if (mt) { |
| 957 | luaC_objbarrier(L, uvalue(obj), mt); |
| 958 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 959 | } |
| 960 | break; |
| 961 | } |
| 962 | default: { |
| 963 | G(L)->mt[ttype(obj)] = mt; |
| 964 | break; |
| 965 | } |
| 966 | } |
| 967 | L->top.p--; |
| 968 | lua_unlock(L); |
| 969 | return 1; |
| 970 | } |
| 971 | |
| 972 | |
| 973 | LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { |
no test coverage detected