diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-04 19:24:51 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-04 19:24:51 -0300 |
commit | 42fa305649199712aad1c96beadb944b01277e3f (patch) | |
tree | d20afcf78aebc8b7fad91ce4e3b9061c2a29b000 /inout.c | |
parent | 9319735744404831f7153653930d56826a4d2f6a (diff) | |
download | lua-42fa305649199712aad1c96beadb944b01277e3f.tar.gz lua-42fa305649199712aad1c96beadb944b01277e3f.tar.bz2 lua-42fa305649199712aad1c96beadb944b01277e3f.zip |
better error messages;
better names for some API functions.
Diffstat (limited to 'inout.c')
-rw-r--r-- | inout.c | 47 |
1 files changed, 23 insertions, 24 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.53 1997/04/02 22:53:35 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.54 1997/04/02 23:04:12 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <string.h> | 11 | #include <string.h> |
@@ -28,7 +28,7 @@ Word lua_linenumber; | |||
28 | char *lua_parsedfile; | 28 | char *lua_parsedfile; |
29 | 29 | ||
30 | 30 | ||
31 | static char *typenames[] = { /* ORDER LUA_T */ | 31 | char *luaI_typenames[] = { /* ORDER LUA_T */ |
32 | "userdata", "line", "cmark", "mark", "function", | 32 | "userdata", "line", "cmark", "mark", "function", |
33 | "function", "table", "string", "number", "nil", | 33 | "function", "table", "string", "number", "nil", |
34 | NULL | 34 | NULL |
@@ -95,8 +95,7 @@ void lua_openstring (char *s) | |||
95 | char buff[SIZE_PREF+25]; | 95 | char buff[SIZE_PREF+25]; |
96 | lua_setinput(stringinput); | 96 | lua_setinput(stringinput); |
97 | st = s; | 97 | st = s; |
98 | strcpy(buff, "(dostring) >> "); | 98 | sprintf(buff, "(dostring) >> %.20s", s); |
99 | strncat(buff, s, SIZE_PREF); | ||
100 | if (strlen(s) > SIZE_PREF) strcat(buff, "..."); | 99 | if (strlen(s) > SIZE_PREF) strcat(buff, "..."); |
101 | lua_parsedfile = luaI_createfixedstring(buff)->str; | 100 | lua_parsedfile = luaI_createfixedstring(buff)->str; |
102 | } | 101 | } |
@@ -148,7 +147,7 @@ static char *tostring (lua_Object obj) | |||
148 | return lua_getstring(obj); | 147 | return lua_getstring(obj); |
149 | case LUA_T_ARRAY: case LUA_T_FUNCTION: | 148 | case LUA_T_ARRAY: case LUA_T_FUNCTION: |
150 | case LUA_T_CFUNCTION: case LUA_T_NIL: | 149 | case LUA_T_CFUNCTION: case LUA_T_NIL: |
151 | return typenames[-ttype(o)]; | 150 | return luaI_typenames[-ttype(o)]; |
152 | case LUA_T_USERDATA: { | 151 | case LUA_T_USERDATA: { |
153 | char *buff = luaI_buffer(100); | 152 | char *buff = luaI_buffer(100); |
154 | int size = o->value.ts->size; | 153 | int size = o->value.ts->size; |
@@ -181,7 +180,7 @@ static void luaI_type (void) | |||
181 | { | 180 | { |
182 | lua_Object o = lua_getparam(1); | 181 | lua_Object o = lua_getparam(1); |
183 | luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument"); | 182 | luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument"); |
184 | lua_pushstring(typenames[-ttype(luaI_Address(o))]); | 183 | lua_pushstring(luaI_typenames[-ttype(luaI_Address(o))]); |
185 | lua_pushnumber(lua_tag(o)); | 184 | lua_pushnumber(lua_tag(o)); |
186 | } | 185 | } |
187 | 186 | ||
@@ -219,12 +218,12 @@ static void luaI_setglobal (void) | |||
219 | lua_pushobject(value); /* return given value */ | 218 | lua_pushobject(value); /* return given value */ |
220 | } | 219 | } |
221 | 220 | ||
222 | static void luaI_basicsetglobal (void) | 221 | static void luaI_rawsetglobal (void) |
223 | { | 222 | { |
224 | lua_Object value = lua_getparam(2); | 223 | lua_Object value = lua_getparam(2); |
225 | luaL_arg_check(value != LUA_NOOBJECT, "basicsetglobal", 2, NULL); | 224 | luaL_arg_check(value != LUA_NOOBJECT, "rawsetglobal", 2, NULL); |
226 | lua_pushobject(value); | 225 | lua_pushobject(value); |
227 | lua_basicsetglobal(luaL_check_string(1, "basicsetglobal")); | 226 | lua_rawsetglobal(luaL_check_string(1, "rawsetglobal")); |
228 | lua_pushobject(value); /* return given value */ | 227 | lua_pushobject(value); /* return given value */ |
229 | } | 228 | } |
230 | 229 | ||
@@ -233,9 +232,9 @@ static void luaI_getglobal (void) | |||
233 | lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal"))); | 232 | lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal"))); |
234 | } | 233 | } |
235 | 234 | ||
236 | static void luaI_basicgetglobal (void) | 235 | static void luaI_rawgetglobal (void) |
237 | { | 236 | { |
238 | lua_pushobject(lua_basicgetglobal(luaL_check_string(1, "basicgetglobal"))); | 237 | lua_pushobject(lua_rawgetglobal(luaL_check_string(1, "rawgetglobal"))); |
239 | } | 238 | } |
240 | 239 | ||
241 | static void luatag (void) | 240 | static void luatag (void) |
@@ -291,28 +290,28 @@ static void luaIl_newtag (void) | |||
291 | lua_pushnumber(lua_newtag()); | 290 | lua_pushnumber(lua_newtag()); |
292 | } | 291 | } |
293 | 292 | ||
294 | static void basicindex (void) | 293 | static void rawgettable (void) |
295 | { | 294 | { |
296 | lua_Object t = lua_getparam(1); | 295 | lua_Object t = lua_getparam(1); |
297 | lua_Object i = lua_getparam(2); | 296 | lua_Object i = lua_getparam(2); |
298 | luaL_arg_check(t != LUA_NOOBJECT, "basicindex", 1, NULL); | 297 | luaL_arg_check(t != LUA_NOOBJECT, "rawgettable", 1, NULL); |
299 | luaL_arg_check(i != LUA_NOOBJECT, "basicindex", 2, NULL); | 298 | luaL_arg_check(i != LUA_NOOBJECT, "rawgettable", 2, NULL); |
300 | lua_pushobject(t); | 299 | lua_pushobject(t); |
301 | lua_pushobject(i); | 300 | lua_pushobject(i); |
302 | lua_pushobject(lua_basicindex()); | 301 | lua_pushobject(lua_rawgettable()); |
303 | } | 302 | } |
304 | 303 | ||
305 | static void basicstoreindex (void) | 304 | static void rawsettable (void) |
306 | { | 305 | { |
307 | lua_Object t = lua_getparam(1); | 306 | lua_Object t = lua_getparam(1); |
308 | lua_Object i = lua_getparam(2); | 307 | lua_Object i = lua_getparam(2); |
309 | lua_Object v = lua_getparam(3); | 308 | lua_Object v = lua_getparam(3); |
310 | luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT, | 309 | luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT, |
311 | "basicindex", 0, NULL); | 310 | "rawsettable", 0, NULL); |
312 | lua_pushobject(t); | 311 | lua_pushobject(t); |
313 | lua_pushobject(i); | 312 | lua_pushobject(i); |
314 | lua_pushobject(v); | 313 | lua_pushobject(v); |
315 | lua_basicstoreindex(); | 314 | lua_rawsettable(); |
316 | } | 315 | } |
317 | 316 | ||
318 | 317 | ||
@@ -325,10 +324,6 @@ static struct { | |||
325 | lua_CFunction func; | 324 | lua_CFunction func; |
326 | } int_funcs[] = { | 325 | } int_funcs[] = { |
327 | {"assert", luaI_assert}, | 326 | {"assert", luaI_assert}, |
328 | {"basicgetglobal", luaI_basicgetglobal}, | ||
329 | {"basicindex", basicindex}, | ||
330 | {"basicsetglobal", luaI_basicsetglobal}, | ||
331 | {"basicstoreindex", basicstoreindex}, | ||
332 | {"call", luaI_call}, | 327 | {"call", luaI_call}, |
333 | {"dofile", lua_internaldofile}, | 328 | {"dofile", lua_internaldofile}, |
334 | {"dostring", lua_internaldostring}, | 329 | {"dostring", lua_internaldostring}, |
@@ -338,11 +333,15 @@ static struct { | |||
338 | {"next", lua_next}, | 333 | {"next", lua_next}, |
339 | {"nextvar", luaI_nextvar}, | 334 | {"nextvar", luaI_nextvar}, |
340 | {"print", luaI_print}, | 335 | {"print", luaI_print}, |
336 | {"rawgetglobal", luaI_rawgetglobal}, | ||
337 | {"rawgettable", rawgettable}, | ||
338 | {"rawsetglobal", luaI_rawsetglobal}, | ||
339 | {"rawsettable", rawsettable}, | ||
341 | {"seterrormethod", luaI_seterrormethod}, | 340 | {"seterrormethod", luaI_seterrormethod}, |
342 | {"setfallback", luaI_setfallback}, | 341 | {"setfallback", luaI_setfallback}, |
343 | {"setglobal", luaI_setglobal}, | 342 | {"setglobal", luaI_setglobal}, |
344 | {"setintmethod", luaI_setintmethod}, | 343 | {"settagmethod", luaI_settagmethod}, |
345 | {"getintmethod", luaI_getintmethod}, | 344 | {"gettagmethod", luaI_gettagmethod}, |
346 | {"settag", luaIl_settag}, | 345 | {"settag", luaIl_settag}, |
347 | {"tonumber", lua_obj2number}, | 346 | {"tonumber", lua_obj2number}, |
348 | {"tostring", luaI_tostring}, | 347 | {"tostring", luaI_tostring}, |