aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-01-26 12:05:28 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-01-26 12:05:28 -0200
commitd845963349dbf5956cb527f3416af0bd1894d8f7 (patch)
treec4bb00b65ffdc09a4ba98f00806fdcf291c91812
parent8dae4657a120a0f01fa599014a55b5d56e846998 (diff)
downloadlua-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.c39
-rw-r--r--inout.h7
2 files changed, 35 insertions, 11 deletions
diff --git a/inout.c b/inout.c
index d59bf274..23d69158 100644
--- a/inout.c
+++ b/inout.c
@@ -5,7 +5,7 @@
5** Also provides some predefined lua functions. 5** Also provides some predefined lua functions.
6*/ 6*/
7 7
8char *rcs_inout="$Id: inout.c,v 2.25 1995/10/25 13:05:51 roberto Exp roberto $"; 8char *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*/
59char *lua_openfile (char *fn) 59int 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
230void 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
237void 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
248void 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}
diff --git a/inout.h b/inout.h
index e145c341..2ad80308 100644
--- a/inout.h
+++ b/inout.h
@@ -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;
14extern Word lua_debugline; 14extern Word lua_debugline;
15extern char *lua_parsedfile; 15extern char *lua_parsedfile;
16 16
17char *lua_openfile (char *fn); 17int lua_openfile (char *fn);
18void lua_closefile (void); 18void lua_closefile (void);
19void lua_openstring (char *s); 19void lua_openstring (char *s);
20void lua_closestring (void); 20void lua_closestring (void);
@@ -26,5 +26,8 @@ void luaI_print (void);
26void luaI_type (void); 26void luaI_type (void);
27void lua_obj2number (void); 27void lua_obj2number (void);
28void luaI_error (void); 28void luaI_error (void);
29void luaI_assert (void);
30void luaI_setglobal (void);
31void luaI_getglobal (void);
29 32
30#endif 33#endif