aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iolib.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/iolib.c b/iolib.c
index 1f411ea1..25cb6cb3 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.4 1994/04/25 20:11:23 celes Exp celes $"; 6char *rcs_iolib="$Id: iolib.c,v 1.5 1994/08/04 16:23:29 celes Exp celes $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
@@ -443,7 +443,7 @@ static void io_write (void)
443** Execute a executable program using "system". 443** Execute a executable program using "system".
444** Return the result of execution. 444** Return the result of execution.
445*/ 445*/
446void io_execute (void) 446static void io_execute (void)
447{ 447{
448 lua_Object o = lua_getparam (1); 448 lua_Object o = lua_getparam (1);
449 if (o == NULL || !lua_isstring (o)) 449 if (o == NULL || !lua_isstring (o))
@@ -463,7 +463,7 @@ void io_execute (void)
463** Remove a file. 463** Remove a file.
464** On error put 0 on stack, otherwise put 1. 464** On error put 0 on stack, otherwise put 1.
465*/ 465*/
466void io_remove (void) 466static void io_remove (void)
467{ 467{
468 lua_Object o = lua_getparam (1); 468 lua_Object o = lua_getparam (1);
469 if (o == NULL || !lua_isstring (o)) 469 if (o == NULL || !lua_isstring (o))
@@ -481,6 +481,35 @@ void io_remove (void)
481 return; 481 return;
482} 482}
483 483
484
485/*
486** To get a environment variables
487*/
488static void io_getenv (void)
489{
490 lua_Object s = lua_getparam(1);
491 if (!lua_isstring(s))
492 lua_pushnil();
493 else
494 {
495 char *env = getenv(lua_getstring(s));
496 if (env == NULL) lua_pushnil();
497 else lua_pushstring(env);
498 }
499}
500
501/*
502** To abort
503*/
504static void io_abort (void)
505{
506 lua_Object o = lua_getparam(1);
507 if (lua_isstring(o))
508 printf("%s\n", lua_getstring(o));
509 exit(1);
510}
511
512
484/* 513/*
485** Open io library 514** Open io library
486*/ 515*/
@@ -493,4 +522,6 @@ void iolib_open (void)
493 lua_register ("write", io_write); 522 lua_register ("write", io_write);
494 lua_register ("execute", io_execute); 523 lua_register ("execute", io_execute);
495 lua_register ("remove", io_remove); 524 lua_register ("remove", io_remove);
525 lua_register ("getenv", io_getenv);
526 lua_register ("abort", io_abort);
496} 527}