diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-22 13:05:53 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-22 13:05:53 -0300 |
| commit | 4244da96bfcf205624487b99b69e9d8dd1857293 (patch) | |
| tree | 3cb62c17f905cab6cac08881483a565a6e4e32ed /lmathlib.c | |
| parent | fcf99bf7889ab33d8be84504378c32865f4a60f3 (diff) | |
| download | lua-4244da96bfcf205624487b99b69e9d8dd1857293.tar.gz lua-4244da96bfcf205624487b99b69e9d8dd1857293.tar.bz2 lua-4244da96bfcf205624487b99b69e9d8dd1857293.zip | |
'debug.subtype' -> 'math.type' (to distinguish integers and floats)
Diffstat (limited to 'lmathlib.c')
| -rw-r--r-- | lmathlib.c | 17 |
1 files changed, 16 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.90 2013/07/03 17:23:19 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.91 2013/07/10 20:57:05 roberto Exp roberto $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -251,6 +251,20 @@ static int math_randomseed (lua_State *L) { | |||
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | 253 | ||
| 254 | static int math_type (lua_State *L) { | ||
| 255 | luaL_checkany(L, 1); | ||
| 256 | if (lua_type(L, 1) == LUA_TNUMBER) { | ||
| 257 | if (lua_isinteger(L, 1)) | ||
| 258 | lua_pushliteral(L, "integer"); | ||
| 259 | else | ||
| 260 | lua_pushliteral(L, "float"); | ||
| 261 | } | ||
| 262 | else | ||
| 263 | lua_pushnil(L); | ||
| 264 | return 1; | ||
| 265 | } | ||
| 266 | |||
| 267 | |||
| 254 | static const luaL_Reg mathlib[] = { | 268 | static const luaL_Reg mathlib[] = { |
| 255 | {"abs", math_abs}, | 269 | {"abs", math_abs}, |
| 256 | {"acos", math_acos}, | 270 | {"acos", math_acos}, |
| @@ -283,6 +297,7 @@ static const luaL_Reg mathlib[] = { | |||
| 283 | {"sqrt", math_sqrt}, | 297 | {"sqrt", math_sqrt}, |
| 284 | {"tanh", math_tanh}, | 298 | {"tanh", math_tanh}, |
| 285 | {"tan", math_tan}, | 299 | {"tan", math_tan}, |
| 300 | {"type", math_type}, | ||
| 286 | {NULL, NULL} | 301 | {NULL, NULL} |
| 287 | }; | 302 | }; |
| 288 | 303 | ||
