aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-10-25 18:31:11 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-10-25 18:31:11 -0200
commitc6b64ffe65549b179bfa565e8329430857e335ee (patch)
tree9fa644de3c5dc2e4edf42aac7249b42264f2f6e5 /lapi.c
parent4590a89b32b62c75fca7ced96c282c7793b8885c (diff)
downloadlua-c6b64ffe65549b179bfa565e8329430857e335ee.tar.gz
lua-c6b64ffe65549b179bfa565e8329430857e335ee.tar.bz2
lua-c6b64ffe65549b179bfa565e8329430857e335ee.zip
new type lua_Unsigned and corresponding projection/injection functions
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/lapi.c b/lapi.c
index 7a51b657..508d050d 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.137 2010/09/07 19:35:04 roberto Exp roberto $ 2** $Id: lapi.c,v 2.138 2010/10/25 19:01:37 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*/
@@ -347,6 +347,23 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
347} 347}
348 348
349 349
350LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) {
351 TValue n;
352 const TValue *o = index2addr(L, idx);
353 if (tonumber(o, &n)) {
354 lua_Unsigned res;
355 lua_Number num = nvalue(o);
356 lua_number2uint(res, num);
357 if (isnum) *isnum = 1;
358 return res;
359 }
360 else {
361 if (isnum) *isnum = 0;
362 return 0;
363 }
364}
365
366
350LUA_API int lua_toboolean (lua_State *L, int idx) { 367LUA_API int lua_toboolean (lua_State *L, int idx) {
351 const TValue *o = index2addr(L, idx); 368 const TValue *o = index2addr(L, idx);
352 return !l_isfalse(o); 369 return !l_isfalse(o);
@@ -452,6 +469,16 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
452} 469}
453 470
454 471
472LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
473 lua_Number n;
474 lua_lock(L);
475 n = lua_uint2number(u);
476 setnvalue(L->top, n);
477 api_incr_top(L);
478 lua_unlock(L);
479}
480
481
455LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { 482LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
456 TString *ts; 483 TString *ts;
457 lua_lock(L); 484 lua_lock(L);