aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-08-09 14:42:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-08-09 14:42:02 -0300
commit894cd31c5227fd4061f6eb2bd6140c540946d394 (patch)
treec5c0e9eac0fd9ccb65ae19944d64d4bd7edfbab2
parentf01a95d4a00d8cef8283f963c8dfaed0fb7d816d (diff)
downloadlua-894cd31c5227fd4061f6eb2bd6140c540946d394.tar.gz
lua-894cd31c5227fd4061f6eb2bd6140c540946d394.tar.bz2
lua-894cd31c5227fd4061f6eb2bd6140c540946d394.zip
#string is primitive
-rw-r--r--lstrlib.c4
-rw-r--r--lvm.c25
2 files changed, 17 insertions, 12 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 4a99d4d2..a80a00ba 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -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
diff --git a/lvm.c b/lvm.c
index adc9019a..037d696e 100644
--- a/lvm.c
+++ b/lvm.c
@@ -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 }