diff --git a/inout.c b/inout.c index d59bf274..23d69158 100644 --- a/inout.c +++ b/inout.c @@ -5,7 +5,7 @@ ** Also provides some predefined lua functions. */ -char *rcs_inout="$Id: inout.c,v 2.25 1995/10/25 13:05:51 roberto Exp roberto $"; +char *rcs_inout="$Id: inout.c,v 2.26 1996/01/22 17:40:00 roberto Exp roberto $"; #include #include @@ -54,9 +54,9 @@ static int stringinput (void) /* ** Function to open a file to be input unit. -** Return 0 on success or error message on error. +** Return 0 on success or 1 error. */ -char *lua_openfile (char *fn) +int lua_openfile (char *fn) { lua_setinput (fileinput); if (fn == NULL) @@ -67,14 +67,10 @@ char *lua_openfile (char *fn) else fp = fopen (fn, "r"); if (fp == NULL) - { - static char buff[255]; - sprintf(buff, "unable to open file `%.200s'", fn); - return buff; - } + return 1; lua_linenumber = 1; lua_parsedfile = lua_constcreate(fn)->ts.str; - return NULL; + return 0; } /* @@ -231,3 +227,28 @@ void luaI_error (void) lua_error(s); } +void luaI_assert (void) +{ + lua_Object p = lua_getparam(1); + if (p == LUA_NOOBJECT || lua_isnil(p)) + lua_error("assertion failed!"); +} + +void luaI_setglobal (void) +{ + lua_Object name = lua_getparam(1); + lua_Object value = lua_getparam(2); + if (!lua_isstring(name)) + lua_error("incorrect argument to function `setglobal'"); + lua_pushobject(value); + lua_storeglobal(lua_getstring(name)); + lua_pushobject(value); /* return given value */ +} + +void luaI_getglobal (void) +{ + lua_Object name = lua_getparam(1); + if (!lua_isstring(name)) + lua_error("incorrect argument to function `getglobal'"); + lua_pushobject(lua_getglobal(lua_getstring(name))); +} diff --git a/inout.h b/inout.h index e145c341..2ad80308 100644 --- a/inout.h +++ b/inout.h @@ -1,5 +1,5 @@ /* -** $Id: inout.h,v 1.10 1995/10/17 11:58:41 roberto Exp roberto $ +** $Id: inout.h,v 1.11 1996/01/22 17:40:00 roberto Exp roberto $ */ @@ -14,7 +14,7 @@ extern Bool lua_debug; extern Word lua_debugline; extern char *lua_parsedfile; -char *lua_openfile (char *fn); +int lua_openfile (char *fn); void lua_closefile (void); void lua_openstring (char *s); void lua_closestring (void); @@ -26,5 +26,8 @@ void luaI_print (void); void luaI_type (void); void lua_obj2number (void); void luaI_error (void); +void luaI_assert (void); +void luaI_setglobal (void); +void luaI_getglobal (void); #endif