diff options
| author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-10-19 15:02:20 -0200 |
|---|---|---|
| committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-10-19 15:02:20 -0200 |
| commit | 2f1de3b1e14699f86ff762e95531c89b99db4727 (patch) | |
| tree | b2f8f454d93f8eb3d64f1da18ab1f5a8025fb6b3 | |
| parent | 1a6536aaadb8218493f763eafd83998ce41c5c70 (diff) | |
| download | lua-2f1de3b1e14699f86ff762e95531c89b99db4727.tar.gz lua-2f1de3b1e14699f86ff762e95531c89b99db4727.tar.bz2 lua-2f1de3b1e14699f86ff762e95531c89b99db4727.zip | |
implementacao das funcoes 'date', 'time' e 'beep'.
troca de nome de 'abort' para 'exit'
| -rw-r--r-- | iolib.c | 50 |
1 files changed, 46 insertions, 4 deletions
| @@ -3,12 +3,13 @@ | |||
| 3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_iolib="$Id: iolib.c,v 1.12 1994/10/13 19:28:54 celes Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.13 1994/10/18 18:34:47 roberto Exp celes $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <ctype.h> | 11 | #include <ctype.h> |
| 12 | #include <time.h> | ||
| 12 | #include <sys/stat.h> | 13 | #include <sys/stat.h> |
| 13 | #ifdef __GNUC__ | 14 | #ifdef __GNUC__ |
| 14 | #include <floatingpoint.h> | 15 | #include <floatingpoint.h> |
| @@ -531,9 +532,47 @@ static void io_getenv (void) | |||
| 531 | } | 532 | } |
| 532 | 533 | ||
| 533 | /* | 534 | /* |
| 534 | ** To abort | 535 | ** Return time: hour, min, sec |
| 535 | */ | 536 | */ |
| 536 | static void io_abort (void) | 537 | static void io_time (void) |
| 538 | { | ||
| 539 | time_t t; | ||
| 540 | struct tm *s; | ||
| 541 | |||
| 542 | time(&t); | ||
| 543 | s = localtime(&t); | ||
| 544 | lua_pushnumber(s->tm_hour); | ||
| 545 | lua_pushnumber(s->tm_min); | ||
| 546 | lua_pushnumber(s->tm_sec); | ||
| 547 | } | ||
| 548 | |||
| 549 | /* | ||
| 550 | ** Return date: dd, mm, yyyy | ||
| 551 | */ | ||
| 552 | static void io_date (void) | ||
| 553 | { | ||
| 554 | time_t t; | ||
| 555 | struct tm *s; | ||
| 556 | |||
| 557 | time(&t); | ||
| 558 | s = localtime(&t); | ||
| 559 | lua_pushnumber(s->tm_mday); | ||
| 560 | lua_pushnumber(s->tm_mon+1); | ||
| 561 | lua_pushnumber(s->tm_year+1900); | ||
| 562 | } | ||
| 563 | |||
| 564 | /* | ||
| 565 | ** Beep | ||
| 566 | */ | ||
| 567 | static void io_beep (void) | ||
| 568 | { | ||
| 569 | printf("\a"); | ||
| 570 | } | ||
| 571 | |||
| 572 | /* | ||
| 573 | ** To exit | ||
| 574 | */ | ||
| 575 | static void io_exit (void) | ||
| 537 | { | 576 | { |
| 538 | lua_Object o = lua_getparam(1); | 577 | lua_Object o = lua_getparam(1); |
| 539 | if (lua_isstring(o)) | 578 | if (lua_isstring(o)) |
| @@ -571,6 +610,9 @@ void iolib_open (void) | |||
| 571 | lua_register ("execute", io_execute); | 610 | lua_register ("execute", io_execute); |
| 572 | lua_register ("remove", io_remove); | 611 | lua_register ("remove", io_remove); |
| 573 | lua_register ("getenv", io_getenv); | 612 | lua_register ("getenv", io_getenv); |
| 574 | lua_register ("abort", io_abort); | 613 | lua_register ("time", io_time); |
| 614 | lua_register ("date", io_date); | ||
| 615 | lua_register ("beep", io_beep); | ||
| 616 | lua_register ("exit", io_exit); | ||
| 575 | lua_register ("debug", io_debug); | 617 | lua_register ("debug", io_debug); |
| 576 | } | 618 | } |
