diff options
| -rw-r--r-- | lstrlib.c | 4 | ||||
| -rw-r--r-- | lvm.c | 25 |
2 files changed, 17 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.119 2005/07/12 14:32:08 roberto Exp $ | 2 | ** $Id: lstrlib.c,v 1.120 2005/07/31 16:47:34 roberto Exp roberto $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -810,8 +810,6 @@ static void createmetatable (lua_State *L) { | |||
| 810 | lua_pop(L, 1); /* pop dummy string */ | 810 | lua_pop(L, 1); /* pop dummy string */ |
| 811 | lua_pushvalue(L, -2); /* string library... */ | 811 | lua_pushvalue(L, -2); /* string library... */ |
| 812 | lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ | 812 | lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ |
| 813 | lua_getfield(L, -2, "len"); | ||
| 814 | lua_setfield(L, -2, "__len"); | ||
| 815 | lua_pop(L, 1); /* pop metatable */ | 813 | lua_pop(L, 1); /* pop metatable */ |
| 816 | } | 814 | } |
| 817 | 815 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.47 2005/06/13 14:15:22 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.48 2005/07/05 14:31:20 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -548,14 +548,21 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 548 | } | 548 | } |
| 549 | case OP_LEN: { | 549 | case OP_LEN: { |
| 550 | const TValue *rb = RB(i); | 550 | const TValue *rb = RB(i); |
| 551 | if (ttype(rb) == LUA_TTABLE) { | 551 | switch (ttype(rb)) { |
| 552 | setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); | 552 | case LUA_TTABLE: { |
| 553 | } | 553 | setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); |
| 554 | else { /* try metamethod */ | 554 | break; |
| 555 | Protect( | 555 | } |
| 556 | if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN)) | 556 | case LUA_TSTRING: { |
| 557 | luaG_typeerror(L, rb, "get length of"); | 557 | setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); |
| 558 | ) | 558 | break; |
| 559 | } | ||
| 560 | default: { /* try metamethod */ | ||
| 561 | Protect( | ||
| 562 | if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN)) | ||
| 563 | luaG_typeerror(L, rb, "get length of"); | ||
| 564 | ) | ||
| 565 | } | ||
| 559 | } | 566 | } |
| 560 | continue; | 567 | continue; |
| 561 | } | 568 | } |
