aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-02-09 17:02:30 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-02-09 17:02:30 -0200
commitca412214cbbeb8f40e9abea534e6171044cc0a57 (patch)
tree41fc8e4b38c1f43147435183f9dbe7b7ff2bab20
parent801722825d94b3bddd94d83887b081c328772147 (diff)
downloadlua-ca412214cbbeb8f40e9abea534e6171044cc0a57.tar.gz
lua-ca412214cbbeb8f40e9abea534e6171044cc0a57.tar.bz2
lua-ca412214cbbeb8f40e9abea534e6171044cc0a57.zip
new function "date", replaces old "date" and "time".
-rw-r--r--iolib.c58
-rw-r--r--manual.tex20
2 files changed, 32 insertions, 46 deletions
diff --git a/iolib.c b/iolib.c
index d014ec4f..a454084e 100644
--- a/iolib.c
+++ b/iolib.c
@@ -3,7 +3,7 @@
3** Input/output library to LUA 3** Input/output library to LUA
4*/ 4*/
5 5
6char *rcs_iolib="$Id: iolib.c,v 1.32 1996/01/29 16:40:09 roberto Exp roberto $"; 6char *rcs_iolib="$Id: iolib.c,v 1.33 1996/02/05 21:32:19 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <ctype.h> 9#include <ctype.h>
@@ -12,6 +12,7 @@ char *rcs_iolib="$Id: iolib.c,v 1.32 1996/01/29 16:40:09 roberto Exp roberto $";
12#include <string.h> 12#include <string.h>
13#include <time.h> 13#include <time.h>
14#include <stdlib.h> 14#include <stdlib.h>
15#include <errno.h>
15 16
16#include "lua.h" 17#include "lua.h"
17#include "luadebug.h" 18#include "luadebug.h"
@@ -490,9 +491,14 @@ static void io_remove (void)
490 lua_pushnil(); 491 lua_pushnil();
491} 492}
492 493
494static void io_errorno (void)
495{
496/* lua_pushstring(strerror(errno));*/
497}
498
493 499
494/* 500/*
495** To get a environment variables 501** To get a environment variable
496*/ 502*/
497static void io_getenv (void) 503static void io_getenv (void)
498{ 504{
@@ -502,42 +508,23 @@ static void io_getenv (void)
502} 508}
503 509
504/* 510/*
505** Return time: hour, min, sec 511** Return user formatted time stamp
506*/
507static void io_time (void)
508{
509 time_t t;
510 struct tm *s;
511
512 time(&t);
513 s = localtime(&t);
514 lua_pushnumber(s->tm_hour);
515 lua_pushnumber(s->tm_min);
516 lua_pushnumber(s->tm_sec);
517}
518
519/*
520** Return date: dd, mm, yyyy, weekday
521*/ 512*/
522static void io_date (void) 513static void io_date (void)
523{ 514{
524 time_t t; 515 time_t t;
525 struct tm *s; 516 struct tm *tm;
526 517 char *s;
527 time(&t); 518 char b[BUFSIZ];
528 s = localtime(&t); 519 if (lua_getparam(1) == LUA_NOOBJECT)
529 lua_pushnumber(s->tm_mday); 520 s = "%c";
530 lua_pushnumber(s->tm_mon+1); 521 else
531 lua_pushnumber(s->tm_year+1900); 522 s = lua_check_string(1, "date");
532 lua_pushnumber(s->tm_wday+1); 523 time(&t); tm = localtime(&t);
533} 524 if (strftime(b,sizeof(b),s,tm))
534 525 lua_pushstring(b);
535/* 526 else
536** Beep 527 lua_error("`date' format too long");
537*/
538static void io_beep (void)
539{
540 printf("\a");
541} 528}
542 529
543/* 530/*
@@ -628,10 +615,9 @@ void iolib_open (void)
628 lua_register ("write", io_write); 615 lua_register ("write", io_write);
629 lua_register ("execute", io_execute); 616 lua_register ("execute", io_execute);
630 lua_register ("remove", io_remove); 617 lua_register ("remove", io_remove);
618 lua_register ("ioerror", io_errorno);
631 lua_register ("getenv", io_getenv); 619 lua_register ("getenv", io_getenv);
632 lua_register ("time", io_time);
633 lua_register ("date", io_date); 620 lua_register ("date", io_date);
634 lua_register ("beep", io_beep);
635 lua_register ("exit", io_exit); 621 lua_register ("exit", io_exit);
636 lua_register ("debug", io_debug); 622 lua_register ("debug", io_debug);
637 lua_register ("print_stack", errorfb); 623 lua_register ("print_stack", errorfb);
diff --git a/manual.tex b/manual.tex
index b3e37013..c83104f0 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.7 1996/02/09 16:37:58 roberto Exp roberto $ 1% $Id: manual.tex,v 1.8 1996/02/09 17:21:27 roberto Exp roberto $
2 2
3\documentstyle[A4,11pt,bnf]{article} 3\documentstyle[A4,11pt,bnf]{article}
4 4
@@ -32,7 +32,7 @@ Waldemar Celes Filho
32Departamento de Inform\'atica --- PUC-Rio 32Departamento de Inform\'atica --- PUC-Rio
33} 33}
34 34
35\date{\small \verb$Date: 1996/02/09 16:37:58 $} 35\date{\small \verb$Date: 1996/02/09 17:21:27 $}
36 36
37\maketitle 37\maketitle
38 38
@@ -1440,17 +1440,17 @@ and strings with \verb'%s'.
1440For better format facilities, 1440For better format facilities,
1441the function \verb'format' should be used (\see{format}). 1441the function \verb'format' should be used (\see{format}).
1442 1442
1443\subsubsection*{{\tt date ()}}\Deffunc{date} 1443\subsubsection*{{\tt date ([format])}}\Deffunc{date}
1444 1444
1445This function returns 4 values: 1445This function returns a string containing date and time
1446the current day of the month, 1446formatted according to the given string \verb'format',
1447the month ([1-12]), the current year, 1447following the same rules of the ANSI C function \verb'strftime'.
1448and the day of the week (1 = Sunday, 7 = Saturday). 1448When called without arguments,
1449it returns a reasonable date and time representation.
1449 1450
1450\subsubsection*{{\tt time ()}}\Deffunc{time} 1451This function replaces functions \verb'date' and \verb'time' from
1452previous Lua versions.
1451 1453
1452This function returns the current time through 3 values:
1453hours ([0-23]), minutes, and seconds.
1454 1454
1455% \subsubsection*{{\tt debug ()}} 1455% \subsubsection*{{\tt debug ()}}
1456% This function, when called, repeatedly presents a prompt \verb'lua_debug> ' 1456% This function, when called, repeatedly presents a prompt \verb'lua_debug> '