new function "date", replaces old "date" and "time".

This commit is contained in:
Roberto Ierusalimschy
1996-02-09 17:02:30 -02:00
parent 801722825d
commit ca412214cb
2 changed files with 32 additions and 46 deletions

58
iolib.c
View File

@@ -3,7 +3,7 @@
** Input/output library to LUA ** Input/output library to LUA
*/ */
char *rcs_iolib="$Id: iolib.c,v 1.32 1996/01/29 16:40:09 roberto Exp roberto $"; char *rcs_iolib="$Id: iolib.c,v 1.33 1996/02/05 21:32:19 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #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 $";
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include "lua.h" #include "lua.h"
#include "luadebug.h" #include "luadebug.h"
@@ -490,9 +491,14 @@ static void io_remove (void)
lua_pushnil(); lua_pushnil();
} }
static void io_errorno (void)
{
/* lua_pushstring(strerror(errno));*/
}
/* /*
** To get a environment variables ** To get a environment variable
*/ */
static void io_getenv (void) static void io_getenv (void)
{ {
@@ -502,42 +508,23 @@ static void io_getenv (void)
} }
/* /*
** Return time: hour, min, sec ** Return user formatted time stamp
*/
static void io_time (void)
{
time_t t;
struct tm *s;
time(&t);
s = localtime(&t);
lua_pushnumber(s->tm_hour);
lua_pushnumber(s->tm_min);
lua_pushnumber(s->tm_sec);
}
/*
** Return date: dd, mm, yyyy, weekday
*/ */
static void io_date (void) static void io_date (void)
{ {
time_t t; time_t t;
struct tm *s; struct tm *tm;
char *s;
time(&t); char b[BUFSIZ];
s = localtime(&t); if (lua_getparam(1) == LUA_NOOBJECT)
lua_pushnumber(s->tm_mday); s = "%c";
lua_pushnumber(s->tm_mon+1); else
lua_pushnumber(s->tm_year+1900); s = lua_check_string(1, "date");
lua_pushnumber(s->tm_wday+1); time(&t); tm = localtime(&t);
} if (strftime(b,sizeof(b),s,tm))
lua_pushstring(b);
/* else
** Beep lua_error("`date' format too long");
*/
static void io_beep (void)
{
printf("\a");
} }
/* /*
@@ -628,10 +615,9 @@ void iolib_open (void)
lua_register ("write", io_write); lua_register ("write", io_write);
lua_register ("execute", io_execute); lua_register ("execute", io_execute);
lua_register ("remove", io_remove); lua_register ("remove", io_remove);
lua_register ("ioerror", io_errorno);
lua_register ("getenv", io_getenv); lua_register ("getenv", io_getenv);
lua_register ("time", io_time);
lua_register ("date", io_date); lua_register ("date", io_date);
lua_register ("beep", io_beep);
lua_register ("exit", io_exit); lua_register ("exit", io_exit);
lua_register ("debug", io_debug); lua_register ("debug", io_debug);
lua_register ("print_stack", errorfb); lua_register ("print_stack", errorfb);

View File

@@ -1,4 +1,4 @@
% $Id: manual.tex,v 1.7 1996/02/09 16:37:58 roberto Exp roberto $ % $Id: manual.tex,v 1.8 1996/02/09 17:21:27 roberto Exp roberto $
\documentstyle[A4,11pt,bnf]{article} \documentstyle[A4,11pt,bnf]{article}
@@ -32,7 +32,7 @@ Waldemar Celes Filho
Departamento de Inform\'atica --- PUC-Rio Departamento de Inform\'atica --- PUC-Rio
} }
\date{\small \verb$Date: 1996/02/09 16:37:58 $} \date{\small \verb$Date: 1996/02/09 17:21:27 $}
\maketitle \maketitle
@@ -1440,17 +1440,17 @@ and strings with \verb'%s'.
For better format facilities, For better format facilities,
the function \verb'format' should be used (\see{format}). the function \verb'format' should be used (\see{format}).
\subsubsection*{{\tt date ()}}\Deffunc{date} \subsubsection*{{\tt date ([format])}}\Deffunc{date}
This function returns 4 values: This function returns a string containing date and time
the current day of the month, formatted according to the given string \verb'format',
the month ([1-12]), the current year, following the same rules of the ANSI C function \verb'strftime'.
and the day of the week (1 = Sunday, 7 = Saturday). When called without arguments,
it returns a reasonable date and time representation.
\subsubsection*{{\tt time ()}}\Deffunc{time} This function replaces functions \verb'date' and \verb'time' from
previous Lua versions.
This function returns the current time through 3 values:
hours ([0-23]), minutes, and seconds.
% \subsubsection*{{\tt debug ()}} % \subsubsection*{{\tt debug ()}}
% This function, when called, repeatedly presents a prompt \verb'lua_debug> ' % This function, when called, repeatedly presents a prompt \verb'lua_debug> '