aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c155
-rw-r--r--lapi.h6
-rw-r--r--lauxlib.c41
-rw-r--r--lauxlib.h20
-rw-r--r--lbuiltin.c44
-rw-r--r--ldblib.c20
-rw-r--r--ldo.c26
-rw-r--r--ldo.h6
-rw-r--r--lfunc.c22
-rw-r--r--lfunc.h4
-rw-r--r--lgc.c52
-rw-r--r--lgc.h6
-rw-r--r--liolib.c48
-rw-r--r--llex.c16
-rw-r--r--llex.h6
-rw-r--r--lmathlib.c4
-rw-r--r--lmem.c30
-rw-r--r--lmem.h4
-rw-r--r--lobject.c18
-rw-r--r--lobject.h10
-rw-r--r--lparser.c25
-rw-r--r--lparser.h6
-rw-r--r--lstate.c8
-rw-r--r--lstring.c20
-rw-r--r--lstring.h12
-rw-r--r--lstrlib.c91
-rw-r--r--ltable.c14
-rw-r--r--ltable.h12
-rw-r--r--ltm.c22
-rw-r--r--ltm.h12
-rw-r--r--lua.c4
-rw-r--r--lua.h35
-rw-r--r--luadebug.h11
-rw-r--r--lualib.h6
-rw-r--r--lundump.c12
-rw-r--r--lundump.h6
-rw-r--r--lvm.c39
-rw-r--r--lvm.h6
-rw-r--r--lzio.c59
-rw-r--r--lzio.h20
40 files changed, 442 insertions, 516 deletions
diff --git a/lapi.c b/lapi.c
index ee982f31..dbeb4f59 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.46 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: lapi.c,v 1.47 1999/06/22 20:37:23 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,8 +24,8 @@
24#include "lvm.h" 24#include "lvm.h"
25 25
26 26
27char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" 27const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
28 "$Authors: " LUA_AUTHORS " $"; 28 "$Authors: " LUA_AUTHORS " $";
29 29
30 30
31 31
@@ -34,8 +34,7 @@ TObject *luaA_Address (lua_Object o) {
34} 34}
35 35
36 36
37static lua_Type normalized_type (TObject *o) 37static lua_Type normalized_type (const TObject *o) {
38{
39 int t = ttype(o); 38 int t = ttype(o);
40 switch (t) { 39 switch (t) {
41 case LUA_T_PMARK: 40 case LUA_T_PMARK:
@@ -50,21 +49,18 @@ static lua_Type normalized_type (TObject *o)
50} 49}
51 50
52 51
53static void set_normalized (TObject *d, TObject *s) 52static void set_normalized (TObject *d, const TObject *s) {
54{
55 d->value = s->value; 53 d->value = s->value;
56 d->ttype = normalized_type(s); 54 d->ttype = normalized_type(s);
57} 55}
58 56
59 57
60static TObject *luaA_protovalue (TObject *o) 58static const TObject *luaA_protovalue (const TObject *o) {
61{
62 return (normalized_type(o) == LUA_T_CLOSURE) ? protovalue(o) : o; 59 return (normalized_type(o) == LUA_T_CLOSURE) ? protovalue(o) : o;
63} 60}
64 61
65 62
66void luaA_packresults (void) 63void luaA_packresults (void) {
67{
68 luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top); 64 luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top);
69 incr_top; 65 incr_top;
70} 66}
@@ -76,14 +72,13 @@ int luaA_passresults (void) {
76} 72}
77 73
78 74
79static void checkCparams (int nParams) 75static void checkCparams (int nParams) {
80{
81 if (L->stack.top-L->stack.stack < L->Cstack.base+nParams) 76 if (L->stack.top-L->stack.stack < L->Cstack.base+nParams)
82 lua_error("API error - wrong number of arguments in C2lua stack"); 77 lua_error("API error - wrong number of arguments in C2lua stack");
83} 78}
84 79
85 80
86static lua_Object put_luaObject (TObject *o) { 81static lua_Object put_luaObject (const TObject *o) {
87 luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base); 82 luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
88 L->stack.stack[L->Cstack.base++] = *o; 83 L->stack.stack[L->Cstack.base++] = *o;
89 return L->Cstack.base; /* this is +1 real position (see Ref) */ 84 return L->Cstack.base; /* this is +1 real position (see Ref) */
@@ -115,8 +110,7 @@ lua_Object lua_pop (void) {
115** Get a parameter, returning the object handle or LUA_NOOBJECT on error. 110** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
116** 'number' must be 1 to get the first parameter. 111** 'number' must be 1 to get the first parameter.
117*/ 112*/
118lua_Object lua_lua2C (int number) 113lua_Object lua_lua2C (int number) {
119{
120 if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT; 114 if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
121 /* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) == 115 /* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) ==
122 L->stack.stack+(L->Cstack.lua2C+number-1)-L->stack.stack+1 == */ 116 L->stack.stack+(L->Cstack.lua2C+number-1)-L->stack.stack+1 == */
@@ -124,8 +118,7 @@ lua_Object lua_lua2C (int number)
124} 118}
125 119
126 120
127int lua_callfunction (lua_Object function) 121int lua_callfunction (lua_Object function) {
128{
129 if (function == LUA_NOOBJECT) 122 if (function == LUA_NOOBJECT)
130 return 1; 123 return 1;
131 else { 124 else {
@@ -136,14 +129,12 @@ int lua_callfunction (lua_Object function)
136} 129}
137 130
138 131
139lua_Object lua_gettagmethod (int tag, char *event) 132lua_Object lua_gettagmethod (int tag, const char *event) {
140{
141 return put_luaObject(luaT_gettagmethod(tag, event)); 133 return put_luaObject(luaT_gettagmethod(tag, event));
142} 134}
143 135
144 136
145lua_Object lua_settagmethod (int tag, char *event) 137lua_Object lua_settagmethod (int tag, const char *event) {
146{
147 checkCparams(1); 138 checkCparams(1);
148 luaT_settagmethod(tag, event, L->stack.top-1); 139 luaT_settagmethod(tag, event, L->stack.top-1);
149 return put_luaObjectonTop(); 140 return put_luaObjectonTop();
@@ -159,8 +150,7 @@ lua_Object lua_seterrormethod (void) {
159} 150}
160 151
161 152
162lua_Object lua_gettable (void) 153lua_Object lua_gettable (void) {
163{
164 checkCparams(2); 154 checkCparams(2);
165 luaV_gettable(); 155 luaV_gettable();
166 return put_luaObjectonTop(); 156 return put_luaObjectonTop();
@@ -190,8 +180,7 @@ void lua_rawsettable (void) {
190} 180}
191 181
192 182
193lua_Object lua_createtable (void) 183lua_Object lua_createtable (void) {
194{
195 TObject o; 184 TObject o;
196 luaC_checkGC(); 185 luaC_checkGC();
197 avalue(&o) = luaH_new(0); 186 avalue(&o) = luaH_new(0);
@@ -200,31 +189,27 @@ lua_Object lua_createtable (void)
200} 189}
201 190
202 191
203lua_Object lua_getglobal (char *name) 192lua_Object lua_getglobal (const char *name) {
204{
205 luaD_checkstack(2); /* may need that to call T.M. */ 193 luaD_checkstack(2); /* may need that to call T.M. */
206 luaV_getglobal(luaS_new(name)); 194 luaV_getglobal(luaS_new(name));
207 return put_luaObjectonTop(); 195 return put_luaObjectonTop();
208} 196}
209 197
210 198
211lua_Object lua_rawgetglobal (char *name) 199lua_Object lua_rawgetglobal (const char *name) {
212{
213 TaggedString *ts = luaS_new(name); 200 TaggedString *ts = luaS_new(name);
214 return put_luaObject(&ts->u.s.globalval); 201 return put_luaObject(&ts->u.s.globalval);
215} 202}
216 203
217 204
218void lua_setglobal (char *name) 205void lua_setglobal (const char *name) {
219{
220 checkCparams(1); 206 checkCparams(1);
221 luaD_checkstack(2); /* may need that to call T.M. */ 207 luaD_checkstack(2); /* may need that to call T.M. */
222 luaV_setglobal(luaS_new(name)); 208 luaV_setglobal(luaS_new(name));
223} 209}
224 210
225 211
226void lua_rawsetglobal (char *name) 212void lua_rawsetglobal (const char *name) {
227{
228 TaggedString *ts = luaS_new(name); 213 TaggedString *ts = luaS_new(name);
229 checkCparams(1); 214 checkCparams(1);
230 luaS_rawsetglobal(ts, --L->stack.top); 215 luaS_rawsetglobal(ts, --L->stack.top);
@@ -232,113 +217,96 @@ void lua_rawsetglobal (char *name)
232 217
233 218
234 219
235int lua_isnil (lua_Object o) 220int lua_isnil (lua_Object o) {
236{
237 return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL); 221 return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL);
238} 222}
239 223
240int lua_istable (lua_Object o) 224int lua_istable (lua_Object o) {
241{
242 return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY); 225 return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY);
243} 226}
244 227
245int lua_isuserdata (lua_Object o) 228int lua_isuserdata (lua_Object o) {
246{
247 return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA); 229 return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA);
248} 230}
249 231
250int lua_iscfunction (lua_Object o) 232int lua_iscfunction (lua_Object o) {
251{
252 return (lua_tag(o) == LUA_T_CPROTO); 233 return (lua_tag(o) == LUA_T_CPROTO);
253} 234}
254 235
255int lua_isnumber (lua_Object o) 236int lua_isnumber (lua_Object o) {
256{
257 return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0); 237 return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
258} 238}
259 239
260int lua_isstring (lua_Object o) 240int lua_isstring (lua_Object o) {
261{
262 int t = lua_tag(o); 241 int t = lua_tag(o);
263 return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); 242 return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
264} 243}
265 244
266int lua_isfunction (lua_Object o) 245int lua_isfunction (lua_Object o) {
267{
268 int t = lua_tag(o); 246 int t = lua_tag(o);
269 return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO); 247 return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO);
270} 248}
271 249
272 250
273double lua_getnumber (lua_Object object) 251double lua_getnumber (lua_Object object) {
274{
275 if (object == LUA_NOOBJECT) return 0.0; 252 if (object == LUA_NOOBJECT) return 0.0;
276 if (tonumber(Address(object))) return 0.0; 253 if (tonumber(Address(object))) return 0.0;
277 else return (nvalue(Address(object))); 254 else return (nvalue(Address(object)));
278} 255}
279 256
280char *lua_getstring (lua_Object object) 257const char *lua_getstring (lua_Object object) {
281{
282 luaC_checkGC(); /* "tostring" may create a new string */ 258 luaC_checkGC(); /* "tostring" may create a new string */
283 if (object == LUA_NOOBJECT || tostring(Address(object))) 259 if (object == LUA_NOOBJECT || tostring(Address(object)))
284 return NULL; 260 return NULL;
285 else return (svalue(Address(object))); 261 else return (svalue(Address(object)));
286} 262}
287 263
288long lua_strlen (lua_Object object) 264long lua_strlen (lua_Object object) {
289{
290 luaC_checkGC(); /* "tostring" may create a new string */ 265 luaC_checkGC(); /* "tostring" may create a new string */
291 if (object == LUA_NOOBJECT || tostring(Address(object))) 266 if (object == LUA_NOOBJECT || tostring(Address(object)))
292 return 0L; 267 return 0L;
293 else return (tsvalue(Address(object))->u.s.len); 268 else return (tsvalue(Address(object))->u.s.len);
294} 269}
295 270
296void *lua_getuserdata (lua_Object object) 271void *lua_getuserdata (lua_Object object) {
297{
298 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) 272 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
299 return NULL; 273 return NULL;
300 else return tsvalue(Address(object))->u.d.v; 274 else return tsvalue(Address(object))->u.d.v;
301} 275}
302 276
303lua_CFunction lua_getcfunction (lua_Object object) 277lua_CFunction lua_getcfunction (lua_Object object) {
304{
305 if (!lua_iscfunction(object)) 278 if (!lua_iscfunction(object))
306 return NULL; 279 return NULL;
307 else return fvalue(luaA_protovalue(Address(object))); 280 else return fvalue(luaA_protovalue(Address(object)));
308} 281}
309 282
310 283
311void lua_pushnil (void) 284void lua_pushnil (void) {
312{
313 ttype(L->stack.top) = LUA_T_NIL; 285 ttype(L->stack.top) = LUA_T_NIL;
314 incr_top; 286 incr_top;
315} 287}
316 288
317void lua_pushnumber (double n) 289void lua_pushnumber (double n) {
318{
319 ttype(L->stack.top) = LUA_T_NUMBER; 290 ttype(L->stack.top) = LUA_T_NUMBER;
320 nvalue(L->stack.top) = n; 291 nvalue(L->stack.top) = n;
321 incr_top; 292 incr_top;
322} 293}
323 294
324void lua_pushlstring (char *s, long len) 295void lua_pushlstring (const char *s, long len) {
325{
326 tsvalue(L->stack.top) = luaS_newlstr(s, len); 296 tsvalue(L->stack.top) = luaS_newlstr(s, len);
327 ttype(L->stack.top) = LUA_T_STRING; 297 ttype(L->stack.top) = LUA_T_STRING;
328 incr_top; 298 incr_top;
329 luaC_checkGC(); 299 luaC_checkGC();
330} 300}
331 301
332void lua_pushstring (char *s) 302void lua_pushstring (const char *s) {
333{
334 if (s == NULL) 303 if (s == NULL)
335 lua_pushnil(); 304 lua_pushnil();
336 else 305 else
337 lua_pushlstring(s, strlen(s)); 306 lua_pushlstring(s, strlen(s));
338} 307}
339 308
340void lua_pushcclosure (lua_CFunction fn, int n) 309void lua_pushcclosure (lua_CFunction fn, int n) {
341{
342 if (fn == NULL) 310 if (fn == NULL)
343 lua_error("API error - attempt to push a NULL Cfunction"); 311 lua_error("API error - attempt to push a NULL Cfunction");
344 checkCparams(n); 312 checkCparams(n);
@@ -349,8 +317,7 @@ void lua_pushcclosure (lua_CFunction fn, int n)
349 luaC_checkGC(); 317 luaC_checkGC();
350} 318}
351 319
352void lua_pushusertag (void *u, int tag) 320void lua_pushusertag (void *u, int tag) {
353{
354 if (tag < 0 && tag != LUA_ANYTAG) 321 if (tag < 0 && tag != LUA_ANYTAG)
355 luaT_realtag(tag); /* error if tag is not valid */ 322 luaT_realtag(tag); /* error if tag is not valid */
356 tsvalue(L->stack.top) = luaS_createudata(u, tag); 323 tsvalue(L->stack.top) = luaS_createudata(u, tag);
@@ -359,8 +326,7 @@ void lua_pushusertag (void *u, int tag)
359 luaC_checkGC(); 326 luaC_checkGC();
360} 327}
361 328
362void luaA_pushobject (TObject *o) 329void luaA_pushobject (const TObject *o) {
363{
364 *L->stack.top = *o; 330 *L->stack.top = *o;
365 incr_top; 331 incr_top;
366} 332}
@@ -373,12 +339,11 @@ void lua_pushobject (lua_Object o) {
373} 339}
374 340
375 341
376int lua_tag (lua_Object lo) 342int lua_tag (lua_Object lo) {
377{
378 if (lo == LUA_NOOBJECT) 343 if (lo == LUA_NOOBJECT)
379 return LUA_T_NIL; 344 return LUA_T_NIL;
380 else { 345 else {
381 TObject *o = Address(lo); 346 const TObject *o = Address(lo);
382 int t; 347 int t;
383 switch (t = ttype(o)) { 348 switch (t = ttype(o)) {
384 case LUA_T_USERDATA: 349 case LUA_T_USERDATA:
@@ -402,8 +367,7 @@ int lua_tag (lua_Object lo)
402} 367}
403 368
404 369
405void lua_settag (int tag) 370void lua_settag (int tag) {
406{
407 checkCparams(1); 371 checkCparams(1);
408 luaT_realtag(tag); 372 luaT_realtag(tag);
409 switch (ttype(L->stack.top-1)) { 373 switch (ttype(L->stack.top-1)) {
@@ -440,7 +404,7 @@ TaggedString *luaA_nextvar (TaggedString *g) {
440} 404}
441 405
442 406
443char *lua_nextvar (char *varname) { 407const char *lua_nextvar (const char *varname) {
444 TaggedString *g = (varname == NULL) ? NULL : luaS_new(varname); 408 TaggedString *g = (varname == NULL) ? NULL : luaS_new(varname);
445 g = luaA_nextvar(g); 409 g = luaA_nextvar(g);
446 if (g) { 410 if (g) {
@@ -454,7 +418,7 @@ char *lua_nextvar (char *varname) {
454} 418}
455 419
456 420
457int luaA_next (Hash *t, int i) { 421int luaA_next (const Hash *t, int i) {
458 int tsize = nhash(t); 422 int tsize = nhash(t);
459 for (; i<tsize; i++) { 423 for (; i<tsize; i++) {
460 Node *n = node(t, i); 424 Node *n = node(t, i);
@@ -469,7 +433,7 @@ int luaA_next (Hash *t, int i) {
469 433
470 434
471int lua_next (lua_Object o, int i) { 435int lua_next (lua_Object o, int i) {
472 TObject *t = Address(o); 436 const TObject *t = Address(o);
473 if (ttype(t) != LUA_T_ARRAY) 437 if (ttype(t) != LUA_T_ARRAY)
474 lua_error("API error - object is not a table in `lua_next'"); 438 lua_error("API error - object is not a table in `lua_next'");
475 i = luaA_next(avalue(t), i); 439 i = luaA_next(avalue(t), i);
@@ -519,8 +483,7 @@ int lua_setdebug (int debug) {
519*/ 483*/
520 484
521 485
522lua_Function lua_stackedfunction (int level) 486lua_Function lua_stackedfunction (int level) {
523{
524 StkId i; 487 StkId i;
525 for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) { 488 for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) {
526 int t = L->stack.stack[i].ttype; 489 int t = L->stack.stack[i].ttype;
@@ -533,20 +496,20 @@ lua_Function lua_stackedfunction (int level)
533 496
534 497
535int lua_nups (lua_Function func) { 498int lua_nups (lua_Function func) {
536 TObject *o = luaA_Address(func); 499 const TObject *o = luaA_Address(func);
537 return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems; 500 return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems;
538} 501}
539 502
540 503
541int lua_currentline (lua_Function func) 504int lua_currentline (lua_Function func) {
542{ 505 const TObject *f = Address(func);
543 TObject *f = Address(func);
544 return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ? 506 return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ?
545 (f+1)->value.i : -1; 507 (f+1)->value.i : -1;
546} 508}
547 509
548 510
549lua_Object lua_getlocal (lua_Function func, int local_number, char **name) { 511lua_Object lua_getlocal (lua_Function func, int local_number,
512 const char **name) {
550 /* check whether func is a Lua function */ 513 /* check whether func is a Lua function */
551 if (lua_tag(func) != LUA_T_PROTO) 514 if (lua_tag(func) != LUA_T_PROTO)
552 return LUA_NOOBJECT; 515 return LUA_NOOBJECT;
@@ -565,15 +528,14 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name) {
565} 528}
566 529
567 530
568int lua_setlocal (lua_Function func, int local_number) 531int lua_setlocal (lua_Function func, int local_number) {
569{
570 /* check whether func is a Lua function */ 532 /* check whether func is a Lua function */
571 if (lua_tag(func) != LUA_T_PROTO) 533 if (lua_tag(func) != LUA_T_PROTO)
572 return 0; 534 return 0;
573 else { 535 else {
574 TObject *f = Address(func); 536 TObject *f = Address(func);
575 TProtoFunc *fp = luaA_protovalue(f)->value.tf; 537 TProtoFunc *fp = luaA_protovalue(f)->value.tf;
576 char *name = luaF_getlocalname(fp, local_number, lua_currentline(func)); 538 const char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
577 checkCparams(1); 539 checkCparams(1);
578 --L->stack.top; 540 --L->stack.top;
579 if (name) { 541 if (name) {
@@ -588,11 +550,11 @@ int lua_setlocal (lua_Function func, int local_number)
588} 550}
589 551
590 552
591void lua_funcinfo (lua_Object func, char **source, int *linedefined) { 553void lua_funcinfo (lua_Object func, const char **source, int *linedefined) {
592 if (!lua_isfunction(func)) 554 if (!lua_isfunction(func))
593 lua_error("API error - `funcinfo' called with a non-function value"); 555 lua_error("API error - `funcinfo' called with a non-function value");
594 else { 556 else {
595 TObject *f = luaA_protovalue(Address(func)); 557 const TObject *f = luaA_protovalue(Address(func));
596 if (normalized_type(f) == LUA_T_PROTO) { 558 if (normalized_type(f) == LUA_T_PROTO) {
597 *source = tfvalue(f)->source->str; 559 *source = tfvalue(f)->source->str;
598 *linedefined = tfvalue(f)->lineDefined; 560 *linedefined = tfvalue(f)->lineDefined;
@@ -605,14 +567,13 @@ void lua_funcinfo (lua_Object func, char **source, int *linedefined) {
605} 567}
606 568
607 569
608static int checkfunc (TObject *o) 570static int checkfunc (TObject *o) {
609{
610 return luaO_equalObj(o, L->stack.top); 571 return luaO_equalObj(o, L->stack.top);
611} 572}
612 573
613 574
614char *lua_getobjname (lua_Object o, char **name) 575const char *lua_getobjname (lua_Object o, const char **name) {
615{ /* try to find a name for given function */ 576 /* try to find a name for given function */
616 set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */ 577 set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */
617 if ((*name = luaS_travsymbol(checkfunc)) != NULL) 578 if ((*name = luaS_travsymbol(checkfunc)) != NULL)
618 return "global"; 579 return "global";
@@ -662,7 +623,7 @@ int lua_ref (int lock) {
662 623
663 624
664lua_Object lua_getref (int ref) { 625lua_Object lua_getref (int ref) {
665 TObject *o = luaC_getref(ref); 626 const TObject *o = luaC_getref(ref);
666 return (o ? put_luaObject(o) : LUA_NOOBJECT); 627 return (o ? put_luaObject(o) : LUA_NOOBJECT);
667} 628}
668 629
diff --git a/lapi.h b/lapi.h
index c3d6fc8d..b836f905 100644
--- a/lapi.h
+++ b/lapi.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.h,v 1.3 1999/02/22 19:13:12 roberto Exp roberto $ 2** $Id: lapi.h,v 1.4 1999/02/23 14:57:28 roberto Exp roberto $
3** Auxiliary functions from Lua API 3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,10 +13,10 @@
13 13
14 14
15TObject *luaA_Address (lua_Object o); 15TObject *luaA_Address (lua_Object o);
16void luaA_pushobject (TObject *o); 16void luaA_pushobject (const TObject *o);
17void luaA_packresults (void); 17void luaA_packresults (void);
18int luaA_passresults (void); 18int luaA_passresults (void);
19TaggedString *luaA_nextvar (TaggedString *g); 19TaggedString *luaA_nextvar (TaggedString *g);
20int luaA_next (Hash *t, int i); 20int luaA_next (const Hash *t, int i);
21 21
22#endif 22#endif
diff --git a/lauxlib.c b/lauxlib.c
index a7746bbe..9387a54a 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.16 1999/03/10 14:19:41 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.17 1999/03/11 18:59:19 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,7 +20,7 @@
20 20
21 21
22 22
23int luaL_findstring (char *name, char *list[]) { 23int luaL_findstring (const char *name, const char *const list[]) {
24 int i; 24 int i;
25 for (i=0; list[i]; i++) 25 for (i=0; list[i]; i++)
26 if (strcmp(list[i], name) == 0) 26 if (strcmp(list[i], name) == 0)
@@ -28,9 +28,9 @@ int luaL_findstring (char *name, char *list[]) {
28 return -1; /* name not found */ 28 return -1; /* name not found */
29} 29}
30 30
31void luaL_argerror (int numarg, char *extramsg) { 31void luaL_argerror (int numarg, const char *extramsg) {
32 lua_Function f = lua_stackedfunction(0); 32 lua_Function f = lua_stackedfunction(0);
33 char *funcname; 33 const char *funcname;
34 lua_getobjname(f, &funcname); 34 lua_getobjname(f, &funcname);
35 numarg -= lua_nups(f); 35 numarg -= lua_nups(f);
36 if (funcname == NULL) 36 if (funcname == NULL)
@@ -42,58 +42,50 @@ void luaL_argerror (int numarg, char *extramsg) {
42 numarg, funcname, extramsg); 42 numarg, funcname, extramsg);
43} 43}
44 44
45char *luaL_check_lstr (int numArg, long *len) 45const char *luaL_check_lstr (int numArg, long *len) {
46{
47 lua_Object o = lua_getparam(numArg); 46 lua_Object o = lua_getparam(numArg);
48 luaL_arg_check(lua_isstring(o), numArg, "string expected"); 47 luaL_arg_check(lua_isstring(o), numArg, "string expected");
49 if (len) *len = lua_strlen(o); 48 if (len) *len = lua_strlen(o);
50 return lua_getstring(o); 49 return lua_getstring(o);
51} 50}
52 51
53char *luaL_opt_lstr (int numArg, char *def, long *len) 52const char *luaL_opt_lstr (int numArg, const char *def, long *len) {
54{
55 return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : 53 return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
56 luaL_check_lstr(numArg, len); 54 luaL_check_lstr(numArg, len);
57} 55}
58 56
59double luaL_check_number (int numArg) 57double luaL_check_number (int numArg) {
60{
61 lua_Object o = lua_getparam(numArg); 58 lua_Object o = lua_getparam(numArg);
62 luaL_arg_check(lua_isnumber(o), numArg, "number expected"); 59 luaL_arg_check(lua_isnumber(o), numArg, "number expected");
63 return lua_getnumber(o); 60 return lua_getnumber(o);
64} 61}
65 62
66 63
67double luaL_opt_number (int numArg, double def) 64double luaL_opt_number (int numArg, double def) {
68{
69 return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : 65 return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
70 luaL_check_number(numArg); 66 luaL_check_number(numArg);
71} 67}
72 68
73 69
74lua_Object luaL_tablearg (int arg) 70lua_Object luaL_tablearg (int arg) {
75{
76 lua_Object o = lua_getparam(arg); 71 lua_Object o = lua_getparam(arg);
77 luaL_arg_check(lua_istable(o), arg, "table expected"); 72 luaL_arg_check(lua_istable(o), arg, "table expected");
78 return o; 73 return o;
79} 74}
80 75
81lua_Object luaL_functionarg (int arg) 76lua_Object luaL_functionarg (int arg) {
82{
83 lua_Object o = lua_getparam(arg); 77 lua_Object o = lua_getparam(arg);
84 luaL_arg_check(lua_isfunction(o), arg, "function expected"); 78 luaL_arg_check(lua_isfunction(o), arg, "function expected");
85 return o; 79 return o;
86} 80}
87 81
88lua_Object luaL_nonnullarg (int numArg) 82lua_Object luaL_nonnullarg (int numArg) {
89{
90 lua_Object o = lua_getparam(numArg); 83 lua_Object o = lua_getparam(numArg);
91 luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected"); 84 luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
92 return o; 85 return o;
93} 86}
94 87
95void luaL_openlib (struct luaL_reg *l, int n) 88void luaL_openlib (const struct luaL_reg *l, int n) {
96{
97 int i; 89 int i;
98 lua_open(); /* make sure lua is already open */ 90 lua_open(); /* make sure lua is already open */
99 for (i=0; i<n; i++) 91 for (i=0; i<n; i++)
@@ -101,8 +93,7 @@ void luaL_openlib (struct luaL_reg *l, int n)
101} 93}
102 94
103 95
104void luaL_verror (char *fmt, ...) 96void luaL_verror (const char *fmt, ...) {
105{
106 char buff[500]; 97 char buff[500];
107 va_list argp; 98 va_list argp;
108 va_start(argp, fmt); 99 va_start(argp, fmt);
@@ -112,14 +103,14 @@ void luaL_verror (char *fmt, ...)
112} 103}
113 104
114 105
115void luaL_chunkid (char *out, char *source, int len) { 106void luaL_chunkid (char *out, const char *source, int len) {
116 len -= 13; /* 13 = strlen("string ''...\0") */ 107 len -= 13; /* 13 = strlen("string ''...\0") */
117 if (*source == '@') 108 if (*source == '@')
118 sprintf(out, "file `%.*s'", len, source+1); 109 sprintf(out, "file `%.*s'", len, source+1);
119 else if (*source == '(') 110 else if (*source == '(')
120 strcpy(out, "(C code)"); 111 strcpy(out, "(C code)");
121 else { 112 else {
122 char *b = strchr(source , '\n'); /* stop string at first new line */ 113 const char *b = strchr(source , '\n'); /* stop string at first new line */
123 int lim = (b && (b-source)<len) ? b-source : len; 114 int lim = (b && (b-source)<len) ? b-source : len;
124 sprintf(out, "string `%.*s'", lim, source); 115 sprintf(out, "string `%.*s'", lim, source);
125 strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */ 116 strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */
@@ -127,7 +118,7 @@ void luaL_chunkid (char *out, char *source, int len) {
127} 118}
128 119
129 120
130void luaL_filesource (char *out, char *filename, int len) { 121void luaL_filesource (char *out, const char *filename, int len) {
131 if (filename == NULL) filename = "(stdin)"; 122 if (filename == NULL) filename = "(stdin)";
132 sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */ 123 sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */
133} 124}
diff --git a/lauxlib.h b/lauxlib.h
index 082a9297..7f17da00 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.11 1999/03/04 21:17:26 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.12 1999/03/10 14:19:41 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,7 +13,7 @@
13 13
14 14
15struct luaL_reg { 15struct luaL_reg {
16 char *name; 16 const char *name;
17 lua_CFunction func; 17 lua_CFunction func;
18}; 18};
19 19
@@ -21,12 +21,12 @@ struct luaL_reg {
21#define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \ 21#define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
22 luaL_argerror(numarg,extramsg) 22 luaL_argerror(numarg,extramsg)
23 23
24void luaL_openlib (struct luaL_reg *l, int n); 24void luaL_openlib (const struct luaL_reg *l, int n);
25void luaL_argerror (int numarg, char *extramsg); 25void luaL_argerror (int numarg, const char *extramsg);
26#define luaL_check_string(n) (luaL_check_lstr((n), NULL)) 26#define luaL_check_string(n) (luaL_check_lstr((n), NULL))
27char *luaL_check_lstr (int numArg, long *len); 27const char *luaL_check_lstr (int numArg, long *len);
28#define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL)) 28#define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
29char *luaL_opt_lstr (int numArg, char *def, long *len); 29const char *luaL_opt_lstr (int numArg, const char *def, long *len);
30double luaL_check_number (int numArg); 30double luaL_check_number (int numArg);
31#define luaL_check_int(n) ((int)luaL_check_number(n)) 31#define luaL_check_int(n) ((int)luaL_check_number(n))
32#define luaL_check_long(n) ((long)luaL_check_number(n)) 32#define luaL_check_long(n) ((long)luaL_check_number(n))
@@ -36,7 +36,7 @@ double luaL_opt_number (int numArg, double def);
36lua_Object luaL_functionarg (int arg); 36lua_Object luaL_functionarg (int arg);
37lua_Object luaL_tablearg (int arg); 37lua_Object luaL_tablearg (int arg);
38lua_Object luaL_nonnullarg (int numArg); 38lua_Object luaL_nonnullarg (int numArg);
39void luaL_verror (char *fmt, ...); 39void luaL_verror (const char *fmt, ...);
40char *luaL_openspace (int size); 40char *luaL_openspace (int size);
41void luaL_resetbuffer (void); 41void luaL_resetbuffer (void);
42void luaL_addchar (int c); 42void luaL_addchar (int c);
@@ -45,9 +45,9 @@ void luaL_addsize (int n);
45int luaL_newbuffer (int size); 45int luaL_newbuffer (int size);
46void luaL_oldbuffer (int old); 46void luaL_oldbuffer (int old);
47char *luaL_buffer (void); 47char *luaL_buffer (void);
48int luaL_findstring (char *name, char *list[]); 48int luaL_findstring (const char *name, const char *const list[]);
49void luaL_chunkid (char *out, char *source, int len); 49void luaL_chunkid (char *out, const char *source, int len);
50void luaL_filesource (char *out, char *filename, int len); 50void luaL_filesource (char *out, const char *filename, int len);
51 51
52 52
53#endif 53#endif
diff --git a/lbuiltin.c b/lbuiltin.c
index ae420830..384f77c0 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.59 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.60 1999/07/22 19:35:41 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -42,7 +42,7 @@ static void pushtagstring (TaggedString *s) {
42} 42}
43 43
44 44
45static real getsize (Hash *h) { 45static real getsize (const Hash *h) {
46 real max = 0; 46 real max = 0;
47 int i; 47 int i;
48 for (i = 0; i<nhash(h); i++) { 48 for (i = 0; i<nhash(h); i++) {
@@ -56,7 +56,7 @@ static real getsize (Hash *h) {
56} 56}
57 57
58 58
59static real getnarg (Hash *a) { 59static real getnarg (const Hash *a) {
60 TObject index; 60 TObject index;
61 TObject *value; 61 TObject *value;
62 /* value = table.n */ 62 /* value = table.n */
@@ -146,10 +146,10 @@ static void luaB_tonumber (void) {
146 else lua_pushnil(); /* not a number */ 146 else lua_pushnil(); /* not a number */
147 } 147 }
148 else { 148 else {
149 char *s = luaL_check_string(1); 149 char *s;
150 long n; 150 long n;
151 luaL_arg_check(0 <= base && base <= 36, 2, "base out of range"); 151 luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
152 n = strtol(s, &s, base); 152 n = strtol(luaL_check_string(1), &s, base);
153 while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */ 153 while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */
154 if (*s) lua_pushnil(); /* invalid format: return nil */ 154 if (*s) lua_pushnil(); /* invalid format: return nil */
155 else lua_pushnumber(n); 155 else lua_pushnumber(n);
@@ -162,7 +162,7 @@ static void luaB_error (void) {
162} 162}
163 163
164static void luaB_setglobal (void) { 164static void luaB_setglobal (void) {
165 char *n = luaL_check_string(1); 165 const char *n = luaL_check_string(1);
166 lua_Object value = luaL_nonnullarg(2); 166 lua_Object value = luaL_nonnullarg(2);
167 lua_pushobject(value); 167 lua_pushobject(value);
168 lua_setglobal(n); 168 lua_setglobal(n);
@@ -170,7 +170,7 @@ static void luaB_setglobal (void) {
170} 170}
171 171
172static void luaB_rawsetglobal (void) { 172static void luaB_rawsetglobal (void) {
173 char *n = luaL_check_string(1); 173 const char *n = luaL_check_string(1);
174 lua_Object value = luaL_nonnullarg(2); 174 lua_Object value = luaL_nonnullarg(2);
175 lua_pushobject(value); 175 lua_pushobject(value);
176 lua_rawsetglobal(n); 176 lua_rawsetglobal(n);
@@ -250,7 +250,7 @@ static void luaB_collectgarbage (void) {
250 250
251static void luaB_dostring (void) { 251static void luaB_dostring (void) {
252 long l; 252 long l;
253 char *s = luaL_check_lstr(1, &l); 253 const char *s = luaL_check_lstr(1, &l);
254 if (*s == ID_CHUNK) 254 if (*s == ID_CHUNK)
255 lua_error("`dostring' cannot run pre-compiled code"); 255 lua_error("`dostring' cannot run pre-compiled code");
256 if (lua_dobuffer(s, l, luaL_opt_string(2, s)) == 0) 256 if (lua_dobuffer(s, l, luaL_opt_string(2, s)) == 0)
@@ -260,7 +260,7 @@ static void luaB_dostring (void) {
260 260
261 261
262static void luaB_dofile (void) { 262static void luaB_dofile (void) {
263 char *fname = luaL_opt_string(1, NULL); 263 const char *fname = luaL_opt_string(1, NULL);
264 if (lua_dofile(fname) == 0) 264 if (lua_dofile(fname) == 0)
265 if (luaA_passresults() == 0) 265 if (luaA_passresults() == 0)
266 lua_pushuserdata(NULL); /* at least one result to signal no errors */ 266 lua_pushuserdata(NULL); /* at least one result to signal no errors */
@@ -269,8 +269,8 @@ static void luaB_dofile (void) {
269 269
270static void luaB_call (void) { 270static void luaB_call (void) {
271 lua_Object f = luaL_nonnullarg(1); 271 lua_Object f = luaL_nonnullarg(1);
272 Hash *arg = gethash(2); 272 const Hash *arg = gethash(2);
273 char *options = luaL_opt_string(3, ""); 273 const char *options = luaL_opt_string(3, "");
274 lua_Object err = lua_getparam(4); 274 lua_Object err = lua_getparam(4);
275 int narg = (int)getnarg(arg); 275 int narg = (int)getnarg(arg);
276 int i, status; 276 int i, status;
@@ -305,7 +305,7 @@ static void luaB_call (void) {
305 305
306 306
307static void luaB_nextvar (void) { 307static void luaB_nextvar (void) {
308 TObject *o = luaA_Address(luaL_nonnullarg(1)); 308 const TObject *o = luaA_Address(luaL_nonnullarg(1));
309 TaggedString *g; 309 TaggedString *g;
310 if (ttype(o) == LUA_T_NIL) 310 if (ttype(o) == LUA_T_NIL)
311 g = NULL; 311 g = NULL;
@@ -319,8 +319,8 @@ static void luaB_nextvar (void) {
319 319
320 320
321static void luaB_next (void) { 321static void luaB_next (void) {
322 Hash *a = gethash(1); 322 const Hash *a = gethash(1);
323 TObject *k = luaA_Address(luaL_nonnullarg(2)); 323 const TObject *k = luaA_Address(luaL_nonnullarg(2));
324 int i = (ttype(k) == LUA_T_NIL) ? 0 : luaH_pos(a, k)+1; 324 int i = (ttype(k) == LUA_T_NIL) ? 0 : luaH_pos(a, k)+1;
325 if (luaA_next(a, i) == 0) 325 if (luaA_next(a, i) == 0)
326 lua_pushnil(); 326 lua_pushnil();
@@ -329,7 +329,7 @@ static void luaB_next (void) {
329 329
330static void luaB_tostring (void) { 330static void luaB_tostring (void) {
331 lua_Object obj = lua_getparam(1); 331 lua_Object obj = lua_getparam(1);
332 TObject *o = luaA_Address(obj); 332 const TObject *o = luaA_Address(obj);
333 char buff[64]; 333 char buff[64];
334 switch (ttype(o)) { 334 switch (ttype(o)) {
335 case LUA_T_NUMBER: 335 case LUA_T_NUMBER:
@@ -391,7 +391,7 @@ static void luaB_assert (void) {
391 391
392 392
393static void luaB_foreachi (void) { 393static void luaB_foreachi (void) {
394 Hash *t = gethash(1); 394 const Hash *t = gethash(1);
395 int i; 395 int i;
396 int n = (int)getnarg(t); 396 int n = (int)getnarg(t);
397 TObject f; 397 TObject f;
@@ -413,13 +413,13 @@ static void luaB_foreachi (void) {
413 413
414 414
415static void luaB_foreach (void) { 415static void luaB_foreach (void) {
416 Hash *a = gethash(1); 416 const Hash *a = gethash(1);
417 int i; 417 int i;
418 TObject f; /* see comment in 'foreachi' */ 418 TObject f; /* see comment in 'foreachi' */
419 f = *luaA_Address(luaL_functionarg(2)); 419 f = *luaA_Address(luaL_functionarg(2));
420 luaD_checkstack(3); /* for f, ref, and val */ 420 luaD_checkstack(3); /* for f, ref, and val */
421 for (i=0; i<a->nhash; i++) { 421 for (i=0; i<a->nhash; i++) {
422 Node *nd = &(a->node[i]); 422 const Node *nd = &(a->node[i]);
423 if (ttype(val(nd)) != LUA_T_NIL) { 423 if (ttype(val(nd)) != LUA_T_NIL) {
424 *(L->stack.top++) = f; 424 *(L->stack.top++) = f;
425 *(L->stack.top++) = *ref(nd); 425 *(L->stack.top++) = *ref(nd);
@@ -504,7 +504,7 @@ static void swap (Hash *a, int i, int j) {
504 luaH_setint(a, j, &temp); 504 luaH_setint(a, j, &temp);
505} 505}
506 506
507static int sort_comp (lua_Object f, TObject *a, TObject *b) { 507static int sort_comp (lua_Object f, const TObject *a, const TObject *b) {
508 /* notice: the caller (auxsort) must check stack space */ 508 /* notice: the caller (auxsort) must check stack space */
509 if (f != LUA_NOOBJECT) { 509 if (f != LUA_NOOBJECT) {
510 *(L->stack.top) = *luaA_Address(f); 510 *(L->stack.top) = *luaA_Address(f);
@@ -604,7 +604,7 @@ static void query_strings (void) {
604 604
605 605
606static void countlist (void) { 606static void countlist (void) {
607 char *s = luaL_check_string(1); 607 const char *s = luaL_check_string(1);
608 GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next : 608 GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next :
609 (s[0]=='p') ? L->rootproto.next : L->rootglobal.next; 609 (s[0]=='p') ? L->rootproto.next : L->rootglobal.next;
610 int i=0; 610 int i=0;
@@ -623,7 +623,7 @@ static void testC (void) {
623 static int locks[10]; 623 static int locks[10];
624 lua_Object reg[10]; 624 lua_Object reg[10];
625 char nome[2]; 625 char nome[2];
626 char *s = luaL_check_string(1); 626 const char *s = luaL_check_string(1);
627 nome[1] = 0; 627 nome[1] = 0;
628 for (;;) { 628 for (;;) {
629 switch (*s++) { 629 switch (*s++) {
@@ -674,7 +674,7 @@ static void testC (void) {
674 674
675 675
676 676
677static struct luaL_reg builtin_funcs[] = { 677static const struct luaL_reg builtin_funcs[] = {
678#ifdef LUA_COMPAT2_5 678#ifdef LUA_COMPAT2_5
679 {"setfallback", luaT_setfallback}, 679 {"setfallback", luaT_setfallback},
680#endif 680#endif
diff --git a/ldblib.c b/ldblib.c
index 18951e3c..432f8426 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.4 1999/02/04 17:47:59 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.5 1999/03/04 21:17:26 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,7 +15,7 @@
15 15
16 16
17 17
18static void settabss (lua_Object t, char *i, char *v) { 18static void settabss (lua_Object t, const char *i, const char *v) {
19 lua_pushobject(t); 19 lua_pushobject(t);
20 lua_pushstring(i); 20 lua_pushstring(i);
21 lua_pushstring(v); 21 lua_pushstring(v);
@@ -23,7 +23,7 @@ static void settabss (lua_Object t, char *i, char *v) {
23} 23}
24 24
25 25
26static void settabsi (lua_Object t, char *i, int v) { 26static void settabsi (lua_Object t, const char *i, int v) {
27 lua_pushobject(t); 27 lua_pushobject(t);
28 lua_pushstring(i); 28 lua_pushstring(i);
29 lua_pushnumber(v); 29 lua_pushnumber(v);
@@ -33,7 +33,7 @@ static void settabsi (lua_Object t, char *i, int v) {
33 33
34static lua_Object getfuncinfo (lua_Object func) { 34static lua_Object getfuncinfo (lua_Object func) {
35 lua_Object result = lua_createtable(); 35 lua_Object result = lua_createtable();
36 char *str; 36 const char *str;
37 int line; 37 int line;
38 lua_funcinfo(func, &str, &line); 38 lua_funcinfo(func, &str, &line);
39 if (line == -1) /* C function? */ 39 if (line == -1) /* C function? */
@@ -48,7 +48,7 @@ static lua_Object getfuncinfo (lua_Object func) {
48 settabss(result, "source", str); 48 settabss(result, "source", str);
49 } 49 }
50 if (line != 0) { /* is it not a "main"? */ 50 if (line != 0) { /* is it not a "main"? */
51 char *kind = lua_getobjname(func, &str); 51 const char *kind = lua_getobjname(func, &str);
52 if (*kind) { 52 if (*kind) {
53 settabss(result, "name", str); 53 settabss(result, "name", str);
54 settabss(result, "where", kind); 54 settabss(result, "where", kind);
@@ -86,10 +86,10 @@ static int findlocal (lua_Object func, int arg) {
86 if (lua_isnumber(v)) 86 if (lua_isnumber(v))
87 return (int)lua_getnumber(v); 87 return (int)lua_getnumber(v);
88 else { 88 else {
89 char *name = luaL_check_string(arg); 89 const char *name = luaL_check_string(arg);
90 int i = 0; 90 int i = 0;
91 int result = -1; 91 int result = -1;
92 char *vname; 92 const char *vname;
93 while (lua_getlocal(func, ++i, &vname) != LUA_NOOBJECT) { 93 while (lua_getlocal(func, ++i, &vname) != LUA_NOOBJECT) {
94 if (strcmp(name, vname) == 0) 94 if (strcmp(name, vname) == 0)
95 result = i; /* keep looping to get the last var with this name */ 95 result = i; /* keep looping to get the last var with this name */
@@ -104,7 +104,7 @@ static int findlocal (lua_Object func, int arg) {
104static void getlocal (void) { 104static void getlocal (void) {
105 lua_Object func = lua_stackedfunction(luaL_check_int(1)); 105 lua_Object func = lua_stackedfunction(luaL_check_int(1));
106 lua_Object val; 106 lua_Object val;
107 char *name; 107 const char *name;
108 if (func == LUA_NOOBJECT) /* level out of range? */ 108 if (func == LUA_NOOBJECT) /* level out of range? */
109 return; /* return nil */ 109 return; /* return nil */
110 else if (lua_getparam(2) != LUA_NOOBJECT) { /* 2nd argument? */ 110 else if (lua_getparam(2) != LUA_NOOBJECT) { /* 2nd argument? */
@@ -161,7 +161,7 @@ static void linef (int line) {
161} 161}
162 162
163 163
164static void callf (lua_Function func, char *file, int line) { 164static void callf (lua_Function func, const char *file, int line) {
165 if (func != LUA_NOOBJECT) { 165 if (func != LUA_NOOBJECT) {
166 lua_pushobject(func); 166 lua_pushobject(func);
167 lua_pushstring(file); 167 lua_pushstring(file);
@@ -201,7 +201,7 @@ static void setlinehook (void) {
201} 201}
202 202
203 203
204static struct luaL_reg dblib[] = { 204static const struct luaL_reg dblib[] = {
205 {"funcinfo", funcinfo}, 205 {"funcinfo", funcinfo},
206 {"getlocal", getlocal}, 206 {"getlocal", getlocal},
207 {"getstack", getstack}, 207 {"getstack", getstack},
diff --git a/ldo.c b/ldo.c
index 71f389d3..81b1b708 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.44 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: ldo.c,v 1.45 1999/06/22 20:37:23 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -159,7 +159,7 @@ static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) {
159} 159}
160 160
161 161
162void luaD_callTM (TObject *f, int nParams, int nResults) { 162void luaD_callTM (const TObject *f, int nParams, int nResults) {
163 luaD_openstack(nParams); 163 luaD_openstack(nParams);
164 *(L->stack.top-nParams-1) = *f; 164 *(L->stack.top-nParams-1) = *f;
165 luaD_calln(nParams, nResults); 165 luaD_calln(nParams, nResults);
@@ -199,7 +199,7 @@ void luaD_calln (int nArgs, int nResults) {
199 } 199 }
200 default: { /* func is not a function */ 200 default: { /* func is not a function */
201 /* Check the tag method for invalid functions */ 201 /* Check the tag method for invalid functions */
202 TObject *im = luaT_getimbyObj(func, IM_FUNCTION); 202 const TObject *im = luaT_getimbyObj(func, IM_FUNCTION);
203 if (ttype(im) == LUA_T_NIL) 203 if (ttype(im) == LUA_T_NIL)
204 lua_error("call expression not a function"); 204 lua_error("call expression not a function");
205 luaD_callTM(im, (S->top-S->stack)-(base-1), nResults); 205 luaD_callTM(im, (S->top-S->stack)-(base-1), nResults);
@@ -222,8 +222,7 @@ void luaD_calln (int nArgs, int nResults) {
222/* 222/*
223** Traverse all objects on L->stack.stack 223** Traverse all objects on L->stack.stack
224*/ 224*/
225void luaD_travstack (int (*fn)(TObject *)) 225void luaD_travstack (int (*fn)(TObject *)) {
226{
227 StkId i; 226 StkId i;
228 for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) 227 for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--)
229 fn(L->stack.stack+i); 228 fn(L->stack.stack+i);
@@ -231,8 +230,8 @@ void luaD_travstack (int (*fn)(TObject *))
231 230
232 231
233 232
234static void message (char *s) { 233static void message (const char *s) {
235 TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval); 234 const TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
236 if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO || 235 if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO ||
237 ttype(em) == LUA_T_CLOSURE) { 236 ttype(em) == LUA_T_CLOSURE) {
238 *L->stack.top = *em; 237 *L->stack.top = *em;
@@ -245,7 +244,7 @@ static void message (char *s) {
245/* 244/*
246** Reports an error, and jumps up to the available recover label 245** Reports an error, and jumps up to the available recover label
247*/ 246*/
248void lua_error (char *s) { 247void lua_error (const char *s) {
249 if (s) message(s); 248 if (s) message(s);
250 if (L->errorJmp) 249 if (L->errorJmp)
251 longjmp(L->errorJmp->b, 1); 250 longjmp(L->errorJmp->b, 1);
@@ -335,9 +334,8 @@ static int do_main (ZIO *z, int bin) {
335} 334}
336 335
337 336
338void luaD_gcIM (TObject *o) 337void luaD_gcIM (const TObject *o) {
339{ 338 const TObject *im = luaT_getimbyObj(o, IM_GC);
340 TObject *im = luaT_getimbyObj(o, IM_GC);
341 if (ttype(im) != LUA_T_NIL) { 339 if (ttype(im) != LUA_T_NIL) {
342 *L->stack.top = *o; 340 *L->stack.top = *o;
343 incr_top; 341 incr_top;
@@ -348,7 +346,7 @@ void luaD_gcIM (TObject *o)
348 346
349#define MAXFILENAME 260 /* maximum part of a file name kept */ 347#define MAXFILENAME 260 /* maximum part of a file name kept */
350 348
351int lua_dofile (char *filename) { 349int lua_dofile (const char *filename) {
352 ZIO z; 350 ZIO z;
353 int status; 351 int status;
354 int c; 352 int c;
@@ -371,12 +369,12 @@ int lua_dofile (char *filename) {
371} 369}
372 370
373 371
374int lua_dostring (char *str) { 372int lua_dostring (const char *str) {
375 return lua_dobuffer(str, strlen(str), str); 373 return lua_dobuffer(str, strlen(str), str);
376} 374}
377 375
378 376
379int lua_dobuffer (char *buff, int size, char *name) { 377int lua_dobuffer (const char *buff, int size, const char *name) {
380 ZIO z; 378 ZIO z;
381 if (!name) name = "?"; 379 if (!name) name = "?";
382 luaZ_mopen(&z, buff, size, name); 380 luaZ_mopen(&z, buff, size, name);
diff --git a/ldo.h b/ldo.h
index cf651423..a4dac9a5 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 1.5 1998/07/12 16:14:34 roberto Exp roberto $ 2** $Id: ldo.h,v 1.6 1999/06/22 20:37:23 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -36,9 +36,9 @@ void luaD_openstack (int nelems);
36void luaD_lineHook (int line); 36void luaD_lineHook (int line);
37void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn); 37void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn);
38void luaD_calln (int nArgs, int nResults); 38void luaD_calln (int nArgs, int nResults);
39void luaD_callTM (TObject *f, int nParams, int nResults); 39void luaD_callTM (const TObject *f, int nParams, int nResults);
40int luaD_protectedrun (void); 40int luaD_protectedrun (void);
41void luaD_gcIM (TObject *o); 41void luaD_gcIM (const TObject *o);
42void luaD_travstack (int (*fn)(TObject *)); 42void luaD_travstack (int (*fn)(TObject *));
43void luaD_checkstack (int n); 43void luaD_checkstack (int n);
44 44
diff --git a/lfunc.c b/lfunc.c
index e1bdd2bd..32fefb29 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.9 1998/06/19 16:14:09 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.10 1999/03/04 21:17:26 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,8 +16,7 @@
16 16
17 17
18 18
19Closure *luaF_newclosure (int nelems) 19Closure *luaF_newclosure (int nelems) {
20{
21 Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject)); 20 Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
22 luaO_insertlist(&(L->rootcl), (GCnode *)c); 21 luaO_insertlist(&(L->rootcl), (GCnode *)c);
23 L->nblocks += gcsizeclosure(c); 22 L->nblocks += gcsizeclosure(c);
@@ -26,8 +25,7 @@ Closure *luaF_newclosure (int nelems)
26} 25}
27 26
28 27
29TProtoFunc *luaF_newproto (void) 28TProtoFunc *luaF_newproto (void) {
30{
31 TProtoFunc *f = luaM_new(TProtoFunc); 29 TProtoFunc *f = luaM_new(TProtoFunc);
32 f->code = NULL; 30 f->code = NULL;
33 f->lineDefined = 0; 31 f->lineDefined = 0;
@@ -42,8 +40,7 @@ TProtoFunc *luaF_newproto (void)
42 40
43 41
44 42
45static void freefunc (TProtoFunc *f) 43static void freefunc (TProtoFunc *f) {
46{
47 luaM_free(f->code); 44 luaM_free(f->code);
48 luaM_free(f->locvars); 45 luaM_free(f->locvars);
49 luaM_free(f->consts); 46 luaM_free(f->consts);
@@ -51,8 +48,7 @@ static void freefunc (TProtoFunc *f)
51} 48}
52 49
53 50
54void luaF_freeproto (TProtoFunc *l) 51void luaF_freeproto (TProtoFunc *l) {
55{
56 while (l) { 52 while (l) {
57 TProtoFunc *next = (TProtoFunc *)l->head.next; 53 TProtoFunc *next = (TProtoFunc *)l->head.next;
58 L->nblocks -= gcsizeproto(l); 54 L->nblocks -= gcsizeproto(l);
@@ -62,8 +58,7 @@ void luaF_freeproto (TProtoFunc *l)
62} 58}
63 59
64 60
65void luaF_freeclosure (Closure *l) 61void luaF_freeclosure (Closure *l) {
66{
67 while (l) { 62 while (l) {
68 Closure *next = (Closure *)l->head.next; 63 Closure *next = (Closure *)l->head.next;
69 L->nblocks -= gcsizeclosure(l); 64 L->nblocks -= gcsizeclosure(l);
@@ -77,10 +72,9 @@ void luaF_freeclosure (Closure *l)
77** Look for n-th local variable at line "line" in function "func". 72** Look for n-th local variable at line "line" in function "func".
78** Returns NULL if not found. 73** Returns NULL if not found.
79*/ 74*/
80char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) 75const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) {
81{
82 int count = 0; 76 int count = 0;
83 char *varname = NULL; 77 const char *varname = NULL;
84 LocVar *lv = func->locvars; 78 LocVar *lv = func->locvars;
85 if (lv == NULL) 79 if (lv == NULL)
86 return NULL; 80 return NULL;
diff --git a/lfunc.h b/lfunc.h
index 7f1e5157..718a76c6 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.h,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $ 2** $Id: lfunc.h,v 1.5 1997/12/15 16:17:20 roberto Exp roberto $
3** Lua Function structures 3** Lua Function structures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -17,7 +17,7 @@ Closure *luaF_newclosure (int nelems);
17void luaF_freeproto (TProtoFunc *l); 17void luaF_freeproto (TProtoFunc *l);
18void luaF_freeclosure (Closure *l); 18void luaF_freeclosure (Closure *l);
19 19
20char *luaF_getlocalname (TProtoFunc *func, int local_number, int line); 20const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line);
21 21
22 22
23#endif 23#endif
diff --git a/lgc.c b/lgc.c
index 66244fbf..b0e4b91a 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.23 1999/03/04 21:17:26 roberto Exp roberto $ 2** $Id: lgc.c,v 1.24 1999/08/11 17:00:59 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -29,7 +29,7 @@ static int markobject (TObject *o);
29*/ 29*/
30 30
31 31
32int luaC_ref (TObject *o, int lock) { 32int luaC_ref (const TObject *o, int lock) {
33 int ref; 33 int ref;
34 if (ttype(o) == LUA_T_NIL) 34 if (ttype(o) == LUA_T_NIL)
35 ref = LUA_REFNIL; 35 ref = LUA_REFNIL;
@@ -48,15 +48,13 @@ int luaC_ref (TObject *o, int lock) {
48} 48}
49 49
50 50
51void lua_unref (int ref) 51void lua_unref (int ref) {
52{
53 if (ref >= 0 && ref < L->refSize) 52 if (ref >= 0 && ref < L->refSize)
54 L->refArray[ref].status = FREE; 53 L->refArray[ref].status = FREE;
55} 54}
56 55
57 56
58TObject* luaC_getref (int ref) 57const TObject *luaC_getref (int ref) {
59{
60 if (ref == LUA_REFNIL) 58 if (ref == LUA_REFNIL)
61 return &luaO_nilobject; 59 return &luaO_nilobject;
62 if (ref >= 0 && ref < L->refSize && 60 if (ref >= 0 && ref < L->refSize &&
@@ -67,8 +65,7 @@ TObject* luaC_getref (int ref)
67} 65}
68 66
69 67
70static void travlock (void) 68static void travlock (void) {
71{
72 int i; 69 int i;
73 for (i=0; i<L->refSize; i++) 70 for (i=0; i<L->refSize; i++)
74 if (L->refArray[i].status == LOCK) 71 if (L->refArray[i].status == LOCK)
@@ -76,8 +73,7 @@ static void travlock (void)
76} 73}
77 74
78 75
79static int ismarked (TObject *o) 76static int ismarked (const TObject *o) {
80{
81 /* valid only for locked objects */ 77 /* valid only for locked objects */
82 switch (o->ttype) { 78 switch (o->ttype) {
83 case LUA_T_STRING: case LUA_T_USERDATA: 79 case LUA_T_STRING: case LUA_T_USERDATA:
@@ -99,8 +95,7 @@ static int ismarked (TObject *o)
99} 95}
100 96
101 97
102static void invalidaterefs (void) 98static void invalidaterefs (void) {
103{
104 int i; 99 int i;
105 for (i=0; i<L->refSize; i++) 100 for (i=0; i<L->refSize; i++)
106 if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o)) 101 if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o))
@@ -109,8 +104,7 @@ static void invalidaterefs (void)
109 104
110 105
111 106
112void luaC_hashcallIM (Hash *l) 107void luaC_hashcallIM (Hash *l) {
113{
114 TObject t; 108 TObject t;
115 ttype(&t) = LUA_T_ARRAY; 109 ttype(&t) = LUA_T_ARRAY;
116 for (; l; l=(Hash *)l->head.next) { 110 for (; l; l=(Hash *)l->head.next) {
@@ -120,8 +114,7 @@ void luaC_hashcallIM (Hash *l)
120} 114}
121 115
122 116
123void luaC_strcallIM (TaggedString *l) 117void luaC_strcallIM (TaggedString *l) {
124{
125 TObject o; 118 TObject o;
126 ttype(&o) = LUA_T_USERDATA; 119 ttype(&o) = LUA_T_USERDATA;
127 for (; l; l=(TaggedString *)l->head.next) 120 for (; l; l=(TaggedString *)l->head.next)
@@ -133,8 +126,7 @@ void luaC_strcallIM (TaggedString *l)
133 126
134 127
135 128
136static GCnode *listcollect (GCnode *l) 129static GCnode *listcollect (GCnode *l) {
137{
138 GCnode *frees = NULL; 130 GCnode *frees = NULL;
139 while (l) { 131 while (l) {
140 GCnode *next = l->next; 132 GCnode *next = l->next;
@@ -151,8 +143,7 @@ static GCnode *listcollect (GCnode *l)
151} 143}
152 144
153 145
154static void strmark (TaggedString *s) 146static void strmark (TaggedString *s) {
155{
156 if (!s->head.marked) 147 if (!s->head.marked)
157 s->head.marked = 1; 148 s->head.marked = 1;
158} 149}
@@ -169,8 +160,7 @@ static void protomark (TProtoFunc *f) {
169} 160}
170 161
171 162
172static void closuremark (Closure *f) 163static void closuremark (Closure *f) {
173{
174 if (!f->head.marked) { 164 if (!f->head.marked) {
175 int i; 165 int i;
176 f->head.marked = 1; 166 f->head.marked = 1;
@@ -180,8 +170,7 @@ static void closuremark (Closure *f)
180} 170}
181 171
182 172
183static void hashmark (Hash *h) 173static void hashmark (Hash *h) {
184{
185 if (!h->head.marked) { 174 if (!h->head.marked) {
186 int i; 175 int i;
187 h->head.marked = 1; 176 h->head.marked = 1;
@@ -196,8 +185,7 @@ static void hashmark (Hash *h)
196} 185}
197 186
198 187
199static void globalmark (void) 188static void globalmark (void) {
200{
201 TaggedString *g; 189 TaggedString *g;
202 for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){ 190 for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){
203 LUA_ASSERT(g->constindex >= 0, "userdata in global list"); 191 LUA_ASSERT(g->constindex >= 0, "userdata in global list");
@@ -209,8 +197,7 @@ static void globalmark (void)
209} 197}
210 198
211 199
212static int markobject (TObject *o) 200static int markobject (TObject *o) {
213{
214 switch (ttype(o)) { 201 switch (ttype(o)) {
215 case LUA_T_USERDATA: case LUA_T_STRING: 202 case LUA_T_USERDATA: case LUA_T_STRING:
216 strmark(tsvalue(o)); 203 strmark(tsvalue(o));
@@ -231,8 +218,7 @@ static int markobject (TObject *o)
231 218
232 219
233 220
234static void markall (void) 221static void markall (void) {
235{
236 luaD_travstack(markobject); /* mark stack objects */ 222 luaD_travstack(markobject); /* mark stack objects */
237 globalmark(); /* mark global variable values and names */ 223 globalmark(); /* mark global variable values and names */
238 travlock(); /* mark locked objects */ 224 travlock(); /* mark locked objects */
@@ -240,8 +226,7 @@ static void markall (void)
240} 226}
241 227
242 228
243long lua_collectgarbage (long limit) 229long lua_collectgarbage (long limit) {
244{
245 unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */ 230 unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */
246 Hash *freetable; 231 Hash *freetable;
247 TaggedString *freestr; 232 TaggedString *freestr;
@@ -267,8 +252,7 @@ long lua_collectgarbage (long limit)
267} 252}
268 253
269 254
270void luaC_checkGC (void) 255void luaC_checkGC (void) {
271{
272 if (L->nblocks >= L->GCthreshold) 256 if (L->nblocks >= L->GCthreshold)
273 lua_collectgarbage(0); 257 lua_collectgarbage(0);
274} 258}
diff --git a/lgc.h b/lgc.h
index 60a0b1ec..8bd7b3b1 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 1.3 1997/11/19 17:29:23 roberto Exp roberto $ 2** $Id: lgc.h,v 1.4 1997/12/01 20:31:25 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,8 +12,8 @@
12 12
13 13
14void luaC_checkGC (void); 14void luaC_checkGC (void);
15TObject* luaC_getref (int ref); 15const TObject *luaC_getref (int ref);
16int luaC_ref (TObject *o, int lock); 16int luaC_ref (const TObject *o, int lock);
17void luaC_hashcallIM (Hash *l); 17void luaC_hashcallIM (Hash *l);
18void luaC_strcallIM (TaggedString *l); 18void luaC_strcallIM (TaggedString *l);
19 19
diff --git a/liolib.c b/liolib.c
index 27f0afbe..fa76b9a1 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.42 1999/07/22 19:35:50 roberto Exp roberto $ 2** $Id: liolib.c,v 1.43 1999/08/10 13:05:16 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -44,8 +44,8 @@
44 44
45 45
46#ifdef POPEN 46#ifdef POPEN
47FILE *popen(); 47/* FILE *popen();
48int pclose(); 48int pclose(); */
49#define CLOSEFILE(f) ((pclose(f) == -1) ? fclose(f) : 0) 49#define CLOSEFILE(f) ((pclose(f) == -1) ? fclose(f) : 0)
50#else 50#else
51/* no support for popen */ 51/* no support for popen */
@@ -88,7 +88,7 @@ static int ishandle (lua_Object f) {
88} 88}
89 89
90 90
91static FILE *getfilebyname (char *name) { 91static FILE *getfilebyname (const char *name) {
92 lua_Object f = lua_rawgetglobal(name); 92 lua_Object f = lua_rawgetglobal(name);
93 if (!ishandle(f)) 93 if (!ishandle(f))
94 luaL_verror("global variable `%.50s' is not a file handle", name); 94 luaL_verror("global variable `%.50s' is not a file handle", name);
@@ -109,7 +109,7 @@ static FILE *getnonullfile (int arg) {
109} 109}
110 110
111 111
112static FILE *getfileparam (char *name, int *arg) { 112static FILE *getfileparam (const char *name, int *arg) {
113 FILE *f = getfile(*arg); 113 FILE *f = getfile(*arg);
114 if (f) { 114 if (f) {
115 (*arg)++; 115 (*arg)++;
@@ -152,13 +152,13 @@ static void io_open (void) {
152} 152}
153 153
154 154
155static void setfile (FILE *f, char *name, int tag) { 155static void setfile (FILE *f, const char *name, int tag) {
156 lua_pushusertag(f, tag); 156 lua_pushusertag(f, tag);
157 lua_setglobal(name); 157 lua_setglobal(name);
158} 158}
159 159
160 160
161static void setreturn (FILE *f, char *name) { 161static void setreturn (FILE *f, const char *name) {
162 if (f == NULL) 162 if (f == NULL)
163 pushresult(0); 163 pushresult(0);
164 else { 164 else {
@@ -181,7 +181,7 @@ static void io_readfrom (void) {
181 else if (lua_tag(f) == gettag()) /* deprecated option */ 181 else if (lua_tag(f) == gettag()) /* deprecated option */
182 current = lua_getuserdata(f); 182 current = lua_getuserdata(f);
183 else { 183 else {
184 char *s = luaL_check_string(FIRSTARG); 184 const char *s = luaL_check_string(FIRSTARG);
185 current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); 185 current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
186 } 186 }
187 setreturn(current, FINPUT); 187 setreturn(current, FINPUT);
@@ -200,7 +200,7 @@ static void io_writeto (void) {
200 else if (lua_tag(f) == gettag()) /* deprecated option */ 200 else if (lua_tag(f) == gettag()) /* deprecated option */
201 current = lua_getuserdata(f); 201 current = lua_getuserdata(f);
202 else { 202 else {
203 char *s = luaL_check_string(FIRSTARG); 203 const char *s = luaL_check_string(FIRSTARG);
204 current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w"); 204 current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w");
205 } 205 }
206 setreturn(current, FOUTPUT); 206 setreturn(current, FOUTPUT);
@@ -228,7 +228,7 @@ static void io_appendto (void) {
228#define NEED_OTHER (EOF-1) /* just some flag different from EOF */ 228#define NEED_OTHER (EOF-1) /* just some flag different from EOF */
229 229
230 230
231static int read_pattern (FILE *f, char *p) { 231static int read_pattern (FILE *f, const char *p) {
232 int inskip = 0; /* {skip} level */ 232 int inskip = 0; /* {skip} level */
233 int c = NEED_OTHER; 233 int c = NEED_OTHER;
234 while (*p != '\0') { 234 while (*p != '\0') {
@@ -243,7 +243,7 @@ static int read_pattern (FILE *f, char *p) {
243 p++; 243 p++;
244 continue; 244 continue;
245 default: { 245 default: {
246 char *ep = luaI_classend(p); /* get what is next */ 246 const char *ep = luaI_classend(p); /* get what is next */
247 int m; /* match result */ 247 int m; /* match result */
248 if (c == NEED_OTHER) c = getc(f); 248 if (c == NEED_OTHER) c = getc(f);
249 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep); 249 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
@@ -317,10 +317,10 @@ static void read_file (FILE *f) {
317 317
318 318
319static void io_read (void) { 319static void io_read (void) {
320 static char *options[] = {"*n", "*l", "*a", ".*", "*w", NULL}; 320 static const char *const options[] = {"*n", "*l", "*a", ".*", "*w", NULL};
321 int arg = FIRSTARG; 321 int arg = FIRSTARG;
322 FILE *f = getfileparam(FINPUT, &arg); 322 FILE *f = getfileparam(FINPUT, &arg);
323 char *p = luaL_opt_string(arg++, "*l"); 323 const char *p = luaL_opt_string(arg++, "*l");
324 do { /* repeat for each part */ 324 do { /* repeat for each part */
325 long l; 325 long l;
326 int success; 326 int success;
@@ -355,7 +355,7 @@ static void io_write (void) {
355 int arg = FIRSTARG; 355 int arg = FIRSTARG;
356 FILE *f = getfileparam(FOUTPUT, &arg); 356 FILE *f = getfileparam(FOUTPUT, &arg);
357 int status = 1; 357 int status = 1;
358 char *s; 358 const char *s;
359 long l; 359 long l;
360 while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL) 360 while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
361 status = status && ((long)fwrite(s, 1, l, f) == l); 361 status = status && ((long)fwrite(s, 1, l, f) == l);
@@ -364,8 +364,8 @@ static void io_write (void) {
364 364
365 365
366static void io_seek (void) { 366static void io_seek (void) {
367 static int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; 367 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
368 static char *modenames[] = {"set", "cur", "end", NULL}; 368 static const char *const modenames[] = {"set", "cur", "end", NULL};
369 FILE *f = getnonullfile(FIRSTARG); 369 FILE *f = getnonullfile(FIRSTARG);
370 int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames); 370 int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames);
371 long offset = luaL_opt_long(FIRSTARG+2, 0); 371 long offset = luaL_opt_long(FIRSTARG+2, 0);
@@ -428,7 +428,7 @@ static void io_clock (void) {
428 428
429static void io_date (void) { 429static void io_date (void) {
430 char b[256]; 430 char b[256];
431 char *s = luaL_opt_string(1, "%c"); 431 const char *s = luaL_opt_string(1, "%c");
432 struct tm *tm; 432 struct tm *tm;
433 time_t t; 433 time_t t;
434 time(&t); tm = localtime(&t); 434 time(&t); tm = localtime(&t);
@@ -440,9 +440,9 @@ static void io_date (void) {
440 440
441 441
442static void setloc (void) { 442static void setloc (void) {
443 static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, 443 static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
444 LC_TIME}; 444 LC_NUMERIC, LC_TIME};
445 static char *catnames[] = {"all", "collate", "ctype", "monetary", 445 static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
446 "numeric", "time", NULL}; 446 "numeric", "time", NULL};
447 int op = luaL_findstring(luaL_opt_string(2, "all"), catnames); 447 int op = luaL_findstring(luaL_opt_string(2, "all"), catnames);
448 luaL_arg_check(op != -1, 2, "invalid option"); 448 luaL_arg_check(op != -1, 2, "invalid option");
@@ -485,9 +485,9 @@ static void errorfb (void) {
485 lua_Object func; 485 lua_Object func;
486 sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1))); 486 sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1)));
487 while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) { 487 while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
488 char *name; 488 const char *name;
489 int currentline; 489 int currentline;
490 char *chunkname; 490 const char *chunkname;
491 char buffchunk[MAXSRC]; 491 char buffchunk[MAXSRC];
492 int linedefined; 492 int linedefined;
493 lua_funcinfo(func, &chunkname, &linedefined); 493 lua_funcinfo(func, &chunkname, &linedefined);
@@ -531,7 +531,7 @@ static void errorfb (void) {
531 531
532 532
533 533
534static struct luaL_reg iolib[] = { 534static const struct luaL_reg iolib[] = {
535 {"_ERRORMESSAGE", errorfb}, 535 {"_ERRORMESSAGE", errorfb},
536 {"clock", io_clock}, 536 {"clock", io_clock},
537 {"date", io_date}, 537 {"date", io_date},
@@ -546,7 +546,7 @@ static struct luaL_reg iolib[] = {
546}; 546};
547 547
548 548
549static struct luaL_reg iolibtag[] = { 549static const struct luaL_reg iolibtag[] = {
550 {"appendto", io_appendto}, 550 {"appendto", io_appendto},
551 {"closefile", io_close}, 551 {"closefile", io_close},
552 {"flush", io_flush}, 552 {"flush", io_flush},
diff --git a/llex.c b/llex.c
index 74aa7d3a..63404c3d 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.36 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: llex.c,v 1.37 1999/07/22 19:29:42 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -28,8 +28,8 @@
28 28
29 29
30/* ORDER RESERVED */ 30/* ORDER RESERVED */
31static char *reserved [] = {"and", "do", "else", "elseif", "end", "function", 31static const char *const reserved [] = {"and", "do", "else", "elseif", "end",
32 "if", "local", "nil", "not", "or", "repeat", "return", "then", 32 "function", "if", "local", "nil", "not", "or", "repeat", "return", "then",
33 "until", "while"}; 33 "until", "while"};
34 34
35 35
@@ -44,7 +44,7 @@ void luaX_init (void) {
44 44
45#define MAXSRC 80 45#define MAXSRC 80
46 46
47void luaX_syntaxerror (LexState *ls, char *s, char *token) { 47void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
48 char buff[MAXSRC]; 48 char buff[MAXSRC];
49 luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff)); 49 luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff));
50 if (token[0] == '\0') 50 if (token[0] == '\0')
@@ -54,7 +54,7 @@ void luaX_syntaxerror (LexState *ls, char *s, char *token) {
54} 54}
55 55
56 56
57void luaX_error (LexState *ls, char *s) { 57void luaX_error (LexState *ls, const char *s) {
58 save('\0'); 58 save('\0');
59 luaX_syntaxerror(ls, s, luaL_buffer()); 59 luaX_syntaxerror(ls, s, luaL_buffer());
60} 60}
@@ -117,8 +117,8 @@ static void skipspace (LexState *LS) {
117} 117}
118 118
119 119
120static int checkcond (LexState *LS, char *buff) { 120static int checkcond (LexState *LS, const char *buff) {
121 static char *opts[] = {"nil", "1", NULL}; 121 static const char *const opts[] = {"nil", "1", NULL};
122 int i = luaL_findstring(buff, opts); 122 int i = luaL_findstring(buff, opts);
123 if (i >= 0) return i; 123 if (i >= 0) return i;
124 else if (isalpha((unsigned char)buff[0]) || buff[0] == '_') 124 else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
@@ -160,7 +160,7 @@ static void ifskip (LexState *LS) {
160 160
161 161
162static void inclinenumber (LexState *LS) { 162static void inclinenumber (LexState *LS) {
163 static char *pragmas [] = 163 static const char *const pragmas [] =
164 {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL}; 164 {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
165 next(LS); /* skip '\n' */ 165 next(LS); /* skip '\n' */
166 ++LS->linenumber; 166 ++LS->linenumber;
diff --git a/llex.h b/llex.h
index 0b0dd4d9..20928075 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.12 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: llex.h,v 1.13 1999/07/22 19:29:42 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -61,8 +61,8 @@ typedef struct LexState {
61void luaX_init (void); 61void luaX_init (void);
62void luaX_setinput (LexState *LS, ZIO *z); 62void luaX_setinput (LexState *LS, ZIO *z);
63int luaX_lex (LexState *LS); 63int luaX_lex (LexState *LS);
64void luaX_syntaxerror (LexState *ls, char *s, char *token); 64void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
65void luaX_error (LexState *ls, char *s); 65void luaX_error (LexState *ls, const char *s);
66void luaX_token2str (int token, char *s); 66void luaX_token2str (int token, char *s);
67 67
68 68
diff --git a/lmathlib.c b/lmathlib.c
index 5e9f10b0..0ea8491e 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.16 1999/02/19 17:33:35 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.17 1999/07/07 17:54:08 roberto Exp roberto $
3** Lua standard mathematical library 3** Lua standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -164,7 +164,7 @@ static void math_randomseed (void) {
164} 164}
165 165
166 166
167static struct luaL_reg mathlib[] = { 167static const struct luaL_reg mathlib[] = {
168{"abs", math_abs}, 168{"abs", math_abs},
169{"sin", math_sin}, 169{"sin", math_sin},
170{"cos", math_cos}, 170{"cos", math_cos},
diff --git a/lmem.c b/lmem.c
index 1c334b64..26aac9c6 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.16 1999/05/20 20:43:06 roberto Exp roberto $ 2** $Id: lmem.c,v 1.17 1999/05/24 17:51:05 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -35,7 +35,7 @@ static unsigned long power2 (unsigned long n) {
35 35
36 36
37void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, 37void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
38 char *errormsg, unsigned long limit) { 38 const char *errormsg, unsigned long limit) {
39 unsigned long newn = nelems+inc; 39 unsigned long newn = nelems+inc;
40 if (newn >= limit) lua_error(errormsg); 40 if (newn >= limit) lua_error(errormsg);
41 if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ 41 if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */
@@ -86,25 +86,23 @@ unsigned long totalmem = 0;
86 86
87 87
88static void *checkblock (void *block) { 88static void *checkblock (void *block) {
89 if (block == NULL) 89 unsigned long *b = blocksize(block);
90 return NULL; 90 unsigned long size = *b;
91 else { 91 int i;
92 unsigned long *b = blocksize(block); 92 for (i=0;i<MARKSIZE;i++)
93 unsigned long size = *b; 93 LUA_ASSERT(*(((char *)b)+HEADER+size+i) == MARK+i, "corrupted block");
94 int i; 94 numblocks--;
95 for (i=0;i<MARKSIZE;i++) 95 totalmem -= size;
96 LUA_ASSERT(*(((char *)b)+HEADER+size+i) == MARK+i, "corrupted block"); 96 return b;
97 numblocks--;
98 totalmem -= size;
99 return b;
100 }
101} 97}
102 98
103 99
104static void freeblock (void *block) { 100static void freeblock (void *block) {
105 if (block) 101 if (block) {
106 memset(block, -1, *blocksize(block)); /* erase block */ 102 memset(block, -1, *blocksize(block)); /* erase block */
107 free(checkblock(block)); 103 block = checkblock(block);
104 free(block);
105 }
108} 106}
109 107
110 108
diff --git a/lmem.h b/lmem.h
index 679c97b4..ee810ab9 100644
--- a/lmem.h
+++ b/lmem.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.h,v 1.7 1999/02/25 15:16:26 roberto Exp roberto $ 2** $Id: lmem.h,v 1.8 1999/02/26 15:48:55 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,7 +20,7 @@
20 20
21void *luaM_realloc (void *oldblock, unsigned long size); 21void *luaM_realloc (void *oldblock, unsigned long size);
22void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, 22void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
23 char *errormsg, unsigned long limit); 23 const char *errormsg, unsigned long limit);
24 24
25#define luaM_free(b) luaM_realloc((b), 0) 25#define luaM_free(b) luaM_realloc((b), 0)
26#define luaM_malloc(t) luaM_realloc(NULL, (t)) 26#define luaM_malloc(t) luaM_realloc(NULL, (t))
diff --git a/lobject.c b/lobject.c
index 840e367f..15775942 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.18 1999/02/26 15:48:30 roberto Exp roberto $ 2** $Id: lobject.c,v 1.19 1999/04/13 19:28:49 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,25 +11,24 @@
11#include "lua.h" 11#include "lua.h"
12 12
13 13
14char *luaO_typenames[] = { /* ORDER LUA_T */ 14const char *const luaO_typenames[] = { /* ORDER LUA_T */
15 "userdata", "number", "string", "table", "function", "function", 15 "userdata", "number", "string", "table", "function", "function",
16 "nil", "function", "mark", "mark", "mark", "line", NULL 16 "nil", "function", "mark", "mark", "mark", "line", NULL
17}; 17};
18 18
19 19
20TObject luaO_nilobject = {LUA_T_NIL, {NULL}}; 20const TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
21 21
22 22
23 23
24/* hash dimensions values */ 24/* hash dimensions values */
25static long dimensions[] = 25static const long dimensions[] =
26 {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L, 26 {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L,
27 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L, 27 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L,
28 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT}; 28 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT};
29 29
30 30
31int luaO_redimension (int oldsize) 31int luaO_redimension (int oldsize) {
32{
33 int i; 32 int i;
34 for (i=0; dimensions[i]<MAX_INT; i++) { 33 for (i=0; dimensions[i]<MAX_INT; i++) {
35 if (dimensions[i] > oldsize) 34 if (dimensions[i] > oldsize)
@@ -40,7 +39,7 @@ int luaO_redimension (int oldsize)
40} 39}
41 40
42 41
43int luaO_equalval (TObject *t1, TObject *t2) { 42int luaO_equalval (const TObject *t1, const TObject *t2) {
44 switch (ttype(t1)) { 43 switch (ttype(t1)) {
45 case LUA_T_NIL: return 1; 44 case LUA_T_NIL: return 1;
46 case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); 45 case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
@@ -56,8 +55,7 @@ int luaO_equalval (TObject *t1, TObject *t2) {
56} 55}
57 56
58 57
59void luaO_insertlist (GCnode *root, GCnode *node) 58void luaO_insertlist (GCnode *root, GCnode *node) {
60{
61 node->next = root->next; 59 node->next = root->next;
62 root->next = node; 60 root->next = node;
63 node->marked = 0; 61 node->marked = 0;
@@ -90,7 +88,7 @@ static double expten (unsigned int e) {
90} 88}
91 89
92 90
93double luaO_str2d (char *s) { /* LUA_NUMBER */ 91double luaO_str2d (const char *s) { /* LUA_NUMBER */
94 double a = 0.0; 92 double a = 0.0;
95 int point = 0; 93 int point = 0;
96 while (isdigit((unsigned char)*s)) { 94 while (isdigit((unsigned char)*s)) {
diff --git a/lobject.h b/lobject.h
index 7c6a4959..91bf0cac 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.27 1999/03/04 21:17:26 roberto Exp roberto $ 2** $Id: lobject.h,v 1.28 1999/03/16 16:43:27 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -178,19 +178,19 @@ typedef struct Hash {
178} Hash; 178} Hash;
179 179
180 180
181extern char *luaO_typenames[]; 181extern const char *const luaO_typenames[];
182 182
183#define luaO_typename(o) luaO_typenames[-ttype(o)] 183#define luaO_typename(o) luaO_typenames[-ttype(o)]
184 184
185 185
186extern TObject luaO_nilobject; 186extern const TObject luaO_nilobject;
187 187
188#define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \ 188#define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \
189 : luaO_equalval(t1,t2)) 189 : luaO_equalval(t1,t2))
190int luaO_equalval (TObject *t1, TObject *t2); 190int luaO_equalval (const TObject *t1, const TObject *t2);
191int luaO_redimension (int oldsize); 191int luaO_redimension (int oldsize);
192void luaO_insertlist (GCnode *root, GCnode *node); 192void luaO_insertlist (GCnode *root, GCnode *node);
193double luaO_str2d (char *s); 193double luaO_str2d (const char *s);
194 194
195#ifdef OLD_ANSI 195#ifdef OLD_ANSI
196void luaO_memup (void *dest, void *src, int size); 196void luaO_memup (void *dest, void *src, int size);
diff --git a/lparser.c b/lparser.c
index 37f1c854..0ba30b5e 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.37 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: lparser.c,v 1.38 1999/07/22 19:29:42 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -142,7 +142,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v);
142 142
143 143
144 144
145static void checklimit (LexState *ls, int val, int limit, char *msg) { 145static void checklimit (LexState *ls, int val, int limit, const char *msg) {
146 if (val > limit) { 146 if (val > limit) {
147 char buff[100]; 147 char buff[100];
148 sprintf(buff, "too many %.50s (limit=%d)", msg, limit); 148 sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
@@ -498,7 +498,7 @@ static void lua_pushvar (LexState *ls, vardesc *var) {
498} 498}
499 499
500 500
501static void storevar (LexState *ls, vardesc *var) { 501static void storevar (LexState *ls, const vardesc *var) {
502 switch (var->k) { 502 switch (var->k) {
503 case VLOCAL: 503 case VLOCAL:
504 code_oparg(ls, SETLOCAL, var->info, -1); 504 code_oparg(ls, SETLOCAL, var->info, -1);
@@ -597,12 +597,13 @@ static void close_func (LexState *ls) {
597 597
598 598
599 599
600static int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME, 600static const int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT,
601 LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';', EOS, ',', 0}; 601 DO, NAME, LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';',
602 EOS, ',', 0};
602 603
603 604
604static int is_in (int tok, int *toks) { 605static int is_in (int tok, const int *toks) {
605 int *t; 606 const int *t;
606 for (t=toks; *t; t++) 607 for (t=toks; *t; t++)
607 if (*t == tok) return t-toks; 608 if (*t == tok) return t-toks;
608 return -1; 609 return -1;
@@ -923,13 +924,13 @@ static void ret (LexState *ls) {
923*/ 924*/
924#define POW 13 925#define POW 13
925 926
926static int binop [] = {EQ, NE, '>', '<', LE, GE, CONC, 927static const int binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
927 '+', '-', '*', '/', '^', 0}; 928 '+', '-', '*', '/', '^', 0};
928 929
929static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6}; 930static const int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
930 931
931static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP, 932static const OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP,
932 LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP}; 933 LTOP, LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
933 934
934#define MAXOPS 20 /* op's stack size (arbitrary limit) */ 935#define MAXOPS 20 /* op's stack size (arbitrary limit) */
935 936
diff --git a/lparser.h b/lparser.h
index 1bd3517c..6b243a98 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.2 1997/12/22 20:57:18 roberto Exp roberto $ 2** $Id: lparser.h,v 1.3 1999/02/25 19:13:56 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,8 +13,8 @@
13 13
14void luaY_codedebugline (int line); 14void luaY_codedebugline (int line);
15TProtoFunc *luaY_parser (ZIO *z); 15TProtoFunc *luaY_parser (ZIO *z);
16void luaY_error (char *s); 16void luaY_error (const char *s);
17void luaY_syntaxerror (char *s, char *token); 17void luaY_syntaxerror (const char *s, const char *token);
18 18
19 19
20#endif 20#endif
diff --git a/lstate.c b/lstate.c
index 1a7fe22e..e5ad27bd 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.11 1999/05/11 14:19:32 roberto Exp roberto $ 2** $Id: lstate.c,v 1.12 1999/05/11 20:08:20 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,8 +20,7 @@
20lua_State *lua_state = NULL; 20lua_State *lua_state = NULL;
21 21
22 22
23void lua_open (void) 23void lua_open (void) {
24{
25 if (lua_state) return; 24 if (lua_state) return;
26 lua_state = luaM_new(lua_State); 25 lua_state = luaM_new(lua_State);
27 L->Cstack.base = 0; 26 L->Cstack.base = 0;
@@ -58,8 +57,7 @@ void lua_open (void)
58} 57}
59 58
60 59
61void lua_close (void) 60void lua_close (void) {
62{
63 TaggedString *alludata = luaS_collectudata(); 61 TaggedString *alludata = luaS_collectudata();
64 L->GCthreshold = MAX_INT; /* to avoid GC during GC */ 62 L->GCthreshold = MAX_INT; /* to avoid GC during GC */
65 luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */ 63 luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */
diff --git a/lstring.c b/lstring.c
index db15fc60..3c399d5a 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.18 1999/02/08 16:28:48 roberto Exp roberto $ 2** $Id: lstring.c,v 1.19 1999/02/26 15:49:53 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -38,7 +38,7 @@ void luaS_init (void) {
38} 38}
39 39
40 40
41static unsigned long hash_s (char *s, long l) { 41static unsigned long hash_s (const char *s, long l) {
42 unsigned long h = 0; /* seed */ 42 unsigned long h = 0; /* seed */
43 while (l--) 43 while (l--)
44 h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); 44 h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++));
@@ -83,7 +83,7 @@ static void grow (stringtable *tb) {
83} 83}
84 84
85 85
86static TaggedString *newone_s (char *str, long l, unsigned long h) { 86static TaggedString *newone_s (const char *str, long l, unsigned long h) {
87 TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l); 87 TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l);
88 memcpy(ts->str, str, l); 88 memcpy(ts->str, str, l);
89 ts->str[l] = 0; /* ending 0 */ 89 ts->str[l] = 0; /* ending 0 */
@@ -97,7 +97,7 @@ static TaggedString *newone_s (char *str, long l, unsigned long h) {
97 return ts; 97 return ts;
98} 98}
99 99
100static TaggedString *newone_u (char *buff, int tag, unsigned long h) { 100static TaggedString *newone_u (void *buff, int tag, unsigned long h) {
101 TaggedString *ts = luaM_new(TaggedString); 101 TaggedString *ts = luaM_new(TaggedString);
102 ts->u.d.v = buff; 102 ts->u.d.v = buff;
103 ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; 103 ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
@@ -109,7 +109,7 @@ static TaggedString *newone_u (char *buff, int tag, unsigned long h) {
109 return ts; 109 return ts;
110} 110}
111 111
112static TaggedString *insert_s (char *str, long l, stringtable *tb) { 112static TaggedString *insert_s (const char *str, long l, stringtable *tb) {
113 TaggedString *ts; 113 TaggedString *ts;
114 unsigned long h = hash_s(str, l); 114 unsigned long h = hash_s(str, l);
115 int size = tb->size; 115 int size = tb->size;
@@ -172,16 +172,16 @@ TaggedString *luaS_createudata (void *udata, int tag) {
172 return insert_u(udata, tag, &L->string_root[t]); 172 return insert_u(udata, tag, &L->string_root[t]);
173} 173}
174 174
175TaggedString *luaS_newlstr (char *str, long l) { 175TaggedString *luaS_newlstr (const char *str, long l) {
176 int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR; 176 int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR;
177 return insert_s(str, l, &L->string_root[t]); 177 return insert_s(str, l, &L->string_root[t]);
178} 178}
179 179
180TaggedString *luaS_new (char *str) { 180TaggedString *luaS_new (const char *str) {
181 return luaS_newlstr(str, strlen(str)); 181 return luaS_newlstr(str, strlen(str));
182} 182}
183 183
184TaggedString *luaS_newfixedstring (char *str) { 184TaggedString *luaS_newfixedstring (const char *str) {
185 TaggedString *ts = luaS_new(str); 185 TaggedString *ts = luaS_new(str);
186 if (ts->head.marked == 0) 186 if (ts->head.marked == 0)
187 ts->head.marked = 2; /* avoid GC */ 187 ts->head.marked = 2; /* avoid GC */
@@ -282,7 +282,7 @@ void luaS_rawsetglobal (TaggedString *ts, TObject *newval) {
282} 282}
283 283
284 284
285char *luaS_travsymbol (int (*fn)(TObject *)) { 285const char *luaS_travsymbol (int (*fn)(TObject *)) {
286 TaggedString *g; 286 TaggedString *g;
287 for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next) 287 for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next)
288 if (fn(&g->u.s.globalval)) 288 if (fn(&g->u.s.globalval))
@@ -291,7 +291,7 @@ char *luaS_travsymbol (int (*fn)(TObject *)) {
291} 291}
292 292
293 293
294int luaS_globaldefined (char *name) { 294int luaS_globaldefined (const char *name) {
295 TaggedString *ts = luaS_new(name); 295 TaggedString *ts = luaS_new(name);
296 return ts->u.s.globalval.ttype != LUA_T_NIL; 296 return ts->u.s.globalval.ttype != LUA_T_NIL;
297} 297}
diff --git a/lstring.h b/lstring.h
index 82cdbabb..0680cf6d 100644
--- a/lstring.h
+++ b/lstring.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.h,v 1.6 1997/12/01 20:31:25 roberto Exp roberto $ 2** $Id: lstring.h,v 1.7 1998/03/06 16:54:42 roberto Exp roberto $
3** String table (keep all strings handled by Lua) 3** String table (keep all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,12 +15,12 @@ void luaS_init (void);
15TaggedString *luaS_createudata (void *udata, int tag); 15TaggedString *luaS_createudata (void *udata, int tag);
16TaggedString *luaS_collector (void); 16TaggedString *luaS_collector (void);
17void luaS_free (TaggedString *l); 17void luaS_free (TaggedString *l);
18TaggedString *luaS_newlstr (char *str, long l); 18TaggedString *luaS_newlstr (const char *str, long l);
19TaggedString *luaS_new (char *str); 19TaggedString *luaS_new (const char *str);
20TaggedString *luaS_newfixedstring (char *str); 20TaggedString *luaS_newfixedstring (const char *str);
21void luaS_rawsetglobal (TaggedString *ts, TObject *newval); 21void luaS_rawsetglobal (TaggedString *ts, TObject *newval);
22char *luaS_travsymbol (int (*fn)(TObject *)); 22const char *luaS_travsymbol (int (*fn)(TObject *));
23int luaS_globaldefined (char *name); 23int luaS_globaldefined (const char *name);
24TaggedString *luaS_collectudata (void); 24TaggedString *luaS_collectudata (void);
25void luaS_freeall (void); 25void luaS_freeall (void);
26 26
diff --git a/lstrlib.c b/lstrlib.c
index a91f1a40..057605b3 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.32 1999/06/17 17:04:03 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.33 1999/08/10 12:55:56 roberto Exp roberto $
3** Standard library for strings and pattern-matching 3** Standard library for strings and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,16 +16,14 @@
16 16
17 17
18 18
19static void addnchar (char *s, int n) 19static void addnchar (const char *s, int n) {
20{
21 char *b = luaL_openspace(n); 20 char *b = luaL_openspace(n);
22 memcpy(b, s, n); 21 memcpy(b, s, n);
23 luaL_addsize(n); 22 luaL_addsize(n);
24} 23}
25 24
26 25
27static void str_len (void) 26static void str_len (void) {
28{
29 long l; 27 long l;
30 luaL_check_lstr(1, &l); 28 luaL_check_lstr(1, &l);
31 lua_pushnumber(l); 29 lua_pushnumber(l);
@@ -45,7 +43,7 @@ static long posrelat (long pos, long len) {
45 43
46static void str_sub (void) { 44static void str_sub (void) {
47 long l; 45 long l;
48 char *s = luaL_check_lstr(1, &l); 46 const char *s = luaL_check_lstr(1, &l);
49 long start = posrelat(luaL_check_long(2), l); 47 long start = posrelat(luaL_check_long(2), l);
50 long end = posrelat(luaL_opt_long(3, -1), l); 48 long end = posrelat(luaL_opt_long(3, -1), l);
51 if (start < 1) start = 1; 49 if (start < 1) start = 1;
@@ -59,7 +57,7 @@ static void str_sub (void) {
59static void str_lower (void) { 57static void str_lower (void) {
60 long l; 58 long l;
61 int i; 59 int i;
62 char *s = luaL_check_lstr(1, &l); 60 const char *s = luaL_check_lstr(1, &l);
63 luaL_resetbuffer(); 61 luaL_resetbuffer();
64 for (i=0; i<l; i++) 62 for (i=0; i<l; i++)
65 luaL_addchar(tolower((unsigned char)(s[i]))); 63 luaL_addchar(tolower((unsigned char)(s[i])));
@@ -70,17 +68,16 @@ static void str_lower (void) {
70static void str_upper (void) { 68static void str_upper (void) {
71 long l; 69 long l;
72 int i; 70 int i;
73 char *s = luaL_check_lstr(1, &l); 71 const char *s = luaL_check_lstr(1, &l);
74 luaL_resetbuffer(); 72 luaL_resetbuffer();
75 for (i=0; i<l; i++) 73 for (i=0; i<l; i++)
76 luaL_addchar(toupper((unsigned char)(s[i]))); 74 luaL_addchar(toupper((unsigned char)(s[i])));
77 closeandpush(); 75 closeandpush();
78} 76}
79 77
80static void str_rep (void) 78static void str_rep (void) {
81{
82 long l; 79 long l;
83 char *s = luaL_check_lstr(1, &l); 80 const char *s = luaL_check_lstr(1, &l);
84 int n = luaL_check_int(2); 81 int n = luaL_check_int(2);
85 luaL_resetbuffer(); 82 luaL_resetbuffer();
86 while (n-- > 0) 83 while (n-- > 0)
@@ -91,7 +88,7 @@ static void str_rep (void)
91 88
92static void str_byte (void) { 89static void str_byte (void) {
93 long l; 90 long l;
94 char *s = luaL_check_lstr(1, &l); 91 const char *s = luaL_check_lstr(1, &l);
95 long pos = posrelat(luaL_opt_long(2, 1), l); 92 long pos = posrelat(luaL_opt_long(2, 1), l);
96 luaL_arg_check(0<pos && pos<=l, 2, "out of range"); 93 luaL_arg_check(0<pos && pos<=l, 2, "out of range");
97 lua_pushnumber((unsigned char)s[pos-1]); 94 lua_pushnumber((unsigned char)s[pos-1]);
@@ -123,10 +120,10 @@ static void str_char (void) {
123 120
124 121
125struct Capture { 122struct Capture {
126 char *src_end; /* end ('\0') of source string */ 123 const char *src_end; /* end ('\0') of source string */
127 int level; /* total number of captures (finished or unfinished) */ 124 int level; /* total number of captures (finished or unfinished) */
128 struct { 125 struct {
129 char *init; 126 const char *init;
130 int len; /* -1 signals unfinished capture */ 127 int len; /* -1 signals unfinished capture */
131 } capture[MAX_CAPT]; 128 } capture[MAX_CAPT];
132}; 129};
@@ -163,7 +160,7 @@ static int capture_to_close (struct Capture *cap) {
163} 160}
164 161
165 162
166char *luaI_classend (char *p) { 163const char *luaI_classend (const char *p) {
167 switch (*p++) { 164 switch (*p++) {
168 case ESC: 165 case ESC:
169 if (*p == '\0') lua_error("incorrect pattern (ends with `%')"); 166 if (*p == '\0') lua_error("incorrect pattern (ends with `%')");
@@ -201,7 +198,7 @@ static int matchclass (int c, int cl) {
201 198
202 199
203 200
204static int matchbracketclass (int c, char *p, char *endclass) { 201static int matchbracketclass (int c, const char *p, const char *endclass) {
205 int sig = 1; 202 int sig = 1;
206 if (*(p+1) == '^') { 203 if (*(p+1) == '^') {
207 sig = 0; 204 sig = 0;
@@ -225,7 +222,7 @@ static int matchbracketclass (int c, char *p, char *endclass) {
225 222
226 223
227 224
228int luaI_singlematch (int c, char *p, char *ep) { 225int luaI_singlematch (int c, const char *p, const char *ep) {
229 switch (*p) { 226 switch (*p) {
230 case '.': /* matches any char */ 227 case '.': /* matches any char */
231 return 1; 228 return 1;
@@ -239,10 +236,11 @@ int luaI_singlematch (int c, char *p, char *ep) {
239} 236}
240 237
241 238
242static char *match (char *s, char *p, struct Capture *cap); 239static const char *match (const char *s, const char *p, struct Capture *cap);
243 240
244 241
245static char *matchbalance (char *s, char *p, struct Capture *cap) { 242static const char *matchbalance (const char *s, const char *p,
243 struct Capture *cap) {
246 if (*p == 0 || *(p+1) == 0) 244 if (*p == 0 || *(p+1) == 0)
247 lua_error("unbalanced pattern"); 245 lua_error("unbalanced pattern");
248 if (*s != *p) return NULL; 246 if (*s != *p) return NULL;
@@ -261,13 +259,14 @@ static char *matchbalance (char *s, char *p, struct Capture *cap) {
261} 259}
262 260
263 261
264static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) { 262static const char *max_expand (const char *s, const char *p, const char *ep,
263 struct Capture *cap) {
265 int i = 0; /* counts maximum expand for item */ 264 int i = 0; /* counts maximum expand for item */
266 while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) 265 while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep))
267 i++; 266 i++;
268 /* keeps trying to match mith the maximum repetitions */ 267 /* keeps trying to match mith the maximum repetitions */
269 while (i>=0) { 268 while (i>=0) {
270 char *res = match((s+i), ep+1, cap); 269 const char *res = match((s+i), ep+1, cap);
271 if (res) return res; 270 if (res) return res;
272 i--; /* else didn't match; reduce 1 repetition to try again */ 271 i--; /* else didn't match; reduce 1 repetition to try again */
273 } 272 }
@@ -275,9 +274,10 @@ static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) {
275} 274}
276 275
277 276
278static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) { 277static const char *min_expand (const char *s, const char *p, const char *ep,
278 struct Capture *cap) {
279 for (;;) { 279 for (;;) {
280 char *res = match(s, ep+1, cap); 280 const char *res = match(s, ep+1, cap);
281 if (res != NULL) 281 if (res != NULL)
282 return res; 282 return res;
283 else if (s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep)) 283 else if (s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep))
@@ -287,8 +287,9 @@ static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) {
287} 287}
288 288
289 289
290static char *start_capt (char *s, char *p, struct Capture *cap) { 290static const char *start_capt (const char *s, const char *p,
291 char *res; 291 struct Capture *cap) {
292 const char *res;
292 int level = cap->level; 293 int level = cap->level;
293 if (level >= MAX_CAPT) lua_error("too many captures"); 294 if (level >= MAX_CAPT) lua_error("too many captures");
294 cap->capture[level].init = s; 295 cap->capture[level].init = s;
@@ -300,9 +301,10 @@ static char *start_capt (char *s, char *p, struct Capture *cap) {
300} 301}
301 302
302 303
303static char *end_capt (char *s, char *p, struct Capture *cap) { 304static const char *end_capt (const char *s, const char *p,
305 struct Capture *cap) {
304 int l = capture_to_close(cap); 306 int l = capture_to_close(cap);
305 char *res; 307 const char *res;
306 cap->capture[l].len = s - cap->capture[l].init; /* close capture */ 308 cap->capture[l].len = s - cap->capture[l].init; /* close capture */
307 if ((res = match(s, p+1, cap)) == NULL) /* match failed? */ 309 if ((res = match(s, p+1, cap)) == NULL) /* match failed? */
308 cap->capture[l].len = -1; /* undo capture */ 310 cap->capture[l].len = -1; /* undo capture */
@@ -310,7 +312,8 @@ static char *end_capt (char *s, char *p, struct Capture *cap) {
310} 312}
311 313
312 314
313static char *match_capture (char *s, int level, struct Capture *cap) { 315static const char *match_capture (const char *s, int level,
316 struct Capture *cap) {
314 int l = check_cap(level, cap); 317 int l = check_cap(level, cap);
315 int len = cap->capture[l].len; 318 int len = cap->capture[l].len;
316 if (cap->src_end-s >= len && 319 if (cap->src_end-s >= len &&
@@ -320,7 +323,7 @@ static char *match_capture (char *s, int level, struct Capture *cap) {
320} 323}
321 324
322 325
323static char *match (char *s, char *p, struct Capture *cap) { 326static const char *match (const char *s, const char *p, struct Capture *cap) {
324 init: /* using goto's to optimize tail recursion */ 327 init: /* using goto's to optimize tail recursion */
325 switch (*p) { 328 switch (*p) {
326 case '(': /* start capture */ 329 case '(': /* start capture */
@@ -346,11 +349,11 @@ static char *match (char *s, char *p, struct Capture *cap) {
346 return (s == cap->src_end) ? s : NULL; /* check end of string */ 349 return (s == cap->src_end) ? s : NULL; /* check end of string */
347 else goto dflt; 350 else goto dflt;
348 default: dflt: { /* it is a pattern item */ 351 default: dflt: { /* it is a pattern item */
349 char *ep = luaI_classend(p); /* points to what is next */ 352 const char *ep = luaI_classend(p); /* points to what is next */
350 int m = s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep); 353 int m = s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep);
351 switch (*ep) { 354 switch (*ep) {
352 case '?': { /* optional */ 355 case '?': { /* optional */
353 char *res; 356 const char *res;
354 if (m && ((res=match(s+1, ep+1, cap)) != NULL)) 357 if (m && ((res=match(s+1, ep+1, cap)) != NULL))
355 return res; 358 return res;
356 p=ep+1; goto init; /* else return match(s, ep+1, cap); */ 359 p=ep+1; goto init; /* else return match(s, ep+1, cap); */
@@ -372,8 +375,8 @@ static char *match (char *s, char *p, struct Capture *cap) {
372 375
373static void str_find (void) { 376static void str_find (void) {
374 long l; 377 long l;
375 char *s = luaL_check_lstr(1, &l); 378 const char *s = luaL_check_lstr(1, &l);
376 char *p = luaL_check_string(2); 379 const char *p = luaL_check_string(2);
377 long init = posrelat(luaL_opt_long(3, 1), l) - 1; 380 long init = posrelat(luaL_opt_long(3, 1), l) - 1;
378 struct Capture cap; 381 struct Capture cap;
379 luaL_arg_check(0 <= init && init <= l, 3, "out of range"); 382 luaL_arg_check(0 <= init && init <= l, 3, "out of range");
@@ -388,10 +391,10 @@ static void str_find (void) {
388 } 391 }
389 else { 392 else {
390 int anchor = (*p == '^') ? (p++, 1) : 0; 393 int anchor = (*p == '^') ? (p++, 1) : 0;
391 char *s1=s+init; 394 const char *s1=s+init;
392 cap.src_end = s+l; 395 cap.src_end = s+l;
393 do { 396 do {
394 char *res; 397 const char *res;
395 cap.level = 0; 398 cap.level = 0;
396 if ((res=match(s1, p, &cap)) != NULL) { 399 if ((res=match(s1, p, &cap)) != NULL) {
397 lua_pushnumber(s1-s+1); /* start */ 400 lua_pushnumber(s1-s+1); /* start */
@@ -407,7 +410,7 @@ static void str_find (void) {
407 410
408static void add_s (lua_Object newp, struct Capture *cap) { 411static void add_s (lua_Object newp, struct Capture *cap) {
409 if (lua_isstring(newp)) { 412 if (lua_isstring(newp)) {
410 char *news = lua_getstring(newp); 413 const char *news = lua_getstring(newp);
411 int l = lua_strlen(newp); 414 int l = lua_strlen(newp);
412 int i; 415 int i;
413 for (i=0; i<l; i++) { 416 for (i=0; i<l; i++) {
@@ -449,8 +452,8 @@ static void add_s (lua_Object newp, struct Capture *cap) {
449 452
450static void str_gsub (void) { 453static void str_gsub (void) {
451 long srcl; 454 long srcl;
452 char *src = luaL_check_lstr(1, &srcl); 455 const char *src = luaL_check_lstr(1, &srcl);
453 char *p = luaL_check_string(2); 456 const char *p = luaL_check_string(2);
454 lua_Object newp = lua_getparam(3); 457 lua_Object newp = lua_getparam(3);
455 int max_s = luaL_opt_int(4, srcl+1); 458 int max_s = luaL_opt_int(4, srcl+1);
456 int anchor = (*p == '^') ? (p++, 1) : 0; 459 int anchor = (*p == '^') ? (p++, 1) : 0;
@@ -461,7 +464,7 @@ static void str_gsub (void) {
461 luaL_resetbuffer(); 464 luaL_resetbuffer();
462 cap.src_end = src+srcl; 465 cap.src_end = src+srcl;
463 while (n < max_s) { 466 while (n < max_s) {
464 char *e; 467 const char *e;
465 cap.level = 0; 468 cap.level = 0;
466 e = match(src, p, &cap); 469 e = match(src, p, &cap);
467 if (e) { 470 if (e) {
@@ -485,7 +488,7 @@ static void str_gsub (void) {
485 488
486static void luaI_addquoted (int arg) { 489static void luaI_addquoted (int arg) {
487 long l; 490 long l;
488 char *s = luaL_check_lstr(arg, &l); 491 const char *s = luaL_check_lstr(arg, &l);
489 luaL_addchar('"'); 492 luaL_addchar('"');
490 while (l--) { 493 while (l--) {
491 switch (*s) { 494 switch (*s) {
@@ -506,7 +509,7 @@ static void luaI_addquoted (int arg) {
506 509
507static void str_format (void) { 510static void str_format (void) {
508 int arg = 1; 511 int arg = 1;
509 char *strfrmt = luaL_check_string(arg); 512 const char *strfrmt = luaL_check_string(arg);
510 luaL_resetbuffer(); 513 luaL_resetbuffer();
511 while (*strfrmt) { 514 while (*strfrmt) {
512 if (*strfrmt != '%') 515 if (*strfrmt != '%')
@@ -517,7 +520,7 @@ static void str_format (void) {
517 struct Capture cap; 520 struct Capture cap;
518 char form[MAX_FORMAT]; /* to store the format ('%...') */ 521 char form[MAX_FORMAT]; /* to store the format ('%...') */
519 char *buff; /* to store the formatted item */ 522 char *buff; /* to store the formatted item */
520 char *initf = strfrmt; 523 const char *initf = strfrmt;
521 form[0] = '%'; 524 form[0] = '%';
522 if (isdigit((unsigned char)*initf) && *(initf+1) == '$') { 525 if (isdigit((unsigned char)*initf) && *(initf+1) == '$') {
523 arg = *initf - '0'; 526 arg = *initf - '0';
@@ -548,7 +551,7 @@ static void str_format (void) {
548 continue; /* skip the "addsize" at the end */ 551 continue; /* skip the "addsize" at the end */
549 case 's': { 552 case 's': {
550 long l; 553 long l;
551 char *s = luaL_check_lstr(arg, &l); 554 const char *s = luaL_check_lstr(arg, &l);
552 if (cap.capture[1].len == 0 && l >= 100) { 555 if (cap.capture[1].len == 0 && l >= 100) {
553 /* no precision and string is too big to be formatted; 556 /* no precision and string is too big to be formatted;
554 keep original string */ 557 keep original string */
@@ -570,7 +573,7 @@ static void str_format (void) {
570} 573}
571 574
572 575
573static struct luaL_reg strlib[] = { 576static const struct luaL_reg strlib[] = {
574{"strlen", str_len}, 577{"strlen", str_len},
575{"strsub", str_sub}, 578{"strsub", str_sub},
576{"strlower", str_lower}, 579{"strlower", str_lower},
diff --git a/ltable.c b/ltable.c
index 73a6011e..53d6c866 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.21 1999/02/23 14:57:28 roberto Exp roberto $ 2** $Id: ltable.c,v 1.22 1999/05/21 19:41:49 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,7 +24,7 @@
24 24
25 25
26 26
27static long int hashindex (TObject *ref) { 27static long int hashindex (const TObject *ref) {
28 long int h; 28 long int h;
29 switch (ttype(ref)) { 29 switch (ttype(ref)) {
30 case LUA_T_NUMBER: 30 case LUA_T_NUMBER:
@@ -53,7 +53,7 @@ static long int hashindex (TObject *ref) {
53} 53}
54 54
55 55
56Node *luaH_present (Hash *t, TObject *key) { 56Node *luaH_present (const Hash *t, const TObject *key) {
57 int tsize = nhash(t); 57 int tsize = nhash(t);
58 long int h = hashindex(key); 58 long int h = hashindex(key);
59 int h1 = h%tsize; 59 int h1 = h%tsize;
@@ -135,7 +135,7 @@ static void rehash (Hash *t) {
135} 135}
136 136
137 137
138void luaH_set (Hash *t, TObject *ref, TObject *val) { 138void luaH_set (Hash *t, const TObject *ref, const TObject *val) {
139 Node *n = luaH_present(t, ref); 139 Node *n = luaH_present(t, ref);
140 if (ttype(ref(n)) != LUA_T_NIL) 140 if (ttype(ref(n)) != LUA_T_NIL)
141 *val(n) = *val; 141 *val(n) = *val;
@@ -153,14 +153,14 @@ void luaH_set (Hash *t, TObject *ref, TObject *val) {
153} 153}
154 154
155 155
156int luaH_pos (Hash *t, TObject *r) { 156int luaH_pos (const Hash *t, const TObject *r) {
157 Node *n = luaH_present(t, r); 157 Node *n = luaH_present(t, r);
158 luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found"); 158 luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found");
159 return n-(t->node); 159 return n-(t->node);
160} 160}
161 161
162 162
163void luaH_setint (Hash *t, int ref, TObject *val) { 163void luaH_setint (Hash *t, int ref, const TObject *val) {
164 TObject index; 164 TObject index;
165 ttype(&index) = LUA_T_NUMBER; 165 ttype(&index) = LUA_T_NUMBER;
166 nvalue(&index) = ref; 166 nvalue(&index) = ref;
@@ -168,7 +168,7 @@ void luaH_setint (Hash *t, int ref, TObject *val) {
168} 168}
169 169
170 170
171TObject *luaH_getint (Hash *t, int ref) { 171TObject *luaH_getint (const Hash *t, int ref) {
172 TObject index; 172 TObject index;
173 ttype(&index) = LUA_T_NUMBER; 173 ttype(&index) = LUA_T_NUMBER;
174 nvalue(&index) = ref; 174 nvalue(&index) = ref;
diff --git a/ltable.h b/ltable.h
index b6a46cd2..6c8bbe40 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.h,v 1.10 1999/01/25 17:40:10 roberto Exp roberto $ 2** $Id: ltable.h,v 1.11 1999/02/23 14:57:28 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,11 +20,11 @@
20 20
21Hash *luaH_new (int nhash); 21Hash *luaH_new (int nhash);
22void luaH_free (Hash *frees); 22void luaH_free (Hash *frees);
23Node *luaH_present (Hash *t, TObject *key); 23Node *luaH_present (const Hash *t, const TObject *key);
24void luaH_set (Hash *t, TObject *ref, TObject *val); 24void luaH_set (Hash *t, const TObject *ref, const TObject *val);
25int luaH_pos (Hash *t, TObject *r); 25int luaH_pos (const Hash *t, const TObject *r);
26void luaH_setint (Hash *t, int ref, TObject *val); 26void luaH_setint (Hash *t, int ref, const TObject *val);
27TObject *luaH_getint (Hash *t, int ref); 27TObject *luaH_getint (const Hash *t, int ref);
28 28
29 29
30#endif 30#endif
diff --git a/ltm.c b/ltm.c
index a9b3b515..4c0a0876 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.24 1999/02/26 15:48:55 roberto Exp roberto $ 2** $Id: ltm.c,v 1.25 1999/05/21 19:41:49 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,14 +15,14 @@
15#include "ltm.h" 15#include "ltm.h"
16 16
17 17
18char *luaT_eventname[] = { /* ORDER IM */ 18const char *const luaT_eventname[] = { /* ORDER IM */
19 "gettable", "settable", "index", "getglobal", "setglobal", "add", 19 "gettable", "settable", "index", "getglobal", "setglobal", "add",
20 "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge", 20 "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
21 "concat", "gc", "function", NULL 21 "concat", "gc", "function", NULL
22}; 22};
23 23
24 24
25static int luaI_checkevent (char *name, char *list[]) { 25static int luaI_checkevent (const char *name, const char *const list[]) {
26 int e = luaL_findstring(name, list); 26 int e = luaL_findstring(name, list);
27 if (e < 0) 27 if (e < 0)
28 luaL_verror("`%.50s' is not a valid event name", name); 28 luaL_verror("`%.50s' is not a valid event name", name);
@@ -34,7 +34,8 @@ static int luaI_checkevent (char *name, char *list[]) {
34/* events in LUA_T_NIL are all allowed, since this is used as a 34/* events in LUA_T_NIL are all allowed, since this is used as a
35* 'placeholder' for "default" fallbacks 35* 'placeholder' for "default" fallbacks
36*/ 36*/
37static char luaT_validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */ 37/* ORDER LUA_T, ORDER IM */
38static const char luaT_validevents[NUM_TAGS][IM_N] = {
38{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */ 39{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */
39{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ 40{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */
40{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ 41{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */
@@ -96,7 +97,7 @@ int lua_copytagmethods (int tagto, int tagfrom) {
96} 97}
97 98
98 99
99int luaT_effectivetag (TObject *o) { 100int luaT_effectivetag (const TObject *o) {
100 int t; 101 int t;
101 switch (t = ttype(o)) { 102 switch (t = ttype(o)) {
102 case LUA_T_ARRAY: 103 case LUA_T_ARRAY:
@@ -118,7 +119,7 @@ int luaT_effectivetag (TObject *o) {
118} 119}
119 120
120 121
121TObject *luaT_gettagmethod (int t, char *event) { 122const TObject *luaT_gettagmethod (int t, const char *event) {
122 int e = luaI_checkevent(event, luaT_eventname); 123 int e = luaI_checkevent(event, luaT_eventname);
123 checktag(t); 124 checktag(t);
124 if (luaT_validevent(t, e)) 125 if (luaT_validevent(t, e))
@@ -128,7 +129,7 @@ TObject *luaT_gettagmethod (int t, char *event) {
128} 129}
129 130
130 131
131void luaT_settagmethod (int t, char *event, TObject *func) { 132void luaT_settagmethod (int t, const char *event, TObject *func) {
132 TObject temp; 133 TObject temp;
133 int e = luaI_checkevent(event, luaT_eventname); 134 int e = luaI_checkevent(event, luaT_eventname);
134 checktag(t); 135 checktag(t);
@@ -143,7 +144,7 @@ void luaT_settagmethod (int t, char *event, TObject *func) {
143} 144}
144 145
145 146
146char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */ 147const char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */
147 int e; 148 int e;
148 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { 149 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) {
149 int t; 150 int t;
@@ -191,10 +192,11 @@ static void fillvalids (IMS e, TObject *func) {
191 192
192 193
193void luaT_setfallback (void) { 194void luaT_setfallback (void) {
194 static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL}; 195 static const char *const oldnames [] = {"error", "getglobal", "arith",
196 "order", NULL};
195 TObject oldfunc; 197 TObject oldfunc;
196 lua_CFunction replace; 198 lua_CFunction replace;
197 char *name = luaL_check_string(1); 199 const char *name = luaL_check_string(1);
198 lua_Object func = lua_getparam(2); 200 lua_Object func = lua_getparam(2);
199 luaL_arg_check(lua_isfunction(func), 2, "function expected"); 201 luaL_arg_check(lua_isfunction(func), 2, "function expected");
200 switch (luaL_findstring(name, oldnames)) { 202 switch (luaL_findstring(name, oldnames)) {
diff --git a/ltm.h b/ltm.h
index 87081874..3eaea82e 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 1.4 1997/11/26 18:53:45 roberto Exp roberto $ 2** $Id: ltm.h,v 1.5 1999/01/15 13:11:57 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -47,15 +47,15 @@ struct IM {
47#define luaT_getim(tag,event) (&L->IMtable[-(tag)].int_method[event]) 47#define luaT_getim(tag,event) (&L->IMtable[-(tag)].int_method[event])
48#define luaT_getimbyObj(o,e) (luaT_getim(luaT_effectivetag(o),(e))) 48#define luaT_getimbyObj(o,e) (luaT_getim(luaT_effectivetag(o),(e)))
49 49
50extern char *luaT_eventname[]; 50extern const char *const luaT_eventname[];
51 51
52 52
53void luaT_init (void); 53void luaT_init (void);
54void luaT_realtag (int tag); 54void luaT_realtag (int tag);
55int luaT_effectivetag (TObject *o); 55int luaT_effectivetag (const TObject *o);
56void luaT_settagmethod (int t, char *event, TObject *func); 56void luaT_settagmethod (int t, const char *event, TObject *func);
57TObject *luaT_gettagmethod (int t, char *event); 57const TObject *luaT_gettagmethod (int t, const char *event);
58char *luaT_travtagmethods (int (*fn)(TObject *)); 58const char *luaT_travtagmethods (int (*fn)(TObject *));
59 59
60void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */ 60void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */
61 61
diff --git a/lua.c b/lua.c
index 625b459d..474e583f 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.20 1999/06/24 19:42:02 roberto Exp roberto $ 2** $Id: lua.c,v 1.21 1999/07/02 18:22:38 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,7 +52,7 @@ static void laction (int i) {
52} 52}
53 53
54 54
55static int ldo (int (*f)(char *), char *name) { 55static int ldo (int (*f)(const char *), const char *name) {
56 int res; 56 int res;
57 handler h = lreset(); 57 handler h = lreset();
58 res = f(name); /* dostring | dofile */ 58 res = f(name); /* dostring | dofile */
diff --git a/lua.h b/lua.h
index ddba13fa..2f0f2b4c 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.32 1999/05/11 20:29:19 roberto Exp roberto $ 2** $Id: lua.h,v 1.33 1999/08/11 17:00:59 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: lua@tecgraf.puc-rio.br 5** e-mail: lua@tecgraf.puc-rio.br
@@ -33,18 +33,21 @@ void lua_open (void);
33void lua_close (void); 33void lua_close (void);
34lua_State *lua_setstate (lua_State *st); 34lua_State *lua_setstate (lua_State *st);
35 35
36lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ 36lua_Object lua_settagmethod (int tag, const char *event);
37lua_Object lua_gettagmethod (int tag, char *event); 37 /* In: new method */
38lua_Object lua_gettagmethod (int tag, const char *event);
38 39
39int lua_newtag (void); 40int lua_newtag (void);
40int lua_copytagmethods (int tagto, int tagfrom); 41int lua_copytagmethods (int tagto, int tagfrom);
41void lua_settag (int tag); /* In: object */ 42void lua_settag (int tag); /* In: object */
42 43
43void lua_error (char *s); 44void lua_error (const char *s);
44int lua_dofile (char *filename); /* Out: returns */ 45int lua_dofile (const char *filename);
45int lua_dostring (char *string); /* Out: returns */ 46 /* Out: returns */
46int lua_dobuffer (char *buff, int size, char *name); 47int lua_dostring (const char *string);
47 /* Out: returns */ 48 /* Out: returns */
49int lua_dobuffer (const char *buff, int size,
50 const char *name); /* Out: returns */
48int lua_callfunction (lua_Object f); 51int lua_callfunction (lua_Object f);
49 /* In: parameters; Out: returns */ 52 /* In: parameters; Out: returns */
50 53
@@ -64,7 +67,7 @@ int lua_isstring (lua_Object object);
64int lua_isfunction (lua_Object object); 67int lua_isfunction (lua_Object object);
65 68
66double lua_getnumber (lua_Object object); 69double lua_getnumber (lua_Object object);
67char *lua_getstring (lua_Object object); 70const char *lua_getstring (lua_Object object);
68long lua_strlen (lua_Object object); 71long lua_strlen (lua_Object object);
69lua_CFunction lua_getcfunction (lua_Object object); 72lua_CFunction lua_getcfunction (lua_Object object);
70void *lua_getuserdata (lua_Object object); 73void *lua_getuserdata (lua_Object object);
@@ -72,18 +75,18 @@ void *lua_getuserdata (lua_Object object);
72 75
73void lua_pushnil (void); 76void lua_pushnil (void);
74void lua_pushnumber (double n); 77void lua_pushnumber (double n);
75void lua_pushlstring (char *s, long len); 78void lua_pushlstring (const char *s, long len);
76void lua_pushstring (char *s); 79void lua_pushstring (const char *s);
77void lua_pushcclosure (lua_CFunction fn, int n); 80void lua_pushcclosure (lua_CFunction fn, int n);
78void lua_pushusertag (void *u, int tag); 81void lua_pushusertag (void *u, int tag);
79void lua_pushobject (lua_Object object); 82void lua_pushobject (lua_Object object);
80 83
81lua_Object lua_pop (void); 84lua_Object lua_pop (void);
82 85
83lua_Object lua_getglobal (char *name); 86lua_Object lua_getglobal (const char *name);
84lua_Object lua_rawgetglobal (char *name); 87lua_Object lua_rawgetglobal (const char *name);
85void lua_setglobal (char *name); /* In: value */ 88void lua_setglobal (const char *name); /* In: value */
86void lua_rawsetglobal (char *name); /* In: value */ 89void lua_rawsetglobal (const char *name); /* In: value */
87 90
88void lua_settable (void); /* In: table, index, value */ 91void lua_settable (void); /* In: table, index, value */
89void lua_rawsettable (void); /* In: table, index, value */ 92void lua_rawsettable (void); /* In: table, index, value */
@@ -92,7 +95,7 @@ lua_Object lua_rawgettable (void); /* In: table, index */
92 95
93int lua_tag (lua_Object object); 96int lua_tag (lua_Object object);
94 97
95char *lua_nextvar (char *varname); /* Out: value */ 98const char *lua_nextvar (const char *varname); /* Out: value */
96int lua_next (lua_Object o, int i); 99int lua_next (lua_Object o, int i);
97 /* Out: ref, value */ 100 /* Out: ref, value */
98 101
diff --git a/luadebug.h b/luadebug.h
index f7727119..53deba78 100644
--- a/luadebug.h
+++ b/luadebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luadebug.h,v 1.5 1999/02/04 17:47:59 roberto Exp roberto $ 2** $Id: luadebug.h,v 1.6 1999/03/04 21:17:26 roberto Exp roberto $
3** Debugging API 3** Debugging API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,14 +14,15 @@
14typedef lua_Object lua_Function; 14typedef lua_Object lua_Function;
15 15
16typedef void (*lua_LHFunction) (int line); 16typedef void (*lua_LHFunction) (int line);
17typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); 17typedef void (*lua_CHFunction) (lua_Function func, const char *file, int line);
18 18
19lua_Function lua_stackedfunction (int level); 19lua_Function lua_stackedfunction (int level);
20void lua_funcinfo (lua_Object func, char **source, int *linedefined); 20void lua_funcinfo (lua_Object func, const char **source, int *linedefined);
21int lua_currentline (lua_Function func); 21int lua_currentline (lua_Function func);
22char *lua_getobjname (lua_Object o, char **name); 22const char *lua_getobjname (lua_Object o, const char **name);
23 23
24lua_Object lua_getlocal (lua_Function func, int local_number, char **name); 24lua_Object lua_getlocal (lua_Function func, int local_number,
25 const char **name);
25int lua_setlocal (lua_Function func, int local_number); 26int lua_setlocal (lua_Function func, int local_number);
26 27
27int lua_nups (lua_Function func); 28int lua_nups (lua_Function func);
diff --git a/lualib.h b/lualib.h
index 805165f0..f60e72d1 100644
--- a/lualib.h
+++ b/lualib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lualib.h,v 1.5 1999/01/08 16:47:44 roberto Exp roberto $ 2** $Id: lualib.h,v 1.6 1999/05/05 19:23:11 roberto Exp roberto $
3** Lua standard libraries 3** Lua standard libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -29,8 +29,8 @@ void lua_userinit (void);
29 29
30/* Auxiliary functions (private) */ 30/* Auxiliary functions (private) */
31 31
32char *luaI_classend (char *p); 32const char *luaI_classend (const char *p);
33int luaI_singlematch (int c, char *p, char *ep); 33int luaI_singlematch (int c, const char *p, const char *ep);
34 34
35#endif 35#endif
36 36
diff --git a/lundump.c b/lundump.c
index 0c3b5fd7..225eda28 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.21 1999/07/02 19:34:26 lhf Exp $ 2** $Id: lundump.c,v 1.12 1999/07/08 12:43:23 roberto Exp roberto $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,7 +50,7 @@ static unsigned long LoadLong (ZIO* Z)
50/* 50/*
51* convert number from text 51* convert number from text
52*/ 52*/
53double luaU_str2d (char* b, char* where) 53double luaU_str2d (const char* b, const char* where)
54{ 54{
55 int negative=(b[0]=='-'); 55 int negative=(b[0]=='-');
56 double x=luaO_str2d(b+negative); 56 double x=luaO_str2d(b+negative);
@@ -76,7 +76,7 @@ static real LoadNumber (ZIO* Z, int native)
76 } 76 }
77} 77}
78 78
79static int LoadInt (ZIO* Z, char* message) 79static int LoadInt (ZIO* Z, const char* message)
80{ 80{
81 unsigned long l=LoadLong(Z); 81 unsigned long l=LoadLong(Z);
82 unsigned int i=l; 82 unsigned int i=l;
@@ -169,7 +169,7 @@ static TProtoFunc* LoadFunction (ZIO* Z, int native)
169 169
170static void LoadSignature (ZIO* Z) 170static void LoadSignature (ZIO* Z)
171{ 171{
172 char* s=SIGNATURE; 172 const char* s=SIGNATURE;
173 while (*s!=0 && ezgetc(Z)==*s) 173 while (*s!=0 && ezgetc(Z)==*s)
174 ++s; 174 ++s;
175 if (*s!=0) luaL_verror("bad signature in %s",zname(Z)); 175 if (*s!=0) luaL_verror("bad signature in %s",zname(Z));
@@ -231,9 +231,9 @@ TProtoFunc* luaU_undump1 (ZIO* Z)
231/* 231/*
232* handle constants that cannot happen 232* handle constants that cannot happen
233*/ 233*/
234void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf) 234void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf)
235{ 235{
236 int t=ttype(o); 236 int t=ttype(o);
237 char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t]; 237 const char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
238 luaL_verror("cannot %s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC); 238 luaL_verror("cannot %s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC);
239} 239}
diff --git a/lundump.h b/lundump.h
index 3f905cb0..915464b0 100644
--- a/lundump.h
+++ b/lundump.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.h,v 1.15 1999/07/02 19:34:26 lhf Exp $ 2** $Id: lundump.h,v 1.9 1999/07/08 12:43:23 roberto Exp roberto $
3** load pre-compiled Lua chunks 3** load pre-compiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,9 +11,9 @@
11#include "lzio.h" 11#include "lzio.h"
12 12
13TProtoFunc* luaU_undump1 (ZIO* Z); /* load one chunk */ 13TProtoFunc* luaU_undump1 (ZIO* Z); /* load one chunk */
14void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf); 14void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf);
15 /* handle cases that cannot happen */ 15 /* handle cases that cannot happen */
16double luaU_str2d (char* b, char* where); 16double luaU_str2d (const char* b, const char* where);
17 /* convert number from text */ 17 /* convert number from text */
18 18
19/* definitions for headers of binary files */ 19/* definitions for headers of binary files */
diff --git a/lvm.c b/lvm.c
index 0da22600..62060d90 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp roberto $ 2** $Id: lvm.c,v 1.59 1999/08/10 12:55:47 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,7 +114,7 @@ void luaV_closure (int nelems) {
114*/ 114*/
115void luaV_gettable (void) { 115void luaV_gettable (void) {
116 TObject *table = L->stack.top-2; 116 TObject *table = L->stack.top-2;
117 TObject *im; 117 const TObject *im;
118 if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ 118 if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */
119 im = luaT_getimbyObj(table, IM_GETTABLE); 119 im = luaT_getimbyObj(table, IM_GETTABLE);
120 if (ttype(im) == LUA_T_NIL) 120 if (ttype(im) == LUA_T_NIL)
@@ -146,9 +146,9 @@ void luaV_gettable (void) {
146/* 146/*
147** Receives table at *t, index at *(t+1) and value at top. 147** Receives table at *t, index at *(t+1) and value at top.
148*/ 148*/
149void luaV_settable (TObject *t) { 149void luaV_settable (const TObject *t) {
150 struct Stack *S = &L->stack; 150 struct Stack *S = &L->stack;
151 TObject *im; 151 const TObject *im;
152 if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */ 152 if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */
153 im = luaT_getimbyObj(t, IM_SETTABLE); 153 im = luaT_getimbyObj(t, IM_SETTABLE);
154 if (ttype(im) == LUA_T_NIL) 154 if (ttype(im) == LUA_T_NIL)
@@ -173,7 +173,7 @@ void luaV_settable (TObject *t) {
173} 173}
174 174
175 175
176void luaV_rawsettable (TObject *t) { 176void luaV_rawsettable (const TObject *t) {
177 if (ttype(t) != LUA_T_ARRAY) 177 if (ttype(t) != LUA_T_ARRAY)
178 lua_error("indexed expression not a table"); 178 lua_error("indexed expression not a table");
179 else { 179 else {
@@ -186,7 +186,7 @@ void luaV_rawsettable (TObject *t) {
186 186
187void luaV_getglobal (TaggedString *ts) { 187void luaV_getglobal (TaggedString *ts) {
188 /* WARNING: caller must assure stack space */ 188 /* WARNING: caller must assure stack space */
189 TObject *value = &ts->u.s.globalval; 189 const TObject *value = &ts->u.s.globalval;
190 switch (ttype(value)) { 190 switch (ttype(value)) {
191 /* only userdata, tables and nil can have getglobal tag methods */ 191 /* only userdata, tables and nil can have getglobal tag methods */
192 case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: { 192 case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: {
@@ -208,8 +208,8 @@ void luaV_getglobal (TaggedString *ts) {
208 208
209 209
210void luaV_setglobal (TaggedString *ts) { 210void luaV_setglobal (TaggedString *ts) {
211 TObject *oldvalue = &ts->u.s.globalval; 211 const TObject *oldvalue = &ts->u.s.globalval;
212 TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); 212 const TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
213 if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ 213 if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
214 luaS_rawsetglobal(ts, --L->stack.top); 214 luaS_rawsetglobal(ts, --L->stack.top);
215 else { 215 else {
@@ -226,9 +226,9 @@ void luaV_setglobal (TaggedString *ts) {
226} 226}
227 227
228 228
229static void call_binTM (IMS event, char *msg) 229static void call_binTM (IMS event, const char *msg) {
230{ 230 /* try first operand */
231 TObject *im = luaT_getimbyObj(L->stack.top-2, event);/* try first operand */ 231 const TObject *im = luaT_getimbyObj(L->stack.top-2, event);
232 if (ttype(im) == LUA_T_NIL) { 232 if (ttype(im) == LUA_T_NIL) {
233 im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */ 233 im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */
234 if (ttype(im) == LUA_T_NIL) { 234 if (ttype(im) == LUA_T_NIL) {
@@ -242,14 +242,12 @@ static void call_binTM (IMS event, char *msg)
242} 242}
243 243
244 244
245static void call_arith (IMS event) 245static void call_arith (IMS event) {
246{
247 call_binTM(event, "unexpected type in arithmetic operation"); 246 call_binTM(event, "unexpected type in arithmetic operation");
248} 247}
249 248
250 249
251static int luaV_strcomp (char *l, long ll, char *r, long lr) 250static int luaV_strcomp (const char *l, long ll, const char *r, long lr) {
252{
253 for (;;) { 251 for (;;) {
254 long temp = strcoll(l, r); 252 long temp = strcoll(l, r);
255 if (temp != 0) return temp; 253 if (temp != 0) return temp;
@@ -268,8 +266,8 @@ static int luaV_strcomp (char *l, long ll, char *r, long lr)
268void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, 266void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal,
269 lua_Type ttype_great, IMS op) { 267 lua_Type ttype_great, IMS op) {
270 struct Stack *S = &L->stack; 268 struct Stack *S = &L->stack;
271 TObject *l = S->top-2; 269 const TObject *l = S->top-2;
272 TObject *r = S->top-1; 270 const TObject *r = S->top-1;
273 real result; 271 real result;
274 if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) 272 if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
275 result = nvalue(l)-nvalue(r); 273 result = nvalue(l)-nvalue(r);
@@ -300,8 +298,7 @@ void luaV_pack (StkId firstel, int nvararg, TObject *tab) {
300} 298}
301 299
302 300
303static void adjust_varargs (StkId first_extra_arg) 301static void adjust_varargs (StkId first_extra_arg) {
304{
305 TObject arg; 302 TObject arg;
306 luaV_pack(first_extra_arg, 303 luaV_pack(first_extra_arg,
307 (L->stack.top-L->stack.stack)-first_extra_arg, &arg); 304 (L->stack.top-L->stack.stack)-first_extra_arg, &arg);
@@ -318,8 +315,8 @@ static void adjust_varargs (StkId first_extra_arg)
318*/ 315*/
319StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { 316StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
320 struct Stack *S = &L->stack; /* to optimize */ 317 struct Stack *S = &L->stack; /* to optimize */
321 register Byte *pc = tf->code; 318 register const Byte *pc = tf->code;
322 TObject *consts = tf->consts; 319 const TObject *consts = tf->consts;
323 if (L->callhook) 320 if (L->callhook)
324 luaD_callHook(base, tf, 0); 321 luaD_callHook(base, tf, 0);
325 luaD_checkstack((*pc++)+EXTRA_STACK); 322 luaD_checkstack((*pc++)+EXTRA_STACK);
diff --git a/lvm.h b/lvm.h
index ed66403b..a0a3fc51 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 1.7 1998/12/30 17:26:49 roberto Exp roberto $ 2** $Id: lvm.h,v 1.8 1999/02/08 17:07:59 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,8 +22,8 @@ int luaV_tonumber (TObject *obj);
22int luaV_tostring (TObject *obj); 22int luaV_tostring (TObject *obj);
23void luaV_setn (Hash *t, int val); 23void luaV_setn (Hash *t, int val);
24void luaV_gettable (void); 24void luaV_gettable (void);
25void luaV_settable (TObject *t); 25void luaV_settable (const TObject *t);
26void luaV_rawsettable (TObject *t); 26void luaV_rawsettable (const TObject *t);
27void luaV_getglobal (TaggedString *ts); 27void luaV_getglobal (TaggedString *ts);
28void luaV_setglobal (TaggedString *ts); 28void luaV_setglobal (TaggedString *ts);
29StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base); 29StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base);
diff --git a/lzio.c b/lzio.c
index aaa900c4..c59ec559 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.6 1999/03/04 14:49:18 roberto Exp roberto $ 2** $Id: lzio.c,v 1.7 1999/03/05 13:15:50 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,51 +16,48 @@
16/* ----------------------------------------------------- memory buffers --- */ 16/* ----------------------------------------------------- memory buffers --- */
17 17
18static int zmfilbuf (ZIO* z) { 18static int zmfilbuf (ZIO* z) {
19 return EOZ; 19 return EOZ;
20} 20}
21 21
22 22
23ZIO* zmopen (ZIO* z, char* b, int size, char *name) 23ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) {
24{ 24 if (b==NULL) return NULL;
25 if (b==NULL) return NULL; 25 z->n = size;
26 z->n=size; 26 z->p = (unsigned const char *)b;
27 z->p= (unsigned char *)b; 27 z->filbuf = zmfilbuf;
28 z->filbuf=zmfilbuf; 28 z->u = NULL;
29 z->u=NULL; 29 z->name = name;
30 z->name=name; 30 return z;
31 return z;
32} 31}
33 32
34/* ------------------------------------------------------------ strings --- */ 33/* ------------------------------------------------------------ strings --- */
35 34
36ZIO* zsopen (ZIO* z, char* s, char *name) 35ZIO* zsopen (ZIO* z, const char* s, const char *name) {
37{ 36 if (s==NULL) return NULL;
38 if (s==NULL) return NULL; 37 return zmopen(z,s,strlen(s),name);
39 return zmopen(z,s,strlen(s),name);
40} 38}
41 39
42/* -------------------------------------------------------------- FILEs --- */ 40/* -------------------------------------------------------------- FILEs --- */
43 41
44static int zffilbuf (ZIO* z) { 42static int zffilbuf (ZIO* z) {
45 int n; 43 int n;
46 if (feof((FILE *)z->u)) return EOZ; 44 if (feof((FILE *)z->u)) return EOZ;
47 n=fread(z->buffer,1,ZBSIZE,z->u); 45 n = fread(z->buffer,1,ZBSIZE,z->u);
48 if (n==0) return EOZ; 46 if (n==0) return EOZ;
49 z->n=n-1; 47 z->n = n-1;
50 z->p=z->buffer; 48 z->p = z->buffer;
51 return *(z->p++); 49 return *(z->p++);
52} 50}
53 51
54 52
55ZIO* zFopen (ZIO* z, FILE* f, char *name) 53ZIO* zFopen (ZIO* z, FILE* f, const char *name) {
56{ 54 if (f==NULL) return NULL;
57 if (f==NULL) return NULL; 55 z->n = 0;
58 z->n=0; 56 z->p = z->buffer;
59 z->p=z->buffer; 57 z->filbuf = zffilbuf;
60 z->filbuf=zffilbuf; 58 z->u = f;
61 z->u=f; 59 z->name = name;
62 z->name=name; 60 return z;
63 return z;
64} 61}
65 62
66 63
diff --git a/lzio.h b/lzio.h
index 94b79da4..448ef059 100644
--- a/lzio.h
+++ b/lzio.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.h,v 1.3 1997/12/22 20:57:18 roberto Exp roberto $ 2** $Id: lzio.h,v 1.4 1998/01/09 14:57:43 roberto Exp roberto $
3** Buffered streams 3** Buffered streams
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,9 +22,9 @@
22 22
23typedef struct zio ZIO; 23typedef struct zio ZIO;
24 24
25ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */ 25ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */
26ZIO* zsopen (ZIO* z, char* s, char *name); /* string */ 26ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */
27ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */ 27ZIO* zmopen (ZIO* z, const char* b, int size, const char *name); /* memory */
28 28
29int zread (ZIO* z, void* b, int n); /* read next n bytes */ 29int zread (ZIO* z, void* b, int n); /* read next n bytes */
30 30
@@ -38,12 +38,12 @@ int zread (ZIO* z, void* b, int n); /* read next n bytes */
38#define ZBSIZE 256 /* buffer size */ 38#define ZBSIZE 256 /* buffer size */
39 39
40struct zio { 40struct zio {
41 int n; /* bytes still unread */ 41 int n; /* bytes still unread */
42 unsigned char* p; /* current position in buffer */ 42 const unsigned char* p; /* current position in buffer */
43 int (*filbuf)(ZIO* z); 43 int (*filbuf)(ZIO* z);
44 void* u; /* additional data */ 44 void* u; /* additional data */
45 char *name; 45 const char *name;
46 unsigned char buffer[ZBSIZE]; /* buffer */ 46 unsigned char buffer[ZBSIZE]; /* buffer */
47}; 47};
48 48
49 49