diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
| commit | c787dccd9b5c3e55547a2c4bb598c0276de65034 (patch) | |
| tree | c4cdf2f7319fee48e048472a2044119f541e8da2 /lapi.c | |
| parent | b44e35b773bcaa9891d80a117392911ab5f656e5 (diff) | |
| download | lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.gz lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.bz2 lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.zip | |
"const" !!!
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 155 |
1 files changed, 58 insertions, 97 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 | ||
