diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-02 14:35:06 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-02 14:35:06 -0300 |
| commit | a9dc7c88283a8046ad40c592f9e626d93e8e14a1 (patch) | |
| tree | 693fa40d1ca9beceb5af5d4d4325401abe3f96a2 /lapi.c | |
| parent | 7192afafeeb1a96b3de60af90a72cd8762b09d94 (diff) | |
| download | lua-a9dc7c88283a8046ad40c592f9e626d93e8e14a1.tar.gz lua-a9dc7c88283a8046ad40c592f9e626d93e8e14a1.tar.bz2 lua-a9dc7c88283a8046ad40c592f9e626d93e8e14a1.zip | |
functions lua_tonumber/lua_tointeger replaced by lua_tonumberx/lua_tointegerx
that have an extra out parameter with conversion status
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 19 |
1 files changed, 13 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.130 2010/05/31 16:08:55 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.131 2010/06/04 13:05:29 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 | */ |
| @@ -316,27 +316,34 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | 318 | ||
| 319 | LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { | 319 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) { |
| 320 | TValue n; | 320 | TValue n; |
| 321 | const TValue *o = index2addr(L, idx); | 321 | const TValue *o = index2addr(L, idx); |
| 322 | if (tonumber(o, &n)) | 322 | if (tonumber(o, &n)) { |
| 323 | if (isnum) *isnum = 1; | ||
| 323 | return nvalue(o); | 324 | return nvalue(o); |
| 324 | else | 325 | } |
| 326 | else { | ||
| 327 | if (isnum) *isnum = 0; | ||
| 325 | return 0; | 328 | return 0; |
| 329 | } | ||
| 326 | } | 330 | } |
| 327 | 331 | ||
| 328 | 332 | ||
| 329 | LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { | 333 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) { |
| 330 | TValue n; | 334 | TValue n; |
| 331 | const TValue *o = index2addr(L, idx); | 335 | const TValue *o = index2addr(L, idx); |
| 332 | if (tonumber(o, &n)) { | 336 | if (tonumber(o, &n)) { |
| 333 | lua_Integer res; | 337 | lua_Integer res; |
| 334 | lua_Number num = nvalue(o); | 338 | lua_Number num = nvalue(o); |
| 335 | lua_number2integer(res, num); | 339 | lua_number2integer(res, num); |
| 340 | if (isnum) *isnum = 1; | ||
| 336 | return res; | 341 | return res; |
| 337 | } | 342 | } |
| 338 | else | 343 | else { |
| 344 | if (isnum) *isnum = 0; | ||
| 339 | return 0; | 345 | return 0; |
| 346 | } | ||
| 340 | } | 347 | } |
| 341 | 348 | ||
| 342 | 349 | ||
