aboutsummaryrefslogtreecommitdiff
path: root/iolib.c
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 /iolib.c
parent801722825d94b3bddd94d83887b081c328772147 (diff)
downloadlua-ca412214cbbeb8f40e9abea534e6171044cc0a57.tar.gz
lua-ca412214cbbeb8f40e9abea534e6171044cc0a57.tar.bz2
lua-ca412214cbbeb8f40e9abea534e6171044cc0a57.zip
new function "date", replaces old "date" and "time".
Diffstat (limited to 'iolib.c')
-rw-r--r--iolib.c58
1 files changed, 22 insertions, 36 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);