Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LUA_API int lua_setmetatable (lua_State *L, int objindex) {
- TValue *obj;
- Table *mt;
- lua_lock(L);
- api_checknelems(L, 1);
- obj = index2addr(L, objindex);
- api_checkvalidindex(L, obj);
- if (ttisnil(L->top - 1))
- mt = NULL;
- else {
- api_check(L, ttistable(L->top - 1), "table expected");
- mt = hvalue(L->top - 1);
- }
- switch (ttypenv(obj)) {
- case LUA_TTABLE: {
- hvalue(obj)->metatable = mt;
- if (mt)
- luaC_objbarrierback(L, gcvalue(obj), mt);
- luaC_checkfinalizer(L, gcvalue(obj), mt);
- break;
- }
- case LUA_TUSERDATA: {
- uvalue(obj)->metatable = mt;
- if (mt) {
- luaC_objbarrier(L, rawuvalue(obj), mt);
- luaC_checkfinalizer(L, gcvalue(obj), mt);
- }
- break;
- }
- default: {
- G(L)->mt[ttypenv(obj)] = mt;
- break;
- }
- }
- L->top--;
- lua_unlock(L);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement