aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-04 10:41:12 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-04 10:41:12 -0200
commit827846804196b1779a61ffdc75d0aeb157f8465d (patch)
tree7f54880a83d66cedad8cf2555144d684569f3427
parent4fbb2531b3e60094e760e30fffbd9c8b2d67a238 (diff)
downloadlua-827846804196b1779a61ffdc75d0aeb157f8465d.tar.gz
lua-827846804196b1779a61ffdc75d0aeb157f8465d.tar.bz2
lua-827846804196b1779a61ffdc75d0aeb157f8465d.zip
comments
-rw-r--r--liolib.c40
-rw-r--r--lmathlib.c19
2 files changed, 42 insertions, 17 deletions
diff --git a/liolib.c b/liolib.c
index 638fe9a6..d9c54370 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.27 1998/12/27 20:21:28 roberto Exp roberto $ 2** $Id: liolib.c,v 1.28 1998/12/28 13:44:54 roberto Exp $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,11 +52,6 @@ int pclose();
52 52
53 53
54 54
55static int gettag (int i) {
56 return (int)lua_getnumber(lua_getparam(i));
57}
58
59
60static void pushresult (int i) { 55static void pushresult (int i) {
61 if (i) 56 if (i)
62 lua_pushuserdata(NULL); 57 lua_pushuserdata(NULL);
@@ -68,6 +63,17 @@ static void pushresult (int i) {
68} 63}
69 64
70 65
66/*
67** {======================================================
68** FILE Operations
69** =======================================================
70*/
71
72static int gettag (int i) {
73 return (int)lua_getnumber(lua_getparam(i));
74}
75
76
71static int ishandler (lua_Object f) { 77static int ishandler (lua_Object f) {
72 if (lua_isuserdata(f)) { 78 if (lua_isuserdata(f)) {
73 if (lua_tag(f) == gettag(CLOSEDTAG)) 79 if (lua_tag(f) == gettag(CLOSEDTAG))
@@ -190,9 +196,11 @@ static void io_appendto (void) {
190 196
191 197
192 198
193/*==================================================== 199/*
200** {======================================================
194** READ 201** READ
195**===================================================*/ 202** =======================================================
203*/
196 204
197static int read_pattern (FILE *f, char *p) { 205static int read_pattern (FILE *f, char *p) {
198 int inskip = 0; /* {skip} level */ 206 int inskip = 0; /* {skip} level */
@@ -314,6 +322,8 @@ static void io_read (void) {
314 } while ((p = luaL_opt_string(arg++, NULL)) != NULL); 322 } while ((p = luaL_opt_string(arg++, NULL)) != NULL);
315} 323}
316 324
325/* }====================================================== */
326
317 327
318static void io_write (void) { 328static void io_write (void) {
319 int arg = FIRSTARG; 329 int arg = FIRSTARG;
@@ -350,6 +360,14 @@ static void io_flush (void) {
350 pushresult(fflush(f) == 0); 360 pushresult(fflush(f) == 0);
351} 361}
352 362
363/* }====================================================== */
364
365
366/*
367** {======================================================
368** Other O.S. Operations
369** =======================================================
370*/
353 371
354static void io_execute (void) { 372static void io_execute (void) {
355 lua_pushnumber(system(luaL_check_string(1))); 373 lua_pushnumber(system(luaL_check_string(1)));
@@ -412,6 +430,9 @@ static void io_exit (void) {
412 exit(lua_isnumber(o) ? (int)lua_getnumber(o) : 1); 430 exit(lua_isnumber(o) ? (int)lua_getnumber(o) : 1);
413} 431}
414 432
433/* }====================================================== */
434
435
415 436
416static void io_debug (void) { 437static void io_debug (void) {
417 for (;;) { 438 for (;;) {
@@ -439,7 +460,8 @@ static void errorfb (void) {
439 char *chunkname; 460 char *chunkname;
440 int linedefined; 461 int linedefined;
441 lua_funcinfo(func, &chunkname, &linedefined); 462 lua_funcinfo(func, &chunkname, &linedefined);
442 strcat(buff, (level==2) ? "Active Stack:\n\t" : "\t"); 463 if (level == 2) strcat(buff, "Active Stack:\n");
464 strcat(buff, "\t");
443 if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { 465 if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) {
444 strcat(buff, "...\n"); 466 strcat(buff, "...\n");
445 break; /* buffer is full */ 467 break; /* buffer is full */
diff --git a/lmathlib.c b/lmathlib.c
index 21bf9308..33af1d14 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.13 1998/12/30 17:22:17 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.14 1998/12/30 21:23:26 roberto Exp $
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*/
@@ -12,15 +12,18 @@
12#include "lua.h" 12#include "lua.h"
13#include "lualib.h" 13#include "lualib.h"
14 14
15#ifdef M_PI
16#define PI M_PI
17#else
18#define PI ((double)3.14159265358979323846)
19#endif
20 15
16#define PI (3.14159265358979323846)
21 17
22#define FROMRAD(a) ((a)*(180.0/PI)) 18
23#define TORAD(a) ((a)*(PI/180.0)) 19/*
20** If you want Lua to operate in radians (instead of degrees),
21** changes these two macros to identities:
22** #define FROMRAD(a) (a)
23** #define TORAD(a) (a)
24*/
25#define FROMRAD(a) ((a)*(180.0/PI))
26#define TORAD(a) ((a)*(PI/180.0))
24 27
25 28
26static void math_abs (void) 29static void math_abs (void)