diff options
Diffstat (limited to 'lmathlib.c')
| -rw-r--r-- | lmathlib.c | 60 |
1 files changed, 33 insertions, 27 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lmathlib.c,v 1.40 2001/12/05 20:15:18 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 | */ |
| @@ -200,39 +200,45 @@ static int math_randomseed (lua_State *L) { | |||
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | static const luaL_reg mathlib[] = { | 202 | static const luaL_reg mathlib[] = { |
| 203 | {"abs", math_abs}, | 203 | {"abs", math_abs}, |
| 204 | {"sin", math_sin}, | 204 | {"sin", math_sin}, |
| 205 | {"cos", math_cos}, | 205 | {"cos", math_cos}, |
| 206 | {"tan", math_tan}, | 206 | {"tan", math_tan}, |
| 207 | {"asin", math_asin}, | 207 | {"asin", math_asin}, |
| 208 | {"acos", math_acos}, | 208 | {"acos", math_acos}, |
| 209 | {"atan", math_atan}, | 209 | {"atan", math_atan}, |
| 210 | {"atan2", math_atan2}, | 210 | {"atan2", math_atan2}, |
| 211 | {"ceil", math_ceil}, | 211 | {"ceil", math_ceil}, |
| 212 | {"floor", math_floor}, | 212 | {"floor", math_floor}, |
| 213 | {"mod", math_mod}, | 213 | {"mod", math_mod}, |
| 214 | {"frexp", math_frexp}, | 214 | {"frexp", math_frexp}, |
| 215 | {"ldexp", math_ldexp}, | 215 | {"ldexp", math_ldexp}, |
| 216 | {"sqrt", math_sqrt}, | 216 | {"sqrt", math_sqrt}, |
| 217 | {"min", math_min}, | 217 | {"min", math_min}, |
| 218 | {"max", math_max}, | 218 | {"max", math_max}, |
| 219 | {"log", math_log}, | 219 | {"log", math_log}, |
| 220 | {"log10", math_log10}, | 220 | {"log10", math_log10}, |
| 221 | {"exp", math_exp}, | 221 | {"exp", math_exp}, |
| 222 | {"deg", math_deg}, | 222 | {"deg", math_deg}, |
| 223 | {"pow", math_pow}, | 223 | {"pow", math_pow}, |
| 224 | {"rad", math_rad}, | 224 | {"rad", math_rad}, |
| 225 | {"random", math_random}, | 225 | {"random", math_random}, |
| 226 | {"randomseed", math_randomseed} | 226 | {"randomseed", math_randomseed}, |
| 227 | {NULL, NULL} | ||
| 227 | }; | 228 | }; |
| 228 | 229 | ||
| 230 | |||
| 229 | /* | 231 | /* |
| 230 | ** Open math library | 232 | ** Open math library |
| 231 | */ | 233 | */ |
| 232 | LUALIB_API int lua_mathlibopen (lua_State *L) { | 234 | LUALIB_API int lua_mathlibopen (lua_State *L) { |
| 233 | luaL_openl(L, mathlib); | 235 | lua_pushliteral(L, "math"); |
| 236 | lua_newtable(L); | ||
| 237 | luaL_openlib(L, mathlib); | ||
| 238 | lua_pushliteral(L, "pi"); | ||
| 234 | lua_pushnumber(L, PI); | 239 | lua_pushnumber(L, PI); |
| 235 | lua_setglobal(L, "PI"); | 240 | lua_settable(L, -3); |
| 241 | lua_settable(L, LUA_GLOBALSINDEX); | ||
| 236 | return 0; | 242 | return 0; |
| 237 | } | 243 | } |
| 238 | 244 | ||
