diff options
| -rw-r--r-- | lapi.c | 155 | ||||
| -rw-r--r-- | lapi.h | 6 | ||||
| -rw-r--r-- | lauxlib.c | 41 | ||||
| -rw-r--r-- | lauxlib.h | 20 | ||||
| -rw-r--r-- | lbuiltin.c | 44 | ||||
| -rw-r--r-- | ldblib.c | 20 | ||||
| -rw-r--r-- | ldo.c | 26 | ||||
| -rw-r--r-- | ldo.h | 6 | ||||
| -rw-r--r-- | lfunc.c | 22 | ||||
| -rw-r--r-- | lfunc.h | 4 | ||||
| -rw-r--r-- | lgc.c | 52 | ||||
| -rw-r--r-- | lgc.h | 6 | ||||
| -rw-r--r-- | liolib.c | 48 | ||||
| -rw-r--r-- | llex.c | 16 | ||||
| -rw-r--r-- | llex.h | 6 | ||||
| -rw-r--r-- | lmathlib.c | 4 | ||||
| -rw-r--r-- | lmem.c | 30 | ||||
| -rw-r--r-- | lmem.h | 4 | ||||
| -rw-r--r-- | lobject.c | 18 | ||||
| -rw-r--r-- | lobject.h | 10 | ||||
| -rw-r--r-- | lparser.c | 25 | ||||
| -rw-r--r-- | lparser.h | 6 | ||||
| -rw-r--r-- | lstate.c | 8 | ||||
| -rw-r--r-- | lstring.c | 20 | ||||
| -rw-r--r-- | lstring.h | 12 | ||||
| -rw-r--r-- | lstrlib.c | 91 | ||||
| -rw-r--r-- | ltable.c | 14 | ||||
| -rw-r--r-- | ltable.h | 12 | ||||
| -rw-r--r-- | ltm.c | 22 | ||||
| -rw-r--r-- | ltm.h | 12 | ||||
| -rw-r--r-- | lua.c | 4 | ||||
| -rw-r--r-- | lua.h | 35 | ||||
| -rw-r--r-- | luadebug.h | 11 | ||||
| -rw-r--r-- | lualib.h | 6 | ||||
| -rw-r--r-- | lundump.c | 12 | ||||
| -rw-r--r-- | lundump.h | 6 | ||||
| -rw-r--r-- | lvm.c | 39 | ||||
| -rw-r--r-- | lvm.h | 6 | ||||
| -rw-r--r-- | lzio.c | 59 | ||||
| -rw-r--r-- | lzio.h | 20 |
40 files changed, 442 insertions, 516 deletions
| @@ -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 | ||
| 27 | char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | 27 | const 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 | ||
| 37 | static lua_Type normalized_type (TObject *o) | 37 | static 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 | ||
| 53 | static void set_normalized (TObject *d, TObject *s) | 52 | static 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 | ||
| 60 | static TObject *luaA_protovalue (TObject *o) | 58 | static 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 | ||
| 66 | void luaA_packresults (void) | 63 | void 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 | ||
| 79 | static void checkCparams (int nParams) | 75 | static 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 | ||
| 86 | static lua_Object put_luaObject (TObject *o) { | 81 | static 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 | */ |
| 118 | lua_Object lua_lua2C (int number) | 113 | lua_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 | ||
| 127 | int lua_callfunction (lua_Object function) | 121 | int 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 | ||
| 139 | lua_Object lua_gettagmethod (int tag, char *event) | 132 | lua_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 | ||
| 145 | lua_Object lua_settagmethod (int tag, char *event) | 137 | lua_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 | ||
| 162 | lua_Object lua_gettable (void) | 153 | lua_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 | ||
| 193 | lua_Object lua_createtable (void) | 183 | lua_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 | ||
| 203 | lua_Object lua_getglobal (char *name) | 192 | lua_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 | ||
| 211 | lua_Object lua_rawgetglobal (char *name) | 199 | lua_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 | ||
| 218 | void lua_setglobal (char *name) | 205 | void 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 | ||
| 226 | void lua_rawsetglobal (char *name) | 212 | void 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 | ||
| 235 | int lua_isnil (lua_Object o) | 220 | int 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 | ||
| 240 | int lua_istable (lua_Object o) | 224 | int 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 | ||
| 245 | int lua_isuserdata (lua_Object o) | 228 | int 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 | ||
| 250 | int lua_iscfunction (lua_Object o) | 232 | int 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 | ||
| 255 | int lua_isnumber (lua_Object o) | 236 | int 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 | ||
| 260 | int lua_isstring (lua_Object o) | 240 | int 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 | ||
| 266 | int lua_isfunction (lua_Object o) | 245 | int 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 | ||
| 273 | double lua_getnumber (lua_Object object) | 251 | double 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 | ||
| 280 | char *lua_getstring (lua_Object object) | 257 | const 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 | ||
| 288 | long lua_strlen (lua_Object object) | 264 | long 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 | ||
| 296 | void *lua_getuserdata (lua_Object object) | 271 | void *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 | ||
| 303 | lua_CFunction lua_getcfunction (lua_Object object) | 277 | lua_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 | ||
| 311 | void lua_pushnil (void) | 284 | void 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 | ||
| 317 | void lua_pushnumber (double n) | 289 | void 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 | ||
| 324 | void lua_pushlstring (char *s, long len) | 295 | void 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 | ||
| 332 | void lua_pushstring (char *s) | 302 | void 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 | ||
| 340 | void lua_pushcclosure (lua_CFunction fn, int n) | 309 | void 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 | ||
| 352 | void lua_pushusertag (void *u, int tag) | 320 | void 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 | ||
| 362 | void luaA_pushobject (TObject *o) | 329 | void 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 | ||
| 376 | int lua_tag (lua_Object lo) | 342 | int 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 | ||
| 405 | void lua_settag (int tag) | 370 | void 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 | ||
| 443 | char *lua_nextvar (char *varname) { | 407 | const 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 | ||
| 457 | int luaA_next (Hash *t, int i) { | 421 | int 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 | ||
| 471 | int lua_next (lua_Object o, int i) { | 435 | int 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 | ||
| 522 | lua_Function lua_stackedfunction (int level) | 486 | lua_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 | ||
| 535 | int lua_nups (lua_Function func) { | 498 | int 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 | ||
| 541 | int lua_currentline (lua_Function func) | 504 | int 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 | ||
| 549 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name) { | 511 | lua_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 | ||
| 568 | int lua_setlocal (lua_Function func, int local_number) | 531 | int 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 | ||
| 591 | void lua_funcinfo (lua_Object func, char **source, int *linedefined) { | 553 | void 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 | ||
| 608 | static int checkfunc (TObject *o) | 570 | static 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 | ||
| 614 | char *lua_getobjname (lua_Object o, char **name) | 575 | const 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 | ||
| 664 | lua_Object lua_getref (int ref) { | 625 | lua_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 | ||
| @@ -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 | ||
| 15 | TObject *luaA_Address (lua_Object o); | 15 | TObject *luaA_Address (lua_Object o); |
| 16 | void luaA_pushobject (TObject *o); | 16 | void luaA_pushobject (const TObject *o); |
| 17 | void luaA_packresults (void); | 17 | void luaA_packresults (void); |
| 18 | int luaA_passresults (void); | 18 | int luaA_passresults (void); |
| 19 | TaggedString *luaA_nextvar (TaggedString *g); | 19 | TaggedString *luaA_nextvar (TaggedString *g); |
| 20 | int luaA_next (Hash *t, int i); | 20 | int luaA_next (const Hash *t, int i); |
| 21 | 21 | ||
| 22 | #endif | 22 | #endif |
| @@ -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 | ||
| 23 | int luaL_findstring (char *name, char *list[]) { | 23 | int 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 | ||
| 31 | void luaL_argerror (int numarg, char *extramsg) { | 31 | void 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 | ||
| 45 | char *luaL_check_lstr (int numArg, long *len) | 45 | const 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 | ||
| 53 | char *luaL_opt_lstr (int numArg, char *def, long *len) | 52 | const 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 | ||
| 59 | double luaL_check_number (int numArg) | 57 | double 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 | ||
| 67 | double luaL_opt_number (int numArg, double def) | 64 | double 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 | ||
| 74 | lua_Object luaL_tablearg (int arg) | 70 | lua_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 | ||
| 81 | lua_Object luaL_functionarg (int arg) | 76 | lua_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 | ||
| 88 | lua_Object luaL_nonnullarg (int numArg) | 82 | lua_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 | ||
| 95 | void luaL_openlib (struct luaL_reg *l, int n) | 88 | void 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 | ||
| 104 | void luaL_verror (char *fmt, ...) | 96 | void 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 | ||
| 115 | void luaL_chunkid (char *out, char *source, int len) { | 106 | void 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 | ||
| 130 | void luaL_filesource (char *out, char *filename, int len) { | 121 | void 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 | } |
| @@ -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 | ||
| 15 | struct luaL_reg { | 15 | struct 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 | ||
| 24 | void luaL_openlib (struct luaL_reg *l, int n); | 24 | void luaL_openlib (const struct luaL_reg *l, int n); |
| 25 | void luaL_argerror (int numarg, char *extramsg); | 25 | void 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)) |
| 27 | char *luaL_check_lstr (int numArg, long *len); | 27 | const 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)) |
| 29 | char *luaL_opt_lstr (int numArg, char *def, long *len); | 29 | const char *luaL_opt_lstr (int numArg, const char *def, long *len); |
| 30 | double luaL_check_number (int numArg); | 30 | double 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); | |||
| 36 | lua_Object luaL_functionarg (int arg); | 36 | lua_Object luaL_functionarg (int arg); |
| 37 | lua_Object luaL_tablearg (int arg); | 37 | lua_Object luaL_tablearg (int arg); |
| 38 | lua_Object luaL_nonnullarg (int numArg); | 38 | lua_Object luaL_nonnullarg (int numArg); |
| 39 | void luaL_verror (char *fmt, ...); | 39 | void luaL_verror (const char *fmt, ...); |
| 40 | char *luaL_openspace (int size); | 40 | char *luaL_openspace (int size); |
| 41 | void luaL_resetbuffer (void); | 41 | void luaL_resetbuffer (void); |
| 42 | void luaL_addchar (int c); | 42 | void luaL_addchar (int c); |
| @@ -45,9 +45,9 @@ void luaL_addsize (int n); | |||
| 45 | int luaL_newbuffer (int size); | 45 | int luaL_newbuffer (int size); |
| 46 | void luaL_oldbuffer (int old); | 46 | void luaL_oldbuffer (int old); |
| 47 | char *luaL_buffer (void); | 47 | char *luaL_buffer (void); |
| 48 | int luaL_findstring (char *name, char *list[]); | 48 | int luaL_findstring (const char *name, const char *const list[]); |
| 49 | void luaL_chunkid (char *out, char *source, int len); | 49 | void luaL_chunkid (char *out, const char *source, int len); |
| 50 | void luaL_filesource (char *out, char *filename, int len); | 50 | void luaL_filesource (char *out, const char *filename, int len); |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | #endif | 53 | #endif |
| @@ -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 | ||
| 45 | static real getsize (Hash *h) { | 45 | static 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 | ||
| 59 | static real getnarg (Hash *a) { | 59 | static 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 | ||
| 164 | static void luaB_setglobal (void) { | 164 | static 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 | ||
| 172 | static void luaB_rawsetglobal (void) { | 172 | static 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 | ||
| 251 | static void luaB_dostring (void) { | 251 | static 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 | ||
| 262 | static void luaB_dofile (void) { | 262 | static 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 | ||
| 270 | static void luaB_call (void) { | 270 | static 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 | ||
| 307 | static void luaB_nextvar (void) { | 307 | static 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 | ||
| 321 | static void luaB_next (void) { | 321 | static 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 | ||
| 330 | static void luaB_tostring (void) { | 330 | static 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 | ||
| 393 | static void luaB_foreachi (void) { | 393 | static 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 | ||
| 415 | static void luaB_foreach (void) { | 415 | static 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 | ||
| 507 | static int sort_comp (lua_Object f, TObject *a, TObject *b) { | 507 | static 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 | ||
| 606 | static void countlist (void) { | 606 | static 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 | ||
| 677 | static struct luaL_reg builtin_funcs[] = { | 677 | static 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 |
| @@ -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 | ||
| 18 | static void settabss (lua_Object t, char *i, char *v) { | 18 | static 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 | ||
| 26 | static void settabsi (lua_Object t, char *i, int v) { | 26 | static 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 | ||
| 34 | static lua_Object getfuncinfo (lua_Object func) { | 34 | static 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) { | |||
| 104 | static void getlocal (void) { | 104 | static 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 | ||
| 164 | static void callf (lua_Function func, char *file, int line) { | 164 | static 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 | ||
| 204 | static struct luaL_reg dblib[] = { | 204 | static const struct luaL_reg dblib[] = { |
| 205 | {"funcinfo", funcinfo}, | 205 | {"funcinfo", funcinfo}, |
| 206 | {"getlocal", getlocal}, | 206 | {"getlocal", getlocal}, |
| 207 | {"getstack", getstack}, | 207 | {"getstack", getstack}, |
| @@ -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 | ||
| 162 | void luaD_callTM (TObject *f, int nParams, int nResults) { | 162 | void 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 | */ |
| 225 | void luaD_travstack (int (*fn)(TObject *)) | 225 | void 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 | ||
| 234 | static void message (char *s) { | 233 | static 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 | */ |
| 248 | void lua_error (char *s) { | 247 | void 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 | ||
| 338 | void luaD_gcIM (TObject *o) | 337 | void 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 | ||
| 351 | int lua_dofile (char *filename) { | 349 | int 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 | ||
| 374 | int lua_dostring (char *str) { | 372 | int 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 | ||
| 379 | int lua_dobuffer (char *buff, int size, char *name) { | 377 | int 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); |
| @@ -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); | |||
| 36 | void luaD_lineHook (int line); | 36 | void luaD_lineHook (int line); |
| 37 | void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn); | 37 | void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn); |
| 38 | void luaD_calln (int nArgs, int nResults); | 38 | void luaD_calln (int nArgs, int nResults); |
| 39 | void luaD_callTM (TObject *f, int nParams, int nResults); | 39 | void luaD_callTM (const TObject *f, int nParams, int nResults); |
| 40 | int luaD_protectedrun (void); | 40 | int luaD_protectedrun (void); |
| 41 | void luaD_gcIM (TObject *o); | 41 | void luaD_gcIM (const TObject *o); |
| 42 | void luaD_travstack (int (*fn)(TObject *)); | 42 | void luaD_travstack (int (*fn)(TObject *)); |
| 43 | void luaD_checkstack (int n); | 43 | void luaD_checkstack (int n); |
| 44 | 44 | ||
| @@ -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 | ||
| 19 | Closure *luaF_newclosure (int nelems) | 19 | Closure *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 | ||
| 29 | TProtoFunc *luaF_newproto (void) | 28 | TProtoFunc *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 | ||
| 45 | static void freefunc (TProtoFunc *f) | 43 | static 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 | ||
| 54 | void luaF_freeproto (TProtoFunc *l) | 51 | void 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 | ||
| 65 | void luaF_freeclosure (Closure *l) | 61 | void 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 | */ |
| 80 | char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) | 75 | const 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; |
| @@ -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); | |||
| 17 | void luaF_freeproto (TProtoFunc *l); | 17 | void luaF_freeproto (TProtoFunc *l); |
| 18 | void luaF_freeclosure (Closure *l); | 18 | void luaF_freeclosure (Closure *l); |
| 19 | 19 | ||
| 20 | char *luaF_getlocalname (TProtoFunc *func, int local_number, int line); | 20 | const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line); |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | #endif | 23 | #endif |
| @@ -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 | ||
| 32 | int luaC_ref (TObject *o, int lock) { | 32 | int 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 | ||
| 51 | void lua_unref (int ref) | 51 | void 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 | ||
| 58 | TObject* luaC_getref (int ref) | 57 | const 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 | ||
| 70 | static void travlock (void) | 68 | static 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 | ||
| 79 | static int ismarked (TObject *o) | 76 | static 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 | ||
| 102 | static void invalidaterefs (void) | 98 | static 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 | ||
| 112 | void luaC_hashcallIM (Hash *l) | 107 | void 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 | ||
| 123 | void luaC_strcallIM (TaggedString *l) | 117 | void 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 | ||
| 136 | static GCnode *listcollect (GCnode *l) | 129 | static 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 | ||
| 154 | static void strmark (TaggedString *s) | 146 | static 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 | ||
| 172 | static void closuremark (Closure *f) | 163 | static 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 | ||
| 183 | static void hashmark (Hash *h) | 173 | static 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 | ||
| 199 | static void globalmark (void) | 188 | static 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 | ||
| 212 | static int markobject (TObject *o) | 200 | static 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 | ||
| 234 | static void markall (void) | 221 | static 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 | ||
| 243 | long lua_collectgarbage (long limit) | 229 | long 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 | ||
| 270 | void luaC_checkGC (void) | 255 | void 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 | } |
| @@ -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 | ||
| 14 | void luaC_checkGC (void); | 14 | void luaC_checkGC (void); |
| 15 | TObject* luaC_getref (int ref); | 15 | const TObject *luaC_getref (int ref); |
| 16 | int luaC_ref (TObject *o, int lock); | 16 | int luaC_ref (const TObject *o, int lock); |
| 17 | void luaC_hashcallIM (Hash *l); | 17 | void luaC_hashcallIM (Hash *l); |
| 18 | void luaC_strcallIM (TaggedString *l); | 18 | void luaC_strcallIM (TaggedString *l); |
| 19 | 19 | ||
| @@ -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 |
| 47 | FILE *popen(); | 47 | /* FILE *popen(); |
| 48 | int pclose(); | 48 | int 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 | ||
| 91 | static FILE *getfilebyname (char *name) { | 91 | static 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 | ||
| 112 | static FILE *getfileparam (char *name, int *arg) { | 112 | static 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 | ||
| 155 | static void setfile (FILE *f, char *name, int tag) { | 155 | static 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 | ||
| 161 | static void setreturn (FILE *f, char *name) { | 161 | static 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 | ||
| 231 | static int read_pattern (FILE *f, char *p) { | 231 | static 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 | ||
| 319 | static void io_read (void) { | 319 | static 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 | ||
| 366 | static void io_seek (void) { | 366 | static 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 | ||
| 429 | static void io_date (void) { | 429 | static 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 | ||
| 442 | static void setloc (void) { | 442 | static 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 | ||
| 534 | static struct luaL_reg iolib[] = { | 534 | static 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 | ||
| 549 | static struct luaL_reg iolibtag[] = { | 549 | static 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}, |
| @@ -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 */ |
| 31 | static char *reserved [] = {"and", "do", "else", "elseif", "end", "function", | 31 | static 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 | ||
| 47 | void luaX_syntaxerror (LexState *ls, char *s, char *token) { | 47 | void 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 | ||
| 57 | void luaX_error (LexState *ls, char *s) { | 57 | void 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 | ||
| 120 | static int checkcond (LexState *LS, char *buff) { | 120 | static 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 | ||
| 162 | static void inclinenumber (LexState *LS) { | 162 | static 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; |
| @@ -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 { | |||
| 61 | void luaX_init (void); | 61 | void luaX_init (void); |
| 62 | void luaX_setinput (LexState *LS, ZIO *z); | 62 | void luaX_setinput (LexState *LS, ZIO *z); |
| 63 | int luaX_lex (LexState *LS); | 63 | int luaX_lex (LexState *LS); |
| 64 | void luaX_syntaxerror (LexState *ls, char *s, char *token); | 64 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token); |
| 65 | void luaX_error (LexState *ls, char *s); | 65 | void luaX_error (LexState *ls, const char *s); |
| 66 | void luaX_token2str (int token, char *s); | 66 | void luaX_token2str (int token, char *s); |
| 67 | 67 | ||
| 68 | 68 | ||
| @@ -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 | ||
| 167 | static struct luaL_reg mathlib[] = { | 167 | static 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}, |
| @@ -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 | ||
| 37 | void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, | 37 | void *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 | ||
| 88 | static void *checkblock (void *block) { | 88 | static 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 | ||
| 104 | static void freeblock (void *block) { | 100 | static 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 | ||
| @@ -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 | ||
| 21 | void *luaM_realloc (void *oldblock, unsigned long size); | 21 | void *luaM_realloc (void *oldblock, unsigned long size); |
| 22 | void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, | 22 | void *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)) |
| @@ -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 | ||
| 14 | char *luaO_typenames[] = { /* ORDER LUA_T */ | 14 | const 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 | ||
| 20 | TObject luaO_nilobject = {LUA_T_NIL, {NULL}}; | 20 | const TObject luaO_nilobject = {LUA_T_NIL, {NULL}}; |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | /* hash dimensions values */ | 24 | /* hash dimensions values */ |
| 25 | static long dimensions[] = | 25 | static 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 | ||
| 31 | int luaO_redimension (int oldsize) | 31 | int 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 | ||
| 43 | int luaO_equalval (TObject *t1, TObject *t2) { | 42 | int 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 | ||
| 59 | void luaO_insertlist (GCnode *root, GCnode *node) | 58 | void 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 | ||
| 93 | double luaO_str2d (char *s) { /* LUA_NUMBER */ | 91 | double 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)) { |
| @@ -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 | ||
| 181 | extern char *luaO_typenames[]; | 181 | extern 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 | ||
| 186 | extern TObject luaO_nilobject; | 186 | extern 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)) |
| 190 | int luaO_equalval (TObject *t1, TObject *t2); | 190 | int luaO_equalval (const TObject *t1, const TObject *t2); |
| 191 | int luaO_redimension (int oldsize); | 191 | int luaO_redimension (int oldsize); |
| 192 | void luaO_insertlist (GCnode *root, GCnode *node); | 192 | void luaO_insertlist (GCnode *root, GCnode *node); |
| 193 | double luaO_str2d (char *s); | 193 | double luaO_str2d (const char *s); |
| 194 | 194 | ||
| 195 | #ifdef OLD_ANSI | 195 | #ifdef OLD_ANSI |
| 196 | void luaO_memup (void *dest, void *src, int size); | 196 | void luaO_memup (void *dest, void *src, int size); |
| @@ -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 | ||
| 145 | static void checklimit (LexState *ls, int val, int limit, char *msg) { | 145 | static 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 | ||
| 501 | static void storevar (LexState *ls, vardesc *var) { | 501 | static 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 | ||
| 600 | static int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME, | 600 | static 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 | ||
| 604 | static int is_in (int tok, int *toks) { | 605 | static 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 | ||
| 926 | static int binop [] = {EQ, NE, '>', '<', LE, GE, CONC, | 927 | static const int binop [] = {EQ, NE, '>', '<', LE, GE, CONC, |
| 927 | '+', '-', '*', '/', '^', 0}; | 928 | '+', '-', '*', '/', '^', 0}; |
| 928 | 929 | ||
| 929 | static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6}; | 930 | static const int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6}; |
| 930 | 931 | ||
| 931 | static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP, | 932 | static 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 | ||
| @@ -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 | ||
| 14 | void luaY_codedebugline (int line); | 14 | void luaY_codedebugline (int line); |
| 15 | TProtoFunc *luaY_parser (ZIO *z); | 15 | TProtoFunc *luaY_parser (ZIO *z); |
| 16 | void luaY_error (char *s); | 16 | void luaY_error (const char *s); |
| 17 | void luaY_syntaxerror (char *s, char *token); | 17 | void luaY_syntaxerror (const char *s, const char *token); |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #endif | 20 | #endif |
| @@ -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 @@ | |||
| 20 | lua_State *lua_state = NULL; | 20 | lua_State *lua_state = NULL; |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | void lua_open (void) | 23 | void 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 | ||
| 61 | void lua_close (void) | 60 | void 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 */ |
| @@ -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 | ||
| 41 | static unsigned long hash_s (char *s, long l) { | 41 | static 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 | ||
| 86 | static TaggedString *newone_s (char *str, long l, unsigned long h) { | 86 | static 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 | ||
| 100 | static TaggedString *newone_u (char *buff, int tag, unsigned long h) { | 100 | static 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 | ||
| 112 | static TaggedString *insert_s (char *str, long l, stringtable *tb) { | 112 | static 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 | ||
| 175 | TaggedString *luaS_newlstr (char *str, long l) { | 175 | TaggedString *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 | ||
| 180 | TaggedString *luaS_new (char *str) { | 180 | TaggedString *luaS_new (const char *str) { |
| 181 | return luaS_newlstr(str, strlen(str)); | 181 | return luaS_newlstr(str, strlen(str)); |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | TaggedString *luaS_newfixedstring (char *str) { | 184 | TaggedString *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 | ||
| 285 | char *luaS_travsymbol (int (*fn)(TObject *)) { | 285 | const 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 | ||
| 294 | int luaS_globaldefined (char *name) { | 294 | int 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 | } |
| @@ -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); | |||
| 15 | TaggedString *luaS_createudata (void *udata, int tag); | 15 | TaggedString *luaS_createudata (void *udata, int tag); |
| 16 | TaggedString *luaS_collector (void); | 16 | TaggedString *luaS_collector (void); |
| 17 | void luaS_free (TaggedString *l); | 17 | void luaS_free (TaggedString *l); |
| 18 | TaggedString *luaS_newlstr (char *str, long l); | 18 | TaggedString *luaS_newlstr (const char *str, long l); |
| 19 | TaggedString *luaS_new (char *str); | 19 | TaggedString *luaS_new (const char *str); |
| 20 | TaggedString *luaS_newfixedstring (char *str); | 20 | TaggedString *luaS_newfixedstring (const char *str); |
| 21 | void luaS_rawsetglobal (TaggedString *ts, TObject *newval); | 21 | void luaS_rawsetglobal (TaggedString *ts, TObject *newval); |
| 22 | char *luaS_travsymbol (int (*fn)(TObject *)); | 22 | const char *luaS_travsymbol (int (*fn)(TObject *)); |
| 23 | int luaS_globaldefined (char *name); | 23 | int luaS_globaldefined (const char *name); |
| 24 | TaggedString *luaS_collectudata (void); | 24 | TaggedString *luaS_collectudata (void); |
| 25 | void luaS_freeall (void); | 25 | void luaS_freeall (void); |
| 26 | 26 | ||
| @@ -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 | ||
| 19 | static void addnchar (char *s, int n) | 19 | static 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 | ||
| 27 | static void str_len (void) | 26 | static 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 | ||
| 46 | static void str_sub (void) { | 44 | static 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) { | |||
| 59 | static void str_lower (void) { | 57 | static 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) { | |||
| 70 | static void str_upper (void) { | 68 | static 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 | ||
| 80 | static void str_rep (void) | 78 | static 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 | ||
| 92 | static void str_byte (void) { | 89 | static 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 | ||
| 125 | struct Capture { | 122 | struct 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 | ||
| 166 | char *luaI_classend (char *p) { | 163 | const 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 | ||
| 204 | static int matchbracketclass (int c, char *p, char *endclass) { | 201 | static 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 | ||
| 228 | int luaI_singlematch (int c, char *p, char *ep) { | 225 | int 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 | ||
| 242 | static char *match (char *s, char *p, struct Capture *cap); | 239 | static const char *match (const char *s, const char *p, struct Capture *cap); |
| 243 | 240 | ||
| 244 | 241 | ||
| 245 | static char *matchbalance (char *s, char *p, struct Capture *cap) { | 242 | static 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 | ||
| 264 | static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) { | 262 | static 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 | ||
| 278 | static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) { | 277 | static 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 | ||
| 290 | static char *start_capt (char *s, char *p, struct Capture *cap) { | 290 | static 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 | ||
| 303 | static char *end_capt (char *s, char *p, struct Capture *cap) { | 304 | static 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 | ||
| 313 | static char *match_capture (char *s, int level, struct Capture *cap) { | 315 | static 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 | ||
| 323 | static char *match (char *s, char *p, struct Capture *cap) { | 326 | static 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 | ||
| 373 | static void str_find (void) { | 376 | static 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 | ||
| 408 | static void add_s (lua_Object newp, struct Capture *cap) { | 411 | static 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 | ||
| 450 | static void str_gsub (void) { | 453 | static 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 | ||
| 486 | static void luaI_addquoted (int arg) { | 489 | static 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 | ||
| 507 | static void str_format (void) { | 510 | static 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 | ||
| 573 | static struct luaL_reg strlib[] = { | 576 | static 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}, |
| @@ -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 | ||
| 27 | static long int hashindex (TObject *ref) { | 27 | static 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 | ||
| 56 | Node *luaH_present (Hash *t, TObject *key) { | 56 | Node *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 | ||
| 138 | void luaH_set (Hash *t, TObject *ref, TObject *val) { | 138 | void 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 | ||
| 156 | int luaH_pos (Hash *t, TObject *r) { | 156 | int 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 | ||
| 163 | void luaH_setint (Hash *t, int ref, TObject *val) { | 163 | void 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 | ||
| 171 | TObject *luaH_getint (Hash *t, int ref) { | 171 | TObject *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; |
| @@ -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 | ||
| 21 | Hash *luaH_new (int nhash); | 21 | Hash *luaH_new (int nhash); |
| 22 | void luaH_free (Hash *frees); | 22 | void luaH_free (Hash *frees); |
| 23 | Node *luaH_present (Hash *t, TObject *key); | 23 | Node *luaH_present (const Hash *t, const TObject *key); |
| 24 | void luaH_set (Hash *t, TObject *ref, TObject *val); | 24 | void luaH_set (Hash *t, const TObject *ref, const TObject *val); |
| 25 | int luaH_pos (Hash *t, TObject *r); | 25 | int luaH_pos (const Hash *t, const TObject *r); |
| 26 | void luaH_setint (Hash *t, int ref, TObject *val); | 26 | void luaH_setint (Hash *t, int ref, const TObject *val); |
| 27 | TObject *luaH_getint (Hash *t, int ref); | 27 | TObject *luaH_getint (const Hash *t, int ref); |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | #endif | 30 | #endif |
| @@ -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 | ||
| 18 | char *luaT_eventname[] = { /* ORDER IM */ | 18 | const 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 | ||
| 25 | static int luaI_checkevent (char *name, char *list[]) { | 25 | static 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 | */ |
| 37 | static char luaT_validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */ | 37 | /* ORDER LUA_T, ORDER IM */ |
| 38 | static 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 | ||
| 99 | int luaT_effectivetag (TObject *o) { | 100 | int 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 | ||
| 121 | TObject *luaT_gettagmethod (int t, char *event) { | 122 | const 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 | ||
| 131 | void luaT_settagmethod (int t, char *event, TObject *func) { | 132 | void 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 | ||
| 146 | char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */ | 147 | const 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 | ||
| 193 | void luaT_setfallback (void) { | 194 | void 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)) { |
| @@ -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 | ||
| 50 | extern char *luaT_eventname[]; | 50 | extern const char *const luaT_eventname[]; |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | void luaT_init (void); | 53 | void luaT_init (void); |
| 54 | void luaT_realtag (int tag); | 54 | void luaT_realtag (int tag); |
| 55 | int luaT_effectivetag (TObject *o); | 55 | int luaT_effectivetag (const TObject *o); |
| 56 | void luaT_settagmethod (int t, char *event, TObject *func); | 56 | void luaT_settagmethod (int t, const char *event, TObject *func); |
| 57 | TObject *luaT_gettagmethod (int t, char *event); | 57 | const TObject *luaT_gettagmethod (int t, const char *event); |
| 58 | char *luaT_travtagmethods (int (*fn)(TObject *)); | 58 | const char *luaT_travtagmethods (int (*fn)(TObject *)); |
| 59 | 59 | ||
| 60 | void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */ | 60 | void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */ |
| 61 | 61 | ||
| @@ -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 | ||
| 55 | static int ldo (int (*f)(char *), char *name) { | 55 | static 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 */ |
| @@ -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); | |||
| 33 | void lua_close (void); | 33 | void lua_close (void); |
| 34 | lua_State *lua_setstate (lua_State *st); | 34 | lua_State *lua_setstate (lua_State *st); |
| 35 | 35 | ||
| 36 | lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ | 36 | lua_Object lua_settagmethod (int tag, const char *event); |
| 37 | lua_Object lua_gettagmethod (int tag, char *event); | 37 | /* In: new method */ |
| 38 | lua_Object lua_gettagmethod (int tag, const char *event); | ||
| 38 | 39 | ||
| 39 | int lua_newtag (void); | 40 | int lua_newtag (void); |
| 40 | int lua_copytagmethods (int tagto, int tagfrom); | 41 | int lua_copytagmethods (int tagto, int tagfrom); |
| 41 | void lua_settag (int tag); /* In: object */ | 42 | void lua_settag (int tag); /* In: object */ |
| 42 | 43 | ||
| 43 | void lua_error (char *s); | 44 | void lua_error (const char *s); |
| 44 | int lua_dofile (char *filename); /* Out: returns */ | 45 | int lua_dofile (const char *filename); |
| 45 | int lua_dostring (char *string); /* Out: returns */ | 46 | /* Out: returns */ |
| 46 | int lua_dobuffer (char *buff, int size, char *name); | 47 | int lua_dostring (const char *string); |
| 47 | /* Out: returns */ | 48 | /* Out: returns */ |
| 49 | int lua_dobuffer (const char *buff, int size, | ||
| 50 | const char *name); /* Out: returns */ | ||
| 48 | int lua_callfunction (lua_Object f); | 51 | int 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); | |||
| 64 | int lua_isfunction (lua_Object object); | 67 | int lua_isfunction (lua_Object object); |
| 65 | 68 | ||
| 66 | double lua_getnumber (lua_Object object); | 69 | double lua_getnumber (lua_Object object); |
| 67 | char *lua_getstring (lua_Object object); | 70 | const char *lua_getstring (lua_Object object); |
| 68 | long lua_strlen (lua_Object object); | 71 | long lua_strlen (lua_Object object); |
| 69 | lua_CFunction lua_getcfunction (lua_Object object); | 72 | lua_CFunction lua_getcfunction (lua_Object object); |
| 70 | void *lua_getuserdata (lua_Object object); | 73 | void *lua_getuserdata (lua_Object object); |
| @@ -72,18 +75,18 @@ void *lua_getuserdata (lua_Object object); | |||
| 72 | 75 | ||
| 73 | void lua_pushnil (void); | 76 | void lua_pushnil (void); |
| 74 | void lua_pushnumber (double n); | 77 | void lua_pushnumber (double n); |
| 75 | void lua_pushlstring (char *s, long len); | 78 | void lua_pushlstring (const char *s, long len); |
| 76 | void lua_pushstring (char *s); | 79 | void lua_pushstring (const char *s); |
| 77 | void lua_pushcclosure (lua_CFunction fn, int n); | 80 | void lua_pushcclosure (lua_CFunction fn, int n); |
| 78 | void lua_pushusertag (void *u, int tag); | 81 | void lua_pushusertag (void *u, int tag); |
| 79 | void lua_pushobject (lua_Object object); | 82 | void lua_pushobject (lua_Object object); |
| 80 | 83 | ||
| 81 | lua_Object lua_pop (void); | 84 | lua_Object lua_pop (void); |
| 82 | 85 | ||
| 83 | lua_Object lua_getglobal (char *name); | 86 | lua_Object lua_getglobal (const char *name); |
| 84 | lua_Object lua_rawgetglobal (char *name); | 87 | lua_Object lua_rawgetglobal (const char *name); |
| 85 | void lua_setglobal (char *name); /* In: value */ | 88 | void lua_setglobal (const char *name); /* In: value */ |
| 86 | void lua_rawsetglobal (char *name); /* In: value */ | 89 | void lua_rawsetglobal (const char *name); /* In: value */ |
| 87 | 90 | ||
| 88 | void lua_settable (void); /* In: table, index, value */ | 91 | void lua_settable (void); /* In: table, index, value */ |
| 89 | void lua_rawsettable (void); /* In: table, index, value */ | 92 | void lua_rawsettable (void); /* In: table, index, value */ |
| @@ -92,7 +95,7 @@ lua_Object lua_rawgettable (void); /* In: table, index */ | |||
| 92 | 95 | ||
| 93 | int lua_tag (lua_Object object); | 96 | int lua_tag (lua_Object object); |
| 94 | 97 | ||
| 95 | char *lua_nextvar (char *varname); /* Out: value */ | 98 | const char *lua_nextvar (const char *varname); /* Out: value */ |
| 96 | int lua_next (lua_Object o, int i); | 99 | int lua_next (lua_Object o, int i); |
| 97 | /* Out: ref, value */ | 100 | /* Out: ref, value */ |
| 98 | 101 | ||
| @@ -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 @@ | |||
| 14 | typedef lua_Object lua_Function; | 14 | typedef lua_Object lua_Function; |
| 15 | 15 | ||
| 16 | typedef void (*lua_LHFunction) (int line); | 16 | typedef void (*lua_LHFunction) (int line); |
| 17 | typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); | 17 | typedef void (*lua_CHFunction) (lua_Function func, const char *file, int line); |
| 18 | 18 | ||
| 19 | lua_Function lua_stackedfunction (int level); | 19 | lua_Function lua_stackedfunction (int level); |
| 20 | void lua_funcinfo (lua_Object func, char **source, int *linedefined); | 20 | void lua_funcinfo (lua_Object func, const char **source, int *linedefined); |
| 21 | int lua_currentline (lua_Function func); | 21 | int lua_currentline (lua_Function func); |
| 22 | char *lua_getobjname (lua_Object o, char **name); | 22 | const char *lua_getobjname (lua_Object o, const char **name); |
| 23 | 23 | ||
| 24 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name); | 24 | lua_Object lua_getlocal (lua_Function func, int local_number, |
| 25 | const char **name); | ||
| 25 | int lua_setlocal (lua_Function func, int local_number); | 26 | int lua_setlocal (lua_Function func, int local_number); |
| 26 | 27 | ||
| 27 | int lua_nups (lua_Function func); | 28 | int lua_nups (lua_Function func); |
| @@ -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 | ||
| 32 | char *luaI_classend (char *p); | 32 | const char *luaI_classend (const char *p); |
| 33 | int luaI_singlematch (int c, char *p, char *ep); | 33 | int luaI_singlematch (int c, const char *p, const char *ep); |
| 34 | 34 | ||
| 35 | #endif | 35 | #endif |
| 36 | 36 | ||
| @@ -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 | */ |
| 53 | double luaU_str2d (char* b, char* where) | 53 | double 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 | ||
| 79 | static int LoadInt (ZIO* Z, char* message) | 79 | static 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 | ||
| 170 | static void LoadSignature (ZIO* Z) | 170 | static 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 | */ |
| 234 | void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf) | 234 | void 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 | } |
| @@ -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 | ||
| 13 | TProtoFunc* luaU_undump1 (ZIO* Z); /* load one chunk */ | 13 | TProtoFunc* luaU_undump1 (ZIO* Z); /* load one chunk */ |
| 14 | void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf); | 14 | void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf); |
| 15 | /* handle cases that cannot happen */ | 15 | /* handle cases that cannot happen */ |
| 16 | double luaU_str2d (char* b, char* where); | 16 | double 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 */ |
| @@ -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 | */ |
| 115 | void luaV_gettable (void) { | 115 | void 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 | */ |
| 149 | void luaV_settable (TObject *t) { | 149 | void 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 | ||
| 176 | void luaV_rawsettable (TObject *t) { | 176 | void 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 | ||
| 187 | void luaV_getglobal (TaggedString *ts) { | 187 | void 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 | ||
| 210 | void luaV_setglobal (TaggedString *ts) { | 210 | void 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 | ||
| 229 | static void call_binTM (IMS event, char *msg) | 229 | static 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 | ||
| 245 | static void call_arith (IMS event) | 245 | static 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 | ||
| 251 | static int luaV_strcomp (char *l, long ll, char *r, long lr) | 250 | static 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) | |||
| 268 | void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, | 266 | void 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 | ||
| 303 | static void adjust_varargs (StkId first_extra_arg) | 301 | static 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 | */ |
| 319 | StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | 316 | StkId 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); |
| @@ -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); | |||
| 22 | int luaV_tostring (TObject *obj); | 22 | int luaV_tostring (TObject *obj); |
| 23 | void luaV_setn (Hash *t, int val); | 23 | void luaV_setn (Hash *t, int val); |
| 24 | void luaV_gettable (void); | 24 | void luaV_gettable (void); |
| 25 | void luaV_settable (TObject *t); | 25 | void luaV_settable (const TObject *t); |
| 26 | void luaV_rawsettable (TObject *t); | 26 | void luaV_rawsettable (const TObject *t); |
| 27 | void luaV_getglobal (TaggedString *ts); | 27 | void luaV_getglobal (TaggedString *ts); |
| 28 | void luaV_setglobal (TaggedString *ts); | 28 | void luaV_setglobal (TaggedString *ts); |
| 29 | StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base); | 29 | StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base); |
| @@ -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 | ||
| 18 | static int zmfilbuf (ZIO* z) { | 18 | static int zmfilbuf (ZIO* z) { |
| 19 | return EOZ; | 19 | return EOZ; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | ZIO* zmopen (ZIO* z, char* b, int size, char *name) | 23 | ZIO* 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 | ||
| 36 | ZIO* zsopen (ZIO* z, char* s, char *name) | 35 | ZIO* 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 | ||
| 44 | static int zffilbuf (ZIO* z) { | 42 | static 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 | ||
| 55 | ZIO* zFopen (ZIO* z, FILE* f, char *name) | 53 | ZIO* 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 | ||
| @@ -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 | ||
| 23 | typedef struct zio ZIO; | 23 | typedef struct zio ZIO; |
| 24 | 24 | ||
| 25 | ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */ | 25 | ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */ |
| 26 | ZIO* zsopen (ZIO* z, char* s, char *name); /* string */ | 26 | ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */ |
| 27 | ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */ | 27 | ZIO* zmopen (ZIO* z, const char* b, int size, const char *name); /* memory */ |
| 28 | 28 | ||
| 29 | int zread (ZIO* z, void* b, int n); /* read next n bytes */ | 29 | int 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 | ||
| 40 | struct zio { | 40 | struct 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 | ||
