diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-04-07 11:36:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-04-07 11:36:08 -0300 |
| commit | d1df829f8dc62966f46525aca24227a3e05db1df (patch) | |
| tree | 63ccbd2f515f7fd668e85cf42e40825d2d496a12 | |
| parent | 2ad947fe031aa739d98474eb933eede3659305ac (diff) | |
| download | lua-d1df829f8dc62966f46525aca24227a3e05db1df.tar.gz lua-d1df829f8dc62966f46525aca24227a3e05db1df.tar.bz2 lua-d1df829f8dc62966f46525aca24227a3e05db1df.zip | |
lua_getmetatable must accept any acceptable index
| -rw-r--r-- | lapi.c | 27 |
1 files changed, 14 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.233 2003/03/14 18:59:21 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.234 2003/04/03 13:35:34 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 | */ |
| @@ -370,6 +370,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { | |||
| 370 | switch (ttype(o)) { | 370 | switch (ttype(o)) { |
| 371 | case LUA_TTABLE: return hvalue(o); | 371 | case LUA_TTABLE: return hvalue(o); |
| 372 | case LUA_TFUNCTION: return clvalue(o); | 372 | case LUA_TFUNCTION: return clvalue(o); |
| 373 | case LUA_TTHREAD: return thvalue(o); | ||
| 373 | case LUA_TUSERDATA: | 374 | case LUA_TUSERDATA: |
| 374 | case LUA_TLIGHTUSERDATA: | 375 | case LUA_TLIGHTUSERDATA: |
| 375 | return lua_touserdata(L, idx); | 376 | return lua_touserdata(L, idx); |
| @@ -520,22 +521,22 @@ LUA_API void lua_newtable (lua_State *L) { | |||
| 520 | 521 | ||
| 521 | 522 | ||
| 522 | LUA_API int lua_getmetatable (lua_State *L, int objindex) { | 523 | LUA_API int lua_getmetatable (lua_State *L, int objindex) { |
| 523 | StkId obj; | 524 | const TObject *obj; |
| 524 | Table *mt; | 525 | Table *mt = NULL; |
| 525 | int res; | 526 | int res; |
| 526 | lua_lock(L); | 527 | lua_lock(L); |
| 527 | obj = luaA_indexAcceptable(L, objindex); | 528 | obj = luaA_indexAcceptable(L, objindex); |
| 528 | switch (ttype(obj)) { | 529 | if (obj != NULL) { |
| 529 | case LUA_TTABLE: | 530 | switch (ttype(obj)) { |
| 530 | mt = hvalue(obj)->metatable; | 531 | case LUA_TTABLE: |
| 531 | break; | 532 | mt = hvalue(obj)->metatable; |
| 532 | case LUA_TUSERDATA: | 533 | break; |
| 533 | mt = uvalue(obj)->uv.metatable; | 534 | case LUA_TUSERDATA: |
| 534 | break; | 535 | mt = uvalue(obj)->uv.metatable; |
| 535 | default: | 536 | break; |
| 536 | mt = hvalue(defaultmeta(L)); | 537 | } |
| 537 | } | 538 | } |
| 538 | if (mt == hvalue(defaultmeta(L))) | 539 | if (mt == NULL || mt == hvalue(defaultmeta(L))) |
| 539 | res = 0; | 540 | res = 0; |
| 540 | else { | 541 | else { |
| 541 | sethvalue(L->top, mt); | 542 | sethvalue(L->top, mt); |
