summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-26 14:25:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-26 14:25:11 -0300
commit84fe52dbeb0f75d31e5c87e801d4bd98ec26ce60 (patch)
tree7dc42b19195feffd2205b5adb9191fc00c5413a8 /lapi.c
parent10200585a7d634b9d8688ecf8afab5b203619508 (diff)
downloadlua-84fe52dbeb0f75d31e5c87e801d4bd98ec26ce60.tar.gz
lua-84fe52dbeb0f75d31e5c87e801d4bd98ec26ce60.tar.bz2
lua-84fe52dbeb0f75d31e5c87e801d4bd98ec26ce60.zip
unsigned-manipulation functions (lua_puhsunsigned, lua_tounsigned, etc.)
deprecated
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c49
1 files changed, 1 insertions, 48 deletions
diff --git a/lapi.c b/lapi.c
index c5d90ac4..fb617eab 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.219 2014/06/19 18:27:20 roberto Exp roberto $ 2** $Id: lapi.c,v 2.220 2014/06/24 17:00:13 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*/
@@ -372,45 +372,6 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {
372} 372}
373 373
374 374
375#if !defined(LUAI_FTWO2N)
376/* 2.0^(numbits in an integer), computed without roundings */
377#define LUAI_FTWO2N (cast_num(LUA_MININTEGER) * cast_num(-2))
378#endif
379
380LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
381 lua_Unsigned res = 0;
382 const TValue *o = index2addr(L, idx);
383 int isnum = 0;
384 switch (ttype(o)) {
385 case LUA_TNUMINT: {
386 res = l_castS2U(ivalue(o));
387 isnum = 1;
388 break;
389 }
390 case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */
391 const lua_Number two2n = LUAI_FTWO2N;
392 lua_Number n = fltvalue(o); /* get value */
393 int neg = 0;
394 n = l_floor(n); /* get its floor */
395 if (n < 0) {
396 neg = 1;
397 n = -n; /* make 'n' positive, so that 'fmod' is the same as '%' */
398 }
399 n = l_mathop(fmod)(n, two2n); /* n = n % 2^(numbits in an integer) */
400 if (luai_numisnan(n)) /* not a number? */
401 break; /* not an integer, too */
402 res = cast(lua_Unsigned, n); /* 'n' now must fit in an unsigned */
403 if (neg) res = 0u - res; /* back to negative, if needed */
404 isnum = 1;
405 break;
406 }
407 default: break;
408 }
409 if (pisnum) *pisnum = isnum;
410 return res;
411}
412
413
414LUA_API int lua_toboolean (lua_State *L, int idx) { 375LUA_API int lua_toboolean (lua_State *L, int idx) {
415 const TValue *o = index2addr(L, idx); 376 const TValue *o = index2addr(L, idx);
416 return !l_isfalse(o); 377 return !l_isfalse(o);
@@ -517,14 +478,6 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
517} 478}
518 479
519 480
520LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
521 lua_lock(L);
522 setivalue(L->top, l_castU2S(u));
523 api_incr_top(L);
524 lua_unlock(L);
525}
526
527
528LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { 481LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
529 TString *ts; 482 TString *ts;
530 lua_lock(L); 483 lua_lock(L);