| 891 | |
| 892 | |
| 893 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 894 | TValue *obj; |
| 895 | Table *mt; |
| 896 | lua_lock(L); |
| 897 | api_checknelems(L, 1); |
| 898 | obj = index2value(L, objindex); |
| 899 | if (ttisnil(s2v(L->top - 1))) |
| 900 | mt = NULL; |
| 901 | else { |
| 902 | api_check(L, ttistable(s2v(L->top - 1)), "table expected"); |
| 903 | mt = hvalue(s2v(L->top - 1)); |
| 904 | } |
| 905 | switch (ttype(obj)) { |
| 906 | case LUA_TTABLE: { |
| 907 | hvalue(obj)->metatable = mt; |
| 908 | if (mt) { |
| 909 | luaC_objbarrier(L, gcvalue(obj), mt); |
| 910 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 911 | } |
| 912 | break; |
| 913 | } |
| 914 | case LUA_TUSERDATA: { |
| 915 | uvalue(obj)->metatable = mt; |
| 916 | if (mt) { |
| 917 | luaC_objbarrier(L, uvalue(obj), mt); |
| 918 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 919 | } |
| 920 | break; |
| 921 | } |
| 922 | default: { |
| 923 | G(L)->mt[ttype(obj)] = mt; |
| 924 | break; |
| 925 | } |
| 926 | } |
| 927 | L->top--; |
| 928 | lua_unlock(L); |
| 929 | return 1; |
| 930 | } |
| 931 | |
| 932 | |
| 933 | LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) { |
no test coverage detected