diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-29 14:12:50 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-29 14:12:50 -0300 |
commit | 88bf2f83c035e612db103d7138a8312c455e4c88 (patch) | |
tree | e11d49feacbe6c78d5f07d621878852590813915 | |
parent | 8fff05f6d00802fa47614d681f1c7a17694856e8 (diff) | |
download | lua-88bf2f83c035e612db103d7138a8312c455e4c88.tar.gz lua-88bf2f83c035e612db103d7138a8312c455e4c88.tar.bz2 lua-88bf2f83c035e612db103d7138a8312c455e4c88.zip |
new function 'tointeger' + 'luaV_arith' replaced by 'luaT_trybinTM'
-rw-r--r-- | lapi.c | 66 | ||||
-rw-r--r-- | ltable.c | 17 | ||||
-rw-r--r-- | lvm.c | 78 | ||||
-rw-r--r-- | lvm.h | 9 |
4 files changed, 70 insertions, 100 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.176 2013/04/26 16:03:50 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.177 2013/04/26 19:51:17 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 | */ |
@@ -311,10 +311,9 @@ LUA_API void lua_arith (lua_State *L, int op) { | |||
311 | o1 = L->top - 2; | 311 | o1 = L->top - 2; |
312 | o2 = L->top - 1; | 312 | o2 = L->top - 1; |
313 | if (tonumber(o1, &n1) && tonumber(o2, &n2)) { | 313 | if (tonumber(o1, &n1) && tonumber(o2, &n2)) { |
314 | setnvalue(o1, luaO_arith(op, n1, n2)); | 314 | setnvalue(o1, luaO_numarith(op, n1, n2)); |
315 | } | 315 | } |
316 | else | 316 | else luaT_trybinTM(L, o1, o2, o1, cast(TMS, op - LUA_OPADD + TM_ADD)); |
317 | luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD)); | ||
318 | L->top--; | 317 | L->top--; |
319 | lua_unlock(L); | 318 | lua_unlock(L); |
320 | } | 319 | } |
@@ -339,53 +338,30 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
339 | } | 338 | } |
340 | 339 | ||
341 | 340 | ||
342 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) { | 341 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { |
343 | lua_Number n; | 342 | lua_Number n; |
344 | const TValue *o = index2addr(L, idx); | 343 | const TValue *o = index2addr(L, idx); |
345 | if (tonumber(o, &n)) { | 344 | int isnum = tonumber(o, &n); |
346 | if (isnum) *isnum = 1; | 345 | if (!isnum) |
347 | return n; | 346 | n = 0; /* call to 'tonumber' may change 'n' even if it fails */ |
348 | } | 347 | if (pisnum) *pisnum = isnum; |
349 | else { | 348 | return n; |
350 | if (isnum) *isnum = 0; | ||
351 | return 0; | ||
352 | } | ||
353 | } | 349 | } |
354 | 350 | ||
355 | 351 | ||
356 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) { | 352 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { |
357 | lua_Number n; | 353 | lua_Integer res; |
358 | const TValue *o = index2addr(L, idx); | 354 | const TValue *o = index2addr(L, idx); |
359 | if (ttisinteger(o)) { | 355 | int isnum = tointeger(o, &res); |
360 | if (isnum) *isnum = 1; | 356 | if (!isnum) |
361 | return ivalue(o); | 357 | res = 0; /* call to 'tointeger' may change 'n' even if it fails */ |
362 | } | 358 | if (pisnum) *pisnum = isnum; |
363 | else if (tonumber(o, &n)) { | 359 | return res; |
364 | lua_Integer res; | ||
365 | lua_number2integer(res, n); | ||
366 | if (isnum) *isnum = 1; | ||
367 | return res; | ||
368 | } | ||
369 | else { | ||
370 | if (isnum) *isnum = 0; | ||
371 | return 0; | ||
372 | } | ||
373 | } | 360 | } |
374 | 361 | ||
375 | 362 | ||
376 | LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) { | 363 | LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { |
377 | lua_Number n; | 364 | return lua_tointegerx(L, idx, pisnum); /* at least for now... <<<< */ |
378 | const TValue *o = index2addr(L, idx); | ||
379 | if (tonumber(o, &n)) { | ||
380 | lua_Unsigned res; | ||
381 | lua_number2unsigned(res, n); | ||
382 | if (isnum) *isnum = 1; | ||
383 | return res; | ||
384 | } | ||
385 | else { | ||
386 | if (isnum) *isnum = 0; | ||
387 | return 0; | ||
388 | } | ||
389 | } | 365 | } |
390 | 366 | ||
391 | 367 | ||
@@ -491,17 +467,15 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
491 | 467 | ||
492 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | 468 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { |
493 | lua_lock(L); | 469 | lua_lock(L); |
494 | setivalue(L->top, cast_num(n)); | 470 | setivalue(L->top, n); |
495 | api_incr_top(L); | 471 | api_incr_top(L); |
496 | lua_unlock(L); | 472 | lua_unlock(L); |
497 | } | 473 | } |
498 | 474 | ||
499 | 475 | ||
500 | LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { | 476 | LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { |
501 | lua_Number n; | ||
502 | lua_lock(L); | 477 | lua_lock(L); |
503 | n = lua_unsigned2number(u); | 478 | setivalue(L->top, cast_integer(u)); |
504 | setnvalue(L->top, n); | ||
505 | api_incr_top(L); | 479 | api_incr_top(L); |
506 | lua_unlock(L); | 480 | lua_unlock(L); |
507 | } | 481 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.73 2013/04/15 15:44:46 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.74 2013/04/26 15:39:25 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -123,17 +123,6 @@ static Node *mainposition (const Table *t, const TValue *key) { | |||
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | static int numisint (lua_Number n, lua_Integer *p) { | ||
127 | lua_Integer k; | ||
128 | lua_number2integer(k, n); | ||
129 | if (luai_numeq(cast_num(k), n)) { /* 'k' is int? */ | ||
130 | *p = k; | ||
131 | return 1; | ||
132 | } | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | |||
137 | /* | 126 | /* |
138 | ** returns the index for `key' if `key' is an appropriate key to live in | 127 | ** returns the index for `key' if `key' is an appropriate key to live in |
139 | ** the array part of the table, -1 otherwise. | 128 | ** the array part of the table, -1 otherwise. |
@@ -423,7 +412,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
423 | lua_Integer k; | 412 | lua_Integer k; |
424 | if (luai_numisnan(L, n)) | 413 | if (luai_numisnan(L, n)) |
425 | luaG_runerror(L, "table index is NaN"); | 414 | luaG_runerror(L, "table index is NaN"); |
426 | if (numisint(n, &k)) { /* index is int? */ | 415 | if (luaV_numtointeger(n, &k)) { /* index is int? */ |
427 | setivalue(&aux, k); | 416 | setivalue(&aux, k); |
428 | key = &aux; /* insert it as an integer */ | 417 | key = &aux; /* insert it as an integer */ |
429 | } | 418 | } |
@@ -505,7 +494,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
505 | case LUA_TNIL: return luaO_nilobject; | 494 | case LUA_TNIL: return luaO_nilobject; |
506 | case LUA_TNUMFLT: { | 495 | case LUA_TNUMFLT: { |
507 | lua_Integer k; | 496 | lua_Integer k; |
508 | if (numisint(fltvalue(key), &k)) /* index is int? */ | 497 | if (luaV_numtointeger(fltvalue(key), &k)) /* index is int? */ |
509 | return luaH_getint(t, k); /* use specialized version */ | 498 | return luaH_getint(t, k); /* use specialized version */ |
510 | /* else go through */ | 499 | /* else go through */ |
511 | } | 500 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.165 2013/04/26 16:06:53 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.166 2013/04/26 19:51:17 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 | */ |
@@ -56,6 +56,28 @@ int luaV_tostring (lua_State *L, StkId obj) { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | int luaV_numtointeger (lua_Number n, lua_Integer *p) { | ||
60 | lua_Integer k; | ||
61 | lua_number2integer(k, n); | ||
62 | if (luai_numeq(cast_num(k), n)) { /* 'k' is int? */ | ||
63 | *p = k; | ||
64 | return 1; | ||
65 | } | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | |||
70 | int luaV_tointeger_ (const TValue *obj, lua_Integer *p) { | ||
71 | lua_Number n; | ||
72 | lua_assert(!ttisinteger(obj)); | ||
73 | if (tonumber(obj, &n)) { | ||
74 | n = l_mathop(floor)(n); | ||
75 | return luaV_numtointeger(n, p); | ||
76 | } | ||
77 | else return 0; | ||
78 | } | ||
79 | |||
80 | |||
59 | void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { | 81 | void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
60 | int loop; | 82 | int loop; |
61 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 83 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
@@ -225,10 +247,8 @@ void luaV_concat (lua_State *L, int total) { | |||
225 | do { | 247 | do { |
226 | StkId top = L->top; | 248 | StkId top = L->top; |
227 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 249 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
228 | if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { | 250 | if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) |
229 | if (!luaT_callbinTM(L, top-2, top-1, top-2, TM_CONCAT)) | 251 | luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT); |
230 | luaG_concaterror(L, top-2, top-1); | ||
231 | } | ||
232 | else if (tsvalue(top-1)->len == 0) /* second operand is empty? */ | 252 | else if (tsvalue(top-1)->len == 0) /* second operand is empty? */ |
233 | (void)tostring(L, top - 2); /* result is first operand */ | 253 | (void)tostring(L, top - 2); /* result is first operand */ |
234 | else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) { | 254 | else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) { |
@@ -335,18 +355,6 @@ lua_Integer luaV_pow (lua_Integer x, lua_Integer y) { | |||
335 | } | 355 | } |
336 | 356 | ||
337 | 357 | ||
338 | void luaV_arith (lua_State *L, StkId ra, const TValue *rb, | ||
339 | const TValue *rc, TMS op) { | ||
340 | lua_Number b, c; | ||
341 | if (tonumber(rb, &b) && tonumber(rc, &c)) { | ||
342 | lua_Number res = luaO_arith(op - TM_ADD + LUA_OPADD, b, c); | ||
343 | setnvalue(ra, res); | ||
344 | } | ||
345 | else if (!luaT_callbinTM(L, rb, rc, ra, op)) | ||
346 | luaG_aritherror(L, rb, rc); | ||
347 | } | ||
348 | |||
349 | |||
350 | /* | 358 | /* |
351 | ** check whether cached closure in prototype 'p' may be reused, that is, | 359 | ** check whether cached closure in prototype 'p' may be reused, that is, |
352 | ** whether there is a cached closure with the same upvalues needed by | 360 | ** whether there is a cached closure with the same upvalues needed by |
@@ -422,7 +430,7 @@ void luaV_finishOp (lua_State *L) { | |||
422 | break; | 430 | break; |
423 | } | 431 | } |
424 | case OP_CONCAT: { | 432 | case OP_CONCAT: { |
425 | StkId top = L->top - 1; /* top when 'luaT_callbinTM' was called */ | 433 | StkId top = L->top - 1; /* top when 'luaT_trybinTM' was called */ |
426 | int b = GETARG_B(inst); /* first element to concatenate */ | 434 | int b = GETARG_B(inst); /* first element to concatenate */ |
427 | int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */ | 435 | int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */ |
428 | setobj2s(L, top - 2, top); /* put TM result in proper position */ | 436 | setobj2s(L, top - 2, top); /* put TM result in proper position */ |
@@ -586,12 +594,12 @@ void luaV_execute (lua_State *L) { | |||
586 | lua_Number nb; lua_Number nc; | 594 | lua_Number nb; lua_Number nc; |
587 | if (ttisinteger(rb) && ttisinteger(rc)) { | 595 | if (ttisinteger(rb) && ttisinteger(rc)) { |
588 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 596 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
589 | setivalue(ra, ib + ic); | 597 | setivalue(ra, cast_integer(cast_unsigned(ib) + cast_unsigned(ic))); |
590 | } | 598 | } |
591 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 599 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
592 | setnvalue(ra, luai_numadd(L, nb, nc)); | 600 | setnvalue(ra, luai_numadd(L, nb, nc)); |
593 | } | 601 | } |
594 | else { Protect(luaV_arith(L, ra, rb, rc, TM_ADD)); } | 602 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); } |
595 | ) | 603 | ) |
596 | vmcase(OP_SUB, | 604 | vmcase(OP_SUB, |
597 | TValue *rb = RKB(i); | 605 | TValue *rb = RKB(i); |
@@ -599,12 +607,12 @@ void luaV_execute (lua_State *L) { | |||
599 | lua_Number nb; lua_Number nc; | 607 | lua_Number nb; lua_Number nc; |
600 | if (ttisinteger(rb) && ttisinteger(rc)) { | 608 | if (ttisinteger(rb) && ttisinteger(rc)) { |
601 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 609 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
602 | setivalue(ra, ib - ic); | 610 | setivalue(ra, cast_integer(cast_unsigned(ib) - cast_unsigned(ic))); |
603 | } | 611 | } |
604 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 612 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
605 | setnvalue(ra, luai_numsub(L, nb, nc)); | 613 | setnvalue(ra, luai_numsub(L, nb, nc)); |
606 | } | 614 | } |
607 | else { Protect(luaV_arith(L, ra, rb, rc, TM_SUB)); } | 615 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); } |
608 | ) | 616 | ) |
609 | vmcase(OP_MUL, | 617 | vmcase(OP_MUL, |
610 | TValue *rb = RKB(i); | 618 | TValue *rb = RKB(i); |
@@ -612,12 +620,12 @@ void luaV_execute (lua_State *L) { | |||
612 | lua_Number nb; lua_Number nc; | 620 | lua_Number nb; lua_Number nc; |
613 | if (ttisinteger(rb) && ttisinteger(rc)) { | 621 | if (ttisinteger(rb) && ttisinteger(rc)) { |
614 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 622 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
615 | setivalue(ra, ib * ic); | 623 | setivalue(ra, cast_integer(cast_unsigned(ib) * cast_unsigned(ic))); |
616 | } | 624 | } |
617 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 625 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
618 | setnvalue(ra, luai_nummul(L, nb, nc)); | 626 | setnvalue(ra, luai_nummul(L, nb, nc)); |
619 | } | 627 | } |
620 | else { Protect(luaV_arith(L, ra, rb, rc, TM_MUL)); } | 628 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); } |
621 | ) | 629 | ) |
622 | vmcase(OP_DIV, /* float division (always with floats) */ | 630 | vmcase(OP_DIV, /* float division (always with floats) */ |
623 | TValue *rb = RKB(i); | 631 | TValue *rb = RKB(i); |
@@ -626,20 +634,16 @@ void luaV_execute (lua_State *L) { | |||
626 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 634 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
627 | setnvalue(ra, luai_numdiv(L, nb, nc)); | 635 | setnvalue(ra, luai_numdiv(L, nb, nc)); |
628 | } | 636 | } |
629 | else { Protect(luaV_arith(L, ra, rb, rc, TM_DIV)); } | 637 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); } |
630 | ) | 638 | ) |
631 | vmcase(OP_IDIV, /* integer division */ | 639 | vmcase(OP_IDIV, /* integer division */ |
632 | TValue *rb = RKB(i); | 640 | TValue *rb = RKB(i); |
633 | TValue *rc = RKC(i); | 641 | TValue *rc = RKC(i); |
634 | lua_Number nb; lua_Number nc; | 642 | lua_Integer ib; lua_Integer ic; |
635 | if (ttisinteger(rb) && ttisinteger(rc)) { | 643 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
636 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | ||
637 | setivalue(ra, luaV_div(L, ib, ic)); | 644 | setivalue(ra, luaV_div(L, ib, ic)); |
638 | } | 645 | } |
639 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 646 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); } |
640 | setnvalue(ra, luai_numidiv(L, nb, nc)); | ||
641 | } | ||
642 | else { Protect(luaV_arith(L, ra, rb, rc, TM_IDIV)); } | ||
643 | ) | 647 | ) |
644 | vmcase(OP_MOD, | 648 | vmcase(OP_MOD, |
645 | TValue *rb = RKB(i); | 649 | TValue *rb = RKB(i); |
@@ -652,7 +656,7 @@ void luaV_execute (lua_State *L) { | |||
652 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 656 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
653 | setnvalue(ra, luai_nummod(L, nb, nc)); | 657 | setnvalue(ra, luai_nummod(L, nb, nc)); |
654 | } | 658 | } |
655 | else { Protect(luaV_arith(L, ra, rb, rc, TM_MOD)); } | 659 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } |
656 | ) | 660 | ) |
657 | vmcase(OP_POW, | 661 | vmcase(OP_POW, |
658 | TValue *rb = RKB(i); | 662 | TValue *rb = RKB(i); |
@@ -667,20 +671,20 @@ void luaV_execute (lua_State *L) { | |||
667 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 671 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
668 | setnvalue(ra, luai_numpow(L, nb, nc)); | 672 | setnvalue(ra, luai_numpow(L, nb, nc)); |
669 | } | 673 | } |
670 | else { Protect(luaV_arith(L, ra, rb, rc, TM_POW)); } | 674 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); } |
671 | ) | 675 | ) |
672 | vmcase(OP_UNM, | 676 | vmcase(OP_UNM, |
673 | TValue *rb = RB(i); | 677 | TValue *rb = RB(i); |
678 | lua_Number nb; | ||
674 | if (ttisinteger(rb)) { | 679 | if (ttisinteger(rb)) { |
675 | lua_Integer ib = ivalue(rb); | 680 | lua_Integer ib = ivalue(rb); |
676 | setivalue(ra, -ib); | 681 | setivalue(ra, -ib); |
677 | } | 682 | } |
678 | else if (ttisfloat(rb)) { | 683 | else if (tonumber(rb, &nb)) { |
679 | lua_Number nb = fltvalue(rb); | ||
680 | setnvalue(ra, luai_numunm(L, nb)); | 684 | setnvalue(ra, luai_numunm(L, nb)); |
681 | } | 685 | } |
682 | else { | 686 | else { |
683 | Protect(luaV_arith(L, ra, rb, rb, TM_UNM)); | 687 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); |
684 | } | 688 | } |
685 | ) | 689 | ) |
686 | vmcase(OP_NOT, | 690 | vmcase(OP_NOT, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.h,v 2.20 2013/04/25 19:12:41 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 2.21 2013/04/26 16:03:50 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 | */ |
@@ -18,6 +18,9 @@ | |||
18 | #define tonumber(o,n) \ | 18 | #define tonumber(o,n) \ |
19 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) | 19 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) |
20 | 20 | ||
21 | #define tointeger(o,i) \ | ||
22 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i)) | ||
23 | |||
21 | 24 | ||
22 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) | 25 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) |
23 | 26 | ||
@@ -26,6 +29,8 @@ LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); | |||
26 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | 29 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); |
27 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); | 30 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); |
28 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); | 31 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); |
32 | LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p); | ||
33 | LUAI_FUNC int luaV_numtointeger (lua_Number n, lua_Integer *p); | ||
29 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); | 34 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); |
30 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, | 35 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, |
31 | StkId val); | 36 | StkId val); |
@@ -37,8 +42,6 @@ LUAI_FUNC void luaV_concat (lua_State *L, int total); | |||
37 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); | 42 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); |
38 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); | 43 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); |
39 | LUAI_FUNC lua_Integer luaV_pow (lua_Integer x, lua_Integer y); | 44 | LUAI_FUNC lua_Integer luaV_pow (lua_Integer x, lua_Integer y); |
40 | LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb, | ||
41 | const TValue *rc, TMS op); | ||
42 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); | 45 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); |
43 | 46 | ||
44 | #endif | 47 | #endif |