aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-07 15:24:05 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-07 15:24:05 -0200
commit67bda7e1363eefaa07e5f60d2745feb1aad6f4b5 (patch)
tree071bb0e7bffd47afa787f377b4d4f1dd118f2625 /lvm.c
parent7c8f1823e7590cf97d1002d48a7bd233136bedcb (diff)
downloadlua-67bda7e1363eefaa07e5f60d2745feb1aad6f4b5.tar.gz
lua-67bda7e1363eefaa07e5f60d2745feb1aad6f4b5.tar.bz2
lua-67bda7e1363eefaa07e5f60d2745feb1aad6f4b5.zip
details.
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/lvm.c b/lvm.c
index 94165d97..cc99b35d 100644
--- a/lvm.c
+++ b/lvm.c
@@ -53,12 +53,12 @@ const TObject *luaV_tonumber (const TObject *obj, TObject *n) {
53 53
54int luaV_tostring (lua_State *L, TObject *obj) { 54int luaV_tostring (lua_State *L, TObject *obj) {
55 if (ttype(obj) != LUA_TNUMBER) 55 if (ttype(obj) != LUA_TNUMBER)
56 return 1; 56 return 0;
57 else { 57 else {
58 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ 58 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
59 lua_number2str(s, nvalue(obj)); /* convert `s' to number */ 59 lua_number2str(s, nvalue(obj)); /* convert `s' to number */
60 setsvalue(obj, luaS_new(L, s)); 60 setsvalue(obj, luaS_new(L, s));
61 return 0; 61 return 1;
62 } 62 }
63} 63}
64 64
@@ -141,7 +141,7 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) {
141 return; 141 return;
142 } 142 }
143 } 143 }
144 /* else will call the tag method */ 144 /* else will try the tag method */
145 } else { /* not a table; try a `gettable' tag method */ 145 } else { /* not a table; try a `gettable' tag method */
146 if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL) { 146 if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL) {
147 luaG_typeerror(L, t, "index"); 147 luaG_typeerror(L, t, "index");
@@ -171,7 +171,7 @@ void luaV_settable (lua_State *L, StkId t, TObject *key, StkId val) {
171 luaH_set(L, hvalue(t), key, val); /* do a primitive set */ 171 luaH_set(L, hvalue(t), key, val); /* do a primitive set */
172 return; 172 return;
173 } 173 }
174 /* else will call the tag method */ 174 /* else will try the tag method */
175 } else { /* not a table; try a `settable' tag method */ 175 } else { /* not a table; try a `settable' tag method */
176 if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) { 176 if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) {
177 luaG_typeerror(L, t, "index"); 177 luaG_typeerror(L, t, "index");
@@ -245,7 +245,7 @@ void luaV_strconc (lua_State *L, int total, int last) {
245 do { 245 do {
246 StkId top = L->ci->base + last + 1; 246 StkId top = L->ci->base + last + 1;
247 int n = 2; /* number of elements handled in this pass (at least 2) */ 247 int n = 2; /* number of elements handled in this pass (at least 2) */
248 if (tostring(L, top-2) || tostring(L, top-1)) { 248 if (!tostring(L, top-2) || !tostring(L, top-1)) {
249 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) 249 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
250 luaG_concaterror(L, top-2, top-1); 250 luaG_concaterror(L, top-2, top-1);
251 } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */ 251 } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
@@ -254,7 +254,7 @@ void luaV_strconc (lua_State *L, int total, int last) {
254 cast(lu_mem, tsvalue(top-2)->tsv.len); 254 cast(lu_mem, tsvalue(top-2)->tsv.len);
255 char *buffer; 255 char *buffer;
256 int i; 256 int i;
257 while (n < total && !tostring(L, top-n-1)) { /* collect total length */ 257 while (n < total && tostring(L, top-n-1)) { /* collect total length */
258 tl += tsvalue(top-n-1)->tsv.len; 258 tl += tsvalue(top-n-1)->tsv.len;
259 n++; 259 n++;
260 } 260 }
@@ -278,8 +278,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
278 const TObject *b = rb; 278 const TObject *b = rb;
279 const TObject *c = rc; 279 const TObject *c = rc;
280 TObject tempb, tempc; 280 TObject tempb, tempc;
281 if ((b = luaV_tonumber(b, &tempb)) != NULL && 281 if (tonumber(b, &tempb) && tonumber(c, &tempc)) {
282 (c = luaV_tonumber(c, &tempc)) != NULL) {
283 TObject f, o; 282 TObject f, o;
284 setsvalue(&o, luaS_newliteral(L, "pow")); 283 setsvalue(&o, luaS_newliteral(L, "pow"));
285 luaV_gettable(L, gt(L), &o, &f); 284 luaV_gettable(L, gt(L), &o, &f);
@@ -310,8 +309,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
310#define Arith(op, optm) { \ 309#define Arith(op, optm) { \
311 const TObject *b = RB(i); const TObject *c = RKC(i); \ 310 const TObject *b = RB(i); const TObject *c = RKC(i); \
312 TObject tempb, tempc; \ 311 TObject tempb, tempc; \
313 if ((b = luaV_tonumber(b, &tempb)) != NULL && \ 312 if (tonumber(b, &tempb) && tonumber(c, &tempc)) { \
314 (c = luaV_tonumber(c, &tempc)) != NULL) { \
315 setnvalue(ra, nvalue(b) op nvalue(c)); \ 313 setnvalue(ra, nvalue(b) op nvalue(c)); \
316 } else \ 314 } else \
317 call_arith(L, RB(i), RKC(i), ra, optm); \ 315 call_arith(L, RB(i), RKC(i), ra, optm); \
@@ -432,7 +430,7 @@ StkId luaV_execute (lua_State *L) {
432 } 430 }
433 case OP_UNM: { 431 case OP_UNM: {
434 const TObject *rb = RB(i); 432 const TObject *rb = RB(i);
435 if ((rb=luaV_tonumber(rb, ra)) != NULL) { 433 if (tonumber(rb, ra)) {
436 setnvalue(ra, -nvalue(rb)); 434 setnvalue(ra, -nvalue(rb));
437 } 435 }
438 else { 436 else {