diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.37 2005/04/04 18:12:51 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.38 2005/04/05 15:35:15 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 | */ |
@@ -319,7 +319,8 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { | |||
319 | const TValue *o = index2adr(L, idx); | 319 | const TValue *o = index2adr(L, idx); |
320 | if (tonumber(o, &n)) { | 320 | if (tonumber(o, &n)) { |
321 | lua_Integer res; | 321 | lua_Integer res; |
322 | lua_number2integer(res, nvalue(o)); | 322 | lua_Number num = nvalue(o); |
323 | lua_number2integer(res, num); | ||
323 | return res; | 324 | return res; |
324 | } | 325 | } |
325 | else | 326 | else |
@@ -587,6 +588,9 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
587 | case LUA_TUSERDATA: | 588 | case LUA_TUSERDATA: |
588 | mt = uvalue(obj)->metatable; | 589 | mt = uvalue(obj)->metatable; |
589 | break; | 590 | break; |
591 | default: | ||
592 | mt = G(L)->mt[ttype(obj)]; | ||
593 | break; | ||
590 | } | 594 | } |
591 | if (mt == NULL) | 595 | if (mt == NULL) |
592 | res = 0; | 596 | res = 0; |
@@ -681,7 +685,6 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { | |||
681 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { | 685 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
682 | TValue *obj; | 686 | TValue *obj; |
683 | Table *mt; | 687 | Table *mt; |
684 | int res = 1; | ||
685 | lua_lock(L); | 688 | lua_lock(L); |
686 | api_checknelems(L, 1); | 689 | api_checknelems(L, 1); |
687 | obj = index2adr(L, objindex); | 690 | obj = index2adr(L, objindex); |
@@ -706,13 +709,13 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
706 | break; | 709 | break; |
707 | } | 710 | } |
708 | default: { | 711 | default: { |
709 | res = 0; /* cannot set */ | 712 | G(L)->mt[ttype(obj)] = mt; |
710 | break; | 713 | break; |
711 | } | 714 | } |
712 | } | 715 | } |
713 | L->top--; | 716 | L->top--; |
714 | lua_unlock(L); | 717 | lua_unlock(L); |
715 | return res; | 718 | return 1; |
716 | } | 719 | } |
717 | 720 | ||
718 | 721 | ||