diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-26 12:05:28 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-26 12:05:28 -0200 |
| commit | d845963349dbf5956cb527f3416af0bd1894d8f7 (patch) | |
| tree | c4bb00b65ffdc09a4ba98f00806fdcf291c91812 | |
| parent | 8dae4657a120a0f01fa599014a55b5d56e846998 (diff) | |
| download | lua-d845963349dbf5956cb527f3416af0bd1894d8f7.tar.gz lua-d845963349dbf5956cb527f3416af0bd1894d8f7.tar.bz2 lua-d845963349dbf5956cb527f3416af0bd1894d8f7.zip | |
"setglobal" and "getglobal" moved to inout.c, as it concentrates pre-defined
library.
new function "assert".
| -rw-r--r-- | inout.c | 39 | ||||
| -rw-r--r-- | inout.h | 7 |
2 files changed, 35 insertions, 11 deletions
| @@ -5,7 +5,7 @@ | |||
| 5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | char *rcs_inout="$Id: inout.c,v 2.25 1995/10/25 13:05:51 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.26 1996/01/22 17:40:00 roberto Exp roberto $"; |
| 9 | 9 | ||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| @@ -54,9 +54,9 @@ static int stringinput (void) | |||
| 54 | 54 | ||
| 55 | /* | 55 | /* |
| 56 | ** Function to open a file to be input unit. | 56 | ** Function to open a file to be input unit. |
| 57 | ** Return 0 on success or error message on error. | 57 | ** Return 0 on success or 1 error. |
| 58 | */ | 58 | */ |
| 59 | char *lua_openfile (char *fn) | 59 | int lua_openfile (char *fn) |
| 60 | { | 60 | { |
| 61 | lua_setinput (fileinput); | 61 | lua_setinput (fileinput); |
| 62 | if (fn == NULL) | 62 | if (fn == NULL) |
| @@ -67,14 +67,10 @@ char *lua_openfile (char *fn) | |||
| 67 | else | 67 | else |
| 68 | fp = fopen (fn, "r"); | 68 | fp = fopen (fn, "r"); |
| 69 | if (fp == NULL) | 69 | if (fp == NULL) |
| 70 | { | 70 | return 1; |
| 71 | static char buff[255]; | ||
| 72 | sprintf(buff, "unable to open file `%.200s'", fn); | ||
| 73 | return buff; | ||
| 74 | } | ||
| 75 | lua_linenumber = 1; | 71 | lua_linenumber = 1; |
| 76 | lua_parsedfile = lua_constcreate(fn)->ts.str; | 72 | lua_parsedfile = lua_constcreate(fn)->ts.str; |
| 77 | return NULL; | 73 | return 0; |
| 78 | } | 74 | } |
| 79 | 75 | ||
| 80 | /* | 76 | /* |
| @@ -231,3 +227,28 @@ void luaI_error (void) | |||
| 231 | lua_error(s); | 227 | lua_error(s); |
| 232 | } | 228 | } |
| 233 | 229 | ||
| 230 | void luaI_assert (void) | ||
| 231 | { | ||
| 232 | lua_Object p = lua_getparam(1); | ||
| 233 | if (p == LUA_NOOBJECT || lua_isnil(p)) | ||
| 234 | lua_error("assertion failed!"); | ||
| 235 | } | ||
| 236 | |||
| 237 | void luaI_setglobal (void) | ||
| 238 | { | ||
| 239 | lua_Object name = lua_getparam(1); | ||
| 240 | lua_Object value = lua_getparam(2); | ||
| 241 | if (!lua_isstring(name)) | ||
| 242 | lua_error("incorrect argument to function `setglobal'"); | ||
| 243 | lua_pushobject(value); | ||
| 244 | lua_storeglobal(lua_getstring(name)); | ||
| 245 | lua_pushobject(value); /* return given value */ | ||
| 246 | } | ||
| 247 | |||
| 248 | void luaI_getglobal (void) | ||
| 249 | { | ||
| 250 | lua_Object name = lua_getparam(1); | ||
| 251 | if (!lua_isstring(name)) | ||
| 252 | lua_error("incorrect argument to function `getglobal'"); | ||
| 253 | lua_pushobject(lua_getglobal(lua_getstring(name))); | ||
| 254 | } | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: inout.h,v 1.10 1995/10/17 11:58:41 roberto Exp roberto $ | 2 | ** $Id: inout.h,v 1.11 1996/01/22 17:40:00 roberto Exp roberto $ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | 5 | ||
| @@ -14,7 +14,7 @@ extern Bool lua_debug; | |||
| 14 | extern Word lua_debugline; | 14 | extern Word lua_debugline; |
| 15 | extern char *lua_parsedfile; | 15 | extern char *lua_parsedfile; |
| 16 | 16 | ||
| 17 | char *lua_openfile (char *fn); | 17 | int lua_openfile (char *fn); |
| 18 | void lua_closefile (void); | 18 | void lua_closefile (void); |
| 19 | void lua_openstring (char *s); | 19 | void lua_openstring (char *s); |
| 20 | void lua_closestring (void); | 20 | void lua_closestring (void); |
| @@ -26,5 +26,8 @@ void luaI_print (void); | |||
| 26 | void luaI_type (void); | 26 | void luaI_type (void); |
| 27 | void lua_obj2number (void); | 27 | void lua_obj2number (void); |
| 28 | void luaI_error (void); | 28 | void luaI_error (void); |
| 29 | void luaI_assert (void); | ||
| 30 | void luaI_setglobal (void); | ||
| 31 | void luaI_getglobal (void); | ||
| 29 | 32 | ||
| 30 | #endif | 33 | #endif |
