| 815 | |
| 816 | |
| 817 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 818 | TValue *obj; |
| 819 | Table *mt; |
| 820 | lua_lock(L); |
| 821 | api_checknelems(L, 1); |
| 822 | obj = index2addr(L, objindex); |
| 823 | if (ttisnil(L->top - 1)) |
| 824 | mt = NULL; |
| 825 | else { |
| 826 | api_check(ttistable(L->top - 1), "table expected"); |
| 827 | mt = hvalue(L->top - 1); |
| 828 | } |
| 829 | switch (ttnov(obj)) { |
| 830 | case LUA_TTABLE: { |
| 831 | hvalue(obj)->metatable = mt; |
| 832 | if (mt) { |
| 833 | luaC_objbarrier(L, gcvalue(obj), mt); |
| 834 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 835 | } |
| 836 | break; |
| 837 | } |
| 838 | case LUA_TUSERDATA: { |
| 839 | uvalue(obj)->metatable = mt; |
| 840 | if (mt) { |
| 841 | luaC_objbarrier(L, uvalue(obj), mt); |
| 842 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 843 | } |
| 844 | break; |
| 845 | } |
| 846 | default: { |
| 847 | G(L)->mt[ttnov(obj)] = mt; |
| 848 | break; |
| 849 | } |
| 850 | } |
| 851 | L->top--; |
| 852 | lua_unlock(L); |
| 853 | return 1; |
| 854 | } |
| 855 | |
| 856 | |
| 857 | LUA_API void lua_setuservalue (lua_State *L, int idx) { |
no test coverage detected