diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-02 18:29:39 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-02 18:29:39 -0200 |
commit | ae77864844d6b933eb8be68694cbb8498af165dc (patch) | |
tree | 1539becf8867562ebad1173d1aa129341bd68c94 | |
parent | 0162decc58cca093a7deeec6651718a5d301468b (diff) | |
download | lua-ae77864844d6b933eb8be68694cbb8498af165dc.tar.gz lua-ae77864844d6b933eb8be68694cbb8498af165dc.tar.bz2 lua-ae77864844d6b933eb8be68694cbb8498af165dc.zip |
tags T_NIL, etc, changed to LUA_T_NIL, etc
some lua_ functions changed form opcode.c to here
-rw-r--r-- | inout.c | 91 | ||||
-rw-r--r-- | inout.h | 7 |
2 files changed, 87 insertions, 11 deletions
@@ -2,9 +2,10 @@ | |||
2 | ** inout.c | 2 | ** inout.c |
3 | ** Provide function to realise the input/output function and debugger | 3 | ** Provide function to realise the input/output function and debugger |
4 | ** facilities. | 4 | ** facilities. |
5 | ** Also provides some predefined lua functions. | ||
5 | */ | 6 | */ |
6 | 7 | ||
7 | char *rcs_inout="$Id: inout.c,v 2.4 1994/10/11 14:38:17 celes Exp $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.5 1994/10/17 19:04:19 celes Exp roberto $"; |
8 | 9 | ||
9 | #include <stdio.h> | 10 | #include <stdio.h> |
10 | #include <stdlib.h> | 11 | #include <stdlib.h> |
@@ -108,15 +109,6 @@ void lua_closestring (void) | |||
108 | lua_delfile(); | 109 | lua_delfile(); |
109 | } | 110 | } |
110 | 111 | ||
111 | /* | ||
112 | ** Call user function to handle error messages, if registred. Or report error | ||
113 | ** using standard function (fprintf). | ||
114 | */ | ||
115 | void lua_error (char *s) | ||
116 | { | ||
117 | if (usererror != NULL) usererror (s); | ||
118 | else fprintf (stderr, "lua: %s\n", s); | ||
119 | } | ||
120 | 112 | ||
121 | /* | 113 | /* |
122 | ** Called to execute SETFUNCTION opcode, this function pushs a function into | 114 | ** Called to execute SETFUNCTION opcode, this function pushs a function into |
@@ -176,3 +168,82 @@ void lua_reportbug (char *s) | |||
176 | lua_error (msg); | 168 | lua_error (msg); |
177 | } | 169 | } |
178 | 170 | ||
171 | |||
172 | /* | ||
173 | ** Internal function: do a string | ||
174 | */ | ||
175 | void lua_internaldostring (void) | ||
176 | { | ||
177 | lua_Object obj = lua_getparam (1); | ||
178 | if (lua_isstring(obj) && !lua_dostring(lua_getstring(obj))) | ||
179 | lua_pushnumber(1); | ||
180 | else | ||
181 | lua_pushnil(); | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | ** Internal function: do a file | ||
186 | */ | ||
187 | void lua_internaldofile (void) | ||
188 | { | ||
189 | lua_Object obj = lua_getparam (1); | ||
190 | if (lua_isstring(obj) && !lua_dofile(lua_getstring(obj))) | ||
191 | lua_pushnumber(1); | ||
192 | else | ||
193 | lua_pushnil(); | ||
194 | } | ||
195 | |||
196 | /* | ||
197 | ** Internal function: print object values | ||
198 | */ | ||
199 | void lua_print (void) | ||
200 | { | ||
201 | int i=1; | ||
202 | Object *obj; | ||
203 | while ((obj=lua_getparam (i++)) != NULL) | ||
204 | { | ||
205 | if (lua_isnumber(obj)) printf("%g\n",lua_getnumber (obj)); | ||
206 | else if (lua_isstring(obj)) printf("%s\n",lua_getstring (obj)); | ||
207 | else if (lua_isfunction(obj)) printf("function: %p\n",bvalue(obj)); | ||
208 | else if (lua_iscfunction(obj)) printf("cfunction: %p\n",lua_getcfunction (obj) | ||
209 | ); | ||
210 | else if (lua_isuserdata(obj)) printf("userdata: %p\n",lua_getuserdata (obj)); | ||
211 | else if (lua_istable(obj)) printf("table: %p\n",obj); | ||
212 | else if (lua_isnil(obj)) printf("nil\n"); | ||
213 | else printf("invalid value to print\n"); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | |||
218 | /* | ||
219 | ** Internal function: return an object type. | ||
220 | */ | ||
221 | void lua_type (void) | ||
222 | { | ||
223 | Object *o = lua_getparam(1); | ||
224 | switch (tag(o)) | ||
225 | { | ||
226 | case LUA_T_NIL : | ||
227 | lua_pushstring("nil"); | ||
228 | break; | ||
229 | case LUA_T_NUMBER : | ||
230 | lua_pushstring("number"); | ||
231 | break; | ||
232 | case LUA_T_STRING : | ||
233 | lua_pushstring("string"); | ||
234 | break; | ||
235 | case LUA_T_ARRAY : | ||
236 | lua_pushstring("table"); | ||
237 | break; | ||
238 | case LUA_T_FUNCTION : | ||
239 | lua_pushstring("function"); | ||
240 | break; | ||
241 | case LUA_T_CFUNCTION : | ||
242 | lua_pushstring("cfunction"); | ||
243 | break; | ||
244 | default : | ||
245 | lua_pushstring("userdata"); | ||
246 | break; | ||
247 | } | ||
248 | } | ||
249 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: inout.h,v 1.1 1993/12/17 18:41:19 celes Exp $ | 2 | ** $Id: inout.h,v 1.2 1994/10/11 14:38:17 celes Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | 5 | ||
@@ -18,4 +18,9 @@ int lua_pushfunction (char *file, int function); | |||
18 | void lua_popfunction (void); | 18 | void lua_popfunction (void); |
19 | void lua_reportbug (char *s); | 19 | void lua_reportbug (char *s); |
20 | 20 | ||
21 | void lua_internaldofile (void); | ||
22 | void lua_internaldostring (void); | ||
23 | void lua_print (void); | ||
24 | void lua_type (void); | ||
25 | |||
21 | #endif | 26 | #endif |