aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-04 19:24:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-04 19:24:51 -0300
commit42fa305649199712aad1c96beadb944b01277e3f (patch)
treed20afcf78aebc8b7fad91ce4e3b9061c2a29b000
parent9319735744404831f7153653930d56826a4d2f6a (diff)
downloadlua-42fa305649199712aad1c96beadb944b01277e3f.tar.gz
lua-42fa305649199712aad1c96beadb944b01277e3f.tar.bz2
lua-42fa305649199712aad1c96beadb944b01277e3f.zip
better error messages;
better names for some API functions.
-rw-r--r--fallback.c33
-rw-r--r--fallback.h8
-rw-r--r--inout.c47
-rw-r--r--iolib.c12
-rw-r--r--lua.c6
-rw-r--r--lua.h30
-rw-r--r--mathlib.c4
-rw-r--r--opcode.c41
-rw-r--r--opcode.h4
-rw-r--r--strlib.c22
10 files changed, 107 insertions, 100 deletions
diff --git a/fallback.c b/fallback.c
index 6337a1b0..220fefa1 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: fallback.c,v 1.38 1997/04/02 23:04:12 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 2.1 1997/04/03 18:24:23 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -115,7 +115,7 @@ static int luaI_checkevent (char *name, char *list[])
115{ 115{
116 int e = findstring(name, list); 116 int e = findstring(name, list);
117 if (e < 0) 117 if (e < 0)
118 luaL_verror("invalid event name `%s'", name); 118 luaL_verror("`%s' is not a valid event name", name);
119 return e; 119 return e;
120} 120}
121 121
@@ -180,17 +180,19 @@ int lua_newtag (void)
180static void checktag (int tag) 180static void checktag (int tag)
181{ 181{
182 if (!(last_tag <= tag && tag <= 0)) 182 if (!(last_tag <= tag && tag <= 0))
183 lua_error("invalid tag"); 183 luaL_verror("%d is not a valid tag", tag);
184} 184}
185 185
186int luaI_userdatatag (int tag) 186void luaI_realtag (int tag)
187{ 187{
188 return (tag >= 0 || (last_tag <= tag && tag < LUA_T_NIL)); 188 if (!(last_tag <= tag && tag < LUA_T_NIL))
189 luaL_verror("tag %d is not result of `newtag'", tag);
189} 190}
190 191
191 192
192void luaI_settag (int tag, TObject *o) 193void luaI_settag (int tag, TObject *o)
193{ 194{
195 luaI_realtag(tag);
194 switch (ttype(o)) { 196 switch (ttype(o)) {
195 case LUA_T_ARRAY: 197 case LUA_T_ARRAY:
196 o->value.a->htag = tag; 198 o->value.a->htag = tag;
@@ -199,7 +201,7 @@ void luaI_settag (int tag, TObject *o)
199 o->value.ts->tag = tag; 201 o->value.ts->tag = tag;
200 break; 202 break;
201 default: 203 default:
202 lua_error("settag: cannot change tag of given object"); 204 luaL_verror("cannot change tag of a %s", luaI_typenames[-ttype(o)]);
203 } 205 }
204} 206}
205 207
@@ -223,25 +225,26 @@ TObject *luaI_getim (int tag, IMS event)
223} 225}
224 226
225 227
226void luaI_getintmethod (void) 228void luaI_gettagmethod (void)
227{ 229{
228 int t = (int)luaL_check_number(1, "getintmethod"); 230 int t = (int)luaL_check_number(1, "gettagmethod");
229 int e = luaI_checkevent(luaL_check_string(2, "getintmethod"), luaI_eventname); 231 int e = luaI_checkevent(luaL_check_string(2, "gettagmethod"), luaI_eventname);
230 checktag(t); 232 checktag(t);
231 if (validevent(t, e)) 233 if (validevent(t, e))
232 luaI_pushobject(&luaI_IMtable[-t].int_method[e]); 234 luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
233} 235}
234 236
235 237
236void luaI_setintmethod (void) 238void luaI_settagmethod (void)
237{ 239{
238 int t = (int)luaL_check_number(1, "setintmethod"); 240 int t = (int)luaL_check_number(1, "settagmethod");
239 int e = luaI_checkevent(luaL_check_string(2, "setintmethod"), luaI_eventname); 241 int e = luaI_checkevent(luaL_check_string(2, "settagmethod"), luaI_eventname);
240 lua_Object func = lua_getparam(3); 242 lua_Object func = lua_getparam(3);
241 checktag(t); 243 checktag(t);
242 if (!validevent(t, e)) 244 if (!validevent(t, e))
243 lua_error("cannot change this internal method"); 245 luaL_verror("cannot change internal method `%s' for tag %d",
244 luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "setintmethod", 246 luaI_eventname[e], t);
247 luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "settagmethod",
245 3, "function expected"); 248 3, "function expected");
246 luaI_pushobject(&luaI_IMtable[-t].int_method[e]); 249 luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
247 luaI_IMtable[-t].int_method[e] = *luaI_Address(func); 250 luaI_IMtable[-t].int_method[e] = *luaI_Address(func);
@@ -352,7 +355,7 @@ void luaI_setfallback (void)
352 replace = typeFB; 355 replace = typeFB;
353 } 356 }
354 else { 357 else {
355 lua_error("invalid fallback name"); 358 luaL_verror("`%s' is not a valid fallback name", name);
356 replace = NULL; /* to avoid warnings */ 359 replace = NULL; /* to avoid warnings */
357 } 360 }
358 if (oldfunc.ttype != LUA_T_NIL) 361 if (oldfunc.ttype != LUA_T_NIL)
diff --git a/fallback.h b/fallback.h
index 1275c6d4..00d23625 100644
--- a/fallback.h
+++ b/fallback.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: fallback.h,v 1.20 1997/04/02 22:52:42 roberto Exp roberto $ 2** $Id: fallback.h,v 1.21 1997/04/02 23:04:12 roberto Exp roberto $
3*/ 3*/
4 4
5#ifndef fallback_h 5#ifndef fallback_h
@@ -46,13 +46,13 @@ void luaI_invalidaterefs (void);
46char *luaI_travfallbacks (int (*fn)(TObject *)); 46char *luaI_travfallbacks (int (*fn)(TObject *));
47 47
48void luaI_settag (int tag, TObject *o); 48void luaI_settag (int tag, TObject *o);
49int luaI_userdatatag (int tag); 49void luaI_realtag (int tag);
50TObject *luaI_getim (int tag, IMS event); 50TObject *luaI_getim (int tag, IMS event);
51#define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e))) 51#define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e)))
52TObject *luaI_geterrorim (void); 52TObject *luaI_geterrorim (void);
53int luaI_tag (TObject *o); 53int luaI_tag (TObject *o);
54void luaI_setintmethod (void); 54void luaI_settagmethod (void);
55void luaI_getintmethod (void); 55void luaI_gettagmethod (void);
56void luaI_seterrormethod (void); 56void luaI_seterrormethod (void);
57void luaI_initfallbacks (void); 57void luaI_initfallbacks (void);
58 58
diff --git a/inout.c b/inout.c
index db48039d..178ccd58 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.53 1997/04/02 22:53:35 roberto Exp roberto $"; 8char *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;
28char *lua_parsedfile; 28char *lua_parsedfile;
29 29
30 30
31static char *typenames[] = { /* ORDER LUA_T */ 31char *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
222static void luaI_basicsetglobal (void) 221static 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
236static void luaI_basicgetglobal (void) 235static 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
241static void luatag (void) 240static 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
294static void basicindex (void) 293static 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
305static void basicstoreindex (void) 304static 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},
diff --git a/iolib.c b/iolib.c
index 1a2a9009..19a832f2 100644
--- a/iolib.c
+++ b/iolib.c
@@ -33,7 +33,7 @@ static void pushresult (int i)
33#ifndef NOSTRERROR 33#ifndef NOSTRERROR
34 lua_pushstring(strerror(errno)); 34 lua_pushstring(strerror(errno));
35#else 35#else
36 lua_pushstring("system unable to define the error"); 36 lua_pushstring("O.S. unable to define the error");
37#endif 37#endif
38 } 38 }
39} 39}
@@ -124,7 +124,7 @@ static void io_read (void)
124 } 124 }
125 else if (*p == '}') { 125 else if (*p == '}') {
126 if (inskip == 0) 126 if (inskip == 0)
127 lua_error("unbalanced `{...}' in read pattern"); 127 lua_error("unbalanced braces in read pattern");
128 inskip--; 128 inskip--;
129 p++; 129 p++;
130 } 130 }
@@ -248,7 +248,7 @@ static void lua_printstack (FILE *f)
248 fprintf(f, "function %s", name); 248 fprintf(f, "function %s", name);
249 break; 249 break;
250 case 'f': 250 case 'f':
251 fprintf(f, "`%s' fallback", name); 251 fprintf(f, "`%s' iternal method", name);
252 break; 252 break;
253 default: { 253 default: {
254 char *filename; 254 char *filename;
@@ -289,7 +289,7 @@ static void getbyte (void)
289 else { 289 else {
290 i--; 290 i--;
291 if (0 <= i && i < lua_getbindatasize(ud)) 291 if (0 <= i && i < lua_getbindatasize(ud))
292 lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i)); 292 lua_pushnumber(*(((char *)lua_getbindata(ud))+i));
293 else 293 else
294 lua_pushnil(); 294 lua_pushnil();
295 } 295 }
@@ -307,7 +307,7 @@ static void createuserdata (void)
307 lua_beginblock(); 307 lua_beginblock();
308 lua_pushobject(t); 308 lua_pushobject(t);
309 lua_pushnumber(i+1); 309 lua_pushnumber(i+1);
310 o = lua_basicindex(); 310 o = lua_rawgettable();
311 if (lua_isnil(o)) { 311 if (lua_isnil(o)) {
312 lua_endblock(); 312 lua_endblock();
313 break; 313 break;
@@ -317,7 +317,7 @@ static void createuserdata (void)
317 luaI_addchar(lua_getnumber(o)); 317 luaI_addchar(lua_getnumber(o));
318 lua_endblock(); 318 lua_endblock();
319 } 319 }
320 lua_pushbinarydata(luaI_addchar(0), i, tag); 320 lua_pushbindata(luaI_addchar(0), i, tag);
321} 321}
322 322
323 323
diff --git a/lua.c b/lua.c
index d5622d86..382b77bb 100644
--- a/lua.c
+++ b/lua.c
@@ -3,7 +3,7 @@
3** Linguagem para Usuarios de Aplicacao 3** Linguagem para Usuarios de Aplicacao
4*/ 4*/
5 5
6char *rcs_lua="$Id: lua.c,v 1.13 1996/07/06 20:20:35 roberto Exp roberto $"; 6char *rcs_lua="$Id: lua.c,v 1.14 1996/09/24 17:30:28 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -59,8 +59,8 @@ int main (int argc, char *argv[])
59 result = lua_dofile (argv[i]); 59 result = lua_dofile (argv[i]);
60 if (result) { 60 if (result) {
61 if (result == 2) { 61 if (result == 2) {
62 fprintf(stderr, "lua: cannot execute file `%s' - ", argv[i]); 62 fprintf(stderr, "lua: cannot execute file ");
63 perror(NULL); 63 perror(argv[i]);
64 } 64 }
65 return 1; 65 return 1;
66 } 66 }
diff --git a/lua.h b/lua.h
index 2c07125f..4ef9f60c 100644
--- a/lua.h
+++ b/lua.h
@@ -2,7 +2,7 @@
2** LUA - An Extensible Extension Language 2** LUA - An Extensible Extension Language
3** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 3** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
4** e-mail: lua@tecgraf.puc-rio.br 4** e-mail: lua@tecgraf.puc-rio.br
5** $Id: lua.h,v 3.42 1997/04/02 23:04:12 roberto Exp roberto $ 5** $Id: lua.h,v 4.1 1997/04/03 18:26:08 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -19,9 +19,8 @@
19typedef void (*lua_CFunction) (void); 19typedef void (*lua_CFunction) (void);
20typedef unsigned int lua_Object; 20typedef unsigned int lua_Object;
21 21
22lua_Object lua_setfallback (char *event, lua_CFunction fallback); 22void lua_settagmethod (int tag, char *event, lua_CFunction method);
23void lua_setintmethod (int tag, char *event, lua_CFunction method); 23void lua_gettagmethod (int tag, char *event); /* out: method */
24void lua_getintmethod (int tag, char *event); /* out: method */
25void lua_seterrormethod (lua_CFunction method); 24void lua_seterrormethod (lua_CFunction method);
26 25
27int lua_newtag (void); 26int lua_newtag (void);
@@ -53,26 +52,26 @@ int lua_isfunction (lua_Object object);
53float lua_getnumber (lua_Object object); 52float lua_getnumber (lua_Object object);
54char *lua_getstring (lua_Object object); 53char *lua_getstring (lua_Object object);
55lua_CFunction lua_getcfunction (lua_Object object); 54lua_CFunction lua_getcfunction (lua_Object object);
56void *lua_getbinarydata (lua_Object object); 55void *lua_getbindata (lua_Object object);
57int lua_getbindatasize (lua_Object object); 56int lua_getbindatasize (lua_Object object);
58 57
59void lua_pushnil (void); 58void lua_pushnil (void);
60void lua_pushnumber (float n); 59void lua_pushnumber (float n);
61void lua_pushstring (char *s); 60void lua_pushstring (char *s);
62void lua_pushcfunction (lua_CFunction fn); 61void lua_pushcfunction (lua_CFunction fn);
63void lua_pushbinarydata (void *buff, int size, int tag); 62void lua_pushbindata (void *buff, int size, int tag);
64void lua_pushusertag (void *u, int tag); 63void lua_pushusertag (void *u, int tag);
65void lua_pushobject (lua_Object object); 64void lua_pushobject (lua_Object object);
66 65
67lua_Object lua_getglobal (char *name); 66lua_Object lua_getglobal (char *name);
68lua_Object lua_basicgetglobal (char *name); 67lua_Object lua_rawgetglobal (char *name);
69void lua_setglobal (char *name); /* In: value */ 68void lua_setglobal (char *name); /* In: value */
70void lua_basicsetglobal (char *name); /* In: value */ 69void lua_rawsetglobal (char *name); /* In: value */
71 70
72void lua_storesubscript (void); /* In: table, index, value */ 71void lua_settable (void); /* In: table, index, value */
73void lua_basicstoreindex (void); /* In: table, index, value */ 72void lua_rawsettable (void); /* In: table, index, value */
74lua_Object lua_getsubscript (void); /* In: table, index */ 73lua_Object lua_gettable (void); /* In: table, index */
75lua_Object lua_basicindex (void); /* In: table, index */ 74lua_Object lua_rawgettable (void); /* In: table, index */
76 75
77int lua_tag (lua_Object object); 76int lua_tag (lua_Object object);
78 77
@@ -98,6 +97,8 @@ lua_Object lua_createtable (void);
98/* =============================================================== */ 97/* =============================================================== */
99/* for compatibility with old versions. Avoid using these macros/functions */ 98/* for compatibility with old versions. Avoid using these macros/functions */
100 99
100lua_Object lua_setfallback (char *event, lua_CFunction fallback);
101
101#define lua_storeglobal(n) lua_setglobal(n) 102#define lua_storeglobal(n) lua_setglobal(n)
102#define lua_type(o) (lua_tag(o)) 103#define lua_type(o) (lua_tag(o))
103 104
@@ -111,9 +112,10 @@ void *lua_getuserdata (lua_Object object);
111 112
112#define lua_pushliteral(o) lua_pushstring(o) 113#define lua_pushliteral(o) lua_pushstring(o)
113 114
114#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) 115#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
115#define lua_getfield(o,f) (lua_pushobject(o), lua_pushliteral(f), lua_getsubscript()) 116#define lua_getfield(o,f) (lua_pushobject(o), lua_pushliteral(f), lua_gettable())
116 117
117#define lua_copystring(o) (strdup(lua_getstring(o))) 118#define lua_copystring(o) (strdup(lua_getstring(o)))
118 119
120#define lua_getsubscript lua_gettable
119#endif 121#endif
diff --git a/mathlib.c b/mathlib.c
index 16d2a815..7a74fe14 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,7 +3,7 @@
3** Mathematics library to LUA 3** Mathematics library to LUA
4*/ 4*/
5 5
6char *rcs_mathlib="$Id: mathlib.c,v 1.20 1997/03/18 15:30:50 roberto Exp roberto $"; 6char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <math.h> 9#include <math.h>
@@ -210,6 +210,6 @@ static struct luaL_reg mathlib[] = {
210void mathlib_open (void) 210void mathlib_open (void)
211{ 211{
212 luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); 212 luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
213 lua_setintmethod(0, "pow", math_pow); 213 lua_settagmethod(0, "pow", math_pow);
214} 214}
215 215
diff --git a/opcode.c b/opcode.c
index 590c0ef7..2b1c02f8 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.93 1997/04/02 23:04:12 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.1 1997/04/03 18:27:06 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -19,6 +19,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.93 1997/04/02 23:04:12 roberto Exp roberto $
19#include "lua.h" 19#include "lua.h"
20#include "fallback.h" 20#include "fallback.h"
21#include "undump.h" 21#include "undump.h"
22#include "auxlib.h"
22 23
23#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) 24#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0))
24#define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) 25#define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0))
@@ -340,11 +341,11 @@ static void pushsubscript (void)
340} 341}
341 342
342 343
343lua_Object lua_basicindex (void) 344lua_Object lua_rawgettable (void)
344{ 345{
345 adjustC(2); 346 adjustC(2);
346 if (ttype(top-2) != LUA_T_ARRAY) 347 if (ttype(top-2) != LUA_T_ARRAY)
347 lua_error("indexed expression not a table in basic indexing"); 348 lua_error("indexed expression not a table in raw gettable");
348 else { 349 else {
349 TObject *h = lua_hashget(avalue(top-2), top-1); 350 TObject *h = lua_hashget(avalue(top-2), top-1);
350 --top; 351 --top;
@@ -360,7 +361,7 @@ lua_Object lua_basicindex (void)
360 361
361/* 362/*
362** Function to store indexed based on values at the top 363** Function to store indexed based on values at the top
363** mode = 0: basic store (without internal methods) 364** mode = 0: raw store (without internal methods)
364** mode = 1: normal store (with internal methods) 365** mode = 1: normal store (with internal methods)
365** mode = 2: "deep stack" store (with internal methods) 366** mode = 2: "deep stack" store (with internal methods)
366*/ 367*/
@@ -656,14 +657,14 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback)
656 return (Ref(top-1)); 657 return (Ref(top-1));
657} 658}
658 659
659void lua_getintmethod (int tag, char *event) 660void lua_gettagmethod (int tag, char *event)
660{ 661{
661 lua_pushnumber(tag); 662 lua_pushnumber(tag);
662 lua_pushstring(event); 663 lua_pushstring(event);
663 do_unprotectedrun(luaI_getintmethod, 2, 1); 664 do_unprotectedrun(luaI_gettagmethod, 2, 1);
664} 665}
665 666
666void lua_setintmethod (int tag, char *event, lua_CFunction method) 667void lua_settagmethod (int tag, char *event, lua_CFunction method)
667{ 668{
668 lua_pushnumber(tag); 669 lua_pushnumber(tag);
669 lua_pushstring(event); 670 lua_pushstring(event);
@@ -671,7 +672,7 @@ void lua_setintmethod (int tag, char *event, lua_CFunction method)
671 lua_pushcfunction (method); 672 lua_pushcfunction (method);
672 else 673 else
673 lua_pushnil(); 674 lua_pushnil();
674 do_unprotectedrun(luaI_setintmethod, 3, 1); 675 do_unprotectedrun(luaI_settagmethod, 3, 1);
675} 676}
676 677
677void lua_seterrormethod (lua_CFunction method) 678void lua_seterrormethod (lua_CFunction method)
@@ -685,7 +686,7 @@ void lua_seterrormethod (lua_CFunction method)
685** API: receives on the stack the table and the index. 686** API: receives on the stack the table and the index.
686** returns the value. 687** returns the value.
687*/ 688*/
688lua_Object lua_getsubscript (void) 689lua_Object lua_gettable (void)
689{ 690{
690 adjustC(2); 691 adjustC(2);
691 pushsubscript(); 692 pushsubscript();
@@ -729,13 +730,13 @@ void lua_settag (int tag)
729/* 730/*
730** API: receives on the stack the table, the index, and the new value. 731** API: receives on the stack the table, the index, and the new value.
731*/ 732*/
732void lua_storesubscript (void) 733void lua_settable (void)
733{ 734{
734 adjustC(3); 735 adjustC(3);
735 storesubscript(top-3, 1); 736 storesubscript(top-3, 1);
736} 737}
737 738
738void lua_basicstoreindex (void) 739void lua_rawsettable (void)
739{ 740{
740 adjustC(3); 741 adjustC(3);
741 storesubscript(top-3, 0); 742 storesubscript(top-3, 0);
@@ -825,7 +826,7 @@ char *lua_getstring (lua_Object object)
825 else return (svalue(Address(object))); 826 else return (svalue(Address(object)));
826} 827}
827 828
828void *lua_getbinarydata (lua_Object object) 829void *lua_getbindata (lua_Object object)
829{ 830{
830 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) 831 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
831 return NULL; 832 return NULL;
@@ -834,7 +835,7 @@ void *lua_getbinarydata (lua_Object object)
834 835
835void *lua_getuserdata (lua_Object object) 836void *lua_getuserdata (lua_Object object)
836{ 837{
837 void *add = lua_getbinarydata(object); 838 void *add = lua_getbindata(object);
838 if (add == NULL) return NULL; 839 if (add == NULL) return NULL;
839 else return *(void **)add; 840 else return *(void **)add;
840} 841}
@@ -875,7 +876,7 @@ void lua_pushref (int ref)
875{ 876{
876 TObject *o = luaI_getref(ref); 877 TObject *o = luaI_getref(ref);
877 if (o == NULL) 878 if (o == NULL)
878 lua_error("access to invalid (possibly garbage collected) reference"); 879 lua_error("access to invalid reference (possibly garbage collected)");
879 luaI_pushobject(o); 880 luaI_pushobject(o);
880} 881}
881 882
@@ -900,7 +901,7 @@ lua_Object lua_getglobal (char *name)
900} 901}
901 902
902 903
903lua_Object lua_basicgetglobal (char *name) 904lua_Object lua_rawgetglobal (char *name)
904{ 905{
905 adjustC(0); 906 adjustC(0);
906 *top = lua_table[luaI_findsymbolbyname(name)].object; 907 *top = lua_table[luaI_findsymbolbyname(name)].object;
@@ -938,7 +939,7 @@ void lua_setglobal (char *name)
938 setglobal(luaI_findsymbolbyname(name)); 939 setglobal(luaI_findsymbolbyname(name));
939} 940}
940 941
941void lua_basicsetglobal (char *name) 942void lua_rawsetglobal (char *name)
942{ 943{
943 Word n = luaI_findsymbolbyname(name); 944 Word n = luaI_findsymbolbyname(name);
944 adjustC(1); 945 adjustC(1);
@@ -989,13 +990,13 @@ void lua_pushcfunction (lua_CFunction fn)
989 incr_top; 990 incr_top;
990} 991}
991 992
992void lua_pushbinarydata (void *buff, int size, int tag) 993void lua_pushbindata (void *buff, int size, int tag)
993{ 994{
994 if (buff == NULL) 995 if (buff == NULL)
995 ttype(top) = LUA_T_NIL; 996 ttype(top) = LUA_T_NIL;
996 else { 997 else {
997 if (!luaI_userdatatag(tag)) 998 if (tag < 0)
998 lua_error("invalid tag for userdata"); 999 luaI_realtag(tag);
999 tsvalue(top) = luaI_createuserdata(buff, size, tag); 1000 tsvalue(top) = luaI_createuserdata(buff, size, tag);
1000 ttype(top) = LUA_T_USERDATA; 1001 ttype(top) = LUA_T_USERDATA;
1001 } 1002 }
@@ -1007,7 +1008,7 @@ void lua_pushbinarydata (void *buff, int size, int tag)
1007*/ 1008*/
1008void lua_pushusertag (void *u, int tag) 1009void lua_pushusertag (void *u, int tag)
1009{ 1010{
1010 lua_pushbinarydata(&u, sizeof(void *), tag); 1011 lua_pushbindata(&u, sizeof(void *), tag);
1011} 1012}
1012 1013
1013/* 1014/*
diff --git a/opcode.h b/opcode.h
index 89490262..957310f3 100644
--- a/opcode.h
+++ b/opcode.h
@@ -1,6 +1,6 @@
1/* 1/*
2** TeCGraf - PUC-Rio 2** TeCGraf - PUC-Rio
3** $Id: opcode.h,v 3.30 1997/03/20 19:20:43 roberto Exp roberto $ 3** $Id: opcode.h,v 3.31 1997/03/31 14:02:58 roberto Exp roberto $
4*/ 4*/
5 5
6#ifndef opcode_h 6#ifndef opcode_h
@@ -35,6 +35,8 @@ typedef enum
35#define NUM_TYPES 10 35#define NUM_TYPES 10
36 36
37 37
38extern char *luaI_typenames[];
39
38typedef enum { 40typedef enum {
39/* name parm before after side effect 41/* name parm before after side effect
40-----------------------------------------------------------------------------*/ 42-----------------------------------------------------------------------------*/
diff --git a/strlib.c b/strlib.c
index 8d9c00d8..8b57e391 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.37 1997/03/18 15:30:50 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.38 1997/03/26 22:23:15 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -84,7 +84,7 @@ static void str_tok (void)
84 lua_pushobject(t); 84 lua_pushobject(t);
85 lua_pushnumber(i++); 85 lua_pushnumber(i++);
86 lua_pushstring(s1); 86 lua_pushstring(s1);
87 lua_storesubscript(); 87 lua_settable();
88 s1 = NULL; /* prepare for next strtok */ 88 s1 = NULL; /* prepare for next strtok */
89 } 89 }
90 lua_pushobject(t); 90 lua_pushobject(t);
@@ -121,10 +121,10 @@ static void str_sub (void)
121*/ 121*/
122static void str_lower (void) 122static void str_lower (void)
123{ 123{
124 char *s = luaL_check_string(1, "strlower"); 124 char *s;
125 luaI_emptybuff(); 125 luaI_emptybuff();
126 while (*s) 126 for (s = luaL_check_string(1, "strlower"); *s; s++)
127 luaI_addchar(tolower((unsigned char)*s++)); 127 luaI_addchar(tolower((unsigned char)*s));
128 lua_pushstring(luaI_addchar(0)); 128 lua_pushstring(luaI_addchar(0));
129} 129}
130 130
@@ -133,10 +133,10 @@ static void str_lower (void)
133*/ 133*/
134static void str_upper (void) 134static void str_upper (void)
135{ 135{
136 char *s = luaL_check_string(1, "strupper"); 136 char *s;
137 luaI_emptybuff(); 137 luaI_emptybuff();
138 while (*s) 138 for (s = luaL_check_string(1, "strupper"); *s; s++)
139 luaI_addchar(toupper((unsigned char)*s++)); 139 luaI_addchar(toupper((unsigned char)*s));
140 lua_pushstring(luaI_addchar(0)); 140 lua_pushstring(luaI_addchar(0));
141} 141}
142 142
@@ -177,11 +177,11 @@ char *luaL_item_end (char *p)
177 switch (*p++) { 177 switch (*p++) {
178 case '\0': return p-1; 178 case '\0': return p-1;
179 case ESC: 179 case ESC:
180 if (*p == 0) lua_error("incorrect pattern"); 180 if (*p == 0) luaL_verror("incorrect pattern (ends with `%c')", ESC);
181 return p+1; 181 return p+1;
182 case '[': { 182 case '[': {
183 char *end = bracket_end(p); 183 char *end = bracket_end(p);
184 if (end == NULL) lua_error("incorrect pattern"); 184 if (end == NULL) lua_error("incorrect pattern (missing `]')");
185 return end+1; 185 return end+1;
186 } 186 }
187 default: 187 default:
@@ -492,7 +492,7 @@ static void str_format (void)
492 char *initf = strfrmt-1; /* -1 to include % */ 492 char *initf = strfrmt-1; /* -1 to include % */
493 strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0); 493 strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0);
494 if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */ 494 if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */
495 lua_error("invalid format (width/precision too long)"); 495 lua_error("invalid format (width or precision too long)");
496 strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */ 496 strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */
497 form[strfrmt-initf+1] = 0; 497 form[strfrmt-initf+1] = 0;
498 buff = openspace(1000); /* to store the formated value */ 498 buff = openspace(1000); /* to store the formated value */