diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-12-01 16:22:56 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-12-01 16:22:56 -0200 |
| commit | af850484a9e01b46b04e4c666f9a9e91308d81c7 (patch) | |
| tree | 38d03f647ddc95d430e4600e432598b7b9d07cd0 /lapi.c | |
| parent | 1d10acb35500df47d6052164e6c56476f520232e (diff) | |
| download | lua-af850484a9e01b46b04e4c666f9a9e91308d81c7.tar.gz lua-af850484a9e01b46b04e4c666f9a9e91308d81c7.tar.bz2 lua-af850484a9e01b46b04e4c666f9a9e91308d81c7.zip | |
default metatable can be NULL
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 19 |
1 files changed, 12 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.248 2003/10/20 12:25:23 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.249 2003/10/20 17:42:41 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -555,7 +555,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
| 555 | mt = uvalue(obj)->uv.metatable; | 555 | mt = uvalue(obj)->uv.metatable; |
| 556 | break; | 556 | break; |
| 557 | } | 557 | } |
| 558 | if (mt == NULL || mt == hvalue(defaultmeta(L))) | 558 | if (mt == NULL) |
| 559 | res = 0; | 559 | res = 0; |
| 560 | else { | 560 | else { |
| 561 | sethvalue(L->top, mt); | 561 | sethvalue(L->top, mt); |
| @@ -634,21 +634,26 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { | |||
| 634 | 634 | ||
| 635 | 635 | ||
| 636 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { | 636 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 637 | TObject *obj, *mt; | 637 | TObject *obj; |
| 638 | Table *mt; | ||
| 638 | int res = 1; | 639 | int res = 1; |
| 639 | lua_lock(L); | 640 | lua_lock(L); |
| 640 | api_checknelems(L, 1); | 641 | api_checknelems(L, 1); |
| 641 | obj = luaA_index(L, objindex); | 642 | obj = luaA_index(L, objindex); |
| 642 | api_checkvalidindex(L, obj); | 643 | api_checkvalidindex(L, obj); |
| 643 | mt = (!ttisnil(L->top - 1)) ? L->top - 1 : defaultmeta(L); | 644 | if (ttisnil(L->top - 1)) |
| 644 | api_check(L, ttistable(mt)); | 645 | mt = NULL; |
| 646 | else { | ||
| 647 | api_check(L, ttistable(L->top - 1)); | ||
| 648 | mt = hvalue(L->top - 1); | ||
| 649 | } | ||
| 645 | switch (ttype(obj)) { | 650 | switch (ttype(obj)) { |
| 646 | case LUA_TTABLE: { | 651 | case LUA_TTABLE: { |
| 647 | hvalue(obj)->metatable = hvalue(mt); /* write barrier */ | 652 | hvalue(obj)->metatable = mt; /* write barrier */ |
| 648 | break; | 653 | break; |
| 649 | } | 654 | } |
| 650 | case LUA_TUSERDATA: { | 655 | case LUA_TUSERDATA: { |
| 651 | uvalue(obj)->uv.metatable = hvalue(mt); /* write barrier */ | 656 | uvalue(obj)->uv.metatable = mt; /* write barrier */ |
| 652 | break; | 657 | break; |
| 653 | } | 658 | } |
| 654 | default: { | 659 | default: { |
