diff options
-rw-r--r-- | lmathlib.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.2 1997/10/24 17:44:22 roberto Exp roberto $ |
3 | ** Lua standard mathematical library | 3 | ** Lua standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -17,20 +17,21 @@ | |||
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | 19 | ||
20 | static double torad = PI/180.0; | ||
21 | 20 | ||
22 | #define FROMRAD(a) ((a)/torad) | 21 | #define FROMRAD(a) ((a)/torad()) |
23 | #define TORAD(a) ((a)*torad) | 22 | #define TORAD(a) ((a)*torad()) |
24 | 23 | ||
25 | 24 | ||
26 | static void modeang (void) | 25 | static double torad (void) |
27 | { | 26 | { |
28 | char *s = luaL_opt_string(1, "degree"); | 27 | char *s = lua_getstring(lua_getglobal("_TRIGMODE")); |
29 | switch (*s) { | 28 | switch (*s) { |
30 | case 'd' : torad = PI/180.0; break; | 29 | case 'd' : return PI/180.0; |
31 | case 'r' : torad = 1.0; break; | 30 | case 'r' : return 1.0; |
32 | case 'g' : torad = PI/50.0; break; | 31 | case 'g' : return PI/50.0; |
33 | default: luaL_arg_check(0, 1, "invalid mode"); | 32 | default: |
33 | luaL_verror("invalid _TRIGMODE (`%s')", s); | ||
34 | return 0; /* to avoid warnings */ | ||
34 | } | 35 | } |
35 | } | 36 | } |
36 | 37 | ||
@@ -173,7 +174,6 @@ static void math_randomseed (void) | |||
173 | 174 | ||
174 | 175 | ||
175 | static struct luaL_reg mathlib[] = { | 176 | static struct luaL_reg mathlib[] = { |
176 | {"modeang", modeang}, | ||
177 | {"abs", math_abs}, | 177 | {"abs", math_abs}, |
178 | {"sin", math_sin}, | 178 | {"sin", math_sin}, |
179 | {"cos", math_cos}, | 179 | {"cos", math_cos}, |
@@ -202,6 +202,7 @@ static struct luaL_reg mathlib[] = { | |||
202 | */ | 202 | */ |
203 | void lua_mathlibopen (void) | 203 | void lua_mathlibopen (void) |
204 | { | 204 | { |
205 | lua_pushstring("deg"); lua_setglobal("_TRIGMODE"); | ||
205 | luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); | 206 | luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); |
206 | lua_pushcfunction(math_pow); | 207 | lua_pushcfunction(math_pow); |
207 | lua_pushnumber(0); /* to get its tag */ | 208 | lua_pushnumber(0); /* to get its tag */ |