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