diff options
| -rw-r--r-- | lapi.c | 63 | ||||
| -rw-r--r-- | lauxlib.c | 45 | ||||
| -rw-r--r-- | lauxlib.h | 36 | ||||
| -rw-r--r-- | lbaselib.c | 227 | ||||
| -rw-r--r-- | lcode.c | 17 | ||||
| -rw-r--r-- | lcode.h | 4 | ||||
| -rw-r--r-- | ldblib.c | 71 | ||||
| -rw-r--r-- | ldebug.c | 87 | ||||
| -rw-r--r-- | ldebug.h | 4 | ||||
| -rw-r--r-- | ldo.c | 39 | ||||
| -rw-r--r-- | ldo.h | 4 | ||||
| -rw-r--r-- | lfunc.c | 5 | ||||
| -rw-r--r-- | lfunc.h | 4 | ||||
| -rw-r--r-- | lgc.c | 5 | ||||
| -rw-r--r-- | liolib.c | 245 | ||||
| -rw-r--r-- | llex.c | 201 | ||||
| -rw-r--r-- | llex.h | 12 | ||||
| -rw-r--r-- | lmathlib.c | 59 | ||||
| -rw-r--r-- | lmem.c | 7 | ||||
| -rw-r--r-- | lmem.h | 4 | ||||
| -rw-r--r-- | lobject.c | 41 | ||||
| -rw-r--r-- | lobject.h | 10 | ||||
| -rw-r--r-- | lopcodes.c | 87 | ||||
| -rw-r--r-- | lopcodes.h | 4 | ||||
| -rw-r--r-- | lparser.c | 167 | ||||
| -rw-r--r-- | lstate.c | 5 | ||||
| -rw-r--r-- | lstring.c | 13 | ||||
| -rw-r--r-- | lstring.h | 10 | ||||
| -rw-r--r-- | lstrlib.c | 277 | ||||
| -rw-r--r-- | ltable.c | 11 | ||||
| -rw-r--r-- | ltests.c | 215 | ||||
| -rw-r--r-- | ltm.c | 43 | ||||
| -rw-r--r-- | ltm.h | 8 | ||||
| -rw-r--r-- | lua.c | 117 | ||||
| -rw-r--r-- | lua.h | 85 | ||||
| -rw-r--r-- | luadebug.h | 20 | ||||
| -rw-r--r-- | lundump.c | 69 | ||||
| -rw-r--r-- | lvm.c | 47 | ||||
| -rw-r--r-- | lzio.c | 3 |
39 files changed, 1161 insertions, 1210 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.159 2001/10/31 19:58:11 roberto Exp $ | 2 | ** $Id: lapi.c,v 1.160 2001/11/16 16:29:51 roberto Exp $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "lapi.h" | 12 | #include "lapi.h" |
| @@ -23,10 +22,10 @@ | |||
| 23 | #include "lvm.h" | 22 | #include "lvm.h" |
| 24 | 23 | ||
| 25 | 24 | ||
| 26 | const l_char lua_ident[] = | 25 | const char lua_ident[] = |
| 27 | l_s("$Lua: ") l_s(LUA_VERSION) l_s(" ") l_s(LUA_COPYRIGHT) l_s(" $\n") | 26 | "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" |
| 28 | l_s("$Authors: ") l_s(LUA_AUTHORS) l_s(" $\n") | 27 | "$Authors: " LUA_AUTHORS " $\n" |
| 29 | l_s("$URL: www.lua.org $\n"); | 28 | "$URL: www.lua.org $\n"; |
| 30 | 29 | ||
| 31 | 30 | ||
| 32 | 31 | ||
| @@ -156,12 +155,12 @@ LUA_API int lua_rawtag (lua_State *L, int index) { | |||
| 156 | } | 155 | } |
| 157 | 156 | ||
| 158 | 157 | ||
| 159 | LUA_API const l_char *lua_type (lua_State *L, int index) { | 158 | LUA_API const char *lua_type (lua_State *L, int index) { |
| 160 | StkId o; | 159 | StkId o; |
| 161 | const l_char *type; | 160 | const char *type; |
| 162 | lua_lock(L); | 161 | lua_lock(L); |
| 163 | o = luaA_indexAcceptable(L, index); | 162 | o = luaA_indexAcceptable(L, index); |
| 164 | type = (o == NULL) ? l_s("no value") : luaT_typename(G(L), o); | 163 | type = (o == NULL) ? "no value" : luaT_typename(G(L), o); |
| 165 | lua_unlock(L); | 164 | lua_unlock(L); |
| 166 | return type; | 165 | return type; |
| 167 | } | 166 | } |
| @@ -230,14 +229,14 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | |||
| 230 | } | 229 | } |
| 231 | 230 | ||
| 232 | 231 | ||
| 233 | LUA_API const l_char *lua_tostring (lua_State *L, int index) { | 232 | LUA_API const char *lua_tostring (lua_State *L, int index) { |
| 234 | StkId o = luaA_indexAcceptable(L, index); | 233 | StkId o = luaA_indexAcceptable(L, index); |
| 235 | if (o == NULL) | 234 | if (o == NULL) |
| 236 | return NULL; | 235 | return NULL; |
| 237 | else if (ttype(o) == LUA_TSTRING) | 236 | else if (ttype(o) == LUA_TSTRING) |
| 238 | return svalue(o); | 237 | return svalue(o); |
| 239 | else { | 238 | else { |
| 240 | const l_char *s; | 239 | const char *s; |
| 241 | lua_lock(L); /* `luaV_tostring' may create a new string */ | 240 | lua_lock(L); /* `luaV_tostring' may create a new string */ |
| 242 | s = (luaV_tostring(L, o) == 0) ? svalue(o) : NULL; | 241 | s = (luaV_tostring(L, o) == 0) ? svalue(o) : NULL; |
| 243 | lua_unlock(L); | 242 | lua_unlock(L); |
| @@ -309,7 +308,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
| 309 | } | 308 | } |
| 310 | 309 | ||
| 311 | 310 | ||
| 312 | LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { | 311 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
| 313 | lua_lock(L); | 312 | lua_lock(L); |
| 314 | setsvalue(L->top, luaS_newlstr(L, s, len)); | 313 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
| 315 | api_incr_top(L); | 314 | api_incr_top(L); |
| @@ -317,7 +316,7 @@ LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { | |||
| 317 | } | 316 | } |
| 318 | 317 | ||
| 319 | 318 | ||
| 320 | LUA_API void lua_pushstring (lua_State *L, const l_char *s) { | 319 | LUA_API void lua_pushstring (lua_State *L, const char *s) { |
| 321 | if (s == NULL) | 320 | if (s == NULL) |
| 322 | lua_pushnil(L); | 321 | lua_pushnil(L); |
| 323 | else | 322 | else |
| @@ -346,7 +345,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
| 346 | */ | 345 | */ |
| 347 | 346 | ||
| 348 | 347 | ||
| 349 | LUA_API void lua_getglobal (lua_State *L, const l_char *name) { | 348 | LUA_API void lua_getglobal (lua_State *L, const char *name) { |
| 350 | lua_lock(L); | 349 | lua_lock(L); |
| 351 | luaV_getglobal(L, luaS_new(L, name), L->top); | 350 | luaV_getglobal(L, luaS_new(L, name), L->top); |
| 352 | api_incr_top(L); | 351 | api_incr_top(L); |
| @@ -398,7 +397,7 @@ LUA_API void lua_newtable (lua_State *L) { | |||
| 398 | */ | 397 | */ |
| 399 | 398 | ||
| 400 | 399 | ||
| 401 | LUA_API void lua_setglobal (lua_State *L, const l_char *name) { | 400 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
| 402 | lua_lock(L); | 401 | lua_lock(L); |
| 403 | api_checknelems(L, 1); | 402 | api_checknelems(L, 1); |
| 404 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); | 403 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); |
| @@ -470,7 +469,7 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
| 470 | } | 469 | } |
| 471 | 470 | ||
| 472 | 471 | ||
| 473 | LUA_API int lua_dofile (lua_State *L, const l_char *filename) { | 472 | LUA_API int lua_dofile (lua_State *L, const char *filename) { |
| 474 | int status; | 473 | int status; |
| 475 | status = lua_loadfile(L, filename); | 474 | status = lua_loadfile(L, filename); |
| 476 | if (status == 0) /* parse OK? */ | 475 | if (status == 0) /* parse OK? */ |
| @@ -479,8 +478,8 @@ LUA_API int lua_dofile (lua_State *L, const l_char *filename) { | |||
| 479 | } | 478 | } |
| 480 | 479 | ||
| 481 | 480 | ||
| 482 | LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, | 481 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, |
| 483 | const l_char *name) { | 482 | const char *name) { |
| 484 | int status; | 483 | int status; |
| 485 | status = lua_loadbuffer(L, buff, size, name); | 484 | status = lua_loadbuffer(L, buff, size, name); |
| 486 | if (status == 0) /* parse OK? */ | 485 | if (status == 0) /* parse OK? */ |
| @@ -489,7 +488,7 @@ LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, | |||
| 489 | } | 488 | } |
| 490 | 489 | ||
| 491 | 490 | ||
| 492 | LUA_API int lua_dostring (lua_State *L, const l_char *str) { | 491 | LUA_API int lua_dostring (lua_State *L, const char *str) { |
| 493 | return lua_dobuffer(L, str, strlen(str), str); | 492 | return lua_dobuffer(L, str, strlen(str), str); |
| 494 | } | 493 | } |
| 495 | 494 | ||
| @@ -534,22 +533,22 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
| 534 | ** miscellaneous functions | 533 | ** miscellaneous functions |
| 535 | */ | 534 | */ |
| 536 | 535 | ||
| 537 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { | 536 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { |
| 538 | int tag; | 537 | int tag; |
| 539 | lua_lock(L); | 538 | lua_lock(L); |
| 540 | if (basictype != LUA_TNONE && | 539 | if (basictype != LUA_TNONE && |
| 541 | basictype != LUA_TTABLE && | 540 | basictype != LUA_TTABLE && |
| 542 | basictype != LUA_TUSERDATA) | 541 | basictype != LUA_TUSERDATA) |
| 543 | luaO_verror(L, l_s("invalid basic type (%d) for new type"), basictype); | 542 | luaO_verror(L, "invalid basic type (%d) for new type", basictype); |
| 544 | tag = luaT_newtag(L, name, basictype); | 543 | tag = luaT_newtag(L, name, basictype); |
| 545 | if (tag == LUA_TNONE) | 544 | if (tag == LUA_TNONE) |
| 546 | luaO_verror(L, l_s("type name '%.30s' already exists"), name); | 545 | luaO_verror(L, "type name '%.30s' already exists", name); |
| 547 | lua_unlock(L); | 546 | lua_unlock(L); |
| 548 | return tag; | 547 | return tag; |
| 549 | } | 548 | } |
| 550 | 549 | ||
| 551 | 550 | ||
| 552 | LUA_API int lua_name2tag (lua_State *L, const l_char *name) { | 551 | LUA_API int lua_name2tag (lua_State *L, const char *name) { |
| 553 | int tag; | 552 | int tag; |
| 554 | const TObject *v; | 553 | const TObject *v; |
| 555 | lua_lock(L); | 554 | lua_lock(L); |
| @@ -565,10 +564,10 @@ LUA_API int lua_name2tag (lua_State *L, const l_char *name) { | |||
| 565 | } | 564 | } |
| 566 | 565 | ||
| 567 | 566 | ||
| 568 | LUA_API const l_char *lua_tag2name (lua_State *L, int tag) { | 567 | LUA_API const char *lua_tag2name (lua_State *L, int tag) { |
| 569 | const l_char *s; | 568 | const char *s; |
| 570 | lua_lock(L); | 569 | lua_lock(L); |
| 571 | s = (tag == LUA_TNONE) ? l_s("no value") : typenamebytag(G(L), tag); | 570 | s = (tag == LUA_TNONE) ? "no value" : typenamebytag(G(L), tag); |
| 572 | lua_unlock(L); | 571 | lua_unlock(L); |
| 573 | return s; | 572 | return s; |
| 574 | } | 573 | } |
| @@ -579,10 +578,10 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
| 579 | lua_lock(L); | 578 | lua_lock(L); |
| 580 | api_checknelems(L, 1); | 579 | api_checknelems(L, 1); |
| 581 | if (tag < 0 || tag >= G(L)->ntag) | 580 | if (tag < 0 || tag >= G(L)->ntag) |
| 582 | luaO_verror(L, l_s("%d is not a valid tag"), tag); | 581 | luaO_verror(L, "%d is not a valid tag", tag); |
| 583 | basictype = G(L)->TMtable[tag].basictype; | 582 | basictype = G(L)->TMtable[tag].basictype; |
| 584 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) | 583 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) |
| 585 | luaO_verror(L, l_s("tag %d can only be used for type '%.20s'"), tag, | 584 | luaO_verror(L, "tag %d can only be used for type '%.20s'", tag, |
| 586 | typenamebytag(G(L), basictype)); | 585 | typenamebytag(G(L), basictype)); |
| 587 | switch (ttype(L->top-1)) { | 586 | switch (ttype(L->top-1)) { |
| 588 | case LUA_TTABLE: | 587 | case LUA_TTABLE: |
| @@ -592,14 +591,14 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
| 592 | uvalue(L->top-1)->uv.tag = tag; | 591 | uvalue(L->top-1)->uv.tag = tag; |
| 593 | break; | 592 | break; |
| 594 | default: | 593 | default: |
| 595 | luaO_verror(L, l_s("cannot change the tag of a %.20s"), | 594 | luaO_verror(L, "cannot change the tag of a %.20s", |
| 596 | luaT_typename(G(L), L->top-1)); | 595 | luaT_typename(G(L), L->top-1)); |
| 597 | } | 596 | } |
| 598 | lua_unlock(L); | 597 | lua_unlock(L); |
| 599 | } | 598 | } |
| 600 | 599 | ||
| 601 | 600 | ||
| 602 | LUA_API void lua_error (lua_State *L, const l_char *s) { | 601 | LUA_API void lua_error (lua_State *L, const char *s) { |
| 603 | lua_lock(L); | 602 | lua_lock(L); |
| 604 | luaD_error(L, s); | 603 | luaD_error(L, s); |
| 605 | lua_unlock(L); | 604 | lua_unlock(L); |
| @@ -630,7 +629,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
| 630 | lua_lock(L); | 629 | lua_lock(L); |
| 631 | t = luaA_index(L, index); | 630 | t = luaA_index(L, index); |
| 632 | api_check(L, ttype(t) == LUA_TTABLE); | 631 | api_check(L, ttype(t) == LUA_TTABLE); |
| 633 | value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */ | 632 | value = luaH_getstr(hvalue(t), luaS_newliteral(L, "n")); /* = t.n */ |
| 634 | if (ttype(value) == LUA_TNUMBER) | 633 | if (ttype(value) == LUA_TNUMBER) |
| 635 | n = cast(int, nvalue(value)); | 634 | n = cast(int, nvalue(value)); |
| 636 | else { | 635 | else { |
| @@ -734,7 +733,7 @@ LUA_API void lua_pushupvalues (lua_State *L) { | |||
| 734 | api_check(L, iscfunction(func)); | 733 | api_check(L, iscfunction(func)); |
| 735 | n = clvalue(func)->c.nupvalues; | 734 | n = clvalue(func)->c.nupvalues; |
| 736 | if (LUA_MINSTACK+n > lua_stackspace(L)) | 735 | if (LUA_MINSTACK+n > lua_stackspace(L)) |
| 737 | luaD_error(L, l_s("stack overflow")); | 736 | luaD_error(L, "stack overflow"); |
| 738 | for (i=0; i<n; i++) { | 737 | for (i=0; i<n; i++) { |
| 739 | setobj(L->top, &clvalue(func)->c.upvalue[i]); | 738 | setobj(L->top, &clvalue(func)->c.upvalue[i]); |
| 740 | L->top++; | 739 | L->top++; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.52 2001/10/26 17:33:30 roberto Exp $ | 2 | ** $Id: lauxlib.c,v 1.53 2001/10/31 19:40:14 roberto Exp $ |
| 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 | */ |
| @@ -14,7 +14,6 @@ | |||
| 14 | ** With care, these functions can be used by other libraries. | 14 | ** With care, these functions can be used by other libraries. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #define LUA_PRIVATE | ||
| 18 | #include "lua.h" | 17 | #include "lua.h" |
| 19 | 18 | ||
| 20 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
| @@ -23,7 +22,7 @@ | |||
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | 24 | ||
| 26 | LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]) { | 25 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { |
| 27 | int i; | 26 | int i; |
| 28 | for (i=0; list[i]; i++) | 27 | for (i=0; list[i]; i++) |
| 29 | if (strcmp(list[i], name) == 0) | 28 | if (strcmp(list[i], name) == 0) |
| @@ -31,20 +30,20 @@ LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]) | |||
| 31 | return -1; /* name not found */ | 30 | return -1; /* name not found */ |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const l_char *extramsg) { | 33 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) { |
| 35 | lua_Debug ar; | 34 | lua_Debug ar; |
| 36 | lua_getstack(L, 0, &ar); | 35 | lua_getstack(L, 0, &ar); |
| 37 | lua_getinfo(L, l_s("n"), &ar); | 36 | lua_getinfo(L, "n", &ar); |
| 38 | if (ar.name == NULL) | 37 | if (ar.name == NULL) |
| 39 | ar.name = l_s("?"); | 38 | ar.name = "?"; |
| 40 | luaL_verror(L, l_s("bad argument #%d to `%.50s' (%.100s)"), | 39 | luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", |
| 41 | narg, ar.name, extramsg); | 40 | narg, ar.name, extramsg); |
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | 43 | ||
| 45 | LUALIB_API void luaL_typerror (lua_State *L, int narg, const l_char *tname) { | 44 | LUALIB_API void luaL_typerror (lua_State *L, int narg, const char *tname) { |
| 46 | l_char buff[80]; | 45 | char buff[80]; |
| 47 | sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_type(L,narg)); | 46 | sprintf(buff, "%.25s expected, got %.25s", tname, lua_type(L,narg)); |
| 48 | luaL_argerror(L, narg, buff); | 47 | luaL_argerror(L, narg, buff); |
| 49 | } | 48 | } |
| 50 | 49 | ||
| @@ -54,9 +53,9 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | 55 | ||
| 57 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const l_char *mes) { | 56 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { |
| 58 | if (space > lua_stackspace(L)) | 57 | if (space > lua_stackspace(L)) |
| 59 | luaL_verror(L, l_s("stack overflow (%.30s)"), mes); | 58 | luaL_verror(L, "stack overflow (%.30s)", mes); |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | 61 | ||
| @@ -68,27 +67,27 @@ LUALIB_API void luaL_check_rawtype(lua_State *L, int narg, int t) { | |||
| 68 | 67 | ||
| 69 | LUALIB_API void luaL_check_any (lua_State *L, int narg) { | 68 | LUALIB_API void luaL_check_any (lua_State *L, int narg) { |
| 70 | if (lua_rawtag(L, narg) == LUA_TNONE) | 69 | if (lua_rawtag(L, narg) == LUA_TNONE) |
| 71 | luaL_argerror(L, narg, l_s("value expected")); | 70 | luaL_argerror(L, narg, "value expected"); |
| 72 | } | 71 | } |
| 73 | 72 | ||
| 74 | 73 | ||
| 75 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, | 74 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, |
| 76 | const l_char *name) { | 75 | const char *name) { |
| 77 | if (strcmp(lua_type(L, narg), name) != 0) | 76 | if (strcmp(lua_type(L, narg), name) != 0) |
| 78 | luaL_typerror(L, narg, name); | 77 | luaL_typerror(L, narg, name); |
| 79 | return lua_touserdata(L, narg); | 78 | return lua_touserdata(L, narg); |
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | 81 | ||
| 83 | LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { | 82 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { |
| 84 | const l_char *s = lua_tostring(L, narg); | 83 | const char *s = lua_tostring(L, narg); |
| 85 | if (!s) tag_error(L, narg, LUA_TSTRING); | 84 | if (!s) tag_error(L, narg, LUA_TSTRING); |
| 86 | if (len) *len = lua_strlen(L, narg); | 85 | if (len) *len = lua_strlen(L, narg); |
| 87 | return s; | 86 | return s; |
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | 89 | ||
| 91 | LUALIB_API const l_char *luaL_opt_lstr (lua_State *L, int narg, const l_char *def, size_t *len) { | 90 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { |
| 92 | if (lua_isnull(L, narg)) { | 91 | if (lua_isnull(L, narg)) { |
| 93 | if (len) | 92 | if (len) |
| 94 | *len = (def ? strlen(def) : 0); | 93 | *len = (def ? strlen(def) : 0); |
| @@ -119,8 +118,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n) { | |||
| 119 | } | 118 | } |
| 120 | 119 | ||
| 121 | 120 | ||
| 122 | LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...) { | 121 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...) { |
| 123 | l_char buff[500]; | 122 | char buff[500]; |
| 124 | va_list argp; | 123 | va_list argp; |
| 125 | va_start(argp, fmt); | 124 | va_start(argp, fmt); |
| 126 | vsprintf(buff, fmt, argp); | 125 | vsprintf(buff, fmt, argp); |
| @@ -174,20 +173,20 @@ static void adjuststack (luaL_Buffer *B) { | |||
| 174 | } | 173 | } |
| 175 | 174 | ||
| 176 | 175 | ||
| 177 | LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B) { | 176 | LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { |
| 178 | if (emptybuffer(B)) | 177 | if (emptybuffer(B)) |
| 179 | adjuststack(B); | 178 | adjuststack(B); |
| 180 | return B->buffer; | 179 | return B->buffer; |
| 181 | } | 180 | } |
| 182 | 181 | ||
| 183 | 182 | ||
| 184 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l) { | 183 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { |
| 185 | while (l--) | 184 | while (l--) |
| 186 | luaL_putchar(B, *s++); | 185 | luaL_putchar(B, *s++); |
| 187 | } | 186 | } |
| 188 | 187 | ||
| 189 | 188 | ||
| 190 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s) { | 189 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { |
| 191 | luaL_addlstring(B, s, strlen(s)); | 190 | luaL_addlstring(B, s, strlen(s)); |
| 192 | } | 191 | } |
| 193 | 192 | ||
| @@ -236,7 +235,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { | |||
| 236 | } | 235 | } |
| 237 | else { /* no free elements */ | 236 | else { /* no free elements */ |
| 238 | ref = lua_getn(L, t) + 1; /* use next `n' */ | 237 | ref = lua_getn(L, t) + 1; /* use next `n' */ |
| 239 | lua_pushliteral(L, l_s("n")); | 238 | lua_pushliteral(L, "n"); |
| 240 | lua_pushnumber(L, ref); | 239 | lua_pushnumber(L, ref); |
| 241 | lua_settable(L, t); /* n = n+1 */ | 240 | lua_settable(L, t); /* n = n+1 */ |
| 242 | } | 241 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.37 2001/10/26 17:33:30 roberto Exp $ | 2 | ** $Id: lauxlib.h,v 1.38 2001/10/31 19:40:14 roberto Exp $ |
| 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 | */ |
| @@ -21,31 +21,31 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | typedef struct luaL_reg { | 23 | typedef struct luaL_reg { |
| 24 | const lua_char *name; | 24 | const char *name; |
| 25 | lua_CFunction func; | 25 | lua_CFunction func; |
| 26 | } luaL_reg; | 26 | } luaL_reg; |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n); | 29 | LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n); |
| 30 | LUALIB_API void luaL_typerror (lua_State *L, int narg, const lua_char *tname); | 30 | LUALIB_API void luaL_typerror (lua_State *L, int narg, const char *tname); |
| 31 | LUALIB_API void luaL_argerror (lua_State *L, int numarg, | 31 | LUALIB_API void luaL_argerror (lua_State *L, int numarg, |
| 32 | const lua_char *extramsg); | 32 | const char *extramsg); |
| 33 | LUALIB_API const lua_char *luaL_check_lstr (lua_State *L, int numArg, | 33 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, |
| 34 | size_t *len); | 34 | size_t *len); |
| 35 | LUALIB_API const lua_char *luaL_opt_lstr (lua_State *L, int numArg, | 35 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, |
| 36 | const lua_char *def, size_t *len); | 36 | const char *def, size_t *len); |
| 37 | LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg); | 37 | LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg); |
| 38 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def); | 38 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def); |
| 39 | 39 | ||
| 40 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const lua_char *msg); | 40 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *msg); |
| 41 | LUALIB_API void luaL_check_rawtype (lua_State *L, int narg, int t); | 41 | LUALIB_API void luaL_check_rawtype (lua_State *L, int narg, int t); |
| 42 | LUALIB_API void luaL_check_any (lua_State *L, int narg); | 42 | LUALIB_API void luaL_check_any (lua_State *L, int narg); |
| 43 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, | 43 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, |
| 44 | const lua_char *name); | 44 | const char *name); |
| 45 | 45 | ||
| 46 | LUALIB_API void luaL_verror (lua_State *L, const lua_char *fmt, ...); | 46 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...); |
| 47 | LUALIB_API int luaL_findstring (const lua_char *name, | 47 | LUALIB_API int luaL_findstring (const char *name, |
| 48 | const lua_char *const list[]); | 48 | const char *const list[]); |
| 49 | 49 | ||
| 50 | LUALIB_API int luaL_ref (lua_State *L, int t); | 50 | LUALIB_API int luaL_ref (lua_State *L, int t); |
| 51 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref); | 51 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref); |
| @@ -81,22 +81,22 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref); | |||
| 81 | 81 | ||
| 82 | 82 | ||
| 83 | typedef struct luaL_Buffer { | 83 | typedef struct luaL_Buffer { |
| 84 | lua_char *p; /* current position in buffer */ | 84 | char *p; /* current position in buffer */ |
| 85 | int level; | 85 | int level; |
| 86 | lua_State *L; | 86 | lua_State *L; |
| 87 | lua_char buffer[LUAL_BUFFERSIZE]; | 87 | char buffer[LUAL_BUFFERSIZE]; |
| 88 | } luaL_Buffer; | 88 | } luaL_Buffer; |
| 89 | 89 | ||
| 90 | #define luaL_putchar(B,c) \ | 90 | #define luaL_putchar(B,c) \ |
| 91 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ | 91 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ |
| 92 | (*(B)->p++ = (lua_char)(c))) | 92 | (*(B)->p++ = (char)(c))) |
| 93 | 93 | ||
| 94 | #define luaL_addsize(B,n) ((B)->p += (n)) | 94 | #define luaL_addsize(B,n) ((B)->p += (n)) |
| 95 | 95 | ||
| 96 | LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B); | 96 | LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B); |
| 97 | LUALIB_API lua_char *luaL_prepbuffer (luaL_Buffer *B); | 97 | LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B); |
| 98 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const lua_char *s, size_t l); | 98 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l); |
| 99 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const lua_char *s); | 99 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s); |
| 100 | LUALIB_API void luaL_addvalue (luaL_Buffer *B); | 100 | LUALIB_API void luaL_addvalue (luaL_Buffer *B); |
| 101 | LUALIB_API void luaL_pushresult (luaL_Buffer *B); | 101 | LUALIB_API void luaL_pushresult (luaL_Buffer *B); |
| 102 | 102 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.44 2001/10/17 21:12:57 roberto Exp $ | 2 | ** $Id: lbaselib.c,v 1.45 2001/10/26 17:33:30 roberto Exp $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -11,7 +11,6 @@ | |||
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| 12 | #include <string.h> | 12 | #include <string.h> |
| 13 | 13 | ||
| 14 | #define LUA_PRIVATE | ||
| 15 | #include "lua.h" | 14 | #include "lua.h" |
| 16 | 15 | ||
| 17 | #include "lauxlib.h" | 16 | #include "lauxlib.h" |
| @@ -21,7 +20,7 @@ | |||
| 21 | 20 | ||
| 22 | 21 | ||
| 23 | static void aux_setn (lua_State *L, int t, int n) { | 22 | static void aux_setn (lua_State *L, int t, int n) { |
| 24 | lua_pushliteral(L, l_s("n")); | 23 | lua_pushliteral(L, "n"); |
| 25 | lua_pushnumber(L, n); | 24 | lua_pushnumber(L, n); |
| 26 | lua_settable(L, t); | 25 | lua_settable(L, t); |
| 27 | } | 26 | } |
| @@ -43,21 +42,21 @@ static int luaB__ALERT (lua_State *L) { | |||
| 43 | */ | 42 | */ |
| 44 | static int luaB__ERRORMESSAGE (lua_State *L) { | 43 | static int luaB__ERRORMESSAGE (lua_State *L) { |
| 45 | luaL_check_rawtype(L, 1, LUA_TSTRING); | 44 | luaL_check_rawtype(L, 1, LUA_TSTRING); |
| 46 | lua_getglobal(L, l_s(LUA_ALERT)); | 45 | lua_getglobal(L, LUA_ALERT); |
| 47 | if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ | 46 | if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ |
| 48 | lua_Debug ar; | 47 | lua_Debug ar; |
| 49 | lua_pushliteral(L, l_s("error: ")); | 48 | lua_pushliteral(L, "error: "); |
| 50 | lua_pushvalue(L, 1); | 49 | lua_pushvalue(L, 1); |
| 51 | if (lua_getstack(L, 1, &ar)) { | 50 | if (lua_getstack(L, 1, &ar)) { |
| 52 | lua_getinfo(L, l_s("Sl"), &ar); | 51 | lua_getinfo(L, "Sl", &ar); |
| 53 | if (ar.source && ar.currentline > 0) { | 52 | if (ar.source && ar.currentline > 0) { |
| 54 | l_char buff[100]; | 53 | char buff[100]; |
| 55 | sprintf(buff, l_s("\n <%.70s: line %d>"), ar.short_src, ar.currentline); | 54 | sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline); |
| 56 | lua_pushstring(L, buff); | 55 | lua_pushstring(L, buff); |
| 57 | lua_concat(L, 2); | 56 | lua_concat(L, 2); |
| 58 | } | 57 | } |
| 59 | } | 58 | } |
| 60 | lua_pushliteral(L, l_s("\n")); | 59 | lua_pushliteral(L, "\n"); |
| 61 | lua_concat(L, 3); | 60 | lua_concat(L, 3); |
| 62 | lua_rawcall(L, 1, 0); | 61 | lua_rawcall(L, 1, 0); |
| 63 | } | 62 | } |
| @@ -74,20 +73,20 @@ static int luaB__ERRORMESSAGE (lua_State *L) { | |||
| 74 | static int luaB_print (lua_State *L) { | 73 | static int luaB_print (lua_State *L) { |
| 75 | int n = lua_gettop(L); /* number of arguments */ | 74 | int n = lua_gettop(L); /* number of arguments */ |
| 76 | int i; | 75 | int i; |
| 77 | lua_getglobal(L, l_s("tostring")); | 76 | lua_getglobal(L, "tostring"); |
| 78 | for (i=1; i<=n; i++) { | 77 | for (i=1; i<=n; i++) { |
| 79 | const l_char *s; | 78 | const char *s; |
| 80 | lua_pushvalue(L, -1); /* function to be called */ | 79 | lua_pushvalue(L, -1); /* function to be called */ |
| 81 | lua_pushvalue(L, i); /* value to print */ | 80 | lua_pushvalue(L, i); /* value to print */ |
| 82 | lua_rawcall(L, 1, 1); | 81 | lua_rawcall(L, 1, 1); |
| 83 | s = lua_tostring(L, -1); /* get result */ | 82 | s = lua_tostring(L, -1); /* get result */ |
| 84 | if (s == NULL) | 83 | if (s == NULL) |
| 85 | lua_error(L, l_s("`tostring' must return a string to `print'")); | 84 | lua_error(L, "`tostring' must return a string to `print'"); |
| 86 | if (i>1) fputs(l_s("\t"), stdout); | 85 | if (i>1) fputs("\t", stdout); |
| 87 | fputs(s, stdout); | 86 | fputs(s, stdout); |
| 88 | lua_pop(L, 1); /* pop result */ | 87 | lua_pop(L, 1); /* pop result */ |
| 89 | } | 88 | } |
| 90 | fputs(l_s("\n"), stdout); | 89 | fputs("\n", stdout); |
| 91 | return 0; | 90 | return 0; |
| 92 | } | 91 | } |
| 93 | 92 | ||
| @@ -102,14 +101,14 @@ static int luaB_tonumber (lua_State *L) { | |||
| 102 | } | 101 | } |
| 103 | } | 102 | } |
| 104 | else { | 103 | else { |
| 105 | const l_char *s1 = luaL_check_string(L, 1); | 104 | const char *s1 = luaL_check_string(L, 1); |
| 106 | l_char *s2; | 105 | char *s2; |
| 107 | unsigned long n; | 106 | unsigned long n; |
| 108 | luaL_arg_check(L, 2 <= base && base <= 36, 2, l_s("base out of range")); | 107 | luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range"); |
| 109 | n = strtoul(s1, &s2, base); | 108 | n = strtoul(s1, &s2, base); |
| 110 | if (s1 != s2) { /* at least one valid digit? */ | 109 | if (s1 != s2) { /* at least one valid digit? */ |
| 111 | while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */ | 110 | while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ |
| 112 | if (*s2 == l_c('\0')) { /* no invalid trailing characters? */ | 111 | if (*s2 == '\0') { /* no invalid trailing characters? */ |
| 113 | lua_pushnumber(L, n); | 112 | lua_pushnumber(L, n); |
| 114 | return 1; | 113 | return 1; |
| 115 | } | 114 | } |
| @@ -143,14 +142,14 @@ static int gettag (lua_State *L, int narg) { | |||
| 143 | case LUA_TNUMBER: | 142 | case LUA_TNUMBER: |
| 144 | return (int)(lua_tonumber(L, narg)); | 143 | return (int)(lua_tonumber(L, narg)); |
| 145 | case LUA_TSTRING: { | 144 | case LUA_TSTRING: { |
| 146 | const l_char *name = lua_tostring(L, narg); | 145 | const char *name = lua_tostring(L, narg); |
| 147 | int tag = lua_name2tag(L, name); | 146 | int tag = lua_name2tag(L, name); |
| 148 | if (tag == LUA_TNONE) | 147 | if (tag == LUA_TNONE) |
| 149 | luaL_verror(L, l_s("'%.30s' is not a valid type name"), name); | 148 | luaL_verror(L, "'%.30s' is not a valid type name", name); |
| 150 | return tag; | 149 | return tag; |
| 151 | } | 150 | } |
| 152 | default: | 151 | default: |
| 153 | luaL_argerror(L, narg, l_s("tag or type name expected")); | 152 | luaL_argerror(L, narg, "tag or type name expected"); |
| 154 | return 0; /* to avoid warnings */ | 153 | return 0; /* to avoid warnings */ |
| 155 | } | 154 | } |
| 156 | } | 155 | } |
| @@ -170,11 +169,11 @@ static int luaB_settype (lua_State *L) { | |||
| 170 | } | 169 | } |
| 171 | 170 | ||
| 172 | static int luaB_weakmode (lua_State *L) { | 171 | static int luaB_weakmode (lua_State *L) { |
| 173 | const l_char *mode = luaL_check_string(L, 2); | 172 | const char *mode = luaL_check_string(L, 2); |
| 174 | luaL_check_rawtype(L, 1, LUA_TTABLE); | 173 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
| 175 | if (*mode == l_c('?')) { | 174 | if (*mode == '?') { |
| 176 | l_char buff[3]; | 175 | char buff[3]; |
| 177 | l_char *s = buff; | 176 | char *s = buff; |
| 178 | int imode = lua_getweakmode(L, 1); | 177 | int imode = lua_getweakmode(L, 1); |
| 179 | if (imode & LUA_WEAK_KEY) *s++ = 'k'; | 178 | if (imode & LUA_WEAK_KEY) *s++ = 'k'; |
| 180 | if (imode & LUA_WEAK_VALUE) *s++ = 'v'; | 179 | if (imode & LUA_WEAK_VALUE) *s++ = 'v'; |
| @@ -184,8 +183,8 @@ static int luaB_weakmode (lua_State *L) { | |||
| 184 | } | 183 | } |
| 185 | else { | 184 | else { |
| 186 | int imode = 0; | 185 | int imode = 0; |
| 187 | if (strchr(mode, l_c('k'))) imode |= LUA_WEAK_KEY; | 186 | if (strchr(mode, 'k')) imode |= LUA_WEAK_KEY; |
| 188 | if (strchr(mode, l_c('v'))) imode |= LUA_WEAK_VALUE; | 187 | if (strchr(mode, 'v')) imode |= LUA_WEAK_VALUE; |
| 189 | lua_pushvalue(L, 1); /* push table */ | 188 | lua_pushvalue(L, 1); /* push table */ |
| 190 | lua_setweakmode(L, imode); | 189 | lua_setweakmode(L, imode); |
| 191 | return 1; /* return the table */ | 190 | return 1; /* return the table */ |
| @@ -193,7 +192,7 @@ static int luaB_weakmode (lua_State *L) { | |||
| 193 | } | 192 | } |
| 194 | 193 | ||
| 195 | static int luaB_newtype (lua_State *L) { | 194 | static int luaB_newtype (lua_State *L) { |
| 196 | const l_char *name = luaL_opt_string(L, 1, NULL); | 195 | const char *name = luaL_opt_string(L, 1, NULL); |
| 197 | lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); | 196 | lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); |
| 198 | return 1; | 197 | return 1; |
| 199 | } | 198 | } |
| @@ -226,11 +225,11 @@ static int luaB_rawset (lua_State *L) { | |||
| 226 | 225 | ||
| 227 | static int luaB_settagmethod (lua_State *L) { | 226 | static int luaB_settagmethod (lua_State *L) { |
| 228 | int tag = gettag(L, 1); | 227 | int tag = gettag(L, 1); |
| 229 | const l_char *event = luaL_check_string(L, 2); | 228 | const char *event = luaL_check_string(L, 2); |
| 230 | luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, | 229 | luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, |
| 231 | l_s("function or nil expected")); | 230 | "function or nil expected"); |
| 232 | if (strcmp(event, l_s("gc")) == 0) | 231 | if (strcmp(event, "gc") == 0) |
| 233 | lua_error(L, l_s("cannot set `gc' tag method from Lua")); | 232 | lua_error(L, "cannot set `gc' tag method from Lua"); |
| 234 | lua_gettagmethod(L, tag, event); | 233 | lua_gettagmethod(L, tag, event); |
| 235 | lua_pushvalue(L, 3); | 234 | lua_pushvalue(L, 3); |
| 236 | lua_settagmethod(L, tag, event); | 235 | lua_settagmethod(L, tag, event); |
| @@ -240,9 +239,9 @@ static int luaB_settagmethod (lua_State *L) { | |||
| 240 | 239 | ||
| 241 | static int luaB_gettagmethod (lua_State *L) { | 240 | static int luaB_gettagmethod (lua_State *L) { |
| 242 | int tag = gettag(L, 1); | 241 | int tag = gettag(L, 1); |
| 243 | const l_char *event = luaL_check_string(L, 2); | 242 | const char *event = luaL_check_string(L, 2); |
| 244 | if (strcmp(event, l_s("gc")) == 0) | 243 | if (strcmp(event, "gc") == 0) |
| 245 | lua_error(L, l_s("cannot get `gc' tag method from Lua")); | 244 | lua_error(L, "cannot get `gc' tag method from Lua"); |
| 246 | lua_gettagmethod(L, tag, event); | 245 | lua_gettagmethod(L, tag, event); |
| 247 | return 1; | 246 | return 1; |
| 248 | } | 247 | } |
| @@ -288,9 +287,9 @@ static int luaB_next (lua_State *L) { | |||
| 288 | 287 | ||
| 289 | 288 | ||
| 290 | static int passresults (lua_State *L, int status, int oldtop) { | 289 | static int passresults (lua_State *L, int status, int oldtop) { |
| 291 | static const l_char *const errornames[] = | 290 | static const char *const errornames[] = |
| 292 | {l_s("ok"), l_s("run-time error"), l_s("file error"), l_s("syntax error"), | 291 | {"ok", "run-time error", "file error", "syntax error", |
| 293 | l_s("memory error"), l_s("error in error handling")}; | 292 | "memory error", "error in error handling"}; |
| 294 | if (status == 0) { | 293 | if (status == 0) { |
| 295 | int nresults = lua_gettop(L) - oldtop; | 294 | int nresults = lua_gettop(L) - oldtop; |
| 296 | if (nresults > 0) | 295 | if (nresults > 0) |
| @@ -311,8 +310,8 @@ static int passresults (lua_State *L, int status, int oldtop) { | |||
| 311 | static int luaB_dostring (lua_State *L) { | 310 | static int luaB_dostring (lua_State *L) { |
| 312 | int oldtop = lua_gettop(L); | 311 | int oldtop = lua_gettop(L); |
| 313 | size_t l; | 312 | size_t l; |
| 314 | const l_char *s = luaL_check_lstr(L, 1, &l); | 313 | const char *s = luaL_check_lstr(L, 1, &l); |
| 315 | const l_char *chunkname = luaL_opt_string(L, 2, s); | 314 | const char *chunkname = luaL_opt_string(L, 2, s); |
| 316 | return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop); | 315 | return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop); |
| 317 | } | 316 | } |
| 318 | 317 | ||
| @@ -320,36 +319,36 @@ static int luaB_dostring (lua_State *L) { | |||
| 320 | static int luaB_loadstring (lua_State *L) { | 319 | static int luaB_loadstring (lua_State *L) { |
| 321 | int oldtop = lua_gettop(L); | 320 | int oldtop = lua_gettop(L); |
| 322 | size_t l; | 321 | size_t l; |
| 323 | const l_char *s = luaL_check_lstr(L, 1, &l); | 322 | const char *s = luaL_check_lstr(L, 1, &l); |
| 324 | const l_char *chunkname = luaL_opt_string(L, 2, s); | 323 | const char *chunkname = luaL_opt_string(L, 2, s); |
| 325 | return passresults(L, lua_loadbuffer(L, s, l, chunkname), oldtop); | 324 | return passresults(L, lua_loadbuffer(L, s, l, chunkname), oldtop); |
| 326 | } | 325 | } |
| 327 | 326 | ||
| 328 | static int luaB_dofile (lua_State *L) { | 327 | static int luaB_dofile (lua_State *L) { |
| 329 | int oldtop = lua_gettop(L); | 328 | int oldtop = lua_gettop(L); |
| 330 | const l_char *fname = luaL_opt_string(L, 1, NULL); | 329 | const char *fname = luaL_opt_string(L, 1, NULL); |
| 331 | return passresults(L, lua_dofile(L, fname), oldtop); | 330 | return passresults(L, lua_dofile(L, fname), oldtop); |
| 332 | } | 331 | } |
| 333 | 332 | ||
| 334 | 333 | ||
| 335 | static int luaB_loadfile (lua_State *L) { | 334 | static int luaB_loadfile (lua_State *L) { |
| 336 | int oldtop = lua_gettop(L); | 335 | int oldtop = lua_gettop(L); |
| 337 | const l_char *fname = luaL_opt_string(L, 1, NULL); | 336 | const char *fname = luaL_opt_string(L, 1, NULL); |
| 338 | return passresults(L, lua_loadfile(L, fname), oldtop); | 337 | return passresults(L, lua_loadfile(L, fname), oldtop); |
| 339 | } | 338 | } |
| 340 | 339 | ||
| 341 | 340 | ||
| 342 | 341 | ||
| 343 | #define LUA_PATH l_s("LUA_PATH") | 342 | #define LUA_PATH "LUA_PATH" |
| 344 | 343 | ||
| 345 | #define LUA_PATH_SEP l_s(";") | 344 | #define LUA_PATH_SEP ";" |
| 346 | 345 | ||
| 347 | #ifndef LUA_PATH_DEFAULT | 346 | #ifndef LUA_PATH_DEFAULT |
| 348 | #define LUA_PATH_DEFAULT l_s("./") | 347 | #define LUA_PATH_DEFAULT "./" |
| 349 | #endif | 348 | #endif |
| 350 | 349 | ||
| 351 | static int luaB_require (lua_State *L) { | 350 | static int luaB_require (lua_State *L) { |
| 352 | const l_char *path; | 351 | const char *path; |
| 353 | luaL_check_string(L, 1); | 352 | luaL_check_string(L, 1); |
| 354 | lua_settop(L, 1); | 353 | lua_settop(L, 1); |
| 355 | lua_getglobal(L, LUA_PATH); /* get path */ | 354 | lua_getglobal(L, LUA_PATH); /* get path */ |
| @@ -379,8 +378,8 @@ static int luaB_require (lua_State *L) { | |||
| 379 | if (res == 0) break; /* ok; file done */ | 378 | if (res == 0) break; /* ok; file done */ |
| 380 | else if (res != LUA_ERRFILE) | 379 | else if (res != LUA_ERRFILE) |
| 381 | lua_error(L, NULL); /* error running package; propagate it */ | 380 | lua_error(L, NULL); /* error running package; propagate it */ |
| 382 | if (*(path+l) == l_c('\0')) /* no more directories? */ | 381 | if (*(path+l) == '\0') /* no more directories? */ |
| 383 | luaL_verror(L, l_s("could not load package `%.20s' from path `%.200s'"), | 382 | luaL_verror(L, "could not load package `%.20s' from path `%.200s'", |
| 384 | lua_tostring(L, 1), lua_tostring(L, 2)); | 383 | lua_tostring(L, 1), lua_tostring(L, 2)); |
| 385 | path += l+1; /* try next directory */ | 384 | path += l+1; /* try next directory */ |
| 386 | } | 385 | } |
| @@ -396,7 +395,7 @@ static int aux_unpack (lua_State *L, int arg) { | |||
| 396 | int n, i; | 395 | int n, i; |
| 397 | luaL_check_rawtype(L, arg, LUA_TTABLE); | 396 | luaL_check_rawtype(L, arg, LUA_TTABLE); |
| 398 | n = lua_getn(L, arg); | 397 | n = lua_getn(L, arg); |
| 399 | luaL_check_stack(L, n, l_s("table too big to unpack")); | 398 | luaL_check_stack(L, n, "table too big to unpack"); |
| 400 | for (i=1; i<=n; i++) /* push arg[1...n] */ | 399 | for (i=1; i<=n; i++) /* push arg[1...n] */ |
| 401 | lua_rawgeti(L, arg, i); | 400 | lua_rawgeti(L, arg, i); |
| 402 | return n; | 401 | return n; |
| @@ -410,15 +409,15 @@ static int luaB_unpack (lua_State *L) { | |||
| 410 | 409 | ||
| 411 | static int luaB_call (lua_State *L) { | 410 | static int luaB_call (lua_State *L) { |
| 412 | int oldtop; | 411 | int oldtop; |
| 413 | const l_char *options = luaL_opt_string(L, 3, l_s("")); | 412 | const char *options = luaL_opt_string(L, 3, ""); |
| 414 | int err = 0; /* index of old error method */ | 413 | int err = 0; /* index of old error method */ |
| 415 | int status; | 414 | int status; |
| 416 | int n; | 415 | int n; |
| 417 | if (!lua_isnull(L, 4)) { /* set new error method */ | 416 | if (!lua_isnull(L, 4)) { /* set new error method */ |
| 418 | lua_getglobal(L, l_s(LUA_ERRORMESSAGE)); | 417 | lua_getglobal(L, LUA_ERRORMESSAGE); |
| 419 | err = lua_gettop(L); /* get index */ | 418 | err = lua_gettop(L); /* get index */ |
| 420 | lua_pushvalue(L, 4); | 419 | lua_pushvalue(L, 4); |
| 421 | lua_setglobal(L, l_s(LUA_ERRORMESSAGE)); | 420 | lua_setglobal(L, LUA_ERRORMESSAGE); |
| 422 | } | 421 | } |
| 423 | oldtop = lua_gettop(L); /* top before function-call preparation */ | 422 | oldtop = lua_gettop(L); /* top before function-call preparation */ |
| 424 | /* push function */ | 423 | /* push function */ |
| @@ -427,23 +426,23 @@ static int luaB_call (lua_State *L) { | |||
| 427 | status = lua_call(L, n, LUA_MULTRET); | 426 | status = lua_call(L, n, LUA_MULTRET); |
| 428 | if (err != 0) { /* restore old error method */ | 427 | if (err != 0) { /* restore old error method */ |
| 429 | lua_pushvalue(L, err); | 428 | lua_pushvalue(L, err); |
| 430 | lua_setglobal(L, l_s(LUA_ERRORMESSAGE)); | 429 | lua_setglobal(L, LUA_ERRORMESSAGE); |
| 431 | } | 430 | } |
| 432 | if (status != 0) { /* error in call? */ | 431 | if (status != 0) { /* error in call? */ |
| 433 | if (strchr(options, l_c('x'))) | 432 | if (strchr(options, 'x')) |
| 434 | lua_pushnil(L); /* return nil to signal the error */ | 433 | lua_pushnil(L); /* return nil to signal the error */ |
| 435 | else | 434 | else |
| 436 | lua_error(L, NULL); /* propagate error without additional messages */ | 435 | lua_error(L, NULL); /* propagate error without additional messages */ |
| 437 | return 1; | 436 | return 1; |
| 438 | } | 437 | } |
| 439 | if (strchr(options, l_c('p'))) /* pack results? */ | 438 | if (strchr(options, 'p')) /* pack results? */ |
| 440 | lua_error(L, l_s("obsolete option `p' in `call'")); | 439 | lua_error(L, "obsolete option `p' in `call'"); |
| 441 | return lua_gettop(L) - oldtop; /* results are already on the stack */ | 440 | return lua_gettop(L) - oldtop; /* results are already on the stack */ |
| 442 | } | 441 | } |
| 443 | 442 | ||
| 444 | 443 | ||
| 445 | static int luaB_tostring (lua_State *L) { | 444 | static int luaB_tostring (lua_State *L) { |
| 446 | l_char buff[64]; | 445 | char buff[64]; |
| 447 | switch (lua_rawtag(L, 1)) { | 446 | switch (lua_rawtag(L, 1)) { |
| 448 | case LUA_TNUMBER: | 447 | case LUA_TNUMBER: |
| 449 | lua_pushstring(L, lua_tostring(L, 1)); | 448 | lua_pushstring(L, lua_tostring(L, 1)); |
| @@ -452,25 +451,25 @@ static int luaB_tostring (lua_State *L) { | |||
| 452 | lua_pushvalue(L, 1); | 451 | lua_pushvalue(L, 1); |
| 453 | return 1; | 452 | return 1; |
| 454 | case LUA_TTABLE: | 453 | case LUA_TTABLE: |
| 455 | sprintf(buff, l_s("%.40s: %p"), lua_type(L, 1), lua_topointer(L, 1)); | 454 | sprintf(buff, "%.40s: %p", lua_type(L, 1), lua_topointer(L, 1)); |
| 456 | break; | 455 | break; |
| 457 | case LUA_TFUNCTION: | 456 | case LUA_TFUNCTION: |
| 458 | sprintf(buff, l_s("function: %p"), lua_topointer(L, 1)); | 457 | sprintf(buff, "function: %p", lua_topointer(L, 1)); |
| 459 | break; | 458 | break; |
| 460 | case LUA_TUSERDATA: { | 459 | case LUA_TUSERDATA: { |
| 461 | const l_char *t = lua_type(L, 1); | 460 | const char *t = lua_type(L, 1); |
| 462 | if (strcmp(t, l_s("userdata")) == 0) | 461 | if (strcmp(t, "userdata") == 0) |
| 463 | sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), | 462 | sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), |
| 464 | lua_touserdata(L, 1)); | 463 | lua_touserdata(L, 1)); |
| 465 | else | 464 | else |
| 466 | sprintf(buff, l_s("%.40s: %p"), t, lua_touserdata(L, 1)); | 465 | sprintf(buff, "%.40s: %p", t, lua_touserdata(L, 1)); |
| 467 | break; | 466 | break; |
| 468 | } | 467 | } |
| 469 | case LUA_TNIL: | 468 | case LUA_TNIL: |
| 470 | lua_pushliteral(L, l_s("nil")); | 469 | lua_pushliteral(L, "nil"); |
| 471 | return 1; | 470 | return 1; |
| 472 | default: | 471 | default: |
| 473 | luaL_argerror(L, 1, l_s("value expected")); | 472 | luaL_argerror(L, 1, "value expected"); |
| 474 | } | 473 | } |
| 475 | lua_pushstring(L, buff); | 474 | lua_pushstring(L, buff); |
| 476 | return 1; | 475 | return 1; |
| @@ -516,8 +515,8 @@ static int luaB_foreach (lua_State *L) { | |||
| 516 | static int luaB_assert (lua_State *L) { | 515 | static int luaB_assert (lua_State *L) { |
| 517 | luaL_check_any(L, 1); | 516 | luaL_check_any(L, 1); |
| 518 | if (lua_isnil(L, 1)) | 517 | if (lua_isnil(L, 1)) |
| 519 | luaL_verror(L, l_s("assertion failed! %.90s"), | 518 | luaL_verror(L, "assertion failed! %.90s", |
| 520 | luaL_opt_string(L, 2, l_s(""))); | 519 | luaL_opt_string(L, 2, "")); |
| 521 | lua_settop(L, 1); | 520 | lua_settop(L, 1); |
| 522 | return 1; | 521 | return 1; |
| 523 | } | 522 | } |
| @@ -635,12 +634,12 @@ static void auxsort (lua_State *L, int l, int u) { | |||
| 635 | for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ | 634 | for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ |
| 636 | /* repeat ++i until a[i] >= P */ | 635 | /* repeat ++i until a[i] >= P */ |
| 637 | while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { | 636 | while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { |
| 638 | if (i>u) lua_error(L, l_s("invalid order function for sorting")); | 637 | if (i>u) lua_error(L, "invalid order function for sorting"); |
| 639 | lua_pop(L, 1); /* remove a[i] */ | 638 | lua_pop(L, 1); /* remove a[i] */ |
| 640 | } | 639 | } |
| 641 | /* repeat --j until a[j] <= P */ | 640 | /* repeat --j until a[j] <= P */ |
| 642 | while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { | 641 | while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { |
| 643 | if (j<l) lua_error(L, l_s("invalid order function for sorting")); | 642 | if (j<l) lua_error(L, "invalid order function for sorting"); |
| 644 | lua_pop(L, 1); /* remove a[j] */ | 643 | lua_pop(L, 1); /* remove a[j] */ |
| 645 | } | 644 | } |
| 646 | if (j<i) { | 645 | if (j<i) { |
| @@ -680,57 +679,57 @@ static int luaB_sort (lua_State *L) { | |||
| 680 | 679 | ||
| 681 | 680 | ||
| 682 | static const luaL_reg base_funcs[] = { | 681 | static const luaL_reg base_funcs[] = { |
| 683 | {l_s(LUA_ALERT), luaB__ALERT}, | 682 | {LUA_ALERT, luaB__ALERT}, |
| 684 | {l_s(LUA_ERRORMESSAGE), luaB__ERRORMESSAGE}, | 683 | {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE}, |
| 685 | {l_s("call"), luaB_call}, | 684 | {"call", luaB_call}, |
| 686 | {l_s("collectgarbage"), luaB_collectgarbage}, | 685 | {"collectgarbage", luaB_collectgarbage}, |
| 687 | {l_s("dofile"), luaB_dofile}, | 686 | {"dofile", luaB_dofile}, |
| 688 | {l_s("dostring"), luaB_dostring}, | 687 | {"dostring", luaB_dostring}, |
| 689 | {l_s("error"), luaB_error}, | 688 | {"error", luaB_error}, |
| 690 | {l_s("foreach"), luaB_foreach}, | 689 | {"foreach", luaB_foreach}, |
| 691 | {l_s("foreachi"), luaB_foreachi}, | 690 | {"foreachi", luaB_foreachi}, |
| 692 | {l_s("gcinfo"), luaB_gcinfo}, | 691 | {"gcinfo", luaB_gcinfo}, |
| 693 | {l_s("getglobal"), luaB_getglobal}, | 692 | {"getglobal", luaB_getglobal}, |
| 694 | {l_s("gettagmethod"), luaB_gettagmethod}, | 693 | {"gettagmethod", luaB_gettagmethod}, |
| 695 | {l_s("globals"), luaB_globals}, | 694 | {"globals", luaB_globals}, |
| 696 | {l_s("loadfile"), luaB_loadfile}, | 695 | {"loadfile", luaB_loadfile}, |
| 697 | {l_s("loadstring"), luaB_loadstring}, | 696 | {"loadstring", luaB_loadstring}, |
| 698 | {l_s("newtype"), luaB_newtype}, | 697 | {"newtype", luaB_newtype}, |
| 699 | {l_s("newtag"), luaB_newtype}, /* for compatibility 4.0 */ | 698 | {"newtag", luaB_newtype}, /* for compatibility 4.0 */ |
| 700 | {l_s("next"), luaB_next}, | 699 | {"next", luaB_next}, |
| 701 | {l_s("print"), luaB_print}, | 700 | {"print", luaB_print}, |
| 702 | {l_s("rawget"), luaB_rawget}, | 701 | {"rawget", luaB_rawget}, |
| 703 | {l_s("rawset"), luaB_rawset}, | 702 | {"rawset", luaB_rawset}, |
| 704 | {l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */ | 703 | {"rawgettable", luaB_rawget}, /* for compatibility 3.2 */ |
| 705 | {l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */ | 704 | {"rawsettable", luaB_rawset}, /* for compatibility 3.2 */ |
| 706 | {l_s("rawtype"), luaB_rawtype}, | 705 | {"rawtype", luaB_rawtype}, |
| 707 | {l_s("setglobal"), luaB_setglobal}, | 706 | {"setglobal", luaB_setglobal}, |
| 708 | {l_s("settag"), luaB_settype}, /* for compatibility 4.0 */ | 707 | {"settag", luaB_settype}, /* for compatibility 4.0 */ |
| 709 | {l_s("settype"), luaB_settype}, | 708 | {"settype", luaB_settype}, |
| 710 | {l_s("settagmethod"), luaB_settagmethod}, | 709 | {"settagmethod", luaB_settagmethod}, |
| 711 | {l_s("tag"), luaB_tag}, | 710 | {"tag", luaB_tag}, |
| 712 | {l_s("tonumber"), luaB_tonumber}, | 711 | {"tonumber", luaB_tonumber}, |
| 713 | {l_s("tostring"), luaB_tostring}, | 712 | {"tostring", luaB_tostring}, |
| 714 | {l_s("type"), luaB_type}, | 713 | {"type", luaB_type}, |
| 715 | {l_s("assert"), luaB_assert}, | 714 | {"assert", luaB_assert}, |
| 716 | {l_s("getn"), luaB_getn}, | 715 | {"getn", luaB_getn}, |
| 717 | {l_s("sort"), luaB_sort}, | 716 | {"sort", luaB_sort}, |
| 718 | {l_s("tinsert"), luaB_tinsert}, | 717 | {"tinsert", luaB_tinsert}, |
| 719 | {l_s("tremove"), luaB_tremove}, | 718 | {"tremove", luaB_tremove}, |
| 720 | {l_s("unpack"), luaB_unpack}, | 719 | {"unpack", luaB_unpack}, |
| 721 | {l_s("weakmode"), luaB_weakmode} | 720 | {"weakmode", luaB_weakmode} |
| 722 | }; | 721 | }; |
| 723 | 722 | ||
| 724 | 723 | ||
| 725 | 724 | ||
| 726 | LUALIB_API int lua_baselibopen (lua_State *L) { | 725 | LUALIB_API int lua_baselibopen (lua_State *L) { |
| 727 | luaL_openl(L, base_funcs); | 726 | luaL_openl(L, base_funcs); |
| 728 | lua_pushliteral(L, l_s(LUA_VERSION)); | 727 | lua_pushliteral(L, LUA_VERSION); |
| 729 | lua_setglobal(L, l_s("_VERSION")); | 728 | lua_setglobal(L, "_VERSION"); |
| 730 | /* `require' needs an empty table as upvalue */ | 729 | /* `require' needs an empty table as upvalue */ |
| 731 | lua_newtable(L); | 730 | lua_newtable(L); |
| 732 | lua_pushcclosure(L, luaB_require, 1); | 731 | lua_pushcclosure(L, luaB_require, 1); |
| 733 | lua_setglobal(L, l_s("require")); | 732 | lua_setglobal(L, "require"); |
| 734 | return 0; | 733 | return 0; |
| 735 | } | 734 | } |
| 736 | 735 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.79 2001/08/27 15:16:28 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.82 2001/09/07 17:39:10 roberto Exp $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "lcode.h" | 12 | #include "lcode.h" |
| @@ -27,7 +26,7 @@ | |||
| 27 | 26 | ||
| 28 | 27 | ||
| 29 | 28 | ||
| 30 | void luaK_error (LexState *ls, const l_char *msg) { | 29 | void luaK_error (LexState *ls, const char *msg) { |
| 31 | luaX_error(ls, msg, ls->t.token); | 30 | luaX_error(ls, msg, ls->t.token); |
| 32 | } | 31 | } |
| 33 | 32 | ||
| @@ -83,7 +82,7 @@ static void luaK_fixjump (FuncState *fs, int pc, int dest) { | |||
| 83 | else { /* jump is relative to position following jump instruction */ | 82 | else { /* jump is relative to position following jump instruction */ |
| 84 | int offset = dest-(pc+1); | 83 | int offset = dest-(pc+1); |
| 85 | if (abs(offset) > MAXARG_sBc) | 84 | if (abs(offset) > MAXARG_sBc) |
| 86 | luaK_error(fs->ls, l_s("control structure too long")); | 85 | luaK_error(fs->ls, "control structure too long"); |
| 87 | SETARG_sBc(*jmp, offset); | 86 | SETARG_sBc(*jmp, offset); |
| 88 | } | 87 | } |
| 89 | } | 88 | } |
| @@ -202,7 +201,7 @@ void luaK_reserveregs (FuncState *fs, int n) { | |||
| 202 | fs->freereg += n; | 201 | fs->freereg += n; |
| 203 | if (fs->freereg > fs->f->maxstacksize) { | 202 | if (fs->freereg > fs->f->maxstacksize) { |
| 204 | if (fs->freereg >= MAXSTACK) | 203 | if (fs->freereg >= MAXSTACK) |
| 205 | luaK_error(fs->ls, l_s("function or expression too complex")); | 204 | luaK_error(fs->ls, "function or expression too complex"); |
| 206 | fs->f->maxstacksize = cast(short, fs->freereg); | 205 | fs->f->maxstacksize = cast(short, fs->freereg); |
| 207 | } | 206 | } |
| 208 | } | 207 | } |
| @@ -232,7 +231,7 @@ static int addk (FuncState *fs, TObject *k) { | |||
| 232 | TObject o; | 231 | TObject o; |
| 233 | Proto *f = fs->f; | 232 | Proto *f = fs->f; |
| 234 | luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject, | 233 | luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject, |
| 235 | MAXARG_Bc, l_s("constant table overflow")); | 234 | MAXARG_Bc, "constant table overflow"); |
| 236 | setobj(&f->k[fs->nk], k); | 235 | setobj(&f->k[fs->nk], k); |
| 237 | setnvalue(&o, fs->nk); | 236 | setnvalue(&o, fs->nk); |
| 238 | luaH_set(fs->L, fs->h, k, &o); | 237 | luaH_set(fs->L, fs->h, k, &o); |
| @@ -771,11 +770,11 @@ static void codelineinfo (FuncState *fs) { | |||
| 771 | if (ls->lastline > fs->lastline) { | 770 | if (ls->lastline > fs->lastline) { |
| 772 | if (ls->lastline > fs->lastline+1) { | 771 | if (ls->lastline > fs->lastline+1) { |
| 773 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, | 772 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, |
| 774 | MAX_INT, l_s("line info overflow")); | 773 | MAX_INT, "line info overflow"); |
| 775 | f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); | 774 | f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); |
| 776 | } | 775 | } |
| 777 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, | 776 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, |
| 778 | MAX_INT, l_s("line info overflow")); | 777 | MAX_INT, "line info overflow"); |
| 779 | f->lineinfo[fs->nlineinfo++] = fs->pc; | 778 | f->lineinfo[fs->nlineinfo++] = fs->pc; |
| 780 | fs->lastline = ls->lastline; | 779 | fs->lastline = ls->lastline; |
| 781 | } | 780 | } |
| @@ -788,7 +787,7 @@ static int luaK_code (FuncState *fs, Instruction i) { | |||
| 788 | f = fs->f; | 787 | f = fs->f; |
| 789 | /* put new instruction in code array */ | 788 | /* put new instruction in code array */ |
| 790 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | 789 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
| 791 | MAX_INT, l_s("code size overflow")); | 790 | MAX_INT, "code size overflow"); |
| 792 | f->code[fs->pc] = i; | 791 | f->code[fs->pc] = i; |
| 793 | /*printf("free: %d ", fs->freereg); printopcode(f, fs->pc);*/ | 792 | /*printf("free: %d ", fs->freereg); printopcode(f, fs->pc);*/ |
| 794 | return fs->pc++; | 793 | return fs->pc++; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.h,v 1.23 2001/06/12 14:36:48 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.24 2001/07/24 17:19:07 roberto Exp $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -38,7 +38,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; | |||
| 38 | 38 | ||
| 39 | #define luaK_codeAsBc(fs,o,A,sBc) luaK_codeABc(fs,o,A,(sBc)+MAXARG_sBc) | 39 | #define luaK_codeAsBc(fs,o,A,sBc) luaK_codeABc(fs,o,A,(sBc)+MAXARG_sBc) |
| 40 | 40 | ||
| 41 | void luaK_error (LexState *ls, const l_char *msg); | 41 | void luaK_error (LexState *ls, const char *msg); |
| 42 | int luaK_codeABc (FuncState *fs, OpCode o, int A, unsigned int Bc); | 42 | int luaK_codeABc (FuncState *fs, OpCode o, int A, unsigned int Bc); |
| 43 | int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | 43 | int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); |
| 44 | void luaK_nil (FuncState *fs, int from, int n); | 44 | void luaK_nil (FuncState *fs, int from, int n); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.39 2001/10/17 21:12:57 roberto Exp $ | 2 | ** $Id: ldblib.c,v 1.40 2001/10/26 17:33:30 roberto Exp $ |
| 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 | */ |
| @@ -9,7 +9,6 @@ | |||
| 9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | 11 | ||
| 12 | #define LUA_PRIVATE | ||
| 13 | #include "lua.h" | 12 | #include "lua.h" |
| 14 | 13 | ||
| 15 | #include "lauxlib.h" | 14 | #include "lauxlib.h" |
| @@ -18,14 +17,14 @@ | |||
| 18 | 17 | ||
| 19 | 18 | ||
| 20 | 19 | ||
| 21 | static void settabss (lua_State *L, const l_char *i, const l_char *v) { | 20 | static void settabss (lua_State *L, const char *i, const char *v) { |
| 22 | lua_pushstring(L, i); | 21 | lua_pushstring(L, i); |
| 23 | lua_pushstring(L, v); | 22 | lua_pushstring(L, v); |
| 24 | lua_settable(L, -3); | 23 | lua_settable(L, -3); |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | static void settabsi (lua_State *L, const l_char *i, int v) { | 27 | static void settabsi (lua_State *L, const char *i, int v) { |
| 29 | lua_pushstring(L, i); | 28 | lua_pushstring(L, i); |
| 30 | lua_pushnumber(L, v); | 29 | lua_pushnumber(L, v); |
| 31 | lua_settable(L, -3); | 30 | lua_settable(L, -3); |
| @@ -34,8 +33,8 @@ static void settabsi (lua_State *L, const l_char *i, int v) { | |||
| 34 | 33 | ||
| 35 | static int getinfo (lua_State *L) { | 34 | static int getinfo (lua_State *L) { |
| 36 | lua_Debug ar; | 35 | lua_Debug ar; |
| 37 | const l_char *options = luaL_opt_string(L, 2, l_s("flnSu")); | 36 | const char *options = luaL_opt_string(L, 2, "flnSu"); |
| 38 | l_char buff[20]; | 37 | char buff[20]; |
| 39 | if (lua_isnumber(L, 1)) { | 38 | if (lua_isnumber(L, 1)) { |
| 40 | if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { | 39 | if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { |
| 41 | lua_pushnil(L); /* level out of range */ | 40 | lua_pushnil(L); /* level out of range */ |
| @@ -44,35 +43,35 @@ static int getinfo (lua_State *L) { | |||
| 44 | } | 43 | } |
| 45 | else if (lua_isfunction(L, 1)) { | 44 | else if (lua_isfunction(L, 1)) { |
| 46 | lua_pushvalue(L, 1); | 45 | lua_pushvalue(L, 1); |
| 47 | sprintf(buff, l_s(">%.10s"), options); | 46 | sprintf(buff, ">%.10s", options); |
| 48 | options = buff; | 47 | options = buff; |
| 49 | } | 48 | } |
| 50 | else | 49 | else |
| 51 | luaL_argerror(L, 1, l_s("function or level expected")); | 50 | luaL_argerror(L, 1, "function or level expected"); |
| 52 | if (!lua_getinfo(L, options, &ar)) | 51 | if (!lua_getinfo(L, options, &ar)) |
| 53 | luaL_argerror(L, 2, l_s("invalid option")); | 52 | luaL_argerror(L, 2, "invalid option"); |
| 54 | lua_newtable(L); | 53 | lua_newtable(L); |
| 55 | for (; *options; options++) { | 54 | for (; *options; options++) { |
| 56 | switch (*options) { | 55 | switch (*options) { |
| 57 | case l_c('S'): | 56 | case 'S': |
| 58 | settabss(L, l_s("source"), ar.source); | 57 | settabss(L, "source", ar.source); |
| 59 | if (ar.source) | 58 | if (ar.source) |
| 60 | settabss(L, l_s("short_src"), ar.short_src); | 59 | settabss(L, "short_src", ar.short_src); |
| 61 | settabsi(L, l_s("linedefined"), ar.linedefined); | 60 | settabsi(L, "linedefined", ar.linedefined); |
| 62 | settabss(L, l_s("what"), ar.what); | 61 | settabss(L, "what", ar.what); |
| 63 | break; | 62 | break; |
| 64 | case l_c('l'): | 63 | case 'l': |
| 65 | settabsi(L, l_s("currentline"), ar.currentline); | 64 | settabsi(L, "currentline", ar.currentline); |
| 66 | break; | 65 | break; |
| 67 | case l_c('u'): | 66 | case 'u': |
| 68 | settabsi(L, l_s("nups"), ar.nups); | 67 | settabsi(L, "nups", ar.nups); |
| 69 | break; | 68 | break; |
| 70 | case l_c('n'): | 69 | case 'n': |
| 71 | settabss(L, l_s("name"), ar.name); | 70 | settabss(L, "name", ar.name); |
| 72 | settabss(L, l_s("namewhat"), ar.namewhat); | 71 | settabss(L, "namewhat", ar.namewhat); |
| 73 | break; | 72 | break; |
| 74 | case l_c('f'): | 73 | case 'f': |
| 75 | lua_pushliteral(L, l_s("func")); | 74 | lua_pushliteral(L, "func"); |
| 76 | lua_pushvalue(L, -3); | 75 | lua_pushvalue(L, -3); |
| 77 | lua_settable(L, -3); | 76 | lua_settable(L, -3); |
| 78 | break; | 77 | break; |
| @@ -84,9 +83,9 @@ static int getinfo (lua_State *L) { | |||
| 84 | 83 | ||
| 85 | static int getlocal (lua_State *L) { | 84 | static int getlocal (lua_State *L) { |
| 86 | lua_Debug ar; | 85 | lua_Debug ar; |
| 87 | const l_char *name; | 86 | const char *name; |
| 88 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 87 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
| 89 | luaL_argerror(L, 1, l_s("level out of range")); | 88 | luaL_argerror(L, 1, "level out of range"); |
| 90 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); | 89 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); |
| 91 | if (name) { | 90 | if (name) { |
| 92 | lua_pushstring(L, name); | 91 | lua_pushstring(L, name); |
| @@ -103,7 +102,7 @@ static int getlocal (lua_State *L) { | |||
| 103 | static int setlocal (lua_State *L) { | 102 | static int setlocal (lua_State *L) { |
| 104 | lua_Debug ar; | 103 | lua_Debug ar; |
| 105 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 104 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
| 106 | luaL_argerror(L, 1, l_s("level out of range")); | 105 | luaL_argerror(L, 1, "level out of range"); |
| 107 | luaL_check_any(L, 3); | 106 | luaL_check_any(L, 3); |
| 108 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); | 107 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); |
| 109 | return 1; | 108 | return 1; |
| @@ -111,11 +110,11 @@ static int setlocal (lua_State *L) { | |||
| 111 | 110 | ||
| 112 | 111 | ||
| 113 | 112 | ||
| 114 | #define KEY_CALLHOOK l_s("luadblibCallhook") | 113 | #define KEY_CALLHOOK "luadblibCallhook" |
| 115 | #define KEY_LINEHOOK l_s("luadblibLinehook") | 114 | #define KEY_LINEHOOK "luadblibLinehook" |
| 116 | 115 | ||
| 117 | 116 | ||
| 118 | static void hookf (lua_State *L, const l_char *key) { | 117 | static void hookf (lua_State *L, const char *key) { |
| 119 | lua_pushstring(L, key); | 118 | lua_pushstring(L, key); |
| 120 | lua_gettable(L, LUA_REGISTRYINDEX); | 119 | lua_gettable(L, LUA_REGISTRYINDEX); |
| 121 | if (lua_isfunction(L, -1)) { | 120 | if (lua_isfunction(L, -1)) { |
| @@ -139,7 +138,7 @@ static void linef (lua_State *L, lua_Debug *ar) { | |||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | 140 | ||
| 142 | static void sethook (lua_State *L, const l_char *key, lua_Hook hook, | 141 | static void sethook (lua_State *L, const char *key, lua_Hook hook, |
| 143 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { | 142 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { |
| 144 | lua_settop(L, 1); | 143 | lua_settop(L, 1); |
| 145 | if (lua_isnil(L, 1)) | 144 | if (lua_isnil(L, 1)) |
| @@ -147,7 +146,7 @@ static void sethook (lua_State *L, const l_char *key, lua_Hook hook, | |||
| 147 | else if (lua_isfunction(L, 1)) | 146 | else if (lua_isfunction(L, 1)) |
| 148 | (*sethookf)(L, hook); | 147 | (*sethookf)(L, hook); |
| 149 | else | 148 | else |
| 150 | luaL_argerror(L, 1, l_s("function expected")); | 149 | luaL_argerror(L, 1, "function expected"); |
| 151 | lua_pushstring(L, key); | 150 | lua_pushstring(L, key); |
| 152 | lua_gettable(L, LUA_REGISTRYINDEX); /* get old value */ | 151 | lua_gettable(L, LUA_REGISTRYINDEX); /* get old value */ |
| 153 | lua_pushstring(L, key); | 152 | lua_pushstring(L, key); |
| @@ -169,11 +168,11 @@ static int setlinehook (lua_State *L) { | |||
| 169 | 168 | ||
| 170 | 169 | ||
| 171 | static const luaL_reg dblib[] = { | 170 | static const luaL_reg dblib[] = { |
| 172 | {l_s("getlocal"), getlocal}, | 171 | {"getlocal", getlocal}, |
| 173 | {l_s("getinfo"), getinfo}, | 172 | {"getinfo", getinfo}, |
| 174 | {l_s("setcallhook"), setcallhook}, | 173 | {"setcallhook", setcallhook}, |
| 175 | {l_s("setlinehook"), setlinehook}, | 174 | {"setlinehook", setlinehook}, |
| 176 | {l_s("setlocal"), setlocal} | 175 | {"setlocal", setlocal} |
| 177 | }; | 176 | }; |
| 178 | 177 | ||
| 179 | 178 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.91 2001/10/25 19:14:14 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.92 2001/10/31 19:58:11 roberto Exp $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "lapi.h" | 12 | #include "lapi.h" |
| @@ -26,8 +25,8 @@ | |||
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | 27 | ||
| 29 | static const l_char *getfuncname (lua_State *L, CallInfo *ci, | 28 | static const char *getfuncname (lua_State *L, CallInfo *ci, |
| 30 | const l_char **name); | 29 | const char **name); |
| 31 | 30 | ||
| 32 | 31 | ||
| 33 | 32 | ||
| @@ -139,8 +138,8 @@ static Proto *getluaproto (CallInfo *ci) { | |||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | 140 | ||
| 142 | LUA_API const l_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | 141 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { |
| 143 | const l_char *name; | 142 | const char *name; |
| 144 | CallInfo *ci; | 143 | CallInfo *ci; |
| 145 | Proto *fp; | 144 | Proto *fp; |
| 146 | lua_lock(L); | 145 | lua_lock(L); |
| @@ -157,8 +156,8 @@ LUA_API const l_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 157 | } | 156 | } |
| 158 | 157 | ||
| 159 | 158 | ||
| 160 | LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | 159 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { |
| 161 | const l_char *name; | 160 | const char *name; |
| 162 | CallInfo *ci; | 161 | CallInfo *ci; |
| 163 | Proto *fp; | 162 | Proto *fp; |
| 164 | lua_lock(L); | 163 | lua_lock(L); |
| @@ -168,7 +167,7 @@ LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 168 | L->top--; /* pop new value */ | 167 | L->top--; /* pop new value */ |
| 169 | if (fp) { /* is a Lua function? */ | 168 | if (fp) { /* is a Lua function? */ |
| 170 | name = luaF_getlocalname(fp, n, currentpc(ci)); | 169 | name = luaF_getlocalname(fp, n, currentpc(ci)); |
| 171 | if (!name || name[0] == l_c('(')) /* `(' starts private locals */ | 170 | if (!name || name[0] == '(') /* `(' starts private locals */ |
| 172 | name = NULL; | 171 | name = NULL; |
| 173 | else | 172 | else |
| 174 | setobj(ci->base+(n-1), L->top); | 173 | setobj(ci->base+(n-1), L->top); |
| @@ -181,7 +180,7 @@ LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 181 | static void infoLproto (lua_Debug *ar, Proto *f) { | 180 | static void infoLproto (lua_Debug *ar, Proto *f) { |
| 182 | ar->source = getstr(f->source); | 181 | ar->source = getstr(f->source); |
| 183 | ar->linedefined = f->lineDefined; | 182 | ar->linedefined = f->lineDefined; |
| 184 | ar->what = l_s("Lua"); | 183 | ar->what = "Lua"; |
| 185 | } | 184 | } |
| 186 | 185 | ||
| 187 | 186 | ||
| @@ -190,23 +189,23 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) { | |||
| 190 | if (ttype(func) == LUA_TFUNCTION) | 189 | if (ttype(func) == LUA_TFUNCTION) |
| 191 | cl = clvalue(func); | 190 | cl = clvalue(func); |
| 192 | else { | 191 | else { |
| 193 | luaD_error(L, l_s("value for `lua_getinfo' is not a function")); | 192 | luaD_error(L, "value for `lua_getinfo' is not a function"); |
| 194 | cl = NULL; /* to avoid warnings */ | 193 | cl = NULL; /* to avoid warnings */ |
| 195 | } | 194 | } |
| 196 | if (cl->c.isC) { | 195 | if (cl->c.isC) { |
| 197 | ar->source = l_s("=C"); | 196 | ar->source = "=C"; |
| 198 | ar->linedefined = -1; | 197 | ar->linedefined = -1; |
| 199 | ar->what = l_s("C"); | 198 | ar->what = "C"; |
| 200 | } | 199 | } |
| 201 | else | 200 | else |
| 202 | infoLproto(ar, cl->l.p); | 201 | infoLproto(ar, cl->l.p); |
| 203 | luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); | 202 | luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); |
| 204 | if (ar->linedefined == 0) | 203 | if (ar->linedefined == 0) |
| 205 | ar->what = l_s("main"); | 204 | ar->what = "main"; |
| 206 | } | 205 | } |
| 207 | 206 | ||
| 208 | 207 | ||
| 209 | static const l_char *travtagmethods (global_State *G, const TObject *o) { | 208 | static const char *travtagmethods (global_State *G, const TObject *o) { |
| 210 | if (ttype(o) == LUA_TFUNCTION) { | 209 | if (ttype(o) == LUA_TFUNCTION) { |
| 211 | int e; | 210 | int e; |
| 212 | for (e=0; e<TM_N; e++) { | 211 | for (e=0; e<TM_N; e++) { |
| @@ -220,7 +219,7 @@ static const l_char *travtagmethods (global_State *G, const TObject *o) { | |||
| 220 | } | 219 | } |
| 221 | 220 | ||
| 222 | 221 | ||
| 223 | static const l_char *travglobals (lua_State *L, const TObject *o) { | 222 | static const char *travglobals (lua_State *L, const TObject *o) { |
| 224 | Table *g = hvalue(&L->gt); | 223 | Table *g = hvalue(&L->gt); |
| 225 | int i = sizenode(g); | 224 | int i = sizenode(g); |
| 226 | while (i--) { | 225 | while (i--) { |
| @@ -235,20 +234,20 @@ static const l_char *travglobals (lua_State *L, const TObject *o) { | |||
| 235 | static void getname (lua_State *L, const TObject *f, lua_Debug *ar) { | 234 | static void getname (lua_State *L, const TObject *f, lua_Debug *ar) { |
| 236 | /* try to find a name for given function */ | 235 | /* try to find a name for given function */ |
| 237 | if ((ar->name = travglobals(L, f)) != NULL) | 236 | if ((ar->name = travglobals(L, f)) != NULL) |
| 238 | ar->namewhat = l_s("global"); | 237 | ar->namewhat = "global"; |
| 239 | /* not found: try tag methods */ | 238 | /* not found: try tag methods */ |
| 240 | else if ((ar->name = travtagmethods(G(L), f)) != NULL) | 239 | else if ((ar->name = travtagmethods(G(L), f)) != NULL) |
| 241 | ar->namewhat = l_s("tag-method"); | 240 | ar->namewhat = "tag-method"; |
| 242 | else ar->namewhat = l_s(""); /* not found at all */ | 241 | else ar->namewhat = ""; /* not found at all */ |
| 243 | } | 242 | } |
| 244 | 243 | ||
| 245 | 244 | ||
| 246 | LUA_API int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar) { | 245 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { |
| 247 | StkId f; | 246 | StkId f; |
| 248 | CallInfo *ci; | 247 | CallInfo *ci; |
| 249 | int status = 1; | 248 | int status = 1; |
| 250 | lua_lock(L); | 249 | lua_lock(L); |
| 251 | if (*what != l_c('>')) { /* function is active? */ | 250 | if (*what != '>') { /* function is active? */ |
| 252 | ci = ar->_ci; | 251 | ci = ar->_ci; |
| 253 | f = ci->base - 1; | 252 | f = ci->base - 1; |
| 254 | } | 253 | } |
| @@ -259,25 +258,25 @@ LUA_API int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar) { | |||
| 259 | } | 258 | } |
| 260 | for (; *what; what++) { | 259 | for (; *what; what++) { |
| 261 | switch (*what) { | 260 | switch (*what) { |
| 262 | case l_c('S'): { | 261 | case 'S': { |
| 263 | funcinfo(L, ar, f); | 262 | funcinfo(L, ar, f); |
| 264 | break; | 263 | break; |
| 265 | } | 264 | } |
| 266 | case l_c('l'): { | 265 | case 'l': { |
| 267 | ar->currentline = currentline(ci); | 266 | ar->currentline = currentline(ci); |
| 268 | break; | 267 | break; |
| 269 | } | 268 | } |
| 270 | case l_c('u'): { | 269 | case 'u': { |
| 271 | ar->nups = (ttype(f) == LUA_TFUNCTION) ? clvalue(f)->c.nupvalues : 0; | 270 | ar->nups = (ttype(f) == LUA_TFUNCTION) ? clvalue(f)->c.nupvalues : 0; |
| 272 | break; | 271 | break; |
| 273 | } | 272 | } |
| 274 | case l_c('n'): { | 273 | case 'n': { |
| 275 | ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; | 274 | ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; |
| 276 | if (ar->namewhat == NULL) | 275 | if (ar->namewhat == NULL) |
| 277 | getname(L, f, ar); | 276 | getname(L, f, ar); |
| 278 | break; | 277 | break; |
| 279 | } | 278 | } |
| 280 | case l_c('f'): { | 279 | case 'f': { |
| 281 | setobj(L->top, f); | 280 | setobj(L->top, f); |
| 282 | incr_top; /* push function */ | 281 | incr_top; /* push function */ |
| 283 | break; | 282 | break; |
| @@ -470,7 +469,7 @@ int luaG_checkcode (const Proto *pt) { | |||
| 470 | } | 469 | } |
| 471 | 470 | ||
| 472 | 471 | ||
| 473 | static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) { | 472 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { |
| 474 | CallInfo *ci = ci_stack(L, obj); | 473 | CallInfo *ci = ci_stack(L, obj); |
| 475 | if (isLmark(ci)) { /* an active Lua function? */ | 474 | if (isLmark(ci)) { /* an active Lua function? */ |
| 476 | Proto *p = ci_func(ci)->l.p; | 475 | Proto *p = ci_func(ci)->l.p; |
| @@ -479,14 +478,14 @@ static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) { | |||
| 479 | Instruction i; | 478 | Instruction i; |
| 480 | *name = luaF_getlocalname(p, stackpos+1, pc); | 479 | *name = luaF_getlocalname(p, stackpos+1, pc); |
| 481 | if (*name) /* is a local? */ | 480 | if (*name) /* is a local? */ |
| 482 | return l_s("local"); | 481 | return "local"; |
| 483 | i = luaG_symbexec(p, pc, stackpos); /* try symbolic execution */ | 482 | i = luaG_symbexec(p, pc, stackpos); /* try symbolic execution */ |
| 484 | lua_assert(pc != -1); | 483 | lua_assert(pc != -1); |
| 485 | switch (GET_OPCODE(i)) { | 484 | switch (GET_OPCODE(i)) { |
| 486 | case OP_GETGLOBAL: { | 485 | case OP_GETGLOBAL: { |
| 487 | lua_assert(ttype(&p->k[GETARG_Bc(i)]) == LUA_TSTRING); | 486 | lua_assert(ttype(&p->k[GETARG_Bc(i)]) == LUA_TSTRING); |
| 488 | *name = svalue(&p->k[GETARG_Bc(i)]); | 487 | *name = svalue(&p->k[GETARG_Bc(i)]); |
| 489 | return l_s("global"); | 488 | return "global"; |
| 490 | } | 489 | } |
| 491 | case OP_MOVE: { | 490 | case OP_MOVE: { |
| 492 | int a = GETARG_A(i); | 491 | int a = GETARG_A(i); |
| @@ -500,7 +499,7 @@ static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) { | |||
| 500 | int c = GETARG_C(i) - MAXSTACK; | 499 | int c = GETARG_C(i) - MAXSTACK; |
| 501 | if (c >= 0 && ttype(&p->k[c]) == LUA_TSTRING) { | 500 | if (c >= 0 && ttype(&p->k[c]) == LUA_TSTRING) { |
| 502 | *name = svalue(&p->k[c]); | 501 | *name = svalue(&p->k[c]); |
| 503 | return l_s("field"); | 502 | return "field"; |
| 504 | } | 503 | } |
| 505 | break; | 504 | break; |
| 506 | } | 505 | } |
| @@ -511,8 +510,8 @@ static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) { | |||
| 511 | } | 510 | } |
| 512 | 511 | ||
| 513 | 512 | ||
| 514 | static const l_char *getfuncname (lua_State *L, CallInfo *ci, | 513 | static const char *getfuncname (lua_State *L, CallInfo *ci, |
| 515 | const l_char **name) { | 514 | const char **name) { |
| 516 | ci = ci->prev; /* calling function */ | 515 | ci = ci->prev; /* calling function */ |
| 517 | if (ci == &L->basefunc || !isLmark(ci)) | 516 | if (ci == &L->basefunc || !isLmark(ci)) |
| 518 | return NULL; /* not an active Lua function */ | 517 | return NULL; /* not an active Lua function */ |
| @@ -529,22 +528,22 @@ static const l_char *getfuncname (lua_State *L, CallInfo *ci, | |||
| 529 | } | 528 | } |
| 530 | 529 | ||
| 531 | 530 | ||
| 532 | void luaG_typeerror (lua_State *L, StkId o, const l_char *op) { | 531 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { |
| 533 | const l_char *name; | 532 | const char *name; |
| 534 | const l_char *kind = getobjname(L, o, &name); | 533 | const char *kind = getobjname(L, o, &name); |
| 535 | const l_char *t = luaT_typename(G(L), o); | 534 | const char *t = luaT_typename(G(L), o); |
| 536 | if (kind) | 535 | if (kind) |
| 537 | luaO_verror(L, l_s("attempt to %.30s %.20s `%.40s' (a %.10s value)"), | 536 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", |
| 538 | op, kind, name, t); | 537 | op, kind, name, t); |
| 539 | else | 538 | else |
| 540 | luaO_verror(L, l_s("attempt to %.30s a %.10s value"), op, t); | 539 | luaO_verror(L, "attempt to %.30s a %.10s value", op, t); |
| 541 | } | 540 | } |
| 542 | 541 | ||
| 543 | 542 | ||
| 544 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { | 543 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { |
| 545 | if (ttype(p1) == LUA_TSTRING) p1 = p2; | 544 | if (ttype(p1) == LUA_TSTRING) p1 = p2; |
| 546 | lua_assert(ttype(p1) != LUA_TSTRING); | 545 | lua_assert(ttype(p1) != LUA_TSTRING); |
| 547 | luaG_typeerror(L, p1, l_s("concat")); | 546 | luaG_typeerror(L, p1, "concat"); |
| 548 | } | 547 | } |
| 549 | 548 | ||
| 550 | 549 | ||
| @@ -552,16 +551,16 @@ void luaG_aritherror (lua_State *L, StkId p1, TObject *p2) { | |||
| 552 | TObject temp; | 551 | TObject temp; |
| 553 | if (luaV_tonumber(p1, &temp) != NULL) | 552 | if (luaV_tonumber(p1, &temp) != NULL) |
| 554 | p1 = p2; /* first operand is OK; error is in the second */ | 553 | p1 = p2; /* first operand is OK; error is in the second */ |
| 555 | luaG_typeerror(L, p1, l_s("perform arithmetic on")); | 554 | luaG_typeerror(L, p1, "perform arithmetic on"); |
| 556 | } | 555 | } |
| 557 | 556 | ||
| 558 | 557 | ||
| 559 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { | 558 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { |
| 560 | const l_char *t1 = luaT_typename(G(L), p1); | 559 | const char *t1 = luaT_typename(G(L), p1); |
| 561 | const l_char *t2 = luaT_typename(G(L), p2); | 560 | const char *t2 = luaT_typename(G(L), p2); |
| 562 | if (t1[2] == t2[2]) | 561 | if (t1[2] == t2[2]) |
| 563 | luaO_verror(L, l_s("attempt to compare two %.10s values"), t1); | 562 | luaO_verror(L, "attempt to compare two %.10s values", t1); |
| 564 | else | 563 | else |
| 565 | luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2); | 564 | luaO_verror(L, "attempt to compare %.10s with %.10s", t1, t2); |
| 566 | } | 565 | } |
| 567 | 566 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.h,v 1.14 2001/06/11 14:56:42 roberto Exp roberto $ | 2 | ** $Id: ldebug.h,v 1.15 2001/06/28 19:58:57 roberto Exp $ |
| 3 | ** Auxiliary functions from Debug Interface module | 3 | ** Auxiliary functions from Debug Interface module |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "luadebug.h" | 12 | #include "luadebug.h" |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | void luaG_typeerror (lua_State *L, StkId o, const l_char *op); | 15 | void luaG_typeerror (lua_State *L, StkId o, const char *op); |
| 16 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2); | 16 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2); |
| 17 | void luaG_aritherror (lua_State *L, StkId p1, TObject *p2); | 17 | void luaG_aritherror (lua_State *L, StkId p1, TObject *p2); |
| 18 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); | 18 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.143 2001/10/17 21:12:57 roberto Exp $ | 2 | ** $Id: ldo.c,v 1.144 2001/11/27 20:56:47 roberto Exp $ |
| 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 | */ |
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| 12 | 12 | ||
| 13 | #define LUA_PRIVATE | ||
| 14 | #include "lua.h" | 13 | #include "lua.h" |
| 15 | 14 | ||
| 16 | #include "ldebug.h" | 15 | #include "ldebug.h" |
| @@ -58,7 +57,7 @@ void luaD_stackerror (lua_State *L) { | |||
| 58 | else { | 57 | else { |
| 59 | L->stack_last += EXTRA_STACK; /* to be used by error message */ | 58 | L->stack_last += EXTRA_STACK; /* to be used by error message */ |
| 60 | lua_assert(L->stack_last == L->stack+L->stacksize-1); | 59 | lua_assert(L->stack_last == L->stack+L->stacksize-1); |
| 61 | luaD_error(L, l_s("stack overflow")); | 60 | luaD_error(L, "stack overflow"); |
| 62 | } | 61 | } |
| 63 | } | 62 | } |
| 64 | 63 | ||
| @@ -99,7 +98,7 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | |||
| 99 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook) { | 98 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook) { |
| 100 | if (L->allowhooks) { | 99 | if (L->allowhooks) { |
| 101 | lua_Debug ar; | 100 | lua_Debug ar; |
| 102 | ar.event = l_s("line"); | 101 | ar.event = "line"; |
| 103 | ar._ci = L->ci; | 102 | ar._ci = L->ci; |
| 104 | ar.currentline = line; | 103 | ar.currentline = line; |
| 105 | dohook(L, &ar, linehook); | 104 | dohook(L, &ar, linehook); |
| @@ -108,7 +107,7 @@ void luaD_lineHook (lua_State *L, int line, lua_Hook linehook) { | |||
| 108 | 107 | ||
| 109 | 108 | ||
| 110 | static void luaD_callHook (lua_State *L, lua_Hook callhook, | 109 | static void luaD_callHook (lua_State *L, lua_Hook callhook, |
| 111 | const l_char *event) { | 110 | const char *event) { |
| 112 | if (L->allowhooks) { | 111 | if (L->allowhooks) { |
| 113 | lua_Debug ar; | 112 | lua_Debug ar; |
| 114 | ar.event = event; | 113 | ar.event = event; |
| @@ -146,7 +145,7 @@ void luaD_call (lua_State *L, StkId func) { | |||
| 146 | /* `func' is not a function; check the `function' tag method */ | 145 | /* `func' is not a function; check the `function' tag method */ |
| 147 | Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); | 146 | Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); |
| 148 | if (tm == NULL) | 147 | if (tm == NULL) |
| 149 | luaG_typeerror(L, func, l_s("call")); | 148 | luaG_typeerror(L, func, "call"); |
| 150 | luaD_openstack(L, func); | 149 | luaD_openstack(L, func); |
| 151 | setclvalue(func, tm); /* tag method is the new function to be called */ | 150 | setclvalue(func, tm); /* tag method is the new function to be called */ |
| 152 | } | 151 | } |
| @@ -155,12 +154,12 @@ void luaD_call (lua_State *L, StkId func) { | |||
| 155 | ci.base = func+1; | 154 | ci.base = func+1; |
| 156 | callhook = L->callhook; | 155 | callhook = L->callhook; |
| 157 | if (callhook) | 156 | if (callhook) |
| 158 | luaD_callHook(L, callhook, l_s("call")); | 157 | luaD_callHook(L, callhook, "call"); |
| 159 | firstResult = (clvalue(func)->c.isC ? | 158 | firstResult = (clvalue(func)->c.isC ? |
| 160 | callCclosure(L, &clvalue(func)->c) : | 159 | callCclosure(L, &clvalue(func)->c) : |
| 161 | luaV_execute(L, &clvalue(func)->l, func+1)); | 160 | luaV_execute(L, &clvalue(func)->l, func+1)); |
| 162 | if (callhook) /* same hook that was active at entry */ | 161 | if (callhook) /* same hook that was active at entry */ |
| 163 | luaD_callHook(L, callhook, l_s("return")); | 162 | luaD_callHook(L, callhook, "return"); |
| 164 | L->ci = ci.prev; /* unchain callinfo */ | 163 | L->ci = ci.prev; /* unchain callinfo */ |
| 165 | /* move results to `func' (to erase parameters and function) */ | 164 | /* move results to `func' (to erase parameters and function) */ |
| 166 | while (firstResult < L->top) | 165 | while (firstResult < L->top) |
| @@ -245,21 +244,21 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
| 245 | } | 244 | } |
| 246 | 245 | ||
| 247 | 246 | ||
| 248 | LUA_API int lua_loadfile (lua_State *L, const l_char *filename) { | 247 | LUA_API int lua_loadfile (lua_State *L, const char *filename) { |
| 249 | ZIO z; | 248 | ZIO z; |
| 250 | int status; | 249 | int status; |
| 251 | int bin; /* flag for file mode */ | 250 | int bin; /* flag for file mode */ |
| 252 | int nlevel; /* level on the stack of filename */ | 251 | int nlevel; /* level on the stack of filename */ |
| 253 | FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r")); | 252 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); |
| 254 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ | 253 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ |
| 255 | bin = (ungetc(getc(f), f) == LUA_SIGNATURE[0]); | 254 | bin = (ungetc(getc(f), f) == LUA_SIGNATURE[0]); |
| 256 | if (bin && f != stdin) { | 255 | if (bin && f != stdin) { |
| 257 | fclose(f); | 256 | fclose(f); |
| 258 | f = fopen(filename, l_s("rb")); /* reopen in binary mode */ | 257 | f = fopen(filename, "rb"); /* reopen in binary mode */ |
| 259 | if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ | 258 | if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ |
| 260 | } | 259 | } |
| 261 | lua_pushliteral(L, l_s("@")); | 260 | lua_pushliteral(L, "@"); |
| 262 | lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename); | 261 | lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); |
| 263 | lua_concat(L, 2); | 262 | lua_concat(L, 2); |
| 264 | nlevel = lua_gettop(L); | 263 | nlevel = lua_gettop(L); |
| 265 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ | 264 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ |
| @@ -272,11 +271,11 @@ LUA_API int lua_loadfile (lua_State *L, const l_char *filename) { | |||
| 272 | } | 271 | } |
| 273 | 272 | ||
| 274 | 273 | ||
| 275 | LUA_API int lua_loadbuffer (lua_State *L, const l_char *buff, size_t size, | 274 | LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size, |
| 276 | const l_char *name) { | 275 | const char *name) { |
| 277 | ZIO z; | 276 | ZIO z; |
| 278 | int status; | 277 | int status; |
| 279 | if (!name) name = l_s("?"); | 278 | if (!name) name = "?"; |
| 280 | luaZ_mopen(&z, buff, size, name); | 279 | luaZ_mopen(&z, buff, size, name); |
| 281 | status = protectedparser(L, &z, buff[0]==LUA_SIGNATURE[0]); | 280 | status = protectedparser(L, &z, buff[0]==LUA_SIGNATURE[0]); |
| 282 | return status; | 281 | return status; |
| @@ -301,9 +300,9 @@ struct lua_longjmp { | |||
| 301 | }; | 300 | }; |
| 302 | 301 | ||
| 303 | 302 | ||
| 304 | static void message (lua_State *L, const l_char *s) { | 303 | static void message (lua_State *L, const char *s) { |
| 305 | StkId top = L->top; | 304 | StkId top = L->top; |
| 306 | luaV_getglobal(L, luaS_newliteral(L, l_s(LUA_ERRORMESSAGE)), top); | 305 | luaV_getglobal(L, luaS_newliteral(L, LUA_ERRORMESSAGE), top); |
| 307 | if (ttype(top) == LUA_TFUNCTION) { | 306 | if (ttype(top) == LUA_TFUNCTION) { |
| 308 | incr_top; | 307 | incr_top; |
| 309 | setsvalue(top+1, luaS_new(L, s)); | 308 | setsvalue(top+1, luaS_new(L, s)); |
| @@ -317,7 +316,7 @@ static void message (lua_State *L, const l_char *s) { | |||
| 317 | /* | 316 | /* |
| 318 | ** Reports an error, and jumps up to the available recovery label | 317 | ** Reports an error, and jumps up to the available recovery label |
| 319 | */ | 318 | */ |
| 320 | void luaD_error (lua_State *L, const l_char *s) { | 319 | void luaD_error (lua_State *L, const char *s) { |
| 321 | if (s) message(L, s); | 320 | if (s) message(L, s); |
| 322 | luaD_breakrun(L, LUA_ERRRUN); | 321 | luaD_breakrun(L, LUA_ERRRUN); |
| 323 | } | 322 | } |
| @@ -330,7 +329,7 @@ void luaD_breakrun (lua_State *L, int errcode) { | |||
| 330 | } | 329 | } |
| 331 | else { | 330 | else { |
| 332 | if (errcode != LUA_ERRMEM) | 331 | if (errcode != LUA_ERRMEM) |
| 333 | message(L, l_s("unable to recover; exiting\n")); | 332 | message(L, "unable to recover; exiting\n"); |
| 334 | exit(EXIT_FAILURE); | 333 | exit(EXIT_FAILURE); |
| 335 | } | 334 | } |
| 336 | } | 335 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 1.33 2001/06/05 19:41:24 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.34 2001/06/08 19:00:57 roberto Exp $ |
| 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 | */ |
| @@ -28,7 +28,7 @@ void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); | |||
| 28 | void luaD_call (lua_State *L, StkId func); | 28 | void luaD_call (lua_State *L, StkId func); |
| 29 | void luaD_stackerror (lua_State *L); | 29 | void luaD_stackerror (lua_State *L); |
| 30 | 30 | ||
| 31 | void luaD_error (lua_State *L, const l_char *s); | 31 | void luaD_error (lua_State *L, const char *s); |
| 32 | void luaD_breakrun (lua_State *L, int errcode); | 32 | void luaD_breakrun (lua_State *L, int errcode); |
| 33 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud); | 33 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud); |
| 34 | 34 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.48 2001/10/02 16:45:03 roberto Exp $ | 2 | ** $Id: lfunc.c,v 1.49 2001/11/06 21:41:53 roberto Exp $ |
| 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 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "lfunc.h" | 12 | #include "lfunc.h" |
| @@ -157,7 +156,7 @@ void luaF_freeclosure (lua_State *L, Closure *c) { | |||
| 157 | ** Look for n-th local variable at line `line' in function `func'. | 156 | ** Look for n-th local variable at line `line' in function `func'. |
| 158 | ** Returns NULL if not found. | 157 | ** Returns NULL if not found. |
| 159 | */ | 158 | */ |
| 160 | const l_char *luaF_getlocalname (const Proto *f, int local_number, int pc) { | 159 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { |
| 161 | int i; | 160 | int i; |
| 162 | for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) { | 161 | for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) { |
| 163 | if (pc < f->locvars[i].endpc) { /* is variable active? */ | 162 | if (pc < f->locvars[i].endpc) { /* is variable active? */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.h,v 1.16 2001/09/07 17:39:10 roberto Exp $ | 2 | ** $Id: lfunc.h,v 1.17 2001/10/02 16:45:03 roberto Exp $ |
| 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 | */ |
| @@ -19,7 +19,7 @@ void luaF_close (lua_State *L, StkId level); | |||
| 19 | void luaF_freeproto (lua_State *L, Proto *f); | 19 | void luaF_freeproto (lua_State *L, Proto *f); |
| 20 | void luaF_freeclosure (lua_State *L, Closure *c); | 20 | void luaF_freeclosure (lua_State *L, Closure *c); |
| 21 | 21 | ||
| 22 | const l_char *luaF_getlocalname (const Proto *func, int local_number, int pc); | 22 | const char *luaF_getlocalname (const Proto *func, int local_number, int pc); |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | #endif | 25 | #endif |
| @@ -1,10 +1,9 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.115 2001/10/31 19:58:11 roberto Exp $ | 2 | ** $Id: lgc.c,v 1.116 2001/11/06 21:41:53 roberto Exp $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #define LUA_PRIVATE | ||
| 8 | #include "lua.h" | 7 | #include "lua.h" |
| 9 | 8 | ||
| 10 | #include "ldebug.h" | 9 | #include "ldebug.h" |
| @@ -352,7 +351,7 @@ static void collectstrings (lua_State *L, int all) { | |||
| 352 | static void checkMbuffer (lua_State *L) { | 351 | static void checkMbuffer (lua_State *L) { |
| 353 | if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ | 352 | if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ |
| 354 | size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ | 353 | size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ |
| 355 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, l_char); | 354 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, char); |
| 356 | G(L)->Mbuffsize = newsize; | 355 | G(L)->Mbuffsize = newsize; |
| 357 | } | 356 | } |
| 358 | } | 357 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.123 2001/10/02 16:41:36 roberto Exp $ | 2 | ** $Id: liolib.c,v 1.124 2001/10/26 17:33:30 roberto Exp $ |
| 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 | */ |
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | #include <time.h> | 11 | #include <time.h> |
| 12 | 12 | ||
| 13 | #define LUA_PRIVATE | ||
| 14 | #include "lua.h" | 13 | #include "lua.h" |
| 15 | 14 | ||
| 16 | #include "lauxlib.h" | 15 | #include "lauxlib.h" |
| @@ -40,12 +39,12 @@ int pclose(); */ | |||
| 40 | #define OUTFILE 1 | 39 | #define OUTFILE 1 |
| 41 | #define NOFILE 2 | 40 | #define NOFILE 2 |
| 42 | 41 | ||
| 43 | #define FILEHANDLE l_s("FileHandle") | 42 | #define FILEHANDLE "FileHandle" |
| 44 | #define CLOSEDFILEHANDLE l_s("ClosedFileHandle") | 43 | #define CLOSEDFILEHANDLE "ClosedFileHandle" |
| 45 | 44 | ||
| 46 | 45 | ||
| 47 | static const l_char *const filenames[] = {l_s("_INPUT"), l_s("_OUTPUT")}; | 46 | static const char *const filenames[] = {"_INPUT", "_OUTPUT"}; |
| 48 | static const l_char *const basicfiles[] = {l_s("_STDIN"), l_s("_STDOUT")}; | 47 | static const char *const basicfiles[] = {"_STDIN", "_STDOUT"}; |
| 49 | 48 | ||
| 50 | 49 | ||
| 51 | static int pushresult (lua_State *L, int i) { | 50 | static int pushresult (lua_State *L, int i) { |
| @@ -77,16 +76,16 @@ static FILE *getopthandle (lua_State *L, int inout) { | |||
| 77 | if (p != NULL) { /* is it a userdata ? */ | 76 | if (p != NULL) { /* is it a userdata ? */ |
| 78 | if (!checkfile(L, 1)) { /* not a valid file handle? */ | 77 | if (!checkfile(L, 1)) { /* not a valid file handle? */ |
| 79 | if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) | 78 | if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) |
| 80 | luaL_argerror(L, 1, l_s("file is closed")); | 79 | luaL_argerror(L, 1, "file is closed"); |
| 81 | else | 80 | else |
| 82 | luaL_argerror(L, 1, l_s("(invalid value)")); | 81 | luaL_argerror(L, 1, "(invalid value)"); |
| 83 | } | 82 | } |
| 84 | lua_pushvalue(L, 1); lua_remove(L, 1); /* move it to stack top */ | 83 | lua_pushvalue(L, 1); lua_remove(L, 1); /* move it to stack top */ |
| 85 | } | 84 | } |
| 86 | else { /* try global value */ | 85 | else { /* try global value */ |
| 87 | lua_getglobal(L, filenames[inout]); | 86 | lua_getglobal(L, filenames[inout]); |
| 88 | if (!checkfile(L,-1)) | 87 | if (!checkfile(L,-1)) |
| 89 | luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"), | 88 | luaL_verror(L, "global variable `%.10s' is not a valid file handle", |
| 90 | filenames[inout]); | 89 | filenames[inout]); |
| 91 | p = (FILE *)(lua_touserdata(L, -1)); | 90 | p = (FILE *)(lua_touserdata(L, -1)); |
| 92 | } | 91 | } |
| @@ -100,7 +99,7 @@ static void newfile (lua_State *L, FILE *f) { | |||
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | 101 | ||
| 103 | static void newfilewithname (lua_State *L, FILE *f, const l_char *name) { | 102 | static void newfilewithname (lua_State *L, FILE *f, const char *name) { |
| 104 | newfile(L, f); | 103 | newfile(L, f); |
| 105 | lua_setglobal(L, name); | 104 | lua_setglobal(L, name); |
| 106 | } | 105 | } |
| @@ -158,7 +157,7 @@ static int io_tmpfile (lua_State *L) { | |||
| 158 | 157 | ||
| 159 | 158 | ||
| 160 | 159 | ||
| 161 | static int io_fromto (lua_State *L, int inout, const l_char *mode) { | 160 | static int io_fromto (lua_State *L, int inout, const char *mode) { |
| 162 | FILE *current; | 161 | FILE *current; |
| 163 | if (lua_isnull(L, 1)) { | 162 | if (lua_isnull(L, 1)) { |
| 164 | getopthandle(L, inout); | 163 | getopthandle(L, inout); |
| @@ -166,25 +165,25 @@ static int io_fromto (lua_State *L, int inout, const l_char *mode) { | |||
| 166 | return io_close(L); | 165 | return io_close(L); |
| 167 | } | 166 | } |
| 168 | else { | 167 | else { |
| 169 | const l_char *s = luaL_check_string(L, 1); | 168 | const char *s = luaL_check_string(L, 1); |
| 170 | current = (*s == l_c('|')) ? popen(s+1, mode) : fopen(s, mode); | 169 | current = (*s == '|') ? popen(s+1, mode) : fopen(s, mode); |
| 171 | return setnewfile(L, current, inout); | 170 | return setnewfile(L, current, inout); |
| 172 | } | 171 | } |
| 173 | } | 172 | } |
| 174 | 173 | ||
| 175 | 174 | ||
| 176 | static int io_readfrom (lua_State *L) { | 175 | static int io_readfrom (lua_State *L) { |
| 177 | return io_fromto(L, INFILE, l_s("r")); | 176 | return io_fromto(L, INFILE, "r"); |
| 178 | } | 177 | } |
| 179 | 178 | ||
| 180 | 179 | ||
| 181 | static int io_writeto (lua_State *L) { | 180 | static int io_writeto (lua_State *L) { |
| 182 | return io_fromto(L, OUTFILE, l_s("w")); | 181 | return io_fromto(L, OUTFILE, "w"); |
| 183 | } | 182 | } |
| 184 | 183 | ||
| 185 | 184 | ||
| 186 | static int io_appendto (lua_State *L) { | 185 | static int io_appendto (lua_State *L) { |
| 187 | FILE *current = fopen(luaL_check_string(L, 1), l_s("a")); | 186 | FILE *current = fopen(luaL_check_string(L, 1), "a"); |
| 188 | return setnewfile(L, current, OUTFILE); | 187 | return setnewfile(L, current, OUTFILE); |
| 189 | } | 188 | } |
| 190 | 189 | ||
| @@ -208,7 +207,7 @@ static int io_appendto (lua_State *L) { | |||
| 208 | ** Addison-Wesley, 1993.) | 207 | ** Addison-Wesley, 1993.) |
| 209 | */ | 208 | */ |
| 210 | 209 | ||
| 211 | static void prep_read_until (int next[], const l_char *p, int pl) { | 210 | static void prep_read_until (int next[], const char *p, int pl) { |
| 212 | int i = 0; | 211 | int i = 0; |
| 213 | int j = -1; | 212 | int j = -1; |
| 214 | next[0] = -1; | 213 | next[0] = -1; |
| @@ -221,8 +220,8 @@ static void prep_read_until (int next[], const l_char *p, int pl) { | |||
| 221 | } | 220 | } |
| 222 | 221 | ||
| 223 | 222 | ||
| 224 | static int read_until (lua_State *L, FILE *f, const l_char *p, int pl) { | 223 | static int read_until (lua_State *L, FILE *f, const char *p, int pl) { |
| 225 | l_charint c; | 224 | int c; |
| 226 | int j; | 225 | int j; |
| 227 | int next[LUA_MAXUNTIL+1]; | 226 | int next[LUA_MAXUNTIL+1]; |
| 228 | luaL_Buffer b; | 227 | luaL_Buffer b; |
| @@ -255,7 +254,7 @@ static int read_until (lua_State *L, FILE *f, const l_char *p, int pl) { | |||
| 255 | 254 | ||
| 256 | static int read_number (lua_State *L, FILE *f) { | 255 | static int read_number (lua_State *L, FILE *f) { |
| 257 | lua_Number d; | 256 | lua_Number d; |
| 258 | if (fscanf(f, l_s(LUA_NUMBER_SCAN), &d) == 1) { | 257 | if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { |
| 259 | lua_pushnumber(L, d); | 258 | lua_pushnumber(L, d); |
| 260 | return 1; | 259 | return 1; |
| 261 | } | 260 | } |
| @@ -264,7 +263,7 @@ static int read_number (lua_State *L, FILE *f) { | |||
| 264 | 263 | ||
| 265 | 264 | ||
| 266 | static int test_eof (lua_State *L, FILE *f) { | 265 | static int test_eof (lua_State *L, FILE *f) { |
| 267 | l_charint c = getc(f); | 266 | int c = getc(f); |
| 268 | ungetc(c, f); | 267 | ungetc(c, f); |
| 269 | lua_pushlstring(L, NULL, 0); | 268 | lua_pushlstring(L, NULL, 0); |
| 270 | return (c != EOF); | 269 | return (c != EOF); |
| @@ -278,9 +277,9 @@ static int read_chars (lua_State *L, FILE *f, size_t n) { | |||
| 278 | luaL_buffinit(L, &b); | 277 | luaL_buffinit(L, &b); |
| 279 | rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ | 278 | rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ |
| 280 | do { | 279 | do { |
| 281 | l_char *p = luaL_prepbuffer(&b); | 280 | char *p = luaL_prepbuffer(&b); |
| 282 | if (rlen > n) rlen = n; /* cannot read more than asked */ | 281 | if (rlen > n) rlen = n; /* cannot read more than asked */ |
| 283 | nr = fread(p, sizeof(l_char), rlen, f); | 282 | nr = fread(p, sizeof(char), rlen, f); |
| 284 | luaL_addsize(&b, nr); | 283 | luaL_addsize(&b, nr); |
| 285 | n -= nr; /* still have to read `n' chars */ | 284 | n -= nr; /* still have to read `n' chars */ |
| 286 | } while (n > 0 && nr == rlen); /* until end of count or eof */ | 285 | } while (n > 0 && nr == rlen); /* until end of count or eof */ |
| @@ -295,11 +294,11 @@ static int io_read (lua_State *L) { | |||
| 295 | int success; | 294 | int success; |
| 296 | int n; | 295 | int n; |
| 297 | if (nargs == 0) { /* no arguments? */ | 296 | if (nargs == 0) { /* no arguments? */ |
| 298 | success = read_until(L, f, l_s("\n"), 1); /* read until \n (a line) */ | 297 | success = read_until(L, f, "\n", 1); /* read until \n (a line) */ |
| 299 | n = 2; /* will return n-1 results */ | 298 | n = 2; /* will return n-1 results */ |
| 300 | } | 299 | } |
| 301 | else { /* ensure stack space for all results and for auxlib's buffer */ | 300 | else { /* ensure stack space for all results and for auxlib's buffer */ |
| 302 | luaL_check_stack(L, nargs+LUA_MINSTACK, l_s("too many arguments")); | 301 | luaL_check_stack(L, nargs+LUA_MINSTACK, "too many arguments"); |
| 303 | success = 1; | 302 | success = 1; |
| 304 | for (n = 1; n<=nargs && success; n++) { | 303 | for (n = 1; n<=nargs && success; n++) { |
| 305 | if (lua_rawtag(L, n) == LUA_TNUMBER) { | 304 | if (lua_rawtag(L, n) == LUA_TNUMBER) { |
| @@ -307,32 +306,32 @@ static int io_read (lua_State *L) { | |||
| 307 | success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); | 306 | success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); |
| 308 | } | 307 | } |
| 309 | else { | 308 | else { |
| 310 | const l_char *p = lua_tostring(L, n); | 309 | const char *p = lua_tostring(L, n); |
| 311 | if (!p || p[0] != l_c('*')) | 310 | if (!p || p[0] != '*') |
| 312 | lua_error(L, l_s("invalid `read' option")); | 311 | lua_error(L, "invalid `read' option"); |
| 313 | switch (p[1]) { | 312 | switch (p[1]) { |
| 314 | case l_c('n'): /* number */ | 313 | case 'n': /* number */ |
| 315 | success = read_number(L, f); | 314 | success = read_number(L, f); |
| 316 | break; | 315 | break; |
| 317 | case l_c('l'): /* line */ | 316 | case 'l': /* line */ |
| 318 | success = read_until(L, f, l_s("\n"), 1); /* read until \n */ | 317 | success = read_until(L, f, "\n", 1); /* read until \n */ |
| 319 | break; | 318 | break; |
| 320 | case l_c('a'): /* file */ | 319 | case 'a': /* file */ |
| 321 | read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ | 320 | read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ |
| 322 | success = 1; /* always success */ | 321 | success = 1; /* always success */ |
| 323 | break; | 322 | break; |
| 324 | case l_c('w'): /* word */ | 323 | case 'w': /* word */ |
| 325 | lua_error(L, l_s("obsolete option `*w'")); | 324 | lua_error(L, "obsolete option `*w'"); |
| 326 | break; | 325 | break; |
| 327 | case l_c('u'): { /* read until */ | 326 | case 'u': { /* read until */ |
| 328 | size_t pl = lua_strlen(L, n) - 2; | 327 | size_t pl = lua_strlen(L, n) - 2; |
| 329 | luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n, | 328 | luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n, |
| 330 | l_s("invalid read-until length")); | 329 | "invalid read-until length"); |
| 331 | success = read_until(L, f, p+2, (int)(pl)); | 330 | success = read_until(L, f, p+2, (int)(pl)); |
| 332 | break; | 331 | break; |
| 333 | } | 332 | } |
| 334 | default: | 333 | default: |
| 335 | luaL_argerror(L, n, l_s("invalid format")); | 334 | luaL_argerror(L, n, "invalid format"); |
| 336 | success = 0; /* to avoid warnings */ | 335 | success = 0; /* to avoid warnings */ |
| 337 | } | 336 | } |
| 338 | } | 337 | } |
| @@ -357,12 +356,12 @@ static int io_write (lua_State *L) { | |||
| 357 | if (lua_rawtag(L, arg) == LUA_TNUMBER) { | 356 | if (lua_rawtag(L, arg) == LUA_TNUMBER) { |
| 358 | /* optimization: could be done exactly as for strings */ | 357 | /* optimization: could be done exactly as for strings */ |
| 359 | status = status && | 358 | status = status && |
| 360 | fprintf(f, l_s(LUA_NUMBER_FMT), lua_tonumber(L, arg)) > 0; | 359 | fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; |
| 361 | } | 360 | } |
| 362 | else { | 361 | else { |
| 363 | size_t l; | 362 | size_t l; |
| 364 | const l_char *s = luaL_check_lstr(L, arg, &l); | 363 | const char *s = luaL_check_lstr(L, arg, &l); |
| 365 | status = status && (fwrite(s, sizeof(l_char), l, f) == l); | 364 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 366 | } | 365 | } |
| 367 | } | 366 | } |
| 368 | pushresult(L, status); | 367 | pushresult(L, status); |
| @@ -372,11 +371,11 @@ static int io_write (lua_State *L) { | |||
| 372 | 371 | ||
| 373 | static int io_seek (lua_State *L) { | 372 | static int io_seek (lua_State *L) { |
| 374 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | 373 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; |
| 375 | static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL}; | 374 | static const char *const modenames[] = {"set", "cur", "end", NULL}; |
| 376 | FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); | 375 | FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); |
| 377 | int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames); | 376 | int op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames); |
| 378 | long offset = luaL_opt_long(L, 3, 0); | 377 | long offset = luaL_opt_long(L, 3, 0); |
| 379 | luaL_arg_check(L, op != -1, 2, l_s("invalid mode")); | 378 | luaL_arg_check(L, op != -1, 2, "invalid mode"); |
| 380 | op = fseek(f, offset, mode[op]); | 379 | op = fseek(f, offset, mode[op]); |
| 381 | if (op) | 380 | if (op) |
| 382 | return pushresult(L, 0); /* error */ | 381 | return pushresult(L, 0); /* error */ |
| @@ -420,9 +419,9 @@ static int io_rename (lua_State *L) { | |||
| 420 | 419 | ||
| 421 | 420 | ||
| 422 | static int io_tmpname (lua_State *L) { | 421 | static int io_tmpname (lua_State *L) { |
| 423 | l_char buff[L_tmpnam]; | 422 | char buff[L_tmpnam]; |
| 424 | if (tmpnam(buff) != buff) | 423 | if (tmpnam(buff) != buff) |
| 425 | lua_error(L, l_s("unable to generate a unique filename")); | 424 | lua_error(L, "unable to generate a unique filename"); |
| 426 | lua_pushstring(L, buff); | 425 | lua_pushstring(L, buff); |
| 427 | return 1; | 426 | return 1; |
| 428 | } | 427 | } |
| @@ -449,14 +448,14 @@ static int io_clock (lua_State *L) { | |||
| 449 | ** ======================================================= | 448 | ** ======================================================= |
| 450 | */ | 449 | */ |
| 451 | 450 | ||
| 452 | static void setfield (lua_State *L, const l_char *key, int value) { | 451 | static void setfield (lua_State *L, const char *key, int value) { |
| 453 | lua_pushstring(L, key); | 452 | lua_pushstring(L, key); |
| 454 | lua_pushnumber(L, value); | 453 | lua_pushnumber(L, value); |
| 455 | lua_rawset(L, -3); | 454 | lua_rawset(L, -3); |
| 456 | } | 455 | } |
| 457 | 456 | ||
| 458 | 457 | ||
| 459 | static int getfield (lua_State *L, const l_char *key, int d) { | 458 | static int getfield (lua_State *L, const char *key, int d) { |
| 460 | int res; | 459 | int res; |
| 461 | lua_pushstring(L, key); | 460 | lua_pushstring(L, key); |
| 462 | lua_rawget(L, -2); | 461 | lua_rawget(L, -2); |
| @@ -464,7 +463,7 @@ static int getfield (lua_State *L, const l_char *key, int d) { | |||
| 464 | res = (int)(lua_tonumber(L, -1)); | 463 | res = (int)(lua_tonumber(L, -1)); |
| 465 | else { | 464 | else { |
| 466 | if (d == -2) | 465 | if (d == -2) |
| 467 | luaL_verror(L, l_s("field `%.20s' missing in date table"), key); | 466 | luaL_verror(L, "field `%.20s' missing in date table", key); |
| 468 | res = d; | 467 | res = d; |
| 469 | } | 468 | } |
| 470 | lua_pop(L, 1); | 469 | lua_pop(L, 1); |
| @@ -473,12 +472,12 @@ static int getfield (lua_State *L, const l_char *key, int d) { | |||
| 473 | 472 | ||
| 474 | 473 | ||
| 475 | static int io_date (lua_State *L) { | 474 | static int io_date (lua_State *L) { |
| 476 | const l_char *s = luaL_opt_string(L, 1, l_s("%c")); | 475 | const char *s = luaL_opt_string(L, 1, "%c"); |
| 477 | time_t t = (time_t)(luaL_opt_number(L, 2, -1)); | 476 | time_t t = (time_t)(luaL_opt_number(L, 2, -1)); |
| 478 | struct tm *stm; | 477 | struct tm *stm; |
| 479 | if (t == (time_t)(-1)) /* no time given? */ | 478 | if (t == (time_t)(-1)) /* no time given? */ |
| 480 | t = time(NULL); /* use current time */ | 479 | t = time(NULL); /* use current time */ |
| 481 | if (*s == l_c('!')) { /* UTC? */ | 480 | if (*s == '!') { /* UTC? */ |
| 482 | stm = gmtime(&t); | 481 | stm = gmtime(&t); |
| 483 | s++; /* skip `!' */ | 482 | s++; /* skip `!' */ |
| 484 | } | 483 | } |
| @@ -486,24 +485,24 @@ static int io_date (lua_State *L) { | |||
| 486 | stm = localtime(&t); | 485 | stm = localtime(&t); |
| 487 | if (stm == NULL) /* invalid date? */ | 486 | if (stm == NULL) /* invalid date? */ |
| 488 | lua_pushnil(L); | 487 | lua_pushnil(L); |
| 489 | else if (strcmp(s, l_s("*t")) == 0) { | 488 | else if (strcmp(s, "*t") == 0) { |
| 490 | lua_newtable(L); | 489 | lua_newtable(L); |
| 491 | setfield(L, l_s("sec"), stm->tm_sec); | 490 | setfield(L, "sec", stm->tm_sec); |
| 492 | setfield(L, l_s("min"), stm->tm_min); | 491 | setfield(L, "min", stm->tm_min); |
| 493 | setfield(L, l_s("hour"), stm->tm_hour); | 492 | setfield(L, "hour", stm->tm_hour); |
| 494 | setfield(L, l_s("day"), stm->tm_mday); | 493 | setfield(L, "day", stm->tm_mday); |
| 495 | setfield(L, l_s("month"), stm->tm_mon+1); | 494 | setfield(L, "month", stm->tm_mon+1); |
| 496 | setfield(L, l_s("year"), stm->tm_year+1900); | 495 | setfield(L, "year", stm->tm_year+1900); |
| 497 | setfield(L, l_s("wday"), stm->tm_wday+1); | 496 | setfield(L, "wday", stm->tm_wday+1); |
| 498 | setfield(L, l_s("yday"), stm->tm_yday+1); | 497 | setfield(L, "yday", stm->tm_yday+1); |
| 499 | setfield(L, l_s("isdst"), stm->tm_isdst); | 498 | setfield(L, "isdst", stm->tm_isdst); |
| 500 | } | 499 | } |
| 501 | else { | 500 | else { |
| 502 | l_char b[256]; | 501 | char b[256]; |
| 503 | if (strftime(b, sizeof(b), s, stm)) | 502 | if (strftime(b, sizeof(b), s, stm)) |
| 504 | lua_pushstring(L, b); | 503 | lua_pushstring(L, b); |
| 505 | else | 504 | else |
| 506 | lua_error(L, l_s("invalid `date' format")); | 505 | lua_error(L, "invalid `date' format"); |
| 507 | } | 506 | } |
| 508 | return 1; | 507 | return 1; |
| 509 | } | 508 | } |
| @@ -517,13 +516,13 @@ static int io_time (lua_State *L) { | |||
| 517 | struct tm ts; | 516 | struct tm ts; |
| 518 | luaL_check_rawtype(L, 1, LUA_TTABLE); | 517 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
| 519 | lua_settop(L, 1); /* make sure table is at the top */ | 518 | lua_settop(L, 1); /* make sure table is at the top */ |
| 520 | ts.tm_sec = getfield(L, l_s("sec"), 0); | 519 | ts.tm_sec = getfield(L, "sec", 0); |
| 521 | ts.tm_min = getfield(L, l_s("min"), 0); | 520 | ts.tm_min = getfield(L, "min", 0); |
| 522 | ts.tm_hour = getfield(L, l_s("hour"), 12); | 521 | ts.tm_hour = getfield(L, "hour", 12); |
| 523 | ts.tm_mday = getfield(L, l_s("day"), -2); | 522 | ts.tm_mday = getfield(L, "day", -2); |
| 524 | ts.tm_mon = getfield(L, l_s("month"), -2)-1; | 523 | ts.tm_mon = getfield(L, "month", -2)-1; |
| 525 | ts.tm_year = getfield(L, l_s("year"), -2)-1900; | 524 | ts.tm_year = getfield(L, "year", -2)-1900; |
| 526 | ts.tm_isdst = getfield(L, l_s("isdst"), -1); | 525 | ts.tm_isdst = getfield(L, "isdst", -1); |
| 527 | t = mktime(&ts); | 526 | t = mktime(&ts); |
| 528 | if (t == (time_t)(-1)) | 527 | if (t == (time_t)(-1)) |
| 529 | lua_pushnil(L); | 528 | lua_pushnil(L); |
| @@ -546,10 +545,10 @@ static int io_difftime (lua_State *L) { | |||
| 546 | static int io_setloc (lua_State *L) { | 545 | static int io_setloc (lua_State *L) { |
| 547 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, | 546 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, |
| 548 | LC_NUMERIC, LC_TIME}; | 547 | LC_NUMERIC, LC_TIME}; |
| 549 | static const l_char *const catnames[] = {l_s("all"), l_s("collate"), l_s("ctype"), l_s("monetary"), | 548 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
| 550 | l_s("numeric"), l_s("time"), NULL}; | 549 | "numeric", "time", NULL}; |
| 551 | int op = luaL_findstring(luaL_opt_string(L, 2, l_s("all")), catnames); | 550 | int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames); |
| 552 | luaL_arg_check(L, op != -1, 2, l_s("invalid option")); | 551 | luaL_arg_check(L, op != -1, 2, "invalid option"); |
| 553 | lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1))); | 552 | lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1))); |
| 554 | return 1; | 553 | return 1; |
| 555 | } | 554 | } |
| @@ -566,10 +565,10 @@ static int io_exit (lua_State *L) { | |||
| 566 | 565 | ||
| 567 | static int io_debug (lua_State *L) { | 566 | static int io_debug (lua_State *L) { |
| 568 | for (;;) { | 567 | for (;;) { |
| 569 | l_char buffer[250]; | 568 | char buffer[250]; |
| 570 | fprintf(stderr, l_s("lua_debug> ")); | 569 | fprintf(stderr, "lua_debug> "); |
| 571 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || | 570 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || |
| 572 | strcmp(buffer, l_s("cont\n")) == 0) | 571 | strcmp(buffer, "cont\n") == 0) |
| 573 | return 0; | 572 | return 0; |
| 574 | lua_dostring(L, buffer); | 573 | lua_dostring(L, buffer); |
| 575 | lua_settop(L, 0); /* remove eventual returns */ | 574 | lua_settop(L, 0); /* remove eventual returns */ |
| @@ -586,61 +585,61 @@ static int errorfb (lua_State *L) { | |||
| 586 | lua_Debug ar; | 585 | lua_Debug ar; |
| 587 | luaL_Buffer b; | 586 | luaL_Buffer b; |
| 588 | luaL_buffinit(L, &b); | 587 | luaL_buffinit(L, &b); |
| 589 | luaL_addstring(&b, l_s("error: ")); | 588 | luaL_addstring(&b, "error: "); |
| 590 | luaL_addstring(&b, luaL_check_string(L, 1)); | 589 | luaL_addstring(&b, luaL_check_string(L, 1)); |
| 591 | luaL_addstring(&b, l_s("\n")); | 590 | luaL_addstring(&b, "\n"); |
| 592 | while (lua_getstack(L, level++, &ar)) { | 591 | while (lua_getstack(L, level++, &ar)) { |
| 593 | l_char buff[120]; /* enough to fit following `sprintf's */ | 592 | char buff[120]; /* enough to fit following `sprintf's */ |
| 594 | if (level == 2) | 593 | if (level == 2) |
| 595 | luaL_addstring(&b, l_s("stack traceback:\n")); | 594 | luaL_addstring(&b, "stack traceback:\n"); |
| 596 | else if (level > LEVELS1 && firstpart) { | 595 | else if (level > LEVELS1 && firstpart) { |
| 597 | /* no more than `LEVELS2' more levels? */ | 596 | /* no more than `LEVELS2' more levels? */ |
| 598 | if (!lua_getstack(L, level+LEVELS2, &ar)) | 597 | if (!lua_getstack(L, level+LEVELS2, &ar)) |
| 599 | level--; /* keep going */ | 598 | level--; /* keep going */ |
| 600 | else { | 599 | else { |
| 601 | luaL_addstring(&b, l_s(" ...\n")); /* too many levels */ | 600 | luaL_addstring(&b, " ...\n"); /* too many levels */ |
| 602 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ | 601 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ |
| 603 | level++; | 602 | level++; |
| 604 | } | 603 | } |
| 605 | firstpart = 0; | 604 | firstpart = 0; |
| 606 | continue; | 605 | continue; |
| 607 | } | 606 | } |
| 608 | sprintf(buff, l_s("%4d: "), level-1); | 607 | sprintf(buff, "%4d: ", level-1); |
| 609 | luaL_addstring(&b, buff); | 608 | luaL_addstring(&b, buff); |
| 610 | lua_getinfo(L, l_s("Snl"), &ar); | 609 | lua_getinfo(L, "Snl", &ar); |
| 611 | switch (*ar.namewhat) { | 610 | switch (*ar.namewhat) { |
| 612 | case l_c('g'): case l_c('l'): /* global, local */ | 611 | case 'g': case 'l': /* global, local */ |
| 613 | sprintf(buff, l_s("function `%.50s'"), ar.name); | 612 | sprintf(buff, "function `%.50s'", ar.name); |
| 614 | break; | 613 | break; |
| 615 | case l_c('f'): /* field */ | 614 | case 'f': /* field */ |
| 616 | sprintf(buff, l_s("method `%.50s'"), ar.name); | 615 | sprintf(buff, "method `%.50s'", ar.name); |
| 617 | break; | 616 | break; |
| 618 | case l_c('t'): /* tag method */ | 617 | case 't': /* tag method */ |
| 619 | sprintf(buff, l_s("`%.50s' tag method"), ar.name); | 618 | sprintf(buff, "`%.50s' tag method", ar.name); |
| 620 | break; | 619 | break; |
| 621 | default: { | 620 | default: { |
| 622 | if (*ar.what == l_c('m')) /* main? */ | 621 | if (*ar.what == 'm') /* main? */ |
| 623 | sprintf(buff, l_s("main of %.70s"), ar.short_src); | 622 | sprintf(buff, "main of %.70s", ar.short_src); |
| 624 | else if (*ar.what == l_c('C')) /* C function? */ | 623 | else if (*ar.what == 'C') /* C function? */ |
| 625 | sprintf(buff, l_s("%.70s"), ar.short_src); | 624 | sprintf(buff, "%.70s", ar.short_src); |
| 626 | else | 625 | else |
| 627 | sprintf(buff, l_s("function <%d:%.70s>"), ar.linedefined, ar.short_src); | 626 | sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src); |
| 628 | ar.source = NULL; /* do not print source again */ | 627 | ar.source = NULL; /* do not print source again */ |
| 629 | } | 628 | } |
| 630 | } | 629 | } |
| 631 | luaL_addstring(&b, buff); | 630 | luaL_addstring(&b, buff); |
| 632 | if (ar.currentline > 0) { | 631 | if (ar.currentline > 0) { |
| 633 | sprintf(buff, l_s(" at line %d"), ar.currentline); | 632 | sprintf(buff, " at line %d", ar.currentline); |
| 634 | luaL_addstring(&b, buff); | 633 | luaL_addstring(&b, buff); |
| 635 | } | 634 | } |
| 636 | if (ar.source) { | 635 | if (ar.source) { |
| 637 | sprintf(buff, l_s(" [%.70s]"), ar.short_src); | 636 | sprintf(buff, " [%.70s]", ar.short_src); |
| 638 | luaL_addstring(&b, buff); | 637 | luaL_addstring(&b, buff); |
| 639 | } | 638 | } |
| 640 | luaL_addstring(&b, l_s("\n")); | 639 | luaL_addstring(&b, "\n"); |
| 641 | } | 640 | } |
| 642 | luaL_pushresult(&b); | 641 | luaL_pushresult(&b); |
| 643 | lua_getglobal(L, l_s(LUA_ALERT)); | 642 | lua_getglobal(L, LUA_ALERT); |
| 644 | if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ | 643 | if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ |
| 645 | lua_pushvalue(L, -2); /* error message */ | 644 | lua_pushvalue(L, -2); /* error message */ |
| 646 | lua_rawcall(L, 1, 0); | 645 | lua_rawcall(L, 1, 0); |
| @@ -651,29 +650,29 @@ static int errorfb (lua_State *L) { | |||
| 651 | 650 | ||
| 652 | 651 | ||
| 653 | static const luaL_reg iolib[] = { | 652 | static const luaL_reg iolib[] = { |
| 654 | {l_s("appendto"), io_appendto}, | 653 | {"appendto", io_appendto}, |
| 655 | {l_s("clock"), io_clock}, | 654 | {"clock", io_clock}, |
| 656 | {l_s("closefile"), io_close}, | 655 | {"closefile", io_close}, |
| 657 | {l_s("date"), io_date}, | 656 | {"date", io_date}, |
| 658 | {l_s("debug"), io_debug}, | 657 | {"debug", io_debug}, |
| 659 | {l_s("difftime"), io_difftime}, | 658 | {"difftime", io_difftime}, |
| 660 | {l_s("execute"), io_execute}, | 659 | {"execute", io_execute}, |
| 661 | {l_s("exit"), io_exit}, | 660 | {"exit", io_exit}, |
| 662 | {l_s("flush"), io_flush}, | 661 | {"flush", io_flush}, |
| 663 | {l_s("getenv"), io_getenv}, | 662 | {"getenv", io_getenv}, |
| 664 | {l_s("openfile"), io_open}, | 663 | {"openfile", io_open}, |
| 665 | {l_s("read"), io_read}, | 664 | {"read", io_read}, |
| 666 | {l_s("readfrom"), io_readfrom}, | 665 | {"readfrom", io_readfrom}, |
| 667 | {l_s("remove"), io_remove}, | 666 | {"remove", io_remove}, |
| 668 | {l_s("rename"), io_rename}, | 667 | {"rename", io_rename}, |
| 669 | {l_s("seek"), io_seek}, | 668 | {"seek", io_seek}, |
| 670 | {l_s("setlocale"), io_setloc}, | 669 | {"setlocale", io_setloc}, |
| 671 | {l_s("time"), io_time}, | 670 | {"time", io_time}, |
| 672 | {l_s("tmpfile"), io_tmpfile}, | 671 | {"tmpfile", io_tmpfile}, |
| 673 | {l_s("tmpname"), io_tmpname}, | 672 | {"tmpname", io_tmpname}, |
| 674 | {l_s("write"), io_write}, | 673 | {"write", io_write}, |
| 675 | {l_s("writeto"), io_writeto}, | 674 | {"writeto", io_writeto}, |
| 676 | {l_s(LUA_ERRORMESSAGE), errorfb} | 675 | {LUA_ERRORMESSAGE, errorfb} |
| 677 | }; | 676 | }; |
| 678 | 677 | ||
| 679 | 678 | ||
| @@ -684,12 +683,12 @@ LUALIB_API int lua_iolibopen (lua_State *L) { | |||
| 684 | /* predefined file handles */ | 683 | /* predefined file handles */ |
| 685 | newfilewithname(L, stdin, basicfiles[INFILE]); | 684 | newfilewithname(L, stdin, basicfiles[INFILE]); |
| 686 | newfilewithname(L, stdout, basicfiles[OUTFILE]); | 685 | newfilewithname(L, stdout, basicfiles[OUTFILE]); |
| 687 | newfilewithname(L, stderr, l_s("_STDERR")); | 686 | newfilewithname(L, stderr, "_STDERR"); |
| 688 | resetfile(L, INFILE); | 687 | resetfile(L, INFILE); |
| 689 | resetfile(L, OUTFILE); | 688 | resetfile(L, OUTFILE); |
| 690 | /* close files when collected */ | 689 | /* close files when collected */ |
| 691 | lua_pushcfunction(L, file_collect); | 690 | lua_pushcfunction(L, file_collect); |
| 692 | lua_settagmethod(L, iotag, l_s("gc")); | 691 | lua_settagmethod(L, iotag, "gc"); |
| 693 | return 0; | 692 | return 0; |
| 694 | } | 693 | } |
| 695 | 694 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.91 2001/08/31 19:46:07 roberto Exp $ | 2 | ** $Id: llex.c,v 1.92 2001/11/16 16:29:10 roberto Exp $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -9,7 +9,6 @@ | |||
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | 11 | ||
| 12 | #define LUA_PRIVATE | ||
| 13 | #include "lua.h" | 12 | #include "lua.h" |
| 14 | 13 | ||
| 15 | #include "llex.h" | 14 | #include "llex.h" |
| @@ -26,13 +25,13 @@ | |||
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | /* ORDER RESERVED */ | 27 | /* ORDER RESERVED */ |
| 29 | static const l_char *const token2string [] = { | 28 | static const char *const token2string [] = { |
| 30 | l_s("and"), l_s("break"), l_s("do"), l_s("else"), l_s("elseif"), | 29 | "and", "break", "do", "else", "elseif", |
| 31 | l_s("end"), l_s("for"), l_s("function"), l_s("global"), l_s("if"), | 30 | "end", "for", "function", "global", "if", |
| 32 | l_s("in"), l_s("local"), l_s("nil"), l_s("not"), l_s("or"), l_s("repeat"), | 31 | "in", "local", "nil", "not", "or", "repeat", |
| 33 | l_s("return"), l_s("then"), l_s("until"), l_s("while"), l_s(""), | 32 | "return", "then", "until", "while", "", |
| 34 | l_s(".."), l_s("..."), l_s("=="), l_s(">="), l_s("<="), l_s("~="), | 33 | "..", "...", "==", ">=", "<=", "~=", |
| 35 | l_s(""), l_s(""), l_s("<eof>") | 34 | "", "", "<eof>" |
| 36 | }; | 35 | }; |
| 37 | 36 | ||
| 38 | 37 | ||
| @@ -49,62 +48,62 @@ void luaX_init (lua_State *L) { | |||
| 49 | #define MAXSRC 80 | 48 | #define MAXSRC 80 |
| 50 | 49 | ||
| 51 | 50 | ||
| 52 | void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg) { | 51 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { |
| 53 | if (val > limit) { | 52 | if (val > limit) { |
| 54 | l_char buff[90]; | 53 | char buff[90]; |
| 55 | sprintf(buff, l_s("too many %.40s (limit=%d)"), msg, limit); | 54 | sprintf(buff, "too many %.40s (limit=%d)", msg, limit); |
| 56 | luaX_error(ls, buff, ls->t.token); | 55 | luaX_error(ls, buff, ls->t.token); |
| 57 | } | 56 | } |
| 58 | } | 57 | } |
| 59 | 58 | ||
| 60 | 59 | ||
| 61 | static void luaX_syntaxerror (LexState *ls, const l_char *s, | 60 | static void luaX_syntaxerror (LexState *ls, const char *s, |
| 62 | const l_char *token) { | 61 | const char *token) { |
| 63 | l_char buff[MAXSRC]; | 62 | char buff[MAXSRC]; |
| 64 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); | 63 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); |
| 65 | luaO_verror(ls->L, | 64 | luaO_verror(ls->L, |
| 66 | l_s("%.99s;\n last token read: `%.30s' at line %d in %.80s"), | 65 | "%.99s;\n last token read: `%.30s' at line %d in %.80s", |
| 67 | s, token, ls->linenumber, buff); | 66 | s, token, ls->linenumber, buff); |
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | 69 | ||
| 71 | void luaX_token2str (int token, l_char *s) { | 70 | void luaX_token2str (int token, char *s) { |
| 72 | if (token < FIRST_RESERVED) { | 71 | if (token < FIRST_RESERVED) { |
| 73 | lua_assert(token == (l_char)token); | 72 | lua_assert(token == (char)token); |
| 74 | s[0] = (l_char)token; | 73 | s[0] = (char)token; |
| 75 | s[1] = l_c('\0'); | 74 | s[1] = '\0'; |
| 76 | } | 75 | } |
| 77 | else | 76 | else |
| 78 | strcpy(s, token2string[token-FIRST_RESERVED]); | 77 | strcpy(s, token2string[token-FIRST_RESERVED]); |
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | 80 | ||
| 82 | static l_char *token2str_all (LexState *ls, int token, l_char *s) { | 81 | static char *token2str_all (LexState *ls, int token, char *s) { |
| 83 | luaX_token2str(token, s); | 82 | luaX_token2str(token, s); |
| 84 | if (s[0] == l_c('\0')) | 83 | if (s[0] == '\0') |
| 85 | return cast(l_char *, G(ls->L)->Mbuffer); | 84 | return cast(char *, G(ls->L)->Mbuffer); |
| 86 | else | 85 | else |
| 87 | return s; | 86 | return s; |
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | 89 | ||
| 91 | void luaX_error (LexState *ls, const l_char *s, int token) { | 90 | void luaX_error (LexState *ls, const char *s, int token) { |
| 92 | l_char buff[TOKEN_LEN]; | 91 | char buff[TOKEN_LEN]; |
| 93 | luaX_syntaxerror(ls, s, token2str_all(ls, token, buff)); | 92 | luaX_syntaxerror(ls, s, token2str_all(ls, token, buff)); |
| 94 | } | 93 | } |
| 95 | 94 | ||
| 96 | 95 | ||
| 97 | static void luaX_invalidchar (LexState *ls, int c) { | 96 | static void luaX_invalidchar (LexState *ls, int c) { |
| 98 | l_char buff[8]; | 97 | char buff[8]; |
| 99 | sprintf(buff, l_s("0x%02X"), uchar(c)); | 98 | sprintf(buff, "0x%02X", (unsigned char)c); |
| 100 | luaX_syntaxerror(ls, l_s("invalid control char"), buff); | 99 | luaX_syntaxerror(ls, "invalid control char", buff); |
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | 102 | ||
| 104 | static void inclinenumber (LexState *LS) { | 103 | static void inclinenumber (LexState *LS) { |
| 105 | next(LS); /* skip `\n' */ | 104 | next(LS); /* skip `\n' */ |
| 106 | ++LS->linenumber; | 105 | ++LS->linenumber; |
| 107 | luaX_checklimit(LS, LS->linenumber, MAX_INT, l_s("lines in a chunk")); | 106 | luaX_checklimit(LS, LS->linenumber, MAX_INT, "lines in a chunk"); |
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | 109 | ||
| @@ -117,10 +116,10 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { | |||
| 117 | LS->lastline = 1; | 116 | LS->lastline = 1; |
| 118 | LS->source = source; | 117 | LS->source = source; |
| 119 | next(LS); /* read first char */ | 118 | next(LS); /* read first char */ |
| 120 | if (LS->current == l_c('#')) { | 119 | if (LS->current == '#') { |
| 121 | do { /* skip first line */ | 120 | do { /* skip first line */ |
| 122 | next(LS); | 121 | next(LS); |
| 123 | } while (LS->current != l_c('\n') && LS->current != EOZ); | 122 | } while (LS->current != '\n' && LS->current != EOZ); |
| 124 | } | 123 | } |
| 125 | } | 124 | } |
| 126 | 125 | ||
| @@ -137,10 +136,10 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { | |||
| 137 | 136 | ||
| 138 | #define EXTRABUFF 128 | 137 | #define EXTRABUFF 128 |
| 139 | #define checkbuffer(L, n, len) \ | 138 | #define checkbuffer(L, n, len) \ |
| 140 | if (((len)+(n))*sizeof(l_char) > G(L)->Mbuffsize) \ | 139 | if (((len)+(n))*sizeof(char) > G(L)->Mbuffsize) \ |
| 141 | luaO_openspace(L, (len)+(n)+EXTRABUFF, l_char) | 140 | luaO_openspace(L, (len)+(n)+EXTRABUFF, char) |
| 142 | 141 | ||
| 143 | #define save(L, c, l) (cast(l_char *, G(L)->Mbuffer)[l++] = (l_char)c) | 142 | #define save(L, c, l) (cast(char *, G(L)->Mbuffer)[l++] = (char)c) |
| 144 | #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) | 143 | #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) |
| 145 | 144 | ||
| 146 | 145 | ||
| @@ -151,8 +150,8 @@ static size_t readname (LexState *LS) { | |||
| 151 | do { | 150 | do { |
| 152 | checkbuffer(L, 10, l); | 151 | checkbuffer(L, 10, l); |
| 153 | save_and_next(L, LS, l); | 152 | save_and_next(L, LS, l); |
| 154 | } while (isalnum(LS->current) || LS->current == l_c('_')); | 153 | } while (isalnum(LS->current) || LS->current == '_'); |
| 155 | save(L, l_c('\0'), l); | 154 | save(L, '\0', l); |
| 156 | return l-1; | 155 | return l-1; |
| 157 | } | 156 | } |
| 158 | 157 | ||
| @@ -162,18 +161,18 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) { | |||
| 162 | lua_State *L = LS->L; | 161 | lua_State *L = LS->L; |
| 163 | size_t l = 0; | 162 | size_t l = 0; |
| 164 | checkbuffer(L, 10, l); | 163 | checkbuffer(L, 10, l); |
| 165 | if (comma) save(L, l_c('.'), l); | 164 | if (comma) save(L, '.', l); |
| 166 | while (isdigit(LS->current)) { | 165 | while (isdigit(LS->current)) { |
| 167 | checkbuffer(L, 10, l); | 166 | checkbuffer(L, 10, l); |
| 168 | save_and_next(L, LS, l); | 167 | save_and_next(L, LS, l); |
| 169 | } | 168 | } |
| 170 | if (LS->current == l_c('.')) { | 169 | if (LS->current == '.') { |
| 171 | save_and_next(L, LS, l); | 170 | save_and_next(L, LS, l); |
| 172 | if (LS->current == l_c('.')) { | 171 | if (LS->current == '.') { |
| 173 | save_and_next(L, LS, l); | 172 | save_and_next(L, LS, l); |
| 174 | save(L, l_c('\0'), l); | 173 | save(L, '\0', l); |
| 175 | luaX_error(LS, | 174 | luaX_error(LS, |
| 176 | l_s("ambiguous syntax (decimal point x string concatenation)"), | 175 | "ambiguous syntax (decimal point x string concatenation)", |
| 177 | TK_NUMBER); | 176 | TK_NUMBER); |
| 178 | } | 177 | } |
| 179 | } | 178 | } |
| @@ -181,18 +180,18 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) { | |||
| 181 | checkbuffer(L, 10, l); | 180 | checkbuffer(L, 10, l); |
| 182 | save_and_next(L, LS, l); | 181 | save_and_next(L, LS, l); |
| 183 | } | 182 | } |
| 184 | if (LS->current == l_c('e') || LS->current == l_c('E')) { | 183 | if (LS->current == 'e' || LS->current == 'E') { |
| 185 | save_and_next(L, LS, l); /* read `E' */ | 184 | save_and_next(L, LS, l); /* read `E' */ |
| 186 | if (LS->current == l_c('+') || LS->current == l_c('-')) | 185 | if (LS->current == '+' || LS->current == '-') |
| 187 | save_and_next(L, LS, l); /* optional exponent sign */ | 186 | save_and_next(L, LS, l); /* optional exponent sign */ |
| 188 | while (isdigit(LS->current)) { | 187 | while (isdigit(LS->current)) { |
| 189 | checkbuffer(L, 10, l); | 188 | checkbuffer(L, 10, l); |
| 190 | save_and_next(L, LS, l); | 189 | save_and_next(L, LS, l); |
| 191 | } | 190 | } |
| 192 | } | 191 | } |
| 193 | save(L, l_c('\0'), l); | 192 | save(L, '\0', l); |
| 194 | if (!luaO_str2d(cast(l_char *, G(L)->Mbuffer), &seminfo->r)) | 193 | if (!luaO_str2d(cast(char *, G(L)->Mbuffer), &seminfo->r)) |
| 195 | luaX_error(LS, l_s("malformed number"), TK_NUMBER); | 194 | luaX_error(LS, "malformed number", TK_NUMBER); |
| 196 | } | 195 | } |
| 197 | 196 | ||
| 198 | 197 | ||
| @@ -201,34 +200,34 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { | |||
| 201 | int cont = 0; | 200 | int cont = 0; |
| 202 | size_t l = 0; | 201 | size_t l = 0; |
| 203 | checkbuffer(L, 10, l); | 202 | checkbuffer(L, 10, l); |
| 204 | save(L, l_c('['), l); /* save first `[' */ | 203 | save(L, '[', l); /* save first `[' */ |
| 205 | save_and_next(L, LS, l); /* pass the second `[' */ | 204 | save_and_next(L, LS, l); /* pass the second `[' */ |
| 206 | if (LS->current == l_c('\n')) /* string starts with a newline? */ | 205 | if (LS->current == '\n') /* string starts with a newline? */ |
| 207 | inclinenumber(LS); /* skip it */ | 206 | inclinenumber(LS); /* skip it */ |
| 208 | for (;;) { | 207 | for (;;) { |
| 209 | checkbuffer(L, 10, l); | 208 | checkbuffer(L, 10, l); |
| 210 | switch (LS->current) { | 209 | switch (LS->current) { |
| 211 | case EOZ: | 210 | case EOZ: |
| 212 | save(L, l_c('\0'), l); | 211 | save(L, '\0', l); |
| 213 | luaX_error(LS, l_s("unfinished long string"), TK_STRING); | 212 | luaX_error(LS, "unfinished long string", TK_STRING); |
| 214 | break; /* to avoid warnings */ | 213 | break; /* to avoid warnings */ |
| 215 | case l_c('['): | 214 | case '[': |
| 216 | save_and_next(L, LS, l); | 215 | save_and_next(L, LS, l); |
| 217 | if (LS->current == l_c('[')) { | 216 | if (LS->current == '[') { |
| 218 | cont++; | 217 | cont++; |
| 219 | save_and_next(L, LS, l); | 218 | save_and_next(L, LS, l); |
| 220 | } | 219 | } |
| 221 | continue; | 220 | continue; |
| 222 | case l_c(']'): | 221 | case ']': |
| 223 | save_and_next(L, LS, l); | 222 | save_and_next(L, LS, l); |
| 224 | if (LS->current == l_c(']')) { | 223 | if (LS->current == ']') { |
| 225 | if (cont == 0) goto endloop; | 224 | if (cont == 0) goto endloop; |
| 226 | cont--; | 225 | cont--; |
| 227 | save_and_next(L, LS, l); | 226 | save_and_next(L, LS, l); |
| 228 | } | 227 | } |
| 229 | continue; | 228 | continue; |
| 230 | case l_c('\n'): | 229 | case '\n': |
| 231 | save(L, l_c('\n'), l); | 230 | save(L, '\n', l); |
| 232 | inclinenumber(LS); | 231 | inclinenumber(LS); |
| 233 | continue; | 232 | continue; |
| 234 | default: | 233 | default: |
| @@ -236,8 +235,8 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { | |||
| 236 | } | 235 | } |
| 237 | } endloop: | 236 | } endloop: |
| 238 | save_and_next(L, LS, l); /* skip the second `]' */ | 237 | save_and_next(L, LS, l); /* skip the second `]' */ |
| 239 | save(L, l_c('\0'), l); | 238 | save(L, '\0', l); |
| 240 | seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+2, l-5); | 239 | seminfo->ts = luaS_newlstr(L, cast(char *, G(L)->Mbuffer)+2, l-5); |
| 241 | } | 240 | } |
| 242 | 241 | ||
| 243 | 242 | ||
| @@ -249,21 +248,21 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
| 249 | while (LS->current != del) { | 248 | while (LS->current != del) { |
| 250 | checkbuffer(L, 10, l); | 249 | checkbuffer(L, 10, l); |
| 251 | switch (LS->current) { | 250 | switch (LS->current) { |
| 252 | case EOZ: case l_c('\n'): | 251 | case EOZ: case '\n': |
| 253 | save(L, l_c('\0'), l); | 252 | save(L, '\0', l); |
| 254 | luaX_error(LS, l_s("unfinished string"), TK_STRING); | 253 | luaX_error(LS, "unfinished string", TK_STRING); |
| 255 | break; /* to avoid warnings */ | 254 | break; /* to avoid warnings */ |
| 256 | case l_c('\\'): | 255 | case '\\': |
| 257 | next(LS); /* do not save the `\' */ | 256 | next(LS); /* do not save the `\' */ |
| 258 | switch (LS->current) { | 257 | switch (LS->current) { |
| 259 | case l_c('a'): save(L, l_c('\a'), l); next(LS); break; | 258 | case 'a': save(L, '\a', l); next(LS); break; |
| 260 | case l_c('b'): save(L, l_c('\b'), l); next(LS); break; | 259 | case 'b': save(L, '\b', l); next(LS); break; |
| 261 | case l_c('f'): save(L, l_c('\f'), l); next(LS); break; | 260 | case 'f': save(L, '\f', l); next(LS); break; |
| 262 | case l_c('n'): save(L, l_c('\n'), l); next(LS); break; | 261 | case 'n': save(L, '\n', l); next(LS); break; |
| 263 | case l_c('r'): save(L, l_c('\r'), l); next(LS); break; | 262 | case 'r': save(L, '\r', l); next(LS); break; |
| 264 | case l_c('t'): save(L, l_c('\t'), l); next(LS); break; | 263 | case 't': save(L, '\t', l); next(LS); break; |
| 265 | case l_c('v'): save(L, l_c('\v'), l); next(LS); break; | 264 | case 'v': save(L, '\v', l); next(LS); break; |
| 266 | case l_c('\n'): save(L, l_c('\n'), l); inclinenumber(LS); break; | 265 | case '\n': save(L, '\n', l); inclinenumber(LS); break; |
| 267 | default: { | 266 | default: { |
| 268 | if (!isdigit(LS->current)) | 267 | if (!isdigit(LS->current)) |
| 269 | save_and_next(L, LS, l); /* handles \\, \", \', and \? */ | 268 | save_and_next(L, LS, l); /* handles \\, \", \', and \? */ |
| @@ -271,12 +270,12 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
| 271 | int c = 0; | 270 | int c = 0; |
| 272 | int i = 0; | 271 | int i = 0; |
| 273 | do { | 272 | do { |
| 274 | c = 10*c + (LS->current-l_c('0')); | 273 | c = 10*c + (LS->current-'0'); |
| 275 | next(LS); | 274 | next(LS); |
| 276 | } while (++i<3 && isdigit(LS->current)); | 275 | } while (++i<3 && isdigit(LS->current)); |
| 277 | if (c > UCHAR_MAX) { | 276 | if (c > UCHAR_MAX) { |
| 278 | save(L, l_c('\0'), l); | 277 | save(L, '\0', l); |
| 279 | luaX_error(LS, l_s("escape sequence too large"), TK_STRING); | 278 | luaX_error(LS, "escape sequence too large", TK_STRING); |
| 280 | } | 279 | } |
| 281 | save(L, c, l); | 280 | save(L, c, l); |
| 282 | } | 281 | } |
| @@ -288,8 +287,8 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
| 288 | } | 287 | } |
| 289 | } | 288 | } |
| 290 | save_and_next(L, LS, l); /* skip delimiter */ | 289 | save_and_next(L, LS, l); /* skip delimiter */ |
| 291 | save(L, l_c('\0'), l); | 290 | save(L, '\0', l); |
| 292 | seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+1, l-3); | 291 | seminfo->ts = luaS_newlstr(L, cast(char *, G(L)->Mbuffer)+1, l-3); |
| 293 | } | 292 | } |
| 294 | 293 | ||
| 295 | 294 | ||
| @@ -297,70 +296,70 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { | |||
| 297 | for (;;) { | 296 | for (;;) { |
| 298 | switch (LS->current) { | 297 | switch (LS->current) { |
| 299 | 298 | ||
| 300 | case l_c(' '): case l_c('\t'): case l_c('\r'): /* `\r' to avoid problems with DOS */ | 299 | case ' ': case '\t': case '\r': /* `\r' to avoid problems with DOS */ |
| 301 | next(LS); | 300 | next(LS); |
| 302 | continue; | 301 | continue; |
| 303 | 302 | ||
| 304 | case l_c('\n'): | 303 | case '\n': |
| 305 | inclinenumber(LS); | 304 | inclinenumber(LS); |
| 306 | continue; | 305 | continue; |
| 307 | 306 | ||
| 308 | case l_c('$'): | 307 | case '$': |
| 309 | luaX_error(LS, | 308 | luaX_error(LS, |
| 310 | l_s("unexpected `$' (pragmas are no longer supported)"), | 309 | "unexpected `$' (pragmas are no longer supported)", |
| 311 | LS->current); | 310 | LS->current); |
| 312 | break; | 311 | break; |
| 313 | 312 | ||
| 314 | case l_c('-'): | 313 | case '-': |
| 315 | next(LS); | 314 | next(LS); |
| 316 | if (LS->current != l_c('-')) return l_c('-'); | 315 | if (LS->current != '-') return '-'; |
| 317 | do { next(LS); } while (LS->current != l_c('\n') && LS->current != EOZ); | 316 | do { next(LS); } while (LS->current != '\n' && LS->current != EOZ); |
| 318 | continue; | 317 | continue; |
| 319 | 318 | ||
| 320 | case l_c('['): | 319 | case '[': |
| 321 | next(LS); | 320 | next(LS); |
| 322 | if (LS->current != l_c('[')) return l_c('['); | 321 | if (LS->current != '[') return '['; |
| 323 | else { | 322 | else { |
| 324 | read_long_string(LS, seminfo); | 323 | read_long_string(LS, seminfo); |
| 325 | return TK_STRING; | 324 | return TK_STRING; |
| 326 | } | 325 | } |
| 327 | 326 | ||
| 328 | case l_c('='): | 327 | case '=': |
| 329 | next(LS); | 328 | next(LS); |
| 330 | if (LS->current != l_c('=')) return l_c('='); | 329 | if (LS->current != '=') return '='; |
| 331 | else { next(LS); return TK_EQ; } | 330 | else { next(LS); return TK_EQ; } |
| 332 | 331 | ||
| 333 | case l_c('<'): | 332 | case '<': |
| 334 | next(LS); | 333 | next(LS); |
| 335 | if (LS->current != l_c('=')) return l_c('<'); | 334 | if (LS->current != '=') return '<'; |
| 336 | else { next(LS); return TK_LE; } | 335 | else { next(LS); return TK_LE; } |
| 337 | 336 | ||
| 338 | case l_c('>'): | 337 | case '>': |
| 339 | next(LS); | 338 | next(LS); |
| 340 | if (LS->current != l_c('=')) return l_c('>'); | 339 | if (LS->current != '=') return '>'; |
| 341 | else { next(LS); return TK_GE; } | 340 | else { next(LS); return TK_GE; } |
| 342 | 341 | ||
| 343 | case l_c('~'): | 342 | case '~': |
| 344 | next(LS); | 343 | next(LS); |
| 345 | if (LS->current != l_c('=')) return l_c('~'); | 344 | if (LS->current != '=') return '~'; |
| 346 | else { next(LS); return TK_NE; } | 345 | else { next(LS); return TK_NE; } |
| 347 | 346 | ||
| 348 | case l_c('"'): | 347 | case '"': |
| 349 | case l_c('\''): | 348 | case '\'': |
| 350 | read_string(LS, LS->current, seminfo); | 349 | read_string(LS, LS->current, seminfo); |
| 351 | return TK_STRING; | 350 | return TK_STRING; |
| 352 | 351 | ||
| 353 | case l_c('.'): | 352 | case '.': |
| 354 | next(LS); | 353 | next(LS); |
| 355 | if (LS->current == l_c('.')) { | 354 | if (LS->current == '.') { |
| 356 | next(LS); | 355 | next(LS); |
| 357 | if (LS->current == l_c('.')) { | 356 | if (LS->current == '.') { |
| 358 | next(LS); | 357 | next(LS); |
| 359 | return TK_DOTS; /* ... */ | 358 | return TK_DOTS; /* ... */ |
| 360 | } | 359 | } |
| 361 | else return TK_CONCAT; /* .. */ | 360 | else return TK_CONCAT; /* .. */ |
| 362 | } | 361 | } |
| 363 | else if (!isdigit(LS->current)) return l_c('.'); | 362 | else if (!isdigit(LS->current)) return '.'; |
| 364 | else { | 363 | else { |
| 365 | read_number(LS, 1, seminfo); | 364 | read_number(LS, 1, seminfo); |
| 366 | return TK_NUMBER; | 365 | return TK_NUMBER; |
| @@ -374,17 +373,17 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { | |||
| 374 | read_number(LS, 0, seminfo); | 373 | read_number(LS, 0, seminfo); |
| 375 | return TK_NUMBER; | 374 | return TK_NUMBER; |
| 376 | } | 375 | } |
| 377 | else if (isalpha(LS->current) || LS->current == l_c('_')) { | 376 | else if (isalpha(LS->current) || LS->current == '_') { |
| 378 | /* identifier or reserved word */ | 377 | /* identifier or reserved word */ |
| 379 | size_t l = readname(LS); | 378 | size_t l = readname(LS); |
| 380 | TString *ts = luaS_newlstr(LS->L, cast(l_char *, G(LS->L)->Mbuffer), l); | 379 | TString *ts = luaS_newlstr(LS->L, cast(char *, G(LS->L)->Mbuffer), l); |
| 381 | if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */ | 380 | if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */ |
| 382 | return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED; | 381 | return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED; |
| 383 | seminfo->ts = ts; | 382 | seminfo->ts = ts; |
| 384 | return TK_NAME; | 383 | return TK_NAME; |
| 385 | } | 384 | } |
| 386 | else { | 385 | else { |
| 387 | l_charint c = LS->current; | 386 | int c = LS->current; |
| 388 | if (iscntrl(c)) | 387 | if (iscntrl(c)) |
| 389 | luaX_invalidchar(LS, c); | 388 | luaX_invalidchar(LS, c); |
| 390 | next(LS); | 389 | next(LS); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.38 2001/08/31 19:46:07 roberto Exp $ | 2 | ** $Id: llex.h,v 1.39 2001/11/16 16:29:10 roberto Exp $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -14,7 +14,7 @@ | |||
| 14 | #define FIRST_RESERVED 257 | 14 | #define FIRST_RESERVED 257 |
| 15 | 15 | ||
| 16 | /* maximum length of a reserved word */ | 16 | /* maximum length of a reserved word */ |
| 17 | #define TOKEN_LEN (sizeof(l_s("function"))/sizeof(l_char)) | 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | /* | 20 | /* |
| @@ -49,7 +49,7 @@ typedef struct Token { | |||
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | typedef struct LexState { | 51 | typedef struct LexState { |
| 52 | l_charint current; /* current character */ | 52 | int current; /* current character (charint) */ |
| 53 | Token t; /* current token */ | 53 | Token t; /* current token */ |
| 54 | Token lookahead; /* look ahead token */ | 54 | Token lookahead; /* look ahead token */ |
| 55 | struct FuncState *fs; /* `FuncState' is private to the parser */ | 55 | struct FuncState *fs; /* `FuncState' is private to the parser */ |
| @@ -64,9 +64,9 @@ typedef struct LexState { | |||
| 64 | void luaX_init (lua_State *L); | 64 | void luaX_init (lua_State *L); |
| 65 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); | 65 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); |
| 66 | int luaX_lex (LexState *LS, SemInfo *seminfo); | 66 | int luaX_lex (LexState *LS, SemInfo *seminfo); |
| 67 | void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg); | 67 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); |
| 68 | void luaX_error (LexState *ls, const l_char *s, int token); | 68 | void luaX_error (LexState *ls, const char *s, int token); |
| 69 | void luaX_token2str (int token, l_char *s); | 69 | void luaX_token2str (int token, char *s); |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | #endif | 72 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.37 2001/03/06 20:09:38 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.38 2001/03/26 14:31:49 roberto Exp $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <math.h> | 9 | #include <math.h> |
| 10 | 10 | ||
| 11 | #define LUA_PRIVATE | ||
| 12 | #include "lua.h" | 11 | #include "lua.h" |
| 13 | 12 | ||
| 14 | #include "lauxlib.h" | 13 | #include "lauxlib.h" |
| @@ -177,18 +176,18 @@ static int math_random (lua_State *L) { | |||
| 177 | } | 176 | } |
| 178 | case 1: { /* only upper limit */ | 177 | case 1: { /* only upper limit */ |
| 179 | int u = luaL_check_int(L, 1); | 178 | int u = luaL_check_int(L, 1); |
| 180 | luaL_arg_check(L, 1<=u, 1, l_s("interval is empty")); | 179 | luaL_arg_check(L, 1<=u, 1, "interval is empty"); |
| 181 | lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */ | 180 | lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */ |
| 182 | break; | 181 | break; |
| 183 | } | 182 | } |
| 184 | case 2: { /* lower and upper limits */ | 183 | case 2: { /* lower and upper limits */ |
| 185 | int l = luaL_check_int(L, 1); | 184 | int l = luaL_check_int(L, 1); |
| 186 | int u = luaL_check_int(L, 2); | 185 | int u = luaL_check_int(L, 2); |
| 187 | luaL_arg_check(L, l<=u, 2, l_s("interval is empty")); | 186 | luaL_arg_check(L, l<=u, 2, "interval is empty"); |
| 188 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ | 187 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ |
| 189 | break; | 188 | break; |
| 190 | } | 189 | } |
| 191 | default: lua_error(L, l_s("wrong number of arguments")); | 190 | default: lua_error(L, "wrong number of arguments"); |
| 192 | } | 191 | } |
| 193 | return 1; | 192 | return 1; |
| 194 | } | 193 | } |
| @@ -201,29 +200,29 @@ static int math_randomseed (lua_State *L) { | |||
| 201 | 200 | ||
| 202 | 201 | ||
| 203 | static const luaL_reg mathlib[] = { | 202 | static const luaL_reg mathlib[] = { |
| 204 | {l_s("abs"), math_abs}, | 203 | {"abs", math_abs}, |
| 205 | {l_s("sin"), math_sin}, | 204 | {"sin", math_sin}, |
| 206 | {l_s("cos"), math_cos}, | 205 | {"cos", math_cos}, |
| 207 | {l_s("tan"), math_tan}, | 206 | {"tan", math_tan}, |
| 208 | {l_s("asin"), math_asin}, | 207 | {"asin", math_asin}, |
| 209 | {l_s("acos"), math_acos}, | 208 | {"acos", math_acos}, |
| 210 | {l_s("atan"), math_atan}, | 209 | {"atan", math_atan}, |
| 211 | {l_s("atan2"), math_atan2}, | 210 | {"atan2", math_atan2}, |
| 212 | {l_s("ceil"), math_ceil}, | 211 | {"ceil", math_ceil}, |
| 213 | {l_s("floor"), math_floor}, | 212 | {"floor", math_floor}, |
| 214 | {l_s("mod"), math_mod}, | 213 | {"mod", math_mod}, |
| 215 | {l_s("frexp"), math_frexp}, | 214 | {"frexp", math_frexp}, |
| 216 | {l_s("ldexp"), math_ldexp}, | 215 | {"ldexp", math_ldexp}, |
| 217 | {l_s("sqrt"), math_sqrt}, | 216 | {"sqrt", math_sqrt}, |
| 218 | {l_s("min"), math_min}, | 217 | {"min", math_min}, |
| 219 | {l_s("max"), math_max}, | 218 | {"max", math_max}, |
| 220 | {l_s("log"), math_log}, | 219 | {"log", math_log}, |
| 221 | {l_s("log10"), math_log10}, | 220 | {"log10", math_log10}, |
| 222 | {l_s("exp"), math_exp}, | 221 | {"exp", math_exp}, |
| 223 | {l_s("deg"), math_deg}, | 222 | {"deg", math_deg}, |
| 224 | {l_s("rad"), math_rad}, | 223 | {"rad", math_rad}, |
| 225 | {l_s("random"), math_random}, | 224 | {"random", math_random}, |
| 226 | {l_s("randomseed"), math_randomseed} | 225 | {"randomseed", math_randomseed} |
| 227 | }; | 226 | }; |
| 228 | 227 | ||
| 229 | /* | 228 | /* |
| @@ -232,9 +231,9 @@ static const luaL_reg mathlib[] = { | |||
| 232 | LUALIB_API int lua_mathlibopen (lua_State *L) { | 231 | LUALIB_API int lua_mathlibopen (lua_State *L) { |
| 233 | luaL_openl(L, mathlib); | 232 | luaL_openl(L, mathlib); |
| 234 | lua_pushcfunction(L, math_pow); | 233 | lua_pushcfunction(L, math_pow); |
| 235 | lua_settagmethod(L, LUA_TNUMBER, l_s("pow")); | 234 | lua_settagmethod(L, LUA_TNUMBER, "pow"); |
| 236 | lua_pushnumber(L, PI); | 235 | lua_pushnumber(L, PI); |
| 237 | lua_setglobal(L, l_s("PI")); | 236 | lua_setglobal(L, "PI"); |
| 238 | return 0; | 237 | return 0; |
| 239 | } | 238 | } |
| 240 | 239 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.50 2001/08/31 19:46:07 roberto Exp $ | 2 | ** $Id: lmem.c,v 1.51 2001/10/25 19:13:33 roberto Exp $ |
| 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 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "ldo.h" | 12 | #include "ldo.h" |
| @@ -27,7 +26,7 @@ | |||
| 27 | 26 | ||
| 28 | 27 | ||
| 29 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | 28 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, |
| 30 | int limit, const l_char *errormsg) { | 29 | int limit, const char *errormsg) { |
| 31 | void *newblock; | 30 | void *newblock; |
| 32 | int newsize = (*size)*2; | 31 | int newsize = (*size)*2; |
| 33 | if (newsize < MINSIZEARRAY) | 32 | if (newsize < MINSIZEARRAY) |
| @@ -54,7 +53,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { | |||
| 54 | block = NULL; | 53 | block = NULL; |
| 55 | } | 54 | } |
| 56 | else if (size >= MAX_SIZET) | 55 | else if (size >= MAX_SIZET) |
| 57 | luaD_error(L, l_s("memory allocation error: block too big")); | 56 | luaD_error(L, "memory allocation error: block too big"); |
| 58 | else { | 57 | else { |
| 59 | block = l_realloc(block, oldsize, size); | 58 | block = l_realloc(block, oldsize, size); |
| 60 | if (block == NULL) { | 59 | if (block == NULL) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.h,v 1.22 2001/02/23 17:17:25 roberto Exp $ | 2 | ** $Id: lmem.h,v 1.24 2001/09/07 17:30:16 roberto Exp $ |
| 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 | */ |
| @@ -16,7 +16,7 @@ | |||
| 16 | void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); | 16 | void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); |
| 17 | 17 | ||
| 18 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, | 18 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, |
| 19 | int limit, const l_char *errormsg); | 19 | int limit, const char *errormsg); |
| 20 | 20 | ||
| 21 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) | 21 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) |
| 22 | #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) | 22 | #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.70 2001/03/26 14:31:49 roberto Exp $ | 2 | ** $Id: lobject.c,v 1.71 2001/10/25 19:14:14 roberto Exp $ |
| 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 | */ |
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| 12 | 12 | ||
| 13 | #define LUA_PRIVATE | ||
| 14 | #include "lua.h" | 13 | #include "lua.h" |
| 15 | 14 | ||
| 16 | #include "ldo.h" | 15 | #include "ldo.h" |
| @@ -73,12 +72,12 @@ void *luaO_openspaceaux (lua_State *L, size_t n) { | |||
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | 74 | ||
| 76 | int luaO_str2d (const l_char *s, lua_Number *result) { | 75 | int luaO_str2d (const char *s, lua_Number *result) { |
| 77 | l_char *endptr; | 76 | char *endptr; |
| 78 | lua_Number res = lua_str2number(s, &endptr); | 77 | lua_Number res = lua_str2number(s, &endptr); |
| 79 | if (endptr == s) return 0; /* no conversion */ | 78 | if (endptr == s) return 0; /* no conversion */ |
| 80 | while (isspace(uchar(*endptr))) endptr++; | 79 | while (isspace((unsigned char)(*endptr))) endptr++; |
| 81 | if (*endptr != l_c('\0')) return 0; /* invalid trailing characters? */ | 80 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ |
| 82 | *result = res; | 81 | *result = res; |
| 83 | return 1; | 82 | return 1; |
| 84 | } | 83 | } |
| @@ -88,9 +87,9 @@ int luaO_str2d (const l_char *s, lua_Number *result) { | |||
| 88 | #define MAX_VERROR 280 | 87 | #define MAX_VERROR 280 |
| 89 | 88 | ||
| 90 | /* this function needs to handle only '%d' and '%.XXs' formats */ | 89 | /* this function needs to handle only '%d' and '%.XXs' formats */ |
| 91 | void luaO_verror (lua_State *L, const l_char *fmt, ...) { | 90 | void luaO_verror (lua_State *L, const char *fmt, ...) { |
| 92 | va_list argp; | 91 | va_list argp; |
| 93 | l_char buff[MAX_VERROR]; /* to hold formatted message */ | 92 | char buff[MAX_VERROR]; /* to hold formatted message */ |
| 94 | va_start(argp, fmt); | 93 | va_start(argp, fmt); |
| 95 | vsprintf(buff, fmt, argp); | 94 | vsprintf(buff, fmt, argp); |
| 96 | va_end(argp); | 95 | va_end(argp); |
| @@ -98,36 +97,36 @@ void luaO_verror (lua_State *L, const l_char *fmt, ...) { | |||
| 98 | } | 97 | } |
| 99 | 98 | ||
| 100 | 99 | ||
| 101 | void luaO_chunkid (l_char *out, const l_char *source, int bufflen) { | 100 | void luaO_chunkid (char *out, const char *source, int bufflen) { |
| 102 | if (*source == l_c('=')) { | 101 | if (*source == '=') { |
| 103 | strncpy(out, source+1, bufflen); /* remove first char */ | 102 | strncpy(out, source+1, bufflen); /* remove first char */ |
| 104 | out[bufflen-1] = l_c('\0'); /* ensures null termination */ | 103 | out[bufflen-1] = '\0'; /* ensures null termination */ |
| 105 | } | 104 | } |
| 106 | else { | 105 | else { |
| 107 | if (*source == l_c('@')) { | 106 | if (*source == '@') { |
| 108 | int l; | 107 | int l; |
| 109 | source++; /* skip the `@' */ | 108 | source++; /* skip the `@' */ |
| 110 | bufflen -= sizeof(l_s("file `...%s'")); | 109 | bufflen -= sizeof("file `...%s'"); |
| 111 | l = strlen(source); | 110 | l = strlen(source); |
| 112 | if (l>bufflen) { | 111 | if (l>bufflen) { |
| 113 | source += (l-bufflen); /* get last part of file name */ | 112 | source += (l-bufflen); /* get last part of file name */ |
| 114 | sprintf(out, l_s("file `...%.99s'"), source); | 113 | sprintf(out, "file `...%.99s'", source); |
| 115 | } | 114 | } |
| 116 | else | 115 | else |
| 117 | sprintf(out, l_s("file `%.99s'"), source); | 116 | sprintf(out, "file `%.99s'", source); |
| 118 | } | 117 | } |
| 119 | else { | 118 | else { |
| 120 | int len = strcspn(source, l_s("\n")); /* stop at first newline */ | 119 | int len = strcspn(source, "\n"); /* stop at first newline */ |
| 121 | bufflen -= sizeof(l_s("string \"%.*s...\"")); | 120 | bufflen -= sizeof("string \"%.*s...\""); |
| 122 | if (len > bufflen) len = bufflen; | 121 | if (len > bufflen) len = bufflen; |
| 123 | if (source[len] != l_c('\0')) { /* must truncate? */ | 122 | if (source[len] != '\0') { /* must truncate? */ |
| 124 | strcpy(out, l_s("string \"")); | 123 | strcpy(out, "string \""); |
| 125 | out += strlen(out); | 124 | out += strlen(out); |
| 126 | strncpy(out, source, len); | 125 | strncpy(out, source, len); |
| 127 | strcpy(out+len, l_s("...\"")); | 126 | strcpy(out+len, "...\""); |
| 128 | } | 127 | } |
| 129 | else | 128 | else |
| 130 | sprintf(out, l_s("string \"%.99s\""), source); | 129 | sprintf(out, "string \"%.99s\"", source); |
| 131 | } | 130 | } |
| 132 | } | 131 | } |
| 133 | } | 132 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.115 2001/10/25 19:14:14 roberto Exp $ | 2 | ** $Id: lobject.h,v 1.116 2001/11/06 21:41:53 roberto Exp $ |
| 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 | */ |
| @@ -114,7 +114,7 @@ typedef union TString { | |||
| 114 | } TString; | 114 | } TString; |
| 115 | 115 | ||
| 116 | 116 | ||
| 117 | #define getstr(ts) cast(l_char *, (ts) + 1) | 117 | #define getstr(ts) cast(char *, (ts) + 1) |
| 118 | #define svalue(o) getstr(tsvalue(o)) | 118 | #define svalue(o) getstr(tsvalue(o)) |
| 119 | 119 | ||
| 120 | 120 | ||
| @@ -277,10 +277,10 @@ int luaO_log2 (unsigned int x); | |||
| 277 | void *luaO_openspaceaux (lua_State *L, size_t n); | 277 | void *luaO_openspaceaux (lua_State *L, size_t n); |
| 278 | 278 | ||
| 279 | int luaO_equalObj (const TObject *t1, const TObject *t2); | 279 | int luaO_equalObj (const TObject *t1, const TObject *t2); |
| 280 | int luaO_str2d (const l_char *s, lua_Number *result); | 280 | int luaO_str2d (const char *s, lua_Number *result); |
| 281 | 281 | ||
| 282 | void luaO_verror (lua_State *L, const l_char *fmt, ...); | 282 | void luaO_verror (lua_State *L, const char *fmt, ...); |
| 283 | void luaO_chunkid (l_char *out, const l_char *source, int len); | 283 | void luaO_chunkid (char *out, const char *source, int len); |
| 284 | 284 | ||
| 285 | 285 | ||
| 286 | #endif | 286 | #endif |
| @@ -1,12 +1,11 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.c,v 1.5 2001/09/07 17:39:10 roberto Exp $ | 2 | ** $Id: lopcodes.c,v 1.6 2001/10/25 19:14:14 roberto Exp $ |
| 3 | ** extracted automatically from lopcodes.h by mkprint.lua | 3 | ** extracted automatically from lopcodes.h by mkprint.lua |
| 4 | ** DO NOT EDIT | 4 | ** DO NOT EDIT |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | #define LUA_PRIVATE | ||
| 10 | #include "lua.h" | 9 | #include "lua.h" |
| 11 | 10 | ||
| 12 | #include "lobject.h" | 11 | #include "lobject.h" |
| @@ -15,48 +14,48 @@ | |||
| 15 | 14 | ||
| 16 | #ifdef LUA_OPNAMES | 15 | #ifdef LUA_OPNAMES |
| 17 | 16 | ||
| 18 | const l_char *const luaP_opnames[] = { | 17 | const char *const luaP_opnames[] = { |
| 19 | l_s("MOVE"), | 18 | "MOVE", |
| 20 | l_s("LOADK"), | 19 | "LOADK", |
| 21 | l_s("LOADINT"), | 20 | "LOADINT", |
| 22 | l_s("LOADNIL"), | 21 | "LOADNIL", |
| 23 | l_s("GETUPVAL"), | 22 | "GETUPVAL", |
| 24 | l_s("GETGLOBAL"), | 23 | "GETGLOBAL", |
| 25 | l_s("GETTABLE"), | 24 | "GETTABLE", |
| 26 | l_s("SETGLOBAL"), | 25 | "SETGLOBAL", |
| 27 | l_s("SETUPVAL"), | 26 | "SETUPVAL", |
| 28 | l_s("SETTABLE"), | 27 | "SETTABLE", |
| 29 | l_s("NEWTABLE"), | 28 | "NEWTABLE", |
| 30 | l_s("SELF"), | 29 | "SELF", |
| 31 | l_s("ADD"), | 30 | "ADD", |
| 32 | l_s("SUB"), | 31 | "SUB", |
| 33 | l_s("MUL"), | 32 | "MUL", |
| 34 | l_s("DIV"), | 33 | "DIV", |
| 35 | l_s("POW"), | 34 | "POW", |
| 36 | l_s("UNM"), | 35 | "UNM", |
| 37 | l_s("NOT"), | 36 | "NOT", |
| 38 | l_s("CONCAT"), | 37 | "CONCAT", |
| 39 | l_s("JMP"), | 38 | "JMP", |
| 40 | l_s("CJMP"), | 39 | "CJMP", |
| 41 | l_s("TESTEQ"), | 40 | "TESTEQ", |
| 42 | l_s("TESTNE"), | 41 | "TESTNE", |
| 43 | l_s("TESTLT"), | 42 | "TESTLT", |
| 44 | l_s("TESTLE"), | 43 | "TESTLE", |
| 45 | l_s("TESTGT"), | 44 | "TESTGT", |
| 46 | l_s("TESTGE"), | 45 | "TESTGE", |
| 47 | l_s("TESTT"), | 46 | "TESTT", |
| 48 | l_s("TESTF"), | 47 | "TESTF", |
| 49 | l_s("NILJMP"), | 48 | "NILJMP", |
| 50 | l_s("CALL"), | 49 | "CALL", |
| 51 | l_s("RETURN"), | 50 | "RETURN", |
| 52 | l_s("FORPREP"), | 51 | "FORPREP", |
| 53 | l_s("FORLOOP"), | 52 | "FORLOOP", |
| 54 | l_s("TFORPREP"), | 53 | "TFORPREP", |
| 55 | l_s("TFORLOOP"), | 54 | "TFORLOOP", |
| 56 | l_s("SETLIST"), | 55 | "SETLIST", |
| 57 | l_s("SETLISTO"), | 56 | "SETLISTO", |
| 58 | l_s("CLOSE"), | 57 | "CLOSE", |
| 59 | l_s("CLOSURE") | 58 | "CLOSURE" |
| 60 | }; | 59 | }; |
| 61 | 60 | ||
| 62 | #endif | 61 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.81 2001/09/07 17:39:10 roberto Exp $ | 2 | ** $Id: lopcodes.h,v 1.82 2001/10/25 19:14:14 roberto Exp $ |
| 3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -224,7 +224,7 @@ extern const lu_byte luaP_opmodes[NUM_OPCODES]; | |||
| 224 | /* | 224 | /* |
| 225 | ** opcode names (only included when compiled with LUA_OPNAMES) | 225 | ** opcode names (only included when compiled with LUA_OPNAMES) |
| 226 | */ | 226 | */ |
| 227 | extern const l_char *const luaP_opnames[]; | 227 | extern const char *const luaP_opnames[]; |
| 228 | 228 | ||
| 229 | 229 | ||
| 230 | #endif | 230 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.159 2001/10/02 16:41:36 roberto Exp $ | 2 | ** $Id: lparser.c,v 1.160 2001/10/25 19:14:14 roberto Exp $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | 10 | ||
| 11 | #define LUA_PRIVATE | ||
| 12 | #include "lua.h" | 11 | #include "lua.h" |
| 13 | 12 | ||
| 14 | #include "lcode.h" | 13 | #include "lcode.h" |
| @@ -76,9 +75,9 @@ static void lookahead (LexState *ls) { | |||
| 76 | 75 | ||
| 77 | 76 | ||
| 78 | static void error_expected (LexState *ls, int token) { | 77 | static void error_expected (LexState *ls, int token) { |
| 79 | l_char buff[30], t[TOKEN_LEN]; | 78 | char buff[30], t[TOKEN_LEN]; |
| 80 | luaX_token2str(token, t); | 79 | luaX_token2str(token, t); |
| 81 | sprintf(buff, l_s("`%.10s' expected"), t); | 80 | sprintf(buff, "`%.10s' expected", t); |
| 82 | luaK_error(ls, buff); | 81 | luaK_error(ls, buff); |
| 83 | } | 82 | } |
| 84 | 83 | ||
| @@ -90,7 +89,7 @@ static void check (LexState *ls, int c) { | |||
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | 91 | ||
| 93 | static void check_condition (LexState *ls, int c, const l_char *msg) { | 92 | static void check_condition (LexState *ls, int c, const char *msg) { |
| 94 | if (!c) luaK_error(ls, msg); | 93 | if (!c) luaK_error(ls, msg); |
| 95 | } | 94 | } |
| 96 | 95 | ||
| @@ -109,11 +108,11 @@ static void check_match (LexState *ls, int what, int who, int where) { | |||
| 109 | if (where == ls->linenumber) | 108 | if (where == ls->linenumber) |
| 110 | error_expected(ls, what); | 109 | error_expected(ls, what); |
| 111 | else { | 110 | else { |
| 112 | l_char buff[70]; | 111 | char buff[70]; |
| 113 | l_char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; | 112 | char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; |
| 114 | luaX_token2str(what, t_what); | 113 | luaX_token2str(what, t_what); |
| 115 | luaX_token2str(who, t_who); | 114 | luaX_token2str(who, t_who); |
| 116 | sprintf(buff, l_s("`%.10s' expected (to close `%.10s' at line %d)"), | 115 | sprintf(buff, "`%.10s' expected (to close `%.10s' at line %d)", |
| 117 | t_what, t_who, where); | 116 | t_what, t_who, where); |
| 118 | luaK_error(ls, buff); | 117 | luaK_error(ls, buff); |
| 119 | } | 118 | } |
| @@ -123,7 +122,7 @@ static void check_match (LexState *ls, int what, int who, int where) { | |||
| 123 | 122 | ||
| 124 | 123 | ||
| 125 | static TString *str_checkname (LexState *ls) { | 124 | static TString *str_checkname (LexState *ls) { |
| 126 | check_condition(ls, (ls->t.token == TK_NAME), l_s("<name> expected")); | 125 | check_condition(ls, (ls->t.token == TK_NAME), "<name> expected"); |
| 127 | return ls->t.seminfo.ts; | 126 | return ls->t.seminfo.ts; |
| 128 | } | 127 | } |
| 129 | 128 | ||
| @@ -150,7 +149,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 150 | FuncState *fs = ls->fs; | 149 | FuncState *fs = ls->fs; |
| 151 | Proto *f = fs->f; | 150 | Proto *f = fs->f; |
| 152 | luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, | 151 | luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, |
| 153 | LocVar, MAX_INT, l_s("")); | 152 | LocVar, MAX_INT, ""); |
| 154 | f->locvars[fs->nlocvars].varname = varname; | 153 | f->locvars[fs->nlocvars].varname = varname; |
| 155 | return fs->nlocvars++; | 154 | return fs->nlocvars++; |
| 156 | } | 155 | } |
| @@ -158,7 +157,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 158 | 157 | ||
| 159 | static void new_localvar (LexState *ls, TString *name, int n) { | 158 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 160 | FuncState *fs = ls->fs; | 159 | FuncState *fs = ls->fs; |
| 161 | luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, l_s("local variables")); | 160 | luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, "local variables"); |
| 162 | fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name); | 161 | fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name); |
| 163 | } | 162 | } |
| 164 | 163 | ||
| @@ -194,7 +193,7 @@ static void removelocalvars (LexState *ls, int nvars, int toclose) { | |||
| 194 | } | 193 | } |
| 195 | 194 | ||
| 196 | 195 | ||
| 197 | static void new_localvarstr (LexState *ls, const l_char *name, int n) { | 196 | static void new_localvarstr (LexState *ls, const char *name, int n) { |
| 198 | new_localvar(ls, luaS_new(ls->L, name), n); | 197 | new_localvar(ls, luaS_new(ls->L, name), n); |
| 199 | } | 198 | } |
| 200 | 199 | ||
| @@ -206,7 +205,7 @@ static int indexupvalue (FuncState *fs, expdesc *v) { | |||
| 206 | return i; | 205 | return i; |
| 207 | } | 206 | } |
| 208 | /* new one */ | 207 | /* new one */ |
| 209 | luaX_checklimit(fs->ls, fs->f->nupvalues+1, MAXUPVALUES, l_s("upvalues")); | 208 | luaX_checklimit(fs->ls, fs->f->nupvalues+1, MAXUPVALUES, "upvalues"); |
| 210 | fs->upvalues[fs->f->nupvalues] = *v; | 209 | fs->upvalues[fs->f->nupvalues] = *v; |
| 211 | return fs->f->nupvalues++; | 210 | return fs->f->nupvalues++; |
| 212 | } | 211 | } |
| @@ -263,11 +262,11 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { | |||
| 263 | static void code_params (LexState *ls, int nparams, short dots) { | 262 | static void code_params (LexState *ls, int nparams, short dots) { |
| 264 | FuncState *fs = ls->fs; | 263 | FuncState *fs = ls->fs; |
| 265 | adjustlocalvars(ls, nparams); | 264 | adjustlocalvars(ls, nparams); |
| 266 | luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters")); | 265 | luaX_checklimit(ls, fs->nactloc, MAXPARAMS, "parameters"); |
| 267 | fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */ | 266 | fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */ |
| 268 | fs->f->is_vararg = dots; | 267 | fs->f->is_vararg = dots; |
| 269 | if (dots) { | 268 | if (dots) { |
| 270 | new_localvarstr(ls, l_s("arg"), 0); | 269 | new_localvarstr(ls, "arg", 0); |
| 271 | adjustlocalvars(ls, 1); | 270 | adjustlocalvars(ls, 1); |
| 272 | } | 271 | } |
| 273 | luaK_reserveregs(fs, fs->nactloc); /* reserve register for parameters */ | 272 | luaK_reserveregs(fs, fs->nactloc); /* reserve register for parameters */ |
| @@ -294,7 +293,7 @@ static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { | |||
| 294 | Proto *f = fs->f; | 293 | Proto *f = fs->f; |
| 295 | int i; | 294 | int i; |
| 296 | luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, | 295 | luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, |
| 297 | MAXARG_Bc, l_s("constant table overflow")); | 296 | MAXARG_Bc, "constant table overflow"); |
| 298 | f->p[fs->np++] = func->f; | 297 | f->p[fs->np++] = func->f; |
| 299 | init_exp(v, VRELOCABLE, luaK_codeABc(fs, OP_CLOSURE, 0, fs->np-1)); | 298 | init_exp(v, VRELOCABLE, luaK_codeABc(fs, OP_CLOSURE, 0, fs->np-1)); |
| 300 | for (i=0; i<func->f->nupvalues; i++) { | 299 | for (i=0; i<func->f->nupvalues; i++) { |
| @@ -366,7 +365,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z) { | |||
| 366 | next(&lexstate); /* read first token */ | 365 | next(&lexstate); /* read first token */ |
| 367 | chunk(&lexstate); | 366 | chunk(&lexstate); |
| 368 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), | 367 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), |
| 369 | l_s("<eof> expected")); | 368 | "<eof> expected"); |
| 370 | close_func(&lexstate); | 369 | close_func(&lexstate); |
| 371 | lua_assert(funcstate.prev == NULL); | 370 | lua_assert(funcstate.prev == NULL); |
| 372 | lua_assert(funcstate.f->nupvalues == 0); | 371 | lua_assert(funcstate.f->nupvalues == 0); |
| @@ -396,7 +395,7 @@ static void luaY_index (LexState *ls, expdesc *v) { | |||
| 396 | next(ls); /* skip the '[' */ | 395 | next(ls); /* skip the '[' */ |
| 397 | expr(ls, v); | 396 | expr(ls, v); |
| 398 | luaK_exp2val(ls->fs, v); | 397 | luaK_exp2val(ls->fs, v); |
| 399 | check(ls, l_c(']')); | 398 | check(ls, ']'); |
| 400 | } | 399 | } |
| 401 | 400 | ||
| 402 | 401 | ||
| @@ -404,7 +403,7 @@ static int explist1 (LexState *ls, expdesc *v) { | |||
| 404 | /* explist1 -> expr { `,' expr } */ | 403 | /* explist1 -> expr { `,' expr } */ |
| 405 | int n = 1; /* at least one expression */ | 404 | int n = 1; /* at least one expression */ |
| 406 | expr(ls, v); | 405 | expr(ls, v); |
| 407 | while (ls->t.token == l_c(',')) { | 406 | while (ls->t.token == ',') { |
| 408 | next(ls); /* skip comma */ | 407 | next(ls); /* skip comma */ |
| 409 | luaK_exp2nextreg(ls->fs, v); | 408 | luaK_exp2nextreg(ls->fs, v); |
| 410 | expr(ls, v); | 409 | expr(ls, v); |
| @@ -419,21 +418,21 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
| 419 | expdesc args; | 418 | expdesc args; |
| 420 | int base, nparams; | 419 | int base, nparams; |
| 421 | switch (ls->t.token) { | 420 | switch (ls->t.token) { |
| 422 | case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */ | 421 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ |
| 423 | int line = ls->linenumber; | 422 | int line = ls->linenumber; |
| 424 | if (line != ls->lastline) | 423 | if (line != ls->lastline) |
| 425 | luaK_error(ls, l_s("ambiguous syntax (function call x new statement)")); | 424 | luaK_error(ls, "ambiguous syntax (function call x new statement)"); |
| 426 | next(ls); | 425 | next(ls); |
| 427 | if (ls->t.token == l_c(')')) /* arg list is empty? */ | 426 | if (ls->t.token == ')') /* arg list is empty? */ |
| 428 | args.k = VVOID; | 427 | args.k = VVOID; |
| 429 | else { | 428 | else { |
| 430 | explist1(ls, &args); | 429 | explist1(ls, &args); |
| 431 | luaK_setcallreturns(fs, &args, LUA_MULTRET); | 430 | luaK_setcallreturns(fs, &args, LUA_MULTRET); |
| 432 | } | 431 | } |
| 433 | check_match(ls, l_c(')'), l_c('('), line); | 432 | check_match(ls, ')', '(', line); |
| 434 | break; | 433 | break; |
| 435 | } | 434 | } |
| 436 | case l_c('{'): { /* funcargs -> constructor */ | 435 | case '{': { /* funcargs -> constructor */ |
| 437 | constructor(ls, &args); | 436 | constructor(ls, &args); |
| 438 | break; | 437 | break; |
| 439 | } | 438 | } |
| @@ -443,7 +442,7 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
| 443 | break; | 442 | break; |
| 444 | } | 443 | } |
| 445 | default: { | 444 | default: { |
| 446 | luaK_error(ls, l_s("function arguments expected")); | 445 | luaK_error(ls, "function arguments expected"); |
| 447 | break; | 446 | break; |
| 448 | } | 447 | } |
| 449 | } | 448 | } |
| @@ -480,13 +479,13 @@ static void recfield (LexState *ls, expdesc *t) { | |||
| 480 | checkname(ls, &key); | 479 | checkname(ls, &key); |
| 481 | break; | 480 | break; |
| 482 | } | 481 | } |
| 483 | case l_c('['): { | 482 | case '[': { |
| 484 | luaY_index(ls, &key); | 483 | luaY_index(ls, &key); |
| 485 | break; | 484 | break; |
| 486 | } | 485 | } |
| 487 | default: luaK_error(ls, l_s("<name> or `[' expected")); | 486 | default: luaK_error(ls, "<name> or `[' expected"); |
| 488 | } | 487 | } |
| 489 | check(ls, l_c('=')); | 488 | check(ls, '='); |
| 490 | luaK_exp2RK(fs, &key); | 489 | luaK_exp2RK(fs, &key); |
| 491 | expr(ls, &val); | 490 | expr(ls, &val); |
| 492 | luaK_exp2anyreg(fs, &val); | 491 | luaK_exp2anyreg(fs, &val); |
| @@ -497,9 +496,9 @@ static void recfield (LexState *ls, expdesc *t) { | |||
| 497 | 496 | ||
| 498 | 497 | ||
| 499 | static int anotherfield (LexState *ls) { | 498 | static int anotherfield (LexState *ls) { |
| 500 | if (ls->t.token != l_c(',')) return 0; | 499 | if (ls->t.token != ',') return 0; |
| 501 | next(ls); /* skip the comma */ | 500 | next(ls); /* skip the comma */ |
| 502 | return (ls->t.token != l_c(';') && ls->t.token != l_c('}')); | 501 | return (ls->t.token != ';' && ls->t.token != '}'); |
| 503 | } | 502 | } |
| 504 | 503 | ||
| 505 | 504 | ||
| @@ -508,7 +507,7 @@ static int recfields (LexState *ls, expdesc *t) { | |||
| 508 | int n = 0; | 507 | int n = 0; |
| 509 | do { /* at least one element */ | 508 | do { /* at least one element */ |
| 510 | recfield(ls, t); | 509 | recfield(ls, t); |
| 511 | luaX_checklimit(ls, n, MAX_INT, l_s("items in a constructor")); | 510 | luaX_checklimit(ls, n, MAX_INT, "items in a constructor"); |
| 512 | n++; | 511 | n++; |
| 513 | } while (anotherfield(ls)); | 512 | } while (anotherfield(ls)); |
| 514 | return n; | 513 | return n; |
| @@ -525,7 +524,7 @@ static int listfields (LexState *ls, expdesc *t) { | |||
| 525 | expr(ls, &v); | 524 | expr(ls, &v); |
| 526 | while (anotherfield(ls)) { | 525 | while (anotherfield(ls)) { |
| 527 | luaK_exp2nextreg(fs, &v); | 526 | luaK_exp2nextreg(fs, &v); |
| 528 | luaX_checklimit(ls, n, MAXARG_Bc, l_s("items in a constructor")); | 527 | luaX_checklimit(ls, n, MAXARG_Bc, "items in a constructor"); |
| 529 | if (n%LFIELDS_PER_FLUSH == 0) { | 528 | if (n%LFIELDS_PER_FLUSH == 0) { |
| 530 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */ | 529 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */ |
| 531 | fs->freereg = reg; /* free registers */ | 530 | fs->freereg = reg; /* free registers */ |
| @@ -548,18 +547,18 @@ static int listfields (LexState *ls, expdesc *t) { | |||
| 548 | 547 | ||
| 549 | static void constructor_part (LexState *ls, expdesc *t, Constdesc *cd) { | 548 | static void constructor_part (LexState *ls, expdesc *t, Constdesc *cd) { |
| 550 | switch (ls->t.token) { | 549 | switch (ls->t.token) { |
| 551 | case l_c(';'): case l_c('}'): { /* constructor_part -> empty */ | 550 | case ';': case '}': { /* constructor_part -> empty */ |
| 552 | cd->narray = cd->nhash = 0; | 551 | cd->narray = cd->nhash = 0; |
| 553 | cd->k = ls->t.token; | 552 | cd->k = ls->t.token; |
| 554 | break; | 553 | break; |
| 555 | } | 554 | } |
| 556 | case TK_NAME: { /* may be listfields or recfields */ | 555 | case TK_NAME: { /* may be listfields or recfields */ |
| 557 | lookahead(ls); | 556 | lookahead(ls); |
| 558 | if (ls->lookahead.token != l_c('=')) /* expression? */ | 557 | if (ls->lookahead.token != '=') /* expression? */ |
| 559 | goto case_default; | 558 | goto case_default; |
| 560 | /* else go through to recfields */ | 559 | /* else go through to recfields */ |
| 561 | } | 560 | } |
| 562 | case l_c('['): { /* constructor_part -> recfields */ | 561 | case '[': { /* constructor_part -> recfields */ |
| 563 | cd->nhash = recfields(ls, t); | 562 | cd->nhash = recfields(ls, t); |
| 564 | cd->narray = 0; | 563 | cd->narray = 0; |
| 565 | cd->k = 1; /* record */ | 564 | cd->k = 1; /* record */ |
| @@ -586,18 +585,18 @@ static void constructor (LexState *ls, expdesc *t) { | |||
| 586 | pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); | 585 | pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); |
| 587 | init_exp(t, VRELOCABLE, pc); | 586 | init_exp(t, VRELOCABLE, pc); |
| 588 | luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ | 587 | luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ |
| 589 | check(ls, l_c('{')); | 588 | check(ls, '{'); |
| 590 | constructor_part(ls, t, &cd); | 589 | constructor_part(ls, t, &cd); |
| 591 | na = cd.narray; | 590 | na = cd.narray; |
| 592 | nh = cd.nhash; | 591 | nh = cd.nhash; |
| 593 | if (optional(ls, l_c(';'))) { | 592 | if (optional(ls, ';')) { |
| 594 | Constdesc other_cd; | 593 | Constdesc other_cd; |
| 595 | constructor_part(ls, t, &other_cd); | 594 | constructor_part(ls, t, &other_cd); |
| 596 | check_condition(ls,(cd.k != other_cd.k), l_s("invalid constructor syntax")); | 595 | check_condition(ls,(cd.k != other_cd.k), "invalid constructor syntax"); |
| 597 | na += other_cd.narray; | 596 | na += other_cd.narray; |
| 598 | nh += other_cd.nhash; | 597 | nh += other_cd.nhash; |
| 599 | } | 598 | } |
| 600 | check_match(ls, l_c('}'), l_c('{'), line); | 599 | check_match(ls, '}', '{', line); |
| 601 | if (na > 0) | 600 | if (na > 0) |
| 602 | SETARG_B(fs->f->code[pc], luaO_log2(na-1)+2); /* set initial table size */ | 601 | SETARG_B(fs->f->code[pc], luaO_log2(na-1)+2); /* set initial table size */ |
| 603 | SETARG_C(fs->f->code[pc], luaO_log2(nh)+1); /* set initial table size */ | 602 | SETARG_C(fs->f->code[pc], luaO_log2(nh)+1); /* set initial table size */ |
| @@ -618,10 +617,10 @@ static void constructor (LexState *ls, expdesc *t) { | |||
| 618 | static void prefixexp (LexState *ls, expdesc *v) { | 617 | static void prefixexp (LexState *ls, expdesc *v) { |
| 619 | /* prefixexp -> NAME | '(' expr ')' */ | 618 | /* prefixexp -> NAME | '(' expr ')' */ |
| 620 | switch (ls->t.token) { | 619 | switch (ls->t.token) { |
| 621 | case l_c('('): { | 620 | case '(': { |
| 622 | next(ls); | 621 | next(ls); |
| 623 | expr(ls, v); | 622 | expr(ls, v); |
| 624 | check(ls, l_c(')')); | 623 | check(ls, ')'); |
| 625 | luaK_dischargevars(ls->fs, v); | 624 | luaK_dischargevars(ls->fs, v); |
| 626 | return; | 625 | return; |
| 627 | } | 626 | } |
| @@ -630,15 +629,15 @@ static void prefixexp (LexState *ls, expdesc *v) { | |||
| 630 | next(ls); | 629 | next(ls); |
| 631 | return; | 630 | return; |
| 632 | } | 631 | } |
| 633 | case l_c('%'): { /* for compatibility only */ | 632 | case '%': { /* for compatibility only */ |
| 634 | next(ls); /* skip `%' */ | 633 | next(ls); /* skip `%' */ |
| 635 | singlevar(ls->fs, str_checkname(ls), v, 1); | 634 | singlevar(ls->fs, str_checkname(ls), v, 1); |
| 636 | check_condition(ls, v->k == VUPVAL, l_s("global upvalues are obsolete")); | 635 | check_condition(ls, v->k == VUPVAL, "global upvalues are obsolete"); |
| 637 | next(ls); | 636 | next(ls); |
| 638 | return; | 637 | return; |
| 639 | } | 638 | } |
| 640 | default: { | 639 | default: { |
| 641 | luaK_error(ls, l_s("unexpected symbol")); | 640 | luaK_error(ls, "unexpected symbol"); |
| 642 | return; | 641 | return; |
| 643 | } | 642 | } |
| 644 | } | 643 | } |
| @@ -652,18 +651,18 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
| 652 | prefixexp(ls, v); | 651 | prefixexp(ls, v); |
| 653 | for (;;) { | 652 | for (;;) { |
| 654 | switch (ls->t.token) { | 653 | switch (ls->t.token) { |
| 655 | case l_c('.'): { /* field */ | 654 | case '.': { /* field */ |
| 656 | luaY_field(ls, v); | 655 | luaY_field(ls, v); |
| 657 | break; | 656 | break; |
| 658 | } | 657 | } |
| 659 | case l_c('['): { /* `[' exp1 `]' */ | 658 | case '[': { /* `[' exp1 `]' */ |
| 660 | expdesc key; | 659 | expdesc key; |
| 661 | luaK_exp2anyreg(fs, v); | 660 | luaK_exp2anyreg(fs, v); |
| 662 | luaY_index(ls, &key); | 661 | luaY_index(ls, &key); |
| 663 | luaK_indexed(fs, v, &key); | 662 | luaK_indexed(fs, v, &key); |
| 664 | break; | 663 | break; |
| 665 | } | 664 | } |
| 666 | case l_c(':'): { /* `:' NAME funcargs */ | 665 | case ':': { /* `:' NAME funcargs */ |
| 667 | expdesc key; | 666 | expdesc key; |
| 668 | next(ls); | 667 | next(ls); |
| 669 | checkname(ls, &key); | 668 | checkname(ls, &key); |
| @@ -671,7 +670,7 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
| 671 | funcargs(ls, v); | 670 | funcargs(ls, v); |
| 672 | break; | 671 | break; |
| 673 | } | 672 | } |
| 674 | case l_c('('): case TK_STRING: case l_c('{'): { /* funcargs */ | 673 | case '(': case TK_STRING: case '{': { /* funcargs */ |
| 675 | luaK_exp2nextreg(fs, v); | 674 | luaK_exp2nextreg(fs, v); |
| 676 | funcargs(ls, v); | 675 | funcargs(ls, v); |
| 677 | break; | 676 | break; |
| @@ -702,7 +701,7 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
| 702 | next(ls); | 701 | next(ls); |
| 703 | break; | 702 | break; |
| 704 | } | 703 | } |
| 705 | case l_c('{'): { /* constructor */ | 704 | case '{': { /* constructor */ |
| 706 | constructor(ls, v); | 705 | constructor(ls, v); |
| 707 | break; | 706 | break; |
| 708 | } | 707 | } |
| @@ -724,7 +723,7 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
| 724 | static UnOpr getunopr (int op) { | 723 | static UnOpr getunopr (int op) { |
| 725 | switch (op) { | 724 | switch (op) { |
| 726 | case TK_NOT: return OPR_NOT; | 725 | case TK_NOT: return OPR_NOT; |
| 727 | case l_c('-'): return OPR_MINUS; | 726 | case '-': return OPR_MINUS; |
| 728 | default: return OPR_NOUNOPR; | 727 | default: return OPR_NOUNOPR; |
| 729 | } | 728 | } |
| 730 | } | 729 | } |
| @@ -732,17 +731,17 @@ static UnOpr getunopr (int op) { | |||
| 732 | 731 | ||
| 733 | static BinOpr getbinopr (int op) { | 732 | static BinOpr getbinopr (int op) { |
| 734 | switch (op) { | 733 | switch (op) { |
| 735 | case l_c('+'): return OPR_ADD; | 734 | case '+': return OPR_ADD; |
| 736 | case l_c('-'): return OPR_SUB; | 735 | case '-': return OPR_SUB; |
| 737 | case l_c('*'): return OPR_MULT; | 736 | case '*': return OPR_MULT; |
| 738 | case l_c('/'): return OPR_DIV; | 737 | case '/': return OPR_DIV; |
| 739 | case l_c('^'): return OPR_POW; | 738 | case '^': return OPR_POW; |
| 740 | case TK_CONCAT: return OPR_CONCAT; | 739 | case TK_CONCAT: return OPR_CONCAT; |
| 741 | case TK_NE: return OPR_NE; | 740 | case TK_NE: return OPR_NE; |
| 742 | case TK_EQ: return OPR_EQ; | 741 | case TK_EQ: return OPR_EQ; |
| 743 | case l_c('<'): return OPR_LT; | 742 | case '<': return OPR_LT; |
| 744 | case TK_LE: return OPR_LE; | 743 | case TK_LE: return OPR_LE; |
| 745 | case l_c('>'): return OPR_GT; | 744 | case '>': return OPR_GT; |
| 746 | case TK_GE: return OPR_GE; | 745 | case TK_GE: return OPR_GE; |
| 747 | case TK_AND: return OPR_AND; | 746 | case TK_AND: return OPR_AND; |
| 748 | case TK_OR: return OPR_OR; | 747 | case TK_OR: return OPR_OR; |
| @@ -870,8 +869,8 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { | |||
| 870 | static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { | 869 | static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { |
| 871 | expdesc e; | 870 | expdesc e; |
| 872 | check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, | 871 | check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, |
| 873 | l_s("syntax error!")); | 872 | "syntax error!"); |
| 874 | if (ls->t.token == l_c(',')) { /* assignment -> `,' primaryexp assignment */ | 873 | if (ls->t.token == ',') { /* assignment -> `,' primaryexp assignment */ |
| 875 | struct LHS_assign nv; | 874 | struct LHS_assign nv; |
| 876 | nv.prev = lh; | 875 | nv.prev = lh; |
| 877 | next(ls); | 876 | next(ls); |
| @@ -882,7 +881,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { | |||
| 882 | } | 881 | } |
| 883 | else { /* assignment -> `=' explist1 */ | 882 | else { /* assignment -> `=' explist1 */ |
| 884 | int nexps; | 883 | int nexps; |
| 885 | check(ls, l_c('=')); | 884 | check(ls, '='); |
| 886 | nexps = explist1(ls, &e); | 885 | nexps = explist1(ls, &e); |
| 887 | if (nexps != nvars) { | 886 | if (nexps != nvars) { |
| 888 | adjust_assign(ls, nvars, nexps, &e); | 887 | adjust_assign(ls, nvars, nexps, &e); |
| @@ -965,19 +964,19 @@ static void forbody (LexState *ls, int nvar, OpCode prepfor, OpCode loopfor) { | |||
| 965 | static void fornum (LexState *ls, TString *varname) { | 964 | static void fornum (LexState *ls, TString *varname) { |
| 966 | /* fornum -> NAME = exp1,exp1[,exp1] forbody */ | 965 | /* fornum -> NAME = exp1,exp1[,exp1] forbody */ |
| 967 | FuncState *fs = ls->fs; | 966 | FuncState *fs = ls->fs; |
| 968 | check(ls, l_c('=')); | 967 | check(ls, '='); |
| 969 | exp1(ls); /* initial value */ | 968 | exp1(ls); /* initial value */ |
| 970 | check(ls, l_c(',')); | 969 | check(ls, ','); |
| 971 | exp1(ls); /* limit */ | 970 | exp1(ls); /* limit */ |
| 972 | if (optional(ls, l_c(','))) | 971 | if (optional(ls, ',')) |
| 973 | exp1(ls); /* optional step */ | 972 | exp1(ls); /* optional step */ |
| 974 | else { | 973 | else { |
| 975 | luaK_codeAsBc(fs, OP_LOADINT, fs->freereg, 1); /* default step */ | 974 | luaK_codeAsBc(fs, OP_LOADINT, fs->freereg, 1); /* default step */ |
| 976 | luaK_reserveregs(fs, 1); | 975 | luaK_reserveregs(fs, 1); |
| 977 | } | 976 | } |
| 978 | new_localvar(ls, varname, 0); | 977 | new_localvar(ls, varname, 0); |
| 979 | new_localvarstr(ls, l_s("(limit)"), 1); | 978 | new_localvarstr(ls, "(limit)", 1); |
| 980 | new_localvarstr(ls, l_s("(step)"), 2); | 979 | new_localvarstr(ls, "(step)", 2); |
| 981 | forbody(ls, 3, OP_FORPREP, OP_FORLOOP); | 980 | forbody(ls, 3, OP_FORPREP, OP_FORLOOP); |
| 982 | } | 981 | } |
| 983 | 982 | ||
| @@ -985,13 +984,13 @@ static void fornum (LexState *ls, TString *varname) { | |||
| 985 | static void forlist (LexState *ls, TString *indexname) { | 984 | static void forlist (LexState *ls, TString *indexname) { |
| 986 | /* forlist -> NAME,NAME IN exp1 forbody */ | 985 | /* forlist -> NAME,NAME IN exp1 forbody */ |
| 987 | TString *valname; | 986 | TString *valname; |
| 988 | check(ls, l_c(',')); | 987 | check(ls, ','); |
| 989 | valname = str_checkname(ls); | 988 | valname = str_checkname(ls); |
| 990 | next(ls); /* skip var name */ | 989 | next(ls); /* skip var name */ |
| 991 | check(ls, TK_IN); | 990 | check(ls, TK_IN); |
| 992 | exp1(ls); /* table */ | 991 | exp1(ls); /* table */ |
| 993 | new_localvarstr(ls, l_s("(table)"), 0); | 992 | new_localvarstr(ls, "(table)", 0); |
| 994 | new_localvarstr(ls, l_s("(index)"), 1); | 993 | new_localvarstr(ls, "(index)", 1); |
| 995 | new_localvar(ls, indexname, 2); | 994 | new_localvar(ls, indexname, 2); |
| 996 | new_localvar(ls, valname, 3); | 995 | new_localvar(ls, valname, 3); |
| 997 | luaK_reserveregs(ls->fs, 3); /* registers for control, index and val */ | 996 | luaK_reserveregs(ls->fs, 3); /* registers for control, index and val */ |
| @@ -1009,9 +1008,9 @@ static void forstat (LexState *ls, int line) { | |||
| 1009 | varname = str_checkname(ls); /* first variable name */ | 1008 | varname = str_checkname(ls); /* first variable name */ |
| 1010 | next(ls); /* skip var name */ | 1009 | next(ls); /* skip var name */ |
| 1011 | switch (ls->t.token) { | 1010 | switch (ls->t.token) { |
| 1012 | case l_c('='): fornum(ls, varname); break; | 1011 | case '=': fornum(ls, varname); break; |
| 1013 | case l_c(','): forlist(ls, varname); break; | 1012 | case ',': forlist(ls, varname); break; |
| 1014 | default: luaK_error(ls, l_s("`=' or `,' expected")); | 1013 | default: luaK_error(ls, "`=' or `,' expected"); |
| 1015 | } | 1014 | } |
| 1016 | check_match(ls, TK_END, TK_FOR, line); | 1015 | check_match(ls, TK_END, TK_FOR, line); |
| 1017 | leavebreak(fs, &bl); | 1016 | leavebreak(fs, &bl); |
| @@ -1060,8 +1059,8 @@ static void localstat (LexState *ls) { | |||
| 1060 | next(ls); /* skip LOCAL or `,' */ | 1059 | next(ls); /* skip LOCAL or `,' */ |
| 1061 | new_localvar(ls, str_checkname(ls), nvars++); | 1060 | new_localvar(ls, str_checkname(ls), nvars++); |
| 1062 | next(ls); /* skip var name */ | 1061 | next(ls); /* skip var name */ |
| 1063 | } while (ls->t.token == l_c(',')); | 1062 | } while (ls->t.token == ','); |
| 1064 | if (optional(ls, l_c('='))) | 1063 | if (optional(ls, '=')) |
| 1065 | nexps = explist1(ls, &e); | 1064 | nexps = explist1(ls, &e); |
| 1066 | else { | 1065 | else { |
| 1067 | e.k = VVOID; | 1066 | e.k = VVOID; |
| @@ -1077,10 +1076,10 @@ static int funcname (LexState *ls, expdesc *v) { | |||
| 1077 | int needself = 0; | 1076 | int needself = 0; |
| 1078 | singlevar(ls->fs, str_checkname(ls), v, 1); | 1077 | singlevar(ls->fs, str_checkname(ls), v, 1); |
| 1079 | next(ls); /* skip var name */ | 1078 | next(ls); /* skip var name */ |
| 1080 | while (ls->t.token == l_c('.')) { | 1079 | while (ls->t.token == '.') { |
| 1081 | luaY_field(ls, v); | 1080 | luaY_field(ls, v); |
| 1082 | } | 1081 | } |
| 1083 | if (ls->t.token == l_c(':')) { | 1082 | if (ls->t.token == ':') { |
| 1084 | needself = 1; | 1083 | needself = 1; |
| 1085 | luaY_field(ls, v); | 1084 | luaY_field(ls, v); |
| 1086 | } | 1085 | } |
| @@ -1120,7 +1119,7 @@ static void retstat (LexState *ls) { | |||
| 1120 | expdesc e; | 1119 | expdesc e; |
| 1121 | int first, nret; /* registers with returned values */ | 1120 | int first, nret; /* registers with returned values */ |
| 1122 | next(ls); /* skip RETURN */ | 1121 | next(ls); /* skip RETURN */ |
| 1123 | if (block_follow(ls->t.token) || ls->t.token == l_c(';')) | 1122 | if (block_follow(ls->t.token) || ls->t.token == ';') |
| 1124 | first = nret = 0; /* return no values */ | 1123 | first = nret = 0; /* return no values */ |
| 1125 | else { | 1124 | else { |
| 1126 | explist1(ls, &e); /* optional return values */ | 1125 | explist1(ls, &e); /* optional return values */ |
| @@ -1145,7 +1144,7 @@ static void breakstat (LexState *ls) { | |||
| 1145 | FuncState *fs = ls->fs; | 1144 | FuncState *fs = ls->fs; |
| 1146 | Breaklabel *bl = fs->bl; | 1145 | Breaklabel *bl = fs->bl; |
| 1147 | if (!bl) | 1146 | if (!bl) |
| 1148 | luaK_error(ls, l_s("no loop to break")); | 1147 | luaK_error(ls, "no loop to break"); |
| 1149 | next(ls); /* skip BREAK */ | 1148 | next(ls); /* skip BREAK */ |
| 1150 | closelevel(ls, bl->nactloc); | 1149 | closelevel(ls, bl->nactloc); |
| 1151 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); | 1150 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); |
| @@ -1205,15 +1204,15 @@ static void parlist (LexState *ls) { | |||
| 1205 | /* parlist -> [ param { `,' param } ] */ | 1204 | /* parlist -> [ param { `,' param } ] */ |
| 1206 | int nparams = 0; | 1205 | int nparams = 0; |
| 1207 | short dots = 0; | 1206 | short dots = 0; |
| 1208 | if (ls->t.token != l_c(')')) { /* is `parlist' not empty? */ | 1207 | if (ls->t.token != ')') { /* is `parlist' not empty? */ |
| 1209 | do { | 1208 | do { |
| 1210 | switch (ls->t.token) { | 1209 | switch (ls->t.token) { |
| 1211 | case TK_DOTS: dots = 1; break; | 1210 | case TK_DOTS: dots = 1; break; |
| 1212 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; | 1211 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; |
| 1213 | default: luaK_error(ls, l_s("<name> or `...' expected")); | 1212 | default: luaK_error(ls, "<name> or `...' expected"); |
| 1214 | } | 1213 | } |
| 1215 | next(ls); | 1214 | next(ls); |
| 1216 | } while (!dots && optional(ls, l_c(','))); | 1215 | } while (!dots && optional(ls, ',')); |
| 1217 | } | 1216 | } |
| 1218 | code_params(ls, nparams, dots); | 1217 | code_params(ls, nparams, dots); |
| 1219 | } | 1218 | } |
| @@ -1224,13 +1223,13 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { | |||
| 1224 | FuncState new_fs; | 1223 | FuncState new_fs; |
| 1225 | open_func(ls, &new_fs); | 1224 | open_func(ls, &new_fs); |
| 1226 | new_fs.f->lineDefined = line; | 1225 | new_fs.f->lineDefined = line; |
| 1227 | check(ls, l_c('(')); | 1226 | check(ls, '('); |
| 1228 | if (needself) { | 1227 | if (needself) { |
| 1229 | new_localvarstr(ls, l_s("self"), 0); | 1228 | new_localvarstr(ls, "self", 0); |
| 1230 | adjustlocalvars(ls, 1); | 1229 | adjustlocalvars(ls, 1); |
| 1231 | } | 1230 | } |
| 1232 | parlist(ls); | 1231 | parlist(ls); |
| 1233 | check(ls, l_c(')')); | 1232 | check(ls, ')'); |
| 1234 | chunk(ls); | 1233 | chunk(ls); |
| 1235 | check_match(ls, TK_END, TK_FUNCTION, line); | 1234 | check_match(ls, TK_END, TK_FUNCTION, line); |
| 1236 | close_func(ls); | 1235 | close_func(ls); |
| @@ -1246,7 +1245,7 @@ static void chunk (LexState *ls) { | |||
| 1246 | int islast = 0; | 1245 | int islast = 0; |
| 1247 | while (!islast && !block_follow(ls->t.token)) { | 1246 | while (!islast && !block_follow(ls->t.token)) { |
| 1248 | islast = statement(ls); | 1247 | islast = statement(ls); |
| 1249 | optional(ls, l_c(';')); | 1248 | optional(ls, ';'); |
| 1250 | lua_assert(ls->fs->freereg >= ls->fs->nactloc); | 1249 | lua_assert(ls->fs->freereg >= ls->fs->nactloc); |
| 1251 | ls->fs->freereg = ls->fs->nactloc; /* free registers */ | 1250 | ls->fs->freereg = ls->fs->nactloc; /* free registers */ |
| 1252 | } | 1251 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 1.71 2001/10/31 19:58:11 roberto Exp $ | 2 | ** $Id: lstate.c,v 1.72 2001/11/06 21:40:51 roberto Exp $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "ldo.h" | 12 | #include "ldo.h" |
| @@ -120,7 +119,7 @@ static void close_state (lua_State *L, lua_State *OL) { | |||
| 120 | lua_assert(G(L)->roottable == NULL); | 119 | lua_assert(G(L)->roottable == NULL); |
| 121 | luaS_freeall(L); | 120 | luaS_freeall(L); |
| 122 | luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM); | 121 | luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM); |
| 123 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, l_char); | 122 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); |
| 124 | luaM_freelem(NULL, L->_G); | 123 | luaM_freelem(NULL, L->_G); |
| 125 | } | 124 | } |
| 126 | luaM_freearray(OL, L->stack, L->stacksize, TObject); | 125 | luaM_freearray(OL, L->stack, L->stacksize, TObject); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.66 2001/08/27 15:16:28 roberto Exp $ | 2 | ** $Id: lstring.c,v 1.67 2001/08/31 19:46:07 roberto Exp $ |
| 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 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "lmem.h" | 12 | #include "lmem.h" |
| @@ -47,15 +46,15 @@ void luaS_resize (lua_State *L, int newsize) { | |||
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | 48 | ||
| 50 | static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) { | 49 | static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { |
| 51 | TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); | 50 | TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); |
| 52 | stringtable *tb; | 51 | stringtable *tb; |
| 53 | ts->tsv.nexthash = NULL; | 52 | ts->tsv.nexthash = NULL; |
| 54 | ts->tsv.len = l; | 53 | ts->tsv.len = l; |
| 55 | ts->tsv.hash = h; | 54 | ts->tsv.hash = h; |
| 56 | ts->tsv.marked = 0; | 55 | ts->tsv.marked = 0; |
| 57 | memcpy(getstr(ts), str, l*sizeof(l_char)); | 56 | memcpy(getstr(ts), str, l*sizeof(char)); |
| 58 | getstr(ts)[l] = l_c('\0'); /* ending 0 */ | 57 | getstr(ts)[l] = '\0'; /* ending 0 */ |
| 59 | tb = &G(L)->strt; | 58 | tb = &G(L)->strt; |
| 60 | h = lmod(h, tb->size); | 59 | h = lmod(h, tb->size); |
| 61 | ts->tsv.nexthash = tb->hash[h]; /* chain new entry */ | 60 | ts->tsv.nexthash = tb->hash[h]; /* chain new entry */ |
| @@ -67,13 +66,13 @@ static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) { | |||
| 67 | } | 66 | } |
| 68 | 67 | ||
| 69 | 68 | ||
| 70 | TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) { | 69 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
| 71 | TString *ts; | 70 | TString *ts; |
| 72 | lu_hash h = l; /* seed */ | 71 | lu_hash h = l; /* seed */ |
| 73 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 72 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
| 74 | size_t l1; | 73 | size_t l1; |
| 75 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 74 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
| 76 | h = h ^ ((h<<5)+(h>>2)+uchar(str[l1-1])); | 75 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1])); |
| 77 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; | 76 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; |
| 78 | ts != NULL; | 77 | ts != NULL; |
| 79 | ts = ts->tsv.nexthash) { | 78 | ts = ts->tsv.nexthash) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.h,v 1.33 2001/06/15 20:36:57 roberto Exp $ | 2 | ** $Id: lstring.h,v 1.34 2001/08/31 19:46:07 roberto Exp $ |
| 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 | */ |
| @@ -22,18 +22,18 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | #define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ | 24 | #define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ |
| 25 | (cast(lu_mem, l)+1)*sizeof(l_char)) | 25 | (cast(lu_mem, l)+1)*sizeof(char)) |
| 26 | 26 | ||
| 27 | #define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) | 27 | #define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) |
| 28 | 28 | ||
| 29 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) | 29 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) |
| 30 | #define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \ | 30 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ |
| 31 | (sizeof(s)/sizeof(l_char))-1)) | 31 | (sizeof(s)/sizeof(char))-1)) |
| 32 | 32 | ||
| 33 | void luaS_resize (lua_State *L, int newsize); | 33 | void luaS_resize (lua_State *L, int newsize); |
| 34 | Udata *luaS_newudata (lua_State *L, size_t s); | 34 | Udata *luaS_newudata (lua_State *L, size_t s); |
| 35 | void luaS_freeall (lua_State *L); | 35 | void luaS_freeall (lua_State *L); |
| 36 | TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l); | 36 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | #endif | 39 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.72 2001/10/16 17:41:43 roberto Exp $ | 2 | ** $Id: lstrlib.c,v 1.73 2001/10/26 17:33:30 roberto Exp $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -11,13 +11,18 @@ | |||
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| 12 | #include <string.h> | 12 | #include <string.h> |
| 13 | 13 | ||
| 14 | #define LUA_PRIVATE | ||
| 15 | #include "lua.h" | 14 | #include "lua.h" |
| 16 | 15 | ||
| 17 | #include "lauxlib.h" | 16 | #include "lauxlib.h" |
| 18 | #include "lualib.h" | 17 | #include "lualib.h" |
| 19 | 18 | ||
| 20 | 19 | ||
| 20 | /* macro to `unsign' a character */ | ||
| 21 | #ifndef uchar | ||
| 22 | #define uchar(c) ((unsigned char)(c)) | ||
| 23 | #endif | ||
| 24 | |||
| 25 | |||
| 21 | typedef long sint32; /* a signed version for size_t */ | 26 | typedef long sint32; /* a signed version for size_t */ |
| 22 | 27 | ||
| 23 | 28 | ||
| @@ -37,14 +42,14 @@ static sint32 posrelat (sint32 pos, size_t len) { | |||
| 37 | 42 | ||
| 38 | static int str_sub (lua_State *L) { | 43 | static int str_sub (lua_State *L) { |
| 39 | size_t l; | 44 | size_t l; |
| 40 | const l_char *s = luaL_check_lstr(L, 1, &l); | 45 | const char *s = luaL_check_lstr(L, 1, &l); |
| 41 | sint32 start = posrelat(luaL_check_long(L, 2), l); | 46 | sint32 start = posrelat(luaL_check_long(L, 2), l); |
| 42 | sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); | 47 | sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); |
| 43 | if (start < 1) start = 1; | 48 | if (start < 1) start = 1; |
| 44 | if (end > (sint32)l) end = l; | 49 | if (end > (sint32)l) end = l; |
| 45 | if (start <= end) | 50 | if (start <= end) |
| 46 | lua_pushlstring(L, s+start-1, end-start+1); | 51 | lua_pushlstring(L, s+start-1, end-start+1); |
| 47 | else lua_pushliteral(L, l_s("")); | 52 | else lua_pushliteral(L, ""); |
| 48 | return 1; | 53 | return 1; |
| 49 | } | 54 | } |
| 50 | 55 | ||
| @@ -53,7 +58,7 @@ static int str_lower (lua_State *L) { | |||
| 53 | size_t l; | 58 | size_t l; |
| 54 | size_t i; | 59 | size_t i; |
| 55 | luaL_Buffer b; | 60 | luaL_Buffer b; |
| 56 | const l_char *s = luaL_check_lstr(L, 1, &l); | 61 | const char *s = luaL_check_lstr(L, 1, &l); |
| 57 | luaL_buffinit(L, &b); | 62 | luaL_buffinit(L, &b); |
| 58 | for (i=0; i<l; i++) | 63 | for (i=0; i<l; i++) |
| 59 | luaL_putchar(&b, tolower(uchar(s[i]))); | 64 | luaL_putchar(&b, tolower(uchar(s[i]))); |
| @@ -66,7 +71,7 @@ static int str_upper (lua_State *L) { | |||
| 66 | size_t l; | 71 | size_t l; |
| 67 | size_t i; | 72 | size_t i; |
| 68 | luaL_Buffer b; | 73 | luaL_Buffer b; |
| 69 | const l_char *s = luaL_check_lstr(L, 1, &l); | 74 | const char *s = luaL_check_lstr(L, 1, &l); |
| 70 | luaL_buffinit(L, &b); | 75 | luaL_buffinit(L, &b); |
| 71 | for (i=0; i<l; i++) | 76 | for (i=0; i<l; i++) |
| 72 | luaL_putchar(&b, toupper(uchar(s[i]))); | 77 | luaL_putchar(&b, toupper(uchar(s[i]))); |
| @@ -77,7 +82,7 @@ static int str_upper (lua_State *L) { | |||
| 77 | static int str_rep (lua_State *L) { | 82 | static int str_rep (lua_State *L) { |
| 78 | size_t l; | 83 | size_t l; |
| 79 | luaL_Buffer b; | 84 | luaL_Buffer b; |
| 80 | const l_char *s = luaL_check_lstr(L, 1, &l); | 85 | const char *s = luaL_check_lstr(L, 1, &l); |
| 81 | int n = luaL_check_int(L, 2); | 86 | int n = luaL_check_int(L, 2); |
| 82 | luaL_buffinit(L, &b); | 87 | luaL_buffinit(L, &b); |
| 83 | while (n-- > 0) | 88 | while (n-- > 0) |
| @@ -108,9 +113,9 @@ static int str_concat (lua_State *L) { | |||
| 108 | 113 | ||
| 109 | static int str_byte (lua_State *L) { | 114 | static int str_byte (lua_State *L) { |
| 110 | size_t l; | 115 | size_t l; |
| 111 | const l_char *s = luaL_check_lstr(L, 1, &l); | 116 | const char *s = luaL_check_lstr(L, 1, &l); |
| 112 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); | 117 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); |
| 113 | luaL_arg_check(L, 0 < pos && (size_t)(pos) <= l, 2, l_s("out of range")); | 118 | luaL_arg_check(L, 0 < pos && (size_t)(pos) <= l, 2, "out of range"); |
| 114 | lua_pushnumber(L, uchar(s[pos-1])); | 119 | lua_pushnumber(L, uchar(s[pos-1])); |
| 115 | return 1; | 120 | return 1; |
| 116 | } | 121 | } |
| @@ -123,7 +128,7 @@ static int str_char (lua_State *L) { | |||
| 123 | luaL_buffinit(L, &b); | 128 | luaL_buffinit(L, &b); |
| 124 | for (i=1; i<=n; i++) { | 129 | for (i=1; i<=n; i++) { |
| 125 | int c = luaL_check_int(L, i); | 130 | int c = luaL_check_int(L, i); |
| 126 | luaL_arg_check(L, uchar(c) == c, i, l_s("invalid value")); | 131 | luaL_arg_check(L, uchar(c) == c, i, "invalid value"); |
| 127 | luaL_putchar(&b, uchar(c)); | 132 | luaL_putchar(&b, uchar(c)); |
| 128 | } | 133 | } |
| 129 | luaL_pushresult(&b); | 134 | luaL_pushresult(&b); |
| @@ -147,25 +152,25 @@ static int str_char (lua_State *L) { | |||
| 147 | #define CAP_POSITION (-2) | 152 | #define CAP_POSITION (-2) |
| 148 | 153 | ||
| 149 | typedef struct MatchState { | 154 | typedef struct MatchState { |
| 150 | const l_char *src_init; /* init of source string */ | 155 | const char *src_init; /* init of source string */ |
| 151 | const l_char *src_end; /* end (`\0') of source string */ | 156 | const char *src_end; /* end (`\0') of source string */ |
| 152 | int level; /* total number of captures (finished or unfinished) */ | 157 | int level; /* total number of captures (finished or unfinished) */ |
| 153 | struct { | 158 | struct { |
| 154 | const l_char *init; | 159 | const char *init; |
| 155 | sint32 len; | 160 | sint32 len; |
| 156 | } capture[MAX_CAPTURES]; | 161 | } capture[MAX_CAPTURES]; |
| 157 | lua_State *L; | 162 | lua_State *L; |
| 158 | } MatchState; | 163 | } MatchState; |
| 159 | 164 | ||
| 160 | 165 | ||
| 161 | #define ESC l_c('%') | 166 | #define ESC '%' |
| 162 | #define SPECIALS l_s("^$*+?.([%-") | 167 | #define SPECIALS "^$*+?.([%-" |
| 163 | 168 | ||
| 164 | 169 | ||
| 165 | static int check_capture (MatchState *ms, int l) { | 170 | static int check_capture (MatchState *ms, int l) { |
| 166 | l -= l_c('1'); | 171 | l -= '1'; |
| 167 | if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) | 172 | if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) |
| 168 | lua_error(ms->L, l_s("invalid capture index")); | 173 | lua_error(ms->L, "invalid capture index"); |
| 169 | return l; | 174 | return l; |
| 170 | } | 175 | } |
| 171 | 176 | ||
| @@ -174,25 +179,25 @@ static int capture_to_close (MatchState *ms) { | |||
| 174 | int level = ms->level; | 179 | int level = ms->level; |
| 175 | for (level--; level>=0; level--) | 180 | for (level--; level>=0; level--) |
| 176 | if (ms->capture[level].len == CAP_UNFINISHED) return level; | 181 | if (ms->capture[level].len == CAP_UNFINISHED) return level; |
| 177 | lua_error(ms->L, l_s("invalid pattern capture")); | 182 | lua_error(ms->L, "invalid pattern capture"); |
| 178 | return 0; /* to avoid warnings */ | 183 | return 0; /* to avoid warnings */ |
| 179 | } | 184 | } |
| 180 | 185 | ||
| 181 | 186 | ||
| 182 | static const l_char *luaI_classend (MatchState *ms, const l_char *p) { | 187 | static const char *luaI_classend (MatchState *ms, const char *p) { |
| 183 | switch (*p++) { | 188 | switch (*p++) { |
| 184 | case ESC: | 189 | case ESC: |
| 185 | if (*p == l_c('\0')) | 190 | if (*p == '\0') |
| 186 | lua_error(ms->L, l_s("malformed pattern (ends with `%')")); | 191 | lua_error(ms->L, "malformed pattern (ends with `%')"); |
| 187 | return p+1; | 192 | return p+1; |
| 188 | case l_c('['): | 193 | case '[': |
| 189 | if (*p == l_c('^')) p++; | 194 | if (*p == '^') p++; |
| 190 | do { /* look for a `]' */ | 195 | do { /* look for a `]' */ |
| 191 | if (*p == l_c('\0')) | 196 | if (*p == '\0') |
| 192 | lua_error(ms->L, l_s("malformed pattern (missing `]')")); | 197 | lua_error(ms->L, "malformed pattern (missing `]')"); |
| 193 | if (*(p++) == ESC && *p != l_c('\0')) | 198 | if (*(p++) == ESC && *p != '\0') |
| 194 | p++; /* skip escapes (e.g. `%]') */ | 199 | p++; /* skip escapes (e.g. `%]') */ |
| 195 | } while (*p != l_c(']')); | 200 | } while (*p != ']'); |
| 196 | return p+1; | 201 | return p+1; |
| 197 | default: | 202 | default: |
| 198 | return p; | 203 | return p; |
| @@ -200,28 +205,28 @@ static const l_char *luaI_classend (MatchState *ms, const l_char *p) { | |||
| 200 | } | 205 | } |
| 201 | 206 | ||
| 202 | 207 | ||
| 203 | static int match_class (l_charint c, l_charint cl) { | 208 | static int match_class (int c, int cl) { |
| 204 | int res; | 209 | int res; |
| 205 | switch (tolower(cl)) { | 210 | switch (tolower(cl)) { |
| 206 | case l_c('a') : res = isalpha(c); break; | 211 | case 'a' : res = isalpha(c); break; |
| 207 | case l_c('c') : res = iscntrl(c); break; | 212 | case 'c' : res = iscntrl(c); break; |
| 208 | case l_c('d') : res = isdigit(c); break; | 213 | case 'd' : res = isdigit(c); break; |
| 209 | case l_c('l') : res = islower(c); break; | 214 | case 'l' : res = islower(c); break; |
| 210 | case l_c('p') : res = ispunct(c); break; | 215 | case 'p' : res = ispunct(c); break; |
| 211 | case l_c('s') : res = isspace(c); break; | 216 | case 's' : res = isspace(c); break; |
| 212 | case l_c('u') : res = isupper(c); break; | 217 | case 'u' : res = isupper(c); break; |
| 213 | case l_c('w') : res = isalnum(c); break; | 218 | case 'w' : res = isalnum(c); break; |
| 214 | case l_c('x') : res = isxdigit(c); break; | 219 | case 'x' : res = isxdigit(c); break; |
| 215 | case l_c('z') : res = (c == 0); break; | 220 | case 'z' : res = (c == 0); break; |
| 216 | default: return (cl == c); | 221 | default: return (cl == c); |
| 217 | } | 222 | } |
| 218 | return (islower(cl) ? res : !res); | 223 | return (islower(cl) ? res : !res); |
| 219 | } | 224 | } |
| 220 | 225 | ||
| 221 | 226 | ||
| 222 | static int matchbracketclass (l_charint c, const l_char *p, const l_char *ec) { | 227 | static int matchbracketclass (int c, const char *p, const char *ec) { |
| 223 | int sig = 1; | 228 | int sig = 1; |
| 224 | if (*(p+1) == l_c('^')) { | 229 | if (*(p+1) == '^') { |
| 225 | sig = 0; | 230 | sig = 0; |
| 226 | p++; /* skip the `^' */ | 231 | p++; /* skip the `^' */ |
| 227 | } | 232 | } |
| @@ -231,7 +236,7 @@ static int matchbracketclass (l_charint c, const l_char *p, const l_char *ec) { | |||
| 231 | if (match_class(c, *p)) | 236 | if (match_class(c, *p)) |
| 232 | return sig; | 237 | return sig; |
| 233 | } | 238 | } |
| 234 | else if ((*(p+1) == l_c('-')) && (p+2 < ec)) { | 239 | else if ((*(p+1) == '-') && (p+2 < ec)) { |
| 235 | p+=2; | 240 | p+=2; |
| 236 | if (uchar(*(p-2)) <= c && c <= uchar(*p)) | 241 | if (uchar(*(p-2)) <= c && c <= uchar(*p)) |
| 237 | return sig; | 242 | return sig; |
| @@ -242,13 +247,13 @@ static int matchbracketclass (l_charint c, const l_char *p, const l_char *ec) { | |||
| 242 | } | 247 | } |
| 243 | 248 | ||
| 244 | 249 | ||
| 245 | static int luaI_singlematch (l_charint c, const l_char *p, const l_char *ep) { | 250 | static int luaI_singlematch (int c, const char *p, const char *ep) { |
| 246 | switch (*p) { | 251 | switch (*p) { |
| 247 | case l_c('.'): /* matches any char */ | 252 | case '.': /* matches any char */ |
| 248 | return 1; | 253 | return 1; |
| 249 | case ESC: | 254 | case ESC: |
| 250 | return match_class(c, *(p+1)); | 255 | return match_class(c, *(p+1)); |
| 251 | case l_c('['): | 256 | case '[': |
| 252 | return matchbracketclass(c, p, ep-1); | 257 | return matchbracketclass(c, p, ep-1); |
| 253 | default: | 258 | default: |
| 254 | return (uchar(*p) == c); | 259 | return (uchar(*p) == c); |
| @@ -256,13 +261,13 @@ static int luaI_singlematch (l_charint c, const l_char *p, const l_char *ep) { | |||
| 256 | } | 261 | } |
| 257 | 262 | ||
| 258 | 263 | ||
| 259 | static const l_char *match (MatchState *ms, const l_char *s, const l_char *p); | 264 | static const char *match (MatchState *ms, const char *s, const char *p); |
| 260 | 265 | ||
| 261 | 266 | ||
| 262 | static const l_char *matchbalance (MatchState *ms, const l_char *s, | 267 | static const char *matchbalance (MatchState *ms, const char *s, |
| 263 | const l_char *p) { | 268 | const char *p) { |
| 264 | if (*p == 0 || *(p+1) == 0) | 269 | if (*p == 0 || *(p+1) == 0) |
| 265 | lua_error(ms->L, l_s("unbalanced pattern")); | 270 | lua_error(ms->L, "unbalanced pattern"); |
| 266 | if (*s != *p) return NULL; | 271 | if (*s != *p) return NULL; |
| 267 | else { | 272 | else { |
| 268 | int b = *p; | 273 | int b = *p; |
| @@ -279,14 +284,14 @@ static const l_char *matchbalance (MatchState *ms, const l_char *s, | |||
| 279 | } | 284 | } |
| 280 | 285 | ||
| 281 | 286 | ||
| 282 | static const l_char *max_expand (MatchState *ms, const l_char *s, | 287 | static const char *max_expand (MatchState *ms, const char *s, |
| 283 | const l_char *p, const l_char *ep) { | 288 | const char *p, const char *ep) { |
| 284 | sint32 i = 0; /* counts maximum expand for item */ | 289 | sint32 i = 0; /* counts maximum expand for item */ |
| 285 | while ((s+i)<ms->src_end && luaI_singlematch(uchar(*(s+i)), p, ep)) | 290 | while ((s+i)<ms->src_end && luaI_singlematch(uchar(*(s+i)), p, ep)) |
| 286 | i++; | 291 | i++; |
| 287 | /* keeps trying to match with the maximum repetitions */ | 292 | /* keeps trying to match with the maximum repetitions */ |
| 288 | while (i>=0) { | 293 | while (i>=0) { |
| 289 | const l_char *res = match(ms, (s+i), ep+1); | 294 | const char *res = match(ms, (s+i), ep+1); |
| 290 | if (res) return res; | 295 | if (res) return res; |
| 291 | i--; /* else didn't match; reduce 1 repetition to try again */ | 296 | i--; /* else didn't match; reduce 1 repetition to try again */ |
| 292 | } | 297 | } |
| @@ -294,10 +299,10 @@ static const l_char *max_expand (MatchState *ms, const l_char *s, | |||
| 294 | } | 299 | } |
| 295 | 300 | ||
| 296 | 301 | ||
| 297 | static const l_char *min_expand (MatchState *ms, const l_char *s, | 302 | static const char *min_expand (MatchState *ms, const char *s, |
| 298 | const l_char *p, const l_char *ep) { | 303 | const char *p, const char *ep) { |
| 299 | for (;;) { | 304 | for (;;) { |
| 300 | const l_char *res = match(ms, s, ep+1); | 305 | const char *res = match(ms, s, ep+1); |
| 301 | if (res != NULL) | 306 | if (res != NULL) |
| 302 | return res; | 307 | return res; |
| 303 | else if (s<ms->src_end && luaI_singlematch(uchar(*s), p, ep)) | 308 | else if (s<ms->src_end && luaI_singlematch(uchar(*s), p, ep)) |
| @@ -307,11 +312,11 @@ static const l_char *min_expand (MatchState *ms, const l_char *s, | |||
| 307 | } | 312 | } |
| 308 | 313 | ||
| 309 | 314 | ||
| 310 | static const l_char *start_capture (MatchState *ms, const l_char *s, | 315 | static const char *start_capture (MatchState *ms, const char *s, |
| 311 | const l_char *p, int what) { | 316 | const char *p, int what) { |
| 312 | const l_char *res; | 317 | const char *res; |
| 313 | int level = ms->level; | 318 | int level = ms->level; |
| 314 | if (level >= MAX_CAPTURES) lua_error(ms->L, l_s("too many captures")); | 319 | if (level >= MAX_CAPTURES) lua_error(ms->L, "too many captures"); |
| 315 | ms->capture[level].init = s; | 320 | ms->capture[level].init = s; |
| 316 | ms->capture[level].len = what; | 321 | ms->capture[level].len = what; |
| 317 | ms->level = level+1; | 322 | ms->level = level+1; |
| @@ -321,10 +326,10 @@ static const l_char *start_capture (MatchState *ms, const l_char *s, | |||
| 321 | } | 326 | } |
| 322 | 327 | ||
| 323 | 328 | ||
| 324 | static const l_char *end_capture (MatchState *ms, const l_char *s, | 329 | static const char *end_capture (MatchState *ms, const char *s, |
| 325 | const l_char *p) { | 330 | const char *p) { |
| 326 | int l = capture_to_close(ms); | 331 | int l = capture_to_close(ms); |
| 327 | const l_char *res; | 332 | const char *res; |
| 328 | ms->capture[l].len = s - ms->capture[l].init; /* close capture */ | 333 | ms->capture[l].len = s - ms->capture[l].init; /* close capture */ |
| 329 | if ((res = match(ms, s, p)) == NULL) /* match failed? */ | 334 | if ((res = match(ms, s, p)) == NULL) /* match failed? */ |
| 330 | ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ | 335 | ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ |
| @@ -332,7 +337,7 @@ static const l_char *end_capture (MatchState *ms, const l_char *s, | |||
| 332 | } | 337 | } |
| 333 | 338 | ||
| 334 | 339 | ||
| 335 | static const l_char *match_capture (MatchState *ms, const l_char *s, int l) { | 340 | static const char *match_capture (MatchState *ms, const char *s, int l) { |
| 336 | size_t len; | 341 | size_t len; |
| 337 | l = check_capture(ms, l); | 342 | l = check_capture(ms, l); |
| 338 | len = ms->capture[l].len; | 343 | len = ms->capture[l].len; |
| @@ -343,15 +348,15 @@ static const l_char *match_capture (MatchState *ms, const l_char *s, int l) { | |||
| 343 | } | 348 | } |
| 344 | 349 | ||
| 345 | 350 | ||
| 346 | static const l_char *match (MatchState *ms, const l_char *s, const l_char *p) { | 351 | static const char *match (MatchState *ms, const char *s, const char *p) { |
| 347 | init: /* using goto's to optimize tail recursion */ | 352 | init: /* using goto's to optimize tail recursion */ |
| 348 | switch (*p) { | 353 | switch (*p) { |
| 349 | case l_c('('): /* start capture */ | 354 | case '(': /* start capture */ |
| 350 | if (*(p+1) == l_c(')')) /* position capture? */ | 355 | if (*(p+1) == ')') /* position capture? */ |
| 351 | return start_capture(ms, s, p+2, CAP_POSITION); | 356 | return start_capture(ms, s, p+2, CAP_POSITION); |
| 352 | else | 357 | else |
| 353 | return start_capture(ms, s, p+1, CAP_UNFINISHED); | 358 | return start_capture(ms, s, p+1, CAP_UNFINISHED); |
| 354 | case l_c(')'): /* end capture */ | 359 | case ')': /* end capture */ |
| 355 | return end_capture(ms, s, p+1); | 360 | return end_capture(ms, s, p+1); |
| 356 | case ESC: /* may be %[0-9] or %b */ | 361 | case ESC: /* may be %[0-9] or %b */ |
| 357 | if (isdigit(uchar(*(p+1)))) { /* capture? */ | 362 | if (isdigit(uchar(*(p+1)))) { /* capture? */ |
| @@ -359,33 +364,33 @@ static const l_char *match (MatchState *ms, const l_char *s, const l_char *p) { | |||
| 359 | if (s == NULL) return NULL; | 364 | if (s == NULL) return NULL; |
| 360 | p+=2; goto init; /* else return match(ms, s, p+2) */ | 365 | p+=2; goto init; /* else return match(ms, s, p+2) */ |
| 361 | } | 366 | } |
| 362 | else if (*(p+1) == l_c('b')) { /* balanced string? */ | 367 | else if (*(p+1) == 'b') { /* balanced string? */ |
| 363 | s = matchbalance(ms, s, p+2); | 368 | s = matchbalance(ms, s, p+2); |
| 364 | if (s == NULL) return NULL; | 369 | if (s == NULL) return NULL; |
| 365 | p+=4; goto init; /* else return match(ms, s, p+4); */ | 370 | p+=4; goto init; /* else return match(ms, s, p+4); */ |
| 366 | } | 371 | } |
| 367 | else goto dflt; /* case default */ | 372 | else goto dflt; /* case default */ |
| 368 | case l_c('\0'): /* end of pattern */ | 373 | case '\0': /* end of pattern */ |
| 369 | return s; /* match succeeded */ | 374 | return s; /* match succeeded */ |
| 370 | case l_c('$'): | 375 | case '$': |
| 371 | if (*(p+1) == l_c('\0')) /* is the `$' the last char in pattern? */ | 376 | if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ |
| 372 | return (s == ms->src_end) ? s : NULL; /* check end of string */ | 377 | return (s == ms->src_end) ? s : NULL; /* check end of string */ |
| 373 | else goto dflt; | 378 | else goto dflt; |
| 374 | default: dflt: { /* it is a pattern item */ | 379 | default: dflt: { /* it is a pattern item */ |
| 375 | const l_char *ep = luaI_classend(ms, p); /* points to what is next */ | 380 | const char *ep = luaI_classend(ms, p); /* points to what is next */ |
| 376 | int m = s<ms->src_end && luaI_singlematch(uchar(*s), p, ep); | 381 | int m = s<ms->src_end && luaI_singlematch(uchar(*s), p, ep); |
| 377 | switch (*ep) { | 382 | switch (*ep) { |
| 378 | case l_c('?'): { /* optional */ | 383 | case '?': { /* optional */ |
| 379 | const l_char *res; | 384 | const char *res; |
| 380 | if (m && ((res=match(ms, s+1, ep+1)) != NULL)) | 385 | if (m && ((res=match(ms, s+1, ep+1)) != NULL)) |
| 381 | return res; | 386 | return res; |
| 382 | p=ep+1; goto init; /* else return match(ms, s, ep+1); */ | 387 | p=ep+1; goto init; /* else return match(ms, s, ep+1); */ |
| 383 | } | 388 | } |
| 384 | case l_c('*'): /* 0 or more repetitions */ | 389 | case '*': /* 0 or more repetitions */ |
| 385 | return max_expand(ms, s, p, ep); | 390 | return max_expand(ms, s, p, ep); |
| 386 | case l_c('+'): /* 1 or more repetitions */ | 391 | case '+': /* 1 or more repetitions */ |
| 387 | return (m ? max_expand(ms, s+1, p, ep) : NULL); | 392 | return (m ? max_expand(ms, s+1, p, ep) : NULL); |
| 388 | case l_c('-'): /* 0 or more repetitions (minimum) */ | 393 | case '-': /* 0 or more repetitions (minimum) */ |
| 389 | return min_expand(ms, s, p, ep); | 394 | return min_expand(ms, s, p, ep); |
| 390 | default: | 395 | default: |
| 391 | if (!m) return NULL; | 396 | if (!m) return NULL; |
| @@ -397,15 +402,15 @@ static const l_char *match (MatchState *ms, const l_char *s, const l_char *p) { | |||
| 397 | 402 | ||
| 398 | 403 | ||
| 399 | 404 | ||
| 400 | static const l_char *lmemfind (const l_char *s1, size_t l1, | 405 | static const char *lmemfind (const char *s1, size_t l1, |
| 401 | const l_char *s2, size_t l2) { | 406 | const char *s2, size_t l2) { |
| 402 | if (l2 == 0) return s1; /* empty strings are everywhere */ | 407 | if (l2 == 0) return s1; /* empty strings are everywhere */ |
| 403 | else if (l2 > l1) return NULL; /* avoids a negative `l1' */ | 408 | else if (l2 > l1) return NULL; /* avoids a negative `l1' */ |
| 404 | else { | 409 | else { |
| 405 | const l_char *init; /* to search for a `*s2' inside `s1' */ | 410 | const char *init; /* to search for a `*s2' inside `s1' */ |
| 406 | l2--; /* 1st char will be checked by `memchr' */ | 411 | l2--; /* 1st char will be checked by `memchr' */ |
| 407 | l1 = l1-l2; /* `s2' cannot be found after that */ | 412 | l1 = l1-l2; /* `s2' cannot be found after that */ |
| 408 | while (l1 > 0 && (init = (const l_char *)memchr(s1, *s2, l1)) != NULL) { | 413 | while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { |
| 409 | init++; /* 1st char is already checked */ | 414 | init++; /* 1st char is already checked */ |
| 410 | if (memcmp(init, s2+1, l2) == 0) | 415 | if (memcmp(init, s2+1, l2) == 0) |
| 411 | return init-1; | 416 | return init-1; |
| @@ -421,7 +426,7 @@ static const l_char *lmemfind (const l_char *s1, size_t l1, | |||
| 421 | 426 | ||
| 422 | static void push_onecapture (MatchState *ms, int i) { | 427 | static void push_onecapture (MatchState *ms, int i) { |
| 423 | int l = ms->capture[i].len; | 428 | int l = ms->capture[i].len; |
| 424 | if (l == CAP_UNFINISHED) lua_error(ms->L, l_s("unfinished capture")); | 429 | if (l == CAP_UNFINISHED) lua_error(ms->L, "unfinished capture"); |
| 425 | if (l == CAP_POSITION) | 430 | if (l == CAP_POSITION) |
| 426 | lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); | 431 | lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); |
| 427 | else | 432 | else |
| @@ -431,7 +436,7 @@ static void push_onecapture (MatchState *ms, int i) { | |||
| 431 | 436 | ||
| 432 | static int push_captures (MatchState *ms) { | 437 | static int push_captures (MatchState *ms) { |
| 433 | int i; | 438 | int i; |
| 434 | luaL_check_stack(ms->L, ms->level, l_s("too many captures")); | 439 | luaL_check_stack(ms->L, ms->level, "too many captures"); |
| 435 | for (i=0; i<ms->level; i++) | 440 | for (i=0; i<ms->level; i++) |
| 436 | push_onecapture(ms, i); | 441 | push_onecapture(ms, i); |
| 437 | return ms->level; /* number of strings pushed */ | 442 | return ms->level; /* number of strings pushed */ |
| @@ -440,13 +445,13 @@ static int push_captures (MatchState *ms) { | |||
| 440 | 445 | ||
| 441 | static int str_find (lua_State *L) { | 446 | static int str_find (lua_State *L) { |
| 442 | size_t l1, l2; | 447 | size_t l1, l2; |
| 443 | const l_char *s = luaL_check_lstr(L, 1, &l1); | 448 | const char *s = luaL_check_lstr(L, 1, &l1); |
| 444 | const l_char *p = luaL_check_lstr(L, 2, &l2); | 449 | const char *p = luaL_check_lstr(L, 2, &l2); |
| 445 | sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; | 450 | sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; |
| 446 | luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, l_s("out of range")); | 451 | luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range"); |
| 447 | if (lua_gettop(L) > 3 || /* extra argument? */ | 452 | if (lua_gettop(L) > 3 || /* extra argument? */ |
| 448 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ | 453 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ |
| 449 | const l_char *s2 = lmemfind(s+init, l1-init, p, l2); | 454 | const char *s2 = lmemfind(s+init, l1-init, p, l2); |
| 450 | if (s2) { | 455 | if (s2) { |
| 451 | lua_pushnumber(L, s2-s+1); | 456 | lua_pushnumber(L, s2-s+1); |
| 452 | lua_pushnumber(L, s2-s+l2); | 457 | lua_pushnumber(L, s2-s+l2); |
| @@ -455,13 +460,13 @@ static int str_find (lua_State *L) { | |||
| 455 | } | 460 | } |
| 456 | else { | 461 | else { |
| 457 | MatchState ms; | 462 | MatchState ms; |
| 458 | int anchor = (*p == l_c('^')) ? (p++, 1) : 0; | 463 | int anchor = (*p == '^') ? (p++, 1) : 0; |
| 459 | const l_char *s1=s+init; | 464 | const char *s1=s+init; |
| 460 | ms.L = L; | 465 | ms.L = L; |
| 461 | ms.src_init = s; | 466 | ms.src_init = s; |
| 462 | ms.src_end = s+l1; | 467 | ms.src_end = s+l1; |
| 463 | do { | 468 | do { |
| 464 | const l_char *res; | 469 | const char *res; |
| 465 | ms.level = 0; | 470 | ms.level = 0; |
| 466 | if ((res=match(&ms, s1, p)) != NULL) { | 471 | if ((res=match(&ms, s1, p)) != NULL) { |
| 467 | lua_pushnumber(L, s1-s+1); /* start */ | 472 | lua_pushnumber(L, s1-s+1); /* start */ |
| @@ -478,7 +483,7 @@ static int str_find (lua_State *L) { | |||
| 478 | static void add_s (MatchState *ms, luaL_Buffer *b) { | 483 | static void add_s (MatchState *ms, luaL_Buffer *b) { |
| 479 | lua_State *L = ms->L; | 484 | lua_State *L = ms->L; |
| 480 | if (lua_isstring(L, 3)) { | 485 | if (lua_isstring(L, 3)) { |
| 481 | const l_char *news = lua_tostring(L, 3); | 486 | const char *news = lua_tostring(L, 3); |
| 482 | size_t l = lua_strlen(L, 3); | 487 | size_t l = lua_strlen(L, 3); |
| 483 | size_t i; | 488 | size_t i; |
| 484 | for (i=0; i<l; i++) { | 489 | for (i=0; i<l; i++) { |
| @@ -511,22 +516,22 @@ static void add_s (MatchState *ms, luaL_Buffer *b) { | |||
| 511 | 516 | ||
| 512 | static int str_gsub (lua_State *L) { | 517 | static int str_gsub (lua_State *L) { |
| 513 | size_t srcl; | 518 | size_t srcl; |
| 514 | const l_char *src = luaL_check_lstr(L, 1, &srcl); | 519 | const char *src = luaL_check_lstr(L, 1, &srcl); |
| 515 | const l_char *p = luaL_check_string(L, 2); | 520 | const char *p = luaL_check_string(L, 2); |
| 516 | int max_s = luaL_opt_int(L, 4, srcl+1); | 521 | int max_s = luaL_opt_int(L, 4, srcl+1); |
| 517 | int anchor = (*p == l_c('^')) ? (p++, 1) : 0; | 522 | int anchor = (*p == '^') ? (p++, 1) : 0; |
| 518 | int n = 0; | 523 | int n = 0; |
| 519 | MatchState ms; | 524 | MatchState ms; |
| 520 | luaL_Buffer b; | 525 | luaL_Buffer b; |
| 521 | luaL_arg_check(L, | 526 | luaL_arg_check(L, |
| 522 | lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), | 527 | lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), |
| 523 | 3, l_s("string or function expected")); | 528 | 3, "string or function expected"); |
| 524 | luaL_buffinit(L, &b); | 529 | luaL_buffinit(L, &b); |
| 525 | ms.L = L; | 530 | ms.L = L; |
| 526 | ms.src_init = src; | 531 | ms.src_init = src; |
| 527 | ms.src_end = src+srcl; | 532 | ms.src_end = src+srcl; |
| 528 | while (n < max_s) { | 533 | while (n < max_s) { |
| 529 | const l_char *e; | 534 | const char *e; |
| 530 | ms.level = 0; | 535 | ms.level = 0; |
| 531 | e = match(&ms, src, p); | 536 | e = match(&ms, src, p); |
| 532 | if (e) { | 537 | if (e) { |
| @@ -557,40 +562,40 @@ static int str_gsub (lua_State *L) { | |||
| 557 | 562 | ||
| 558 | static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { | 563 | static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { |
| 559 | size_t l; | 564 | size_t l; |
| 560 | const l_char *s = luaL_check_lstr(L, arg, &l); | 565 | const char *s = luaL_check_lstr(L, arg, &l); |
| 561 | luaL_putchar(b, l_c('"')); | 566 | luaL_putchar(b, '"'); |
| 562 | while (l--) { | 567 | while (l--) { |
| 563 | switch (*s) { | 568 | switch (*s) { |
| 564 | case l_c('"'): case l_c('\\'): case l_c('\n'): | 569 | case '"': case '\\': case '\n': |
| 565 | luaL_putchar(b, l_c('\\')); | 570 | luaL_putchar(b, '\\'); |
| 566 | luaL_putchar(b, *s); | 571 | luaL_putchar(b, *s); |
| 567 | break; | 572 | break; |
| 568 | case l_c('\0'): luaL_addlstring(b, l_s("\\000"), 4); break; | 573 | case '\0': luaL_addlstring(b, "\\000", 4); break; |
| 569 | default: luaL_putchar(b, *s); | 574 | default: luaL_putchar(b, *s); |
| 570 | } | 575 | } |
| 571 | s++; | 576 | s++; |
| 572 | } | 577 | } |
| 573 | luaL_putchar(b, l_c('"')); | 578 | luaL_putchar(b, '"'); |
| 574 | } | 579 | } |
| 575 | 580 | ||
| 576 | 581 | ||
| 577 | static const l_char *scanformat (lua_State *L, const l_char *strfrmt, | 582 | static const char *scanformat (lua_State *L, const char *strfrmt, |
| 578 | l_char *form, int *hasprecision) { | 583 | char *form, int *hasprecision) { |
| 579 | const l_char *p = strfrmt; | 584 | const char *p = strfrmt; |
| 580 | while (strchr(l_s("-+ #0"), *p)) p++; /* skip flags */ | 585 | while (strchr("-+ #0", *p)) p++; /* skip flags */ |
| 581 | if (isdigit(uchar(*p))) p++; /* skip width */ | 586 | if (isdigit(uchar(*p))) p++; /* skip width */ |
| 582 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ | 587 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 583 | if (*p == l_c('.')) { | 588 | if (*p == '.') { |
| 584 | p++; | 589 | p++; |
| 585 | *hasprecision = 1; | 590 | *hasprecision = 1; |
| 586 | if (isdigit(uchar(*p))) p++; /* skip precision */ | 591 | if (isdigit(uchar(*p))) p++; /* skip precision */ |
| 587 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ | 592 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 588 | } | 593 | } |
| 589 | if (isdigit(uchar(*p))) | 594 | if (isdigit(uchar(*p))) |
| 590 | lua_error(L, l_s("invalid format (width or precision too long)")); | 595 | lua_error(L, "invalid format (width or precision too long)"); |
| 591 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ | 596 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ |
| 592 | lua_error(L, l_s("invalid format (too long)")); | 597 | lua_error(L, "invalid format (too long)"); |
| 593 | form[0] = l_c('%'); | 598 | form[0] = '%'; |
| 594 | strncpy(form+1, strfrmt, p-strfrmt+1); | 599 | strncpy(form+1, strfrmt, p-strfrmt+1); |
| 595 | form[p-strfrmt+2] = 0; | 600 | form[p-strfrmt+2] = 0; |
| 596 | return p; | 601 | return p; |
| @@ -600,40 +605,40 @@ static const l_char *scanformat (lua_State *L, const l_char *strfrmt, | |||
| 600 | static int str_format (lua_State *L) { | 605 | static int str_format (lua_State *L) { |
| 601 | int arg = 1; | 606 | int arg = 1; |
| 602 | size_t sfl; | 607 | size_t sfl; |
| 603 | const l_char *strfrmt = luaL_check_lstr(L, arg, &sfl); | 608 | const char *strfrmt = luaL_check_lstr(L, arg, &sfl); |
| 604 | const l_char *strfrmt_end = strfrmt+sfl; | 609 | const char *strfrmt_end = strfrmt+sfl; |
| 605 | luaL_Buffer b; | 610 | luaL_Buffer b; |
| 606 | luaL_buffinit(L, &b); | 611 | luaL_buffinit(L, &b); |
| 607 | while (strfrmt < strfrmt_end) { | 612 | while (strfrmt < strfrmt_end) { |
| 608 | if (*strfrmt != l_c('%')) | 613 | if (*strfrmt != '%') |
| 609 | luaL_putchar(&b, *strfrmt++); | 614 | luaL_putchar(&b, *strfrmt++); |
| 610 | else if (*++strfrmt == l_c('%')) | 615 | else if (*++strfrmt == '%') |
| 611 | luaL_putchar(&b, *strfrmt++); /* %% */ | 616 | luaL_putchar(&b, *strfrmt++); /* %% */ |
| 612 | else { /* format item */ | 617 | else { /* format item */ |
| 613 | l_char form[MAX_FORMAT]; /* to store the format (`%...') */ | 618 | char form[MAX_FORMAT]; /* to store the format (`%...') */ |
| 614 | l_char buff[MAX_ITEM]; /* to store the formatted item */ | 619 | char buff[MAX_ITEM]; /* to store the formatted item */ |
| 615 | int hasprecision = 0; | 620 | int hasprecision = 0; |
| 616 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == l_c('$')) | 621 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') |
| 617 | lua_error(L, l_s("obsolete `format' option (d$)")); | 622 | lua_error(L, "obsolete `format' option (d$)"); |
| 618 | arg++; | 623 | arg++; |
| 619 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); | 624 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); |
| 620 | switch (*strfrmt++) { | 625 | switch (*strfrmt++) { |
| 621 | case l_c('c'): case l_c('d'): case l_c('i'): | 626 | case 'c': case 'd': case 'i': |
| 622 | sprintf(buff, form, luaL_check_int(L, arg)); | 627 | sprintf(buff, form, luaL_check_int(L, arg)); |
| 623 | break; | 628 | break; |
| 624 | case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'): | 629 | case 'o': case 'u': case 'x': case 'X': |
| 625 | sprintf(buff, form, (unsigned int)(luaL_check_number(L, arg))); | 630 | sprintf(buff, form, (unsigned int)(luaL_check_number(L, arg))); |
| 626 | break; | 631 | break; |
| 627 | case l_c('e'): case l_c('E'): case l_c('f'): | 632 | case 'e': case 'E': case 'f': |
| 628 | case l_c('g'): case l_c('G'): | 633 | case 'g': case 'G': |
| 629 | sprintf(buff, form, luaL_check_number(L, arg)); | 634 | sprintf(buff, form, luaL_check_number(L, arg)); |
| 630 | break; | 635 | break; |
| 631 | case l_c('q'): | 636 | case 'q': |
| 632 | luaI_addquoted(L, &b, arg); | 637 | luaI_addquoted(L, &b, arg); |
| 633 | continue; /* skip the `addsize' at the end */ | 638 | continue; /* skip the `addsize' at the end */ |
| 634 | case l_c('s'): { | 639 | case 's': { |
| 635 | size_t l; | 640 | size_t l; |
| 636 | const l_char *s = luaL_check_lstr(L, arg, &l); | 641 | const char *s = luaL_check_lstr(L, arg, &l); |
| 637 | if (!hasprecision && l >= 100) { | 642 | if (!hasprecision && l >= 100) { |
| 638 | /* no precision and string is too long to be formatted; | 643 | /* no precision and string is too long to be formatted; |
| 639 | keep original string */ | 644 | keep original string */ |
| @@ -647,7 +652,7 @@ static int str_format (lua_State *L) { | |||
| 647 | } | 652 | } |
| 648 | } | 653 | } |
| 649 | default: /* also treat cases `pnLlh' */ | 654 | default: /* also treat cases `pnLlh' */ |
| 650 | lua_error(L, l_s("invalid option in `format'")); | 655 | lua_error(L, "invalid option in `format'"); |
| 651 | } | 656 | } |
| 652 | luaL_addlstring(&b, buff, strlen(buff)); | 657 | luaL_addlstring(&b, buff, strlen(buff)); |
| 653 | } | 658 | } |
| @@ -658,17 +663,17 @@ static int str_format (lua_State *L) { | |||
| 658 | 663 | ||
| 659 | 664 | ||
| 660 | static const luaL_reg strlib[] = { | 665 | static const luaL_reg strlib[] = { |
| 661 | {l_s("strlen"), str_len}, | 666 | {"strlen", str_len}, |
| 662 | {l_s("strsub"), str_sub}, | 667 | {"strsub", str_sub}, |
| 663 | {l_s("strlower"), str_lower}, | 668 | {"strlower", str_lower}, |
| 664 | {l_s("strupper"), str_upper}, | 669 | {"strupper", str_upper}, |
| 665 | {l_s("strchar"), str_char}, | 670 | {"strchar", str_char}, |
| 666 | {l_s("strrep"), str_rep}, | 671 | {"strrep", str_rep}, |
| 667 | {l_s("strbyte"), str_byte}, | 672 | {"strbyte", str_byte}, |
| 668 | {l_s("concat"), str_concat}, | 673 | {"concat", str_concat}, |
| 669 | {l_s("format"), str_format}, | 674 | {"format", str_format}, |
| 670 | {l_s("strfind"), str_find}, | 675 | {"strfind", str_find}, |
| 671 | {l_s("gsub"), str_gsub} | 676 | {"gsub", str_gsub} |
| 672 | }; | 677 | }; |
| 673 | 678 | ||
| 674 | 679 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.87 2001/10/25 19:14:14 roberto Exp $ | 2 | ** $Id: ltable.c,v 1.88 2001/11/16 16:29:51 roberto Exp $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,7 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | #define LUA_PRIVATE | ||
| 27 | #include "lua.h" | 26 | #include "lua.h" |
| 28 | 27 | ||
| 29 | #include "ldo.h" | 28 | #include "ldo.h" |
| @@ -101,7 +100,7 @@ int luaH_index (lua_State *L, Table *t, const TObject *key) { | |||
| 101 | else { | 100 | else { |
| 102 | const TObject *v = luaH_get(t, key); | 101 | const TObject *v = luaH_get(t, key); |
| 103 | if (v == &luaO_nilobject) | 102 | if (v == &luaO_nilobject) |
| 104 | luaD_error(L, l_s("invalid key for `next'")); | 103 | luaD_error(L, "invalid key for `next'"); |
| 105 | i = cast(int, (cast(const lu_byte *, v) - | 104 | i = cast(int, (cast(const lu_byte *, v) - |
| 106 | cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)); | 105 | cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)); |
| 107 | return i + t->sizearray; /* hash elements are numbered after array ones */ | 106 | return i + t->sizearray; /* hash elements are numbered after array ones */ |
| @@ -193,7 +192,7 @@ static void numuse (const Table *t, int *narray, int *nhash) { | |||
| 193 | static void setarrayvector (lua_State *L, Table *t, int size) { | 192 | static void setarrayvector (lua_State *L, Table *t, int size) { |
| 194 | int i; | 193 | int i; |
| 195 | if (size > twoto(MAXBITS)) | 194 | if (size > twoto(MAXBITS)) |
| 196 | luaD_error(L, l_s("table overflow")); | 195 | luaD_error(L, "table overflow"); |
| 197 | luaM_reallocvector(L, t->array, t->sizearray, size, TObject); | 196 | luaM_reallocvector(L, t->array, t->sizearray, size, TObject); |
| 198 | for (i=t->sizearray; i<size; i++) | 197 | for (i=t->sizearray; i<size; i++) |
| 199 | setnilvalue(&t->array[i]); | 198 | setnilvalue(&t->array[i]); |
| @@ -206,7 +205,7 @@ static void setnodevector (lua_State *L, Table *t, int lsize) { | |||
| 206 | int size; | 205 | int size; |
| 207 | if (lsize < MINHASHSIZE) lsize = MINHASHSIZE; | 206 | if (lsize < MINHASHSIZE) lsize = MINHASHSIZE; |
| 208 | else if (lsize > MAXBITS) | 207 | else if (lsize > MAXBITS) |
| 209 | luaD_error(L, l_s("table overflow")); | 208 | luaD_error(L, "table overflow"); |
| 210 | size = twoto(lsize); | 209 | size = twoto(lsize); |
| 211 | t->node = luaM_newvector(L, size, Node); | 210 | t->node = luaM_newvector(L, size, Node); |
| 212 | for (i=0; i<size; i++) { | 211 | for (i=0; i<size; i++) { |
| @@ -417,7 +416,7 @@ void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val) { | |||
| 417 | settableval(p, val); | 416 | settableval(p, val); |
| 418 | } | 417 | } |
| 419 | else { | 418 | else { |
| 420 | if (ttype(key) == LUA_TNIL) luaD_error(L, l_s("table index is nil")); | 419 | if (ttype(key) == LUA_TNIL) luaD_error(L, "table index is nil"); |
| 421 | newkey(L, t, key, val); | 420 | newkey(L, t, key, val); |
| 422 | } | 421 | } |
| 423 | } | 422 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.95 2001/10/26 17:33:30 roberto Exp $ | 2 | ** $Id: ltests.c,v 1.96 2001/11/06 21:41:43 roberto Exp $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -12,7 +12,6 @@ | |||
| 12 | #include <string.h> | 12 | #include <string.h> |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | #define LUA_PRIVATE | ||
| 16 | #include "lua.h" | 15 | #include "lua.h" |
| 17 | 16 | ||
| 18 | #include "lapi.h" | 17 | #include "lapi.h" |
| @@ -43,7 +42,7 @@ int islocked = 0; | |||
| 43 | 42 | ||
| 44 | 43 | ||
| 45 | 44 | ||
| 46 | static void setnameval (lua_State *L, const l_char *name, int val) { | 45 | static void setnameval (lua_State *L, const char *name, int val) { |
| 47 | lua_pushstring(L, name); | 46 | lua_pushstring(L, name); |
| 48 | lua_pushnumber(L, val); | 47 | lua_pushnumber(L, val); |
| 49 | lua_settable(L, -3); | 48 | lua_settable(L, -3); |
| @@ -139,21 +138,21 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) { | |||
| 139 | */ | 138 | */ |
| 140 | 139 | ||
| 141 | 140 | ||
| 142 | static l_char *buildop (Proto *p, int pc, l_char *buff) { | 141 | static char *buildop (Proto *p, int pc, char *buff) { |
| 143 | Instruction i = p->code[pc]; | 142 | Instruction i = p->code[pc]; |
| 144 | OpCode o = GET_OPCODE(i); | 143 | OpCode o = GET_OPCODE(i); |
| 145 | const l_char *name = luaP_opnames[o]; | 144 | const char *name = luaP_opnames[o]; |
| 146 | sprintf(buff, l_s("%4d - "), pc); | 145 | sprintf(buff, "%4d - ", pc); |
| 147 | switch (getOpMode(o)) { | 146 | switch (getOpMode(o)) { |
| 148 | case iABC: | 147 | case iABC: |
| 149 | sprintf(buff+strlen(buff), l_s("%-12s%4d %4d %4d"), name, | 148 | sprintf(buff+strlen(buff), "%-12s%4d %4d %4d", name, |
| 150 | GETARG_A(i), GETARG_B(i), GETARG_C(i)); | 149 | GETARG_A(i), GETARG_B(i), GETARG_C(i)); |
| 151 | break; | 150 | break; |
| 152 | case iABc: | 151 | case iABc: |
| 153 | sprintf(buff+strlen(buff), l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_Bc(i)); | 152 | sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), GETARG_Bc(i)); |
| 154 | break; | 153 | break; |
| 155 | case iAsBc: | 154 | case iAsBc: |
| 156 | sprintf(buff+strlen(buff), l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_sBc(i)); | 155 | sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBc(i)); |
| 157 | break; | 156 | break; |
| 158 | } | 157 | } |
| 159 | return buff; | 158 | return buff; |
| @@ -164,13 +163,13 @@ static int listcode (lua_State *L) { | |||
| 164 | int pc; | 163 | int pc; |
| 165 | Proto *p; | 164 | Proto *p; |
| 166 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 165 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 167 | 1, l_s("Lua function expected")); | 166 | 1, "Lua function expected"); |
| 168 | p = clvalue(luaA_index(L, 1))->l.p; | 167 | p = clvalue(luaA_index(L, 1))->l.p; |
| 169 | lua_newtable(L); | 168 | lua_newtable(L); |
| 170 | setnameval(L, l_s("maxstack"), p->maxstacksize); | 169 | setnameval(L, "maxstack", p->maxstacksize); |
| 171 | setnameval(L, l_s("numparams"), p->numparams); | 170 | setnameval(L, "numparams", p->numparams); |
| 172 | for (pc=0; pc<p->sizecode; pc++) { | 171 | for (pc=0; pc<p->sizecode; pc++) { |
| 173 | l_char buff[100]; | 172 | char buff[100]; |
| 174 | lua_pushnumber(L, pc+1); | 173 | lua_pushnumber(L, pc+1); |
| 175 | lua_pushstring(L, buildop(p, pc, buff)); | 174 | lua_pushstring(L, buildop(p, pc, buff)); |
| 176 | lua_settable(L, -3); | 175 | lua_settable(L, -3); |
| @@ -183,7 +182,7 @@ static int listk (lua_State *L) { | |||
| 183 | Proto *p; | 182 | Proto *p; |
| 184 | int i; | 183 | int i; |
| 185 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 184 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 186 | 1, l_s("Lua function expected")); | 185 | 1, "Lua function expected"); |
| 187 | p = clvalue(luaA_index(L, 1))->l.p; | 186 | p = clvalue(luaA_index(L, 1))->l.p; |
| 188 | lua_newtable(L); | 187 | lua_newtable(L); |
| 189 | for (i=0; i<p->sizek; i++) { | 188 | for (i=0; i<p->sizek; i++) { |
| @@ -199,9 +198,9 @@ static int listlocals (lua_State *L) { | |||
| 199 | Proto *p; | 198 | Proto *p; |
| 200 | int pc = luaL_check_int(L, 2) - 1; | 199 | int pc = luaL_check_int(L, 2) - 1; |
| 201 | int i = 0; | 200 | int i = 0; |
| 202 | const l_char *name; | 201 | const char *name; |
| 203 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 202 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 204 | 1, l_s("Lua function expected")); | 203 | 1, "Lua function expected"); |
| 205 | p = clvalue(luaA_index(L, 1))->l.p; | 204 | p = clvalue(luaA_index(L, 1))->l.p; |
| 206 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) | 205 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
| 207 | lua_pushstring(L, name); | 206 | lua_pushstring(L, name); |
| @@ -215,12 +214,12 @@ static int listlocals (lua_State *L) { | |||
| 215 | 214 | ||
| 216 | static int get_limits (lua_State *L) { | 215 | static int get_limits (lua_State *L) { |
| 217 | lua_newtable(L); | 216 | lua_newtable(L); |
| 218 | setnameval(L, l_s("BITS_INT"), BITS_INT); | 217 | setnameval(L, "BITS_INT", BITS_INT); |
| 219 | setnameval(L, l_s("LFPF"), LFIELDS_PER_FLUSH); | 218 | setnameval(L, "LFPF", LFIELDS_PER_FLUSH); |
| 220 | setnameval(L, l_s("MAXLOCALS"), MAXLOCALS); | 219 | setnameval(L, "MAXLOCALS", MAXLOCALS); |
| 221 | setnameval(L, l_s("MAXPARAMS"), MAXPARAMS); | 220 | setnameval(L, "MAXPARAMS", MAXPARAMS); |
| 222 | setnameval(L, l_s("MAXSTACK"), MAXSTACK); | 221 | setnameval(L, "MAXSTACK", MAXSTACK); |
| 223 | setnameval(L, l_s("MAXUPVALUES"), MAXUPVALUES); | 222 | setnameval(L, "MAXUPVALUES", MAXUPVALUES); |
| 224 | return 1; | 223 | return 1; |
| 225 | } | 224 | } |
| 226 | 225 | ||
| @@ -241,7 +240,7 @@ static int mem_query (lua_State *L) { | |||
| 241 | 240 | ||
| 242 | static int hash_query (lua_State *L) { | 241 | static int hash_query (lua_State *L) { |
| 243 | if (lua_isnull(L, 2)) { | 242 | if (lua_isnull(L, 2)) { |
| 244 | luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected")); | 243 | luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, "string expected"); |
| 245 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash); | 244 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash); |
| 246 | } | 245 | } |
| 247 | else { | 246 | else { |
| @@ -336,8 +335,8 @@ static int unref (lua_State *L) { | |||
| 336 | 335 | ||
| 337 | static int newuserdata (lua_State *L) { | 336 | static int newuserdata (lua_State *L) { |
| 338 | size_t size = luaL_check_int(L, 1); | 337 | size_t size = luaL_check_int(L, 1); |
| 339 | l_char *p = cast(l_char *, lua_newuserdata(L, size)); | 338 | char *p = cast(char *, lua_newuserdata(L, size)); |
| 340 | while (size--) *p++ = l_c('\0'); | 339 | while (size--) *p++ = '\0'; |
| 341 | return 1; | 340 | return 1; |
| 342 | } | 341 | } |
| 343 | 342 | ||
| @@ -383,7 +382,7 @@ static int s2d (lua_State *L) { | |||
| 383 | 382 | ||
| 384 | static int d2s (lua_State *L) { | 383 | static int d2s (lua_State *L) { |
| 385 | double d = luaL_check_number(L, 1); | 384 | double d = luaL_check_number(L, 1); |
| 386 | lua_pushlstring(L, cast(l_char *, &d), sizeof(d)); | 385 | lua_pushlstring(L, cast(char *, &d), sizeof(d)); |
| 387 | return 1; | 386 | return 1; |
| 388 | } | 387 | } |
| 389 | 388 | ||
| @@ -418,7 +417,7 @@ static int closestate (lua_State *L) { | |||
| 418 | 417 | ||
| 419 | static int doremote (lua_State *L) { | 418 | static int doremote (lua_State *L) { |
| 420 | lua_State *L1; | 419 | lua_State *L1; |
| 421 | const l_char *code = luaL_check_string(L, 2); | 420 | const char *code = luaL_check_string(L, 2); |
| 422 | int status; | 421 | int status; |
| 423 | L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1))); | 422 | L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1))); |
| 424 | status = lua_dostring(L1, code); | 423 | status = lua_dostring(L1, code); |
| @@ -438,7 +437,7 @@ static int doremote (lua_State *L) { | |||
| 438 | 437 | ||
| 439 | static int settagmethod (lua_State *L) { | 438 | static int settagmethod (lua_State *L) { |
| 440 | int tag = luaL_check_int(L, 1); | 439 | int tag = luaL_check_int(L, 1); |
| 441 | const l_char *event = luaL_check_string(L, 2); | 440 | const char *event = luaL_check_string(L, 2); |
| 442 | luaL_check_any(L, 3); | 441 | luaL_check_any(L, 3); |
| 443 | lua_gettagmethod(L, tag, event); | 442 | lua_gettagmethod(L, tag, event); |
| 444 | lua_pushvalue(L, 3); | 443 | lua_pushvalue(L, 3); |
| @@ -460,36 +459,36 @@ static int log2_aux (lua_State *L) { | |||
| 460 | ** ======================================================= | 459 | ** ======================================================= |
| 461 | */ | 460 | */ |
| 462 | 461 | ||
| 463 | static const l_char *const delimits = l_s(" \t\n,;"); | 462 | static const char *const delimits = " \t\n,;"; |
| 464 | 463 | ||
| 465 | static void skip (const l_char **pc) { | 464 | static void skip (const char **pc) { |
| 466 | while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++; | 465 | while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; |
| 467 | } | 466 | } |
| 468 | 467 | ||
| 469 | static int getnum_aux (lua_State *L, const l_char **pc) { | 468 | static int getnum_aux (lua_State *L, const char **pc) { |
| 470 | int res = 0; | 469 | int res = 0; |
| 471 | int sig = 1; | 470 | int sig = 1; |
| 472 | skip(pc); | 471 | skip(pc); |
| 473 | if (**pc == l_c('.')) { | 472 | if (**pc == '.') { |
| 474 | res = cast(int, lua_tonumber(L, -1)); | 473 | res = cast(int, lua_tonumber(L, -1)); |
| 475 | lua_pop(L, 1); | 474 | lua_pop(L, 1); |
| 476 | (*pc)++; | 475 | (*pc)++; |
| 477 | return res; | 476 | return res; |
| 478 | } | 477 | } |
| 479 | else if (**pc == l_c('-')) { | 478 | else if (**pc == '-') { |
| 480 | sig = -1; | 479 | sig = -1; |
| 481 | (*pc)++; | 480 | (*pc)++; |
| 482 | } | 481 | } |
| 483 | while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - l_c('0'); | 482 | while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - '0'; |
| 484 | return sig*res; | 483 | return sig*res; |
| 485 | } | 484 | } |
| 486 | 485 | ||
| 487 | static const l_char *getname_aux (l_char *buff, const l_char **pc) { | 486 | static const char *getname_aux (char *buff, const char **pc) { |
| 488 | int i = 0; | 487 | int i = 0; |
| 489 | skip(pc); | 488 | skip(pc); |
| 490 | while (**pc != l_c('\0') && !strchr(delimits, **pc)) | 489 | while (**pc != '\0' && !strchr(delimits, **pc)) |
| 491 | buff[i++] = *(*pc)++; | 490 | buff[i++] = *(*pc)++; |
| 492 | buff[i] = l_c('\0'); | 491 | buff[i] = '\0'; |
| 493 | return buff; | 492 | return buff; |
| 494 | } | 493 | } |
| 495 | 494 | ||
| @@ -501,134 +500,134 @@ static const l_char *getname_aux (l_char *buff, const l_char **pc) { | |||
| 501 | 500 | ||
| 502 | 501 | ||
| 503 | static int testC (lua_State *L) { | 502 | static int testC (lua_State *L) { |
| 504 | l_char buff[30]; | 503 | char buff[30]; |
| 505 | const l_char *pc = luaL_check_string(L, 1); | 504 | const char *pc = luaL_check_string(L, 1); |
| 506 | for (;;) { | 505 | for (;;) { |
| 507 | const l_char *inst = getname; | 506 | const char *inst = getname; |
| 508 | if EQ(l_s("")) return 0; | 507 | if EQ("") return 0; |
| 509 | else if EQ(l_s("isnumber")) { | 508 | else if EQ("isnumber") { |
| 510 | lua_pushnumber(L, lua_isnumber(L, getnum)); | 509 | lua_pushnumber(L, lua_isnumber(L, getnum)); |
| 511 | } | 510 | } |
| 512 | else if EQ(l_s("isstring")) { | 511 | else if EQ("isstring") { |
| 513 | lua_pushnumber(L, lua_isstring(L, getnum)); | 512 | lua_pushnumber(L, lua_isstring(L, getnum)); |
| 514 | } | 513 | } |
| 515 | else if EQ(l_s("istable")) { | 514 | else if EQ("istable") { |
| 516 | lua_pushnumber(L, lua_istable(L, getnum)); | 515 | lua_pushnumber(L, lua_istable(L, getnum)); |
| 517 | } | 516 | } |
| 518 | else if EQ(l_s("iscfunction")) { | 517 | else if EQ("iscfunction") { |
| 519 | lua_pushnumber(L, lua_iscfunction(L, getnum)); | 518 | lua_pushnumber(L, lua_iscfunction(L, getnum)); |
| 520 | } | 519 | } |
| 521 | else if EQ(l_s("isfunction")) { | 520 | else if EQ("isfunction") { |
| 522 | lua_pushnumber(L, lua_isfunction(L, getnum)); | 521 | lua_pushnumber(L, lua_isfunction(L, getnum)); |
| 523 | } | 522 | } |
| 524 | else if EQ(l_s("isuserdata")) { | 523 | else if EQ("isuserdata") { |
| 525 | lua_pushnumber(L, lua_isuserdata(L, getnum)); | 524 | lua_pushnumber(L, lua_isuserdata(L, getnum)); |
| 526 | } | 525 | } |
| 527 | else if EQ(l_s("isnil")) { | 526 | else if EQ("isnil") { |
| 528 | lua_pushnumber(L, lua_isnil(L, getnum)); | 527 | lua_pushnumber(L, lua_isnil(L, getnum)); |
| 529 | } | 528 | } |
| 530 | else if EQ(l_s("isnull")) { | 529 | else if EQ("isnull") { |
| 531 | lua_pushnumber(L, lua_isnull(L, getnum)); | 530 | lua_pushnumber(L, lua_isnull(L, getnum)); |
| 532 | } | 531 | } |
| 533 | else if EQ(l_s("tonumber")) { | 532 | else if EQ("tonumber") { |
| 534 | lua_pushnumber(L, lua_tonumber(L, getnum)); | 533 | lua_pushnumber(L, lua_tonumber(L, getnum)); |
| 535 | } | 534 | } |
| 536 | else if EQ(l_s("tostring")) { | 535 | else if EQ("tostring") { |
| 537 | const l_char *s = lua_tostring(L, getnum); | 536 | const char *s = lua_tostring(L, getnum); |
| 538 | lua_pushstring(L, s); | 537 | lua_pushstring(L, s); |
| 539 | } | 538 | } |
| 540 | else if EQ(l_s("tonumber")) { | 539 | else if EQ("tonumber") { |
| 541 | lua_pushnumber(L, lua_tonumber(L, getnum)); | 540 | lua_pushnumber(L, lua_tonumber(L, getnum)); |
| 542 | } | 541 | } |
| 543 | else if EQ(l_s("strlen")) { | 542 | else if EQ("strlen") { |
| 544 | lua_pushnumber(L, lua_strlen(L, getnum)); | 543 | lua_pushnumber(L, lua_strlen(L, getnum)); |
| 545 | } | 544 | } |
| 546 | else if EQ(l_s("tocfunction")) { | 545 | else if EQ("tocfunction") { |
| 547 | lua_pushcfunction(L, lua_tocfunction(L, getnum)); | 546 | lua_pushcfunction(L, lua_tocfunction(L, getnum)); |
| 548 | } | 547 | } |
| 549 | else if EQ(l_s("return")) { | 548 | else if EQ("return") { |
| 550 | return getnum; | 549 | return getnum; |
| 551 | } | 550 | } |
| 552 | else if EQ(l_s("gettop")) { | 551 | else if EQ("gettop") { |
| 553 | lua_pushnumber(L, lua_gettop(L)); | 552 | lua_pushnumber(L, lua_gettop(L)); |
| 554 | } | 553 | } |
| 555 | else if EQ(l_s("settop")) { | 554 | else if EQ("settop") { |
| 556 | lua_settop(L, getnum); | 555 | lua_settop(L, getnum); |
| 557 | } | 556 | } |
| 558 | else if EQ(l_s("pop")) { | 557 | else if EQ("pop") { |
| 559 | lua_pop(L, getnum); | 558 | lua_pop(L, getnum); |
| 560 | } | 559 | } |
| 561 | else if EQ(l_s("pushnum")) { | 560 | else if EQ("pushnum") { |
| 562 | lua_pushnumber(L, getnum); | 561 | lua_pushnumber(L, getnum); |
| 563 | } | 562 | } |
| 564 | else if EQ(l_s("pushvalue")) { | 563 | else if EQ("pushvalue") { |
| 565 | lua_pushvalue(L, getnum); | 564 | lua_pushvalue(L, getnum); |
| 566 | } | 565 | } |
| 567 | else if EQ(l_s("pushcclosure")) { | 566 | else if EQ("pushcclosure") { |
| 568 | lua_pushcclosure(L, testC, getnum); | 567 | lua_pushcclosure(L, testC, getnum); |
| 569 | } | 568 | } |
| 570 | else if EQ(l_s("pushupvalues")) { | 569 | else if EQ("pushupvalues") { |
| 571 | lua_pushupvalues(L); | 570 | lua_pushupvalues(L); |
| 572 | } | 571 | } |
| 573 | else if EQ(l_s("remove")) { | 572 | else if EQ("remove") { |
| 574 | lua_remove(L, getnum); | 573 | lua_remove(L, getnum); |
| 575 | } | 574 | } |
| 576 | else if EQ(l_s("insert")) { | 575 | else if EQ("insert") { |
| 577 | lua_insert(L, getnum); | 576 | lua_insert(L, getnum); |
| 578 | } | 577 | } |
| 579 | else if EQ(l_s("gettable")) { | 578 | else if EQ("gettable") { |
| 580 | lua_gettable(L, getnum); | 579 | lua_gettable(L, getnum); |
| 581 | } | 580 | } |
| 582 | else if EQ(l_s("settable")) { | 581 | else if EQ("settable") { |
| 583 | lua_settable(L, getnum); | 582 | lua_settable(L, getnum); |
| 584 | } | 583 | } |
| 585 | else if EQ(l_s("next")) { | 584 | else if EQ("next") { |
| 586 | lua_next(L, -2); | 585 | lua_next(L, -2); |
| 587 | } | 586 | } |
| 588 | else if EQ(l_s("concat")) { | 587 | else if EQ("concat") { |
| 589 | lua_concat(L, getnum); | 588 | lua_concat(L, getnum); |
| 590 | } | 589 | } |
| 591 | else if EQ(l_s("lessthan")) { | 590 | else if EQ("lessthan") { |
| 592 | int a = getnum; | 591 | int a = getnum; |
| 593 | if (lua_lessthan(L, a, getnum)) | 592 | if (lua_lessthan(L, a, getnum)) |
| 594 | lua_pushnumber(L, 1); | 593 | lua_pushnumber(L, 1); |
| 595 | else | 594 | else |
| 596 | lua_pushnil(L); | 595 | lua_pushnil(L); |
| 597 | } | 596 | } |
| 598 | else if EQ(l_s("equal")) { | 597 | else if EQ("equal") { |
| 599 | int a = getnum; | 598 | int a = getnum; |
| 600 | if (lua_equal(L, a, getnum)) | 599 | if (lua_equal(L, a, getnum)) |
| 601 | lua_pushnumber(L, 1); | 600 | lua_pushnumber(L, 1); |
| 602 | else | 601 | else |
| 603 | lua_pushnil(L); | 602 | lua_pushnil(L); |
| 604 | } | 603 | } |
| 605 | else if EQ(l_s("rawcall")) { | 604 | else if EQ("rawcall") { |
| 606 | int narg = getnum; | 605 | int narg = getnum; |
| 607 | int nres = getnum; | 606 | int nres = getnum; |
| 608 | lua_rawcall(L, narg, nres); | 607 | lua_rawcall(L, narg, nres); |
| 609 | } | 608 | } |
| 610 | else if EQ(l_s("call")) { | 609 | else if EQ("call") { |
| 611 | int narg = getnum; | 610 | int narg = getnum; |
| 612 | int nres = getnum; | 611 | int nres = getnum; |
| 613 | lua_call(L, narg, nres); | 612 | lua_call(L, narg, nres); |
| 614 | } | 613 | } |
| 615 | else if EQ(l_s("dostring")) { | 614 | else if EQ("dostring") { |
| 616 | lua_dostring(L, luaL_check_string(L, getnum)); | 615 | lua_dostring(L, luaL_check_string(L, getnum)); |
| 617 | } | 616 | } |
| 618 | else if EQ(l_s("settagmethod")) { | 617 | else if EQ("settagmethod") { |
| 619 | int tag = getnum; | 618 | int tag = getnum; |
| 620 | const l_char *event = getname; | 619 | const char *event = getname; |
| 621 | lua_settagmethod(L, tag, event); | 620 | lua_settagmethod(L, tag, event); |
| 622 | } | 621 | } |
| 623 | else if EQ(l_s("gettagmethod")) { | 622 | else if EQ("gettagmethod") { |
| 624 | int tag = getnum; | 623 | int tag = getnum; |
| 625 | const l_char *event = getname; | 624 | const char *event = getname; |
| 626 | lua_gettagmethod(L, tag, event); | 625 | lua_gettagmethod(L, tag, event); |
| 627 | } | 626 | } |
| 628 | else if EQ(l_s("type")) { | 627 | else if EQ("type") { |
| 629 | lua_pushstring(L, lua_type(L, getnum)); | 628 | lua_pushstring(L, lua_type(L, getnum)); |
| 630 | } | 629 | } |
| 631 | else luaL_verror(L, l_s("unknown instruction %.30s"), buff); | 630 | else luaL_verror(L, "unknown instruction %.30s", buff); |
| 632 | } | 631 | } |
| 633 | return 0; | 632 | return 0; |
| 634 | } | 633 | } |
| @@ -638,32 +637,32 @@ static int testC (lua_State *L) { | |||
| 638 | 637 | ||
| 639 | 638 | ||
| 640 | static const struct luaL_reg tests_funcs[] = { | 639 | static const struct luaL_reg tests_funcs[] = { |
| 641 | {l_s("hash"), hash_query}, | 640 | {"hash", hash_query}, |
| 642 | {l_s("limits"), get_limits}, | 641 | {"limits", get_limits}, |
| 643 | {l_s("listcode"), listcode}, | 642 | {"listcode", listcode}, |
| 644 | {l_s("listk"), listk}, | 643 | {"listk", listk}, |
| 645 | {l_s("listlocals"), listlocals}, | 644 | {"listlocals", listlocals}, |
| 646 | {l_s("loadlib"), loadlib}, | 645 | {"loadlib", loadlib}, |
| 647 | {l_s("querystr"), string_query}, | 646 | {"querystr", string_query}, |
| 648 | {l_s("querytab"), table_query}, | 647 | {"querytab", table_query}, |
| 649 | {l_s("testC"), testC}, | 648 | {"testC", testC}, |
| 650 | {l_s("ref"), tref}, | 649 | {"ref", tref}, |
| 651 | {l_s("getref"), getref}, | 650 | {"getref", getref}, |
| 652 | {l_s("unref"), unref}, | 651 | {"unref", unref}, |
| 653 | {l_s("d2s"), d2s}, | 652 | {"d2s", d2s}, |
| 654 | {l_s("s2d"), s2d}, | 653 | {"s2d", s2d}, |
| 655 | {l_s("newuserdata"), newuserdata}, | 654 | {"newuserdata", newuserdata}, |
| 656 | {l_s("newuserdatabox"), newuserdatabox}, | 655 | {"newuserdatabox", newuserdatabox}, |
| 657 | {l_s("settag"), settag}, | 656 | {"settag", settag}, |
| 658 | {l_s("udataval"), udataval}, | 657 | {"udataval", udataval}, |
| 659 | {l_s("newtag"), newtag}, | 658 | {"newtag", newtag}, |
| 660 | {l_s("doonnewstack"), doonnewstack}, | 659 | {"doonnewstack", doonnewstack}, |
| 661 | {l_s("newstate"), newstate}, | 660 | {"newstate", newstate}, |
| 662 | {l_s("closestate"), closestate}, | 661 | {"closestate", closestate}, |
| 663 | {l_s("doremote"), doremote}, | 662 | {"doremote", doremote}, |
| 664 | {l_s("settagmethod"), settagmethod}, | 663 | {"settagmethod", settagmethod}, |
| 665 | {l_s("log2"), log2_aux}, | 664 | {"log2", log2_aux}, |
| 666 | {l_s("totalmem"), mem_query} | 665 | {"totalmem", mem_query} |
| 667 | }; | 666 | }; |
| 668 | 667 | ||
| 669 | 668 | ||
| @@ -677,7 +676,7 @@ void luaB_opentests (lua_State *L) { | |||
| 677 | lua_setglobals(L); | 676 | lua_setglobals(L); |
| 678 | luaL_openl(L, tests_funcs); /* open functions inside new table */ | 677 | luaL_openl(L, tests_funcs); /* open functions inside new table */ |
| 679 | lua_setglobals(L); /* restore old table of globals */ | 678 | lua_setglobals(L); /* restore old table of globals */ |
| 680 | lua_setglobal(L, l_s("T")); /* set new table as global T */ | 679 | lua_setglobal(L, "T"); /* set new table as global T */ |
| 681 | } | 680 | } |
| 682 | 681 | ||
| 683 | #endif | 682 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.78 2001/08/31 19:46:07 roberto Exp $ | 2 | ** $Id: ltm.c,v 1.80 2001/10/11 21:41:21 roberto Exp $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | 10 | ||
| 11 | #define LUA_PRIVATE | ||
| 12 | #include "lua.h" | 11 | #include "lua.h" |
| 13 | 12 | ||
| 14 | #include "ldo.h" | 13 | #include "ldo.h" |
| @@ -20,16 +19,16 @@ | |||
| 20 | #include "ltm.h" | 19 | #include "ltm.h" |
| 21 | 20 | ||
| 22 | 21 | ||
| 23 | const l_char *const luaT_eventname[] = { /* ORDER TM */ | 22 | const char *const luaT_eventname[] = { /* ORDER TM */ |
| 24 | l_s("gettable"), l_s("settable"), l_s("index"), l_s("getglobal"), | 23 | "gettable", "settable", "index", "getglobal", |
| 25 | l_s("setglobal"), l_s("add"), l_s("sub"), l_s("mul"), l_s("div"), | 24 | "setglobal", "add", "sub", "mul", "div", |
| 26 | l_s("pow"), l_s("unm"), l_s("lt"), l_s("concat"), l_s("gc"), | 25 | "pow", "unm", "lt", "concat", "gc", |
| 27 | l_s("function"), | 26 | "function", |
| 28 | NULL | 27 | NULL |
| 29 | }; | 28 | }; |
| 30 | 29 | ||
| 31 | 30 | ||
| 32 | static int findevent (const l_char *name) { | 31 | static int findevent (const char *name) { |
| 33 | int i; | 32 | int i; |
| 34 | for (i=0; luaT_eventname[i]; i++) | 33 | for (i=0; luaT_eventname[i]; i++) |
| 35 | if (strcmp(luaT_eventname[i], name) == 0) | 34 | if (strcmp(luaT_eventname[i], name) == 0) |
| @@ -38,10 +37,10 @@ static int findevent (const l_char *name) { | |||
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | 39 | ||
| 41 | static int luaI_checkevent (lua_State *L, const l_char *name) { | 40 | static int luaI_checkevent (lua_State *L, const char *name) { |
| 42 | int e = findevent(name); | 41 | int e = findevent(name); |
| 43 | if (e < 0) | 42 | if (e < 0) |
| 44 | luaO_verror(L, l_s("`%.50s' is not a valid event name"), name); | 43 | luaO_verror(L, "`%.50s' is not a valid event name", name); |
| 45 | return e; | 44 | return e; |
| 46 | } | 45 | } |
| 47 | 46 | ||
| @@ -66,9 +65,9 @@ static int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | |||
| 66 | 65 | ||
| 67 | 66 | ||
| 68 | void luaT_init (lua_State *L) { | 67 | void luaT_init (lua_State *L) { |
| 69 | static const l_char *const typenames[NUM_TAGS] = { | 68 | static const char *const typenames[NUM_TAGS] = { |
| 70 | l_s("userdata"), l_s("nil"), l_s("number"), l_s("string"), | 69 | "userdata", "nil", "number", "string", |
| 71 | l_s("table"), l_s("function") | 70 | "table", "function" |
| 72 | }; | 71 | }; |
| 73 | int i; | 72 | int i; |
| 74 | for (i=0; i<NUM_TAGS; i++) | 73 | for (i=0; i<NUM_TAGS; i++) |
| @@ -76,12 +75,12 @@ void luaT_init (lua_State *L) { | |||
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | 77 | ||
| 79 | int luaT_newtag (lua_State *L, const l_char *name, int basictype) { | 78 | int luaT_newtag (lua_State *L, const char *name, int basictype) { |
| 80 | int tag; | 79 | int tag; |
| 81 | int i; | 80 | int i; |
| 82 | TString *ts = NULL; | 81 | TString *ts = NULL; |
| 83 | luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, | 82 | luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, |
| 84 | MAX_INT, l_s("tag table overflow")); | 83 | MAX_INT, "tag table overflow"); |
| 85 | tag = G(L)->ntag; | 84 | tag = G(L)->ntag; |
| 86 | if (name) { | 85 | if (name) { |
| 87 | const TObject *v; | 86 | const TObject *v; |
| @@ -104,7 +103,7 @@ int luaT_newtag (lua_State *L, const l_char *name, int basictype) { | |||
| 104 | 103 | ||
| 105 | static void checktag (lua_State *L, int tag) { | 104 | static void checktag (lua_State *L, int tag) { |
| 106 | if (!(0 <= tag && tag < G(L)->ntag)) | 105 | if (!(0 <= tag && tag < G(L)->ntag)) |
| 107 | luaO_verror(L, l_s("%d is not a valid tag"), tag); | 106 | luaO_verror(L, "%d is not a valid tag", tag); |
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | 109 | ||
| @@ -118,7 +117,7 @@ int luaT_tag (const TObject *o) { | |||
| 118 | } | 117 | } |
| 119 | 118 | ||
| 120 | 119 | ||
| 121 | const l_char *luaT_typename (global_State *G, const TObject *o) { | 120 | const char *luaT_typename (global_State *G, const TObject *o) { |
| 122 | int t = ttype(o); | 121 | int t = ttype(o); |
| 123 | int tag; | 122 | int tag; |
| 124 | TString *ts; | 123 | TString *ts; |
| @@ -139,7 +138,7 @@ const l_char *luaT_typename (global_State *G, const TObject *o) { | |||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | 140 | ||
| 142 | LUA_API void lua_gettagmethod (lua_State *L, int t, const l_char *event) { | 141 | LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { |
| 143 | int e; | 142 | int e; |
| 144 | lua_lock(L); | 143 | lua_lock(L); |
| 145 | e = luaI_checkevent(L, event); | 144 | e = luaI_checkevent(L, event); |
| @@ -154,16 +153,16 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const l_char *event) { | |||
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | 155 | ||
| 157 | LUA_API void lua_settagmethod (lua_State *L, int t, const l_char *event) { | 156 | LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { |
| 158 | int e; | 157 | int e; |
| 159 | lua_lock(L); | 158 | lua_lock(L); |
| 160 | e = luaI_checkevent(L, event); | 159 | e = luaI_checkevent(L, event); |
| 161 | checktag(L, t); | 160 | checktag(L, t); |
| 162 | if (!luaT_validevent(t, e)) | 161 | if (!luaT_validevent(t, e)) |
| 163 | luaO_verror(L, l_s("cannot change `%.20s' tag method for type `%.20s'%.20s"), | 162 | luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", |
| 164 | luaT_eventname[e], typenamebytag(G(L), t), | 163 | luaT_eventname[e], typenamebytag(G(L), t), |
| 165 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? | 164 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? |
| 166 | l_s(" with default tag") : l_s("")); | 165 | " with default tag" : ""); |
| 167 | switch (ttype(L->top - 1)) { | 166 | switch (ttype(L->top - 1)) { |
| 168 | case LUA_TNIL: | 167 | case LUA_TNIL: |
| 169 | luaT_gettm(G(L), t, e) = NULL; | 168 | luaT_gettm(G(L), t, e) = NULL; |
| @@ -172,7 +171,7 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const l_char *event) { | |||
| 172 | luaT_gettm(G(L), t, e) = clvalue(L->top - 1); | 171 | luaT_gettm(G(L), t, e) = clvalue(L->top - 1); |
| 173 | break; | 172 | break; |
| 174 | default: | 173 | default: |
| 175 | luaD_error(L, l_s("tag method must be a function (or nil)")); | 174 | luaD_error(L, "tag method must be a function (or nil)"); |
| 176 | } | 175 | } |
| 177 | L->top--; | 176 | L->top--; |
| 178 | lua_unlock(L); | 177 | lua_unlock(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 1.27 2001/08/27 15:13:59 roberto Exp $ | 2 | ** $Id: ltm.h,v 1.28 2001/10/02 16:43:54 roberto Exp $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -67,12 +67,12 @@ struct TM { | |||
| 67 | 67 | ||
| 68 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) | 68 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) |
| 69 | 69 | ||
| 70 | extern const l_char *const luaT_eventname[]; | 70 | extern const char *const luaT_eventname[]; |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | void luaT_init (lua_State *L); | 73 | void luaT_init (lua_State *L); |
| 74 | int luaT_newtag (lua_State *L, const l_char *name, int basictype); | 74 | int luaT_newtag (lua_State *L, const char *name, int basictype); |
| 75 | const l_char *luaT_typename (global_State *G, const TObject *o); | 75 | const char *luaT_typename (global_State *G, const TObject *o); |
| 76 | int luaT_tag (const TObject *o); | 76 | int luaT_tag (const TObject *o); |
| 77 | 77 | ||
| 78 | 78 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.71 2001/10/17 21:12:57 roberto Exp $ | 2 | ** $Id: lua.c,v 1.72 2001/11/27 20:56:47 roberto Exp $ |
| 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 | */ |
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| 12 | 12 | ||
| 13 | #define LUA_PRIVATE | ||
| 14 | #include "lua.h" | 13 | #include "lua.h" |
| 15 | 14 | ||
| 16 | #include "luadebug.h" | 15 | #include "luadebug.h" |
| @@ -25,12 +24,12 @@ static int isatty (int x) { return x==0; } /* assume stdin is a tty */ | |||
| 25 | 24 | ||
| 26 | 25 | ||
| 27 | #ifndef LUA_PROGNAME | 26 | #ifndef LUA_PROGNAME |
| 28 | #define LUA_PROGNAME l_s("lua: ") | 27 | #define LUA_PROGNAME "lua: " |
| 29 | #endif | 28 | #endif |
| 30 | 29 | ||
| 31 | 30 | ||
| 32 | #ifndef PROMPT | 31 | #ifndef PROMPT |
| 33 | #define PROMPT l_s("> ") | 32 | #define PROMPT "> " |
| 34 | #endif | 33 | #endif |
| 35 | 34 | ||
| 36 | 35 | ||
| @@ -62,7 +61,7 @@ static void lstop (void) { | |||
| 62 | lua_setlinehook(L, old_linehook); | 61 | lua_setlinehook(L, old_linehook); |
| 63 | lua_setcallhook(L, old_callhook); | 62 | lua_setcallhook(L, old_callhook); |
| 64 | lreset(); | 63 | lreset(); |
| 65 | lua_error(L, l_s("interrupted!")); | 64 | lua_error(L, "interrupted!"); |
| 66 | } | 65 | } |
| 67 | 66 | ||
| 68 | 67 | ||
| @@ -75,7 +74,7 @@ static void laction (int i) { | |||
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | 76 | ||
| 78 | static int ldo (int (*f)(lua_State *l, const l_char *), const l_char *name, | 77 | static int ldo (int (*f)(lua_State *l, const char *), const char *name, |
| 79 | int clear) { | 78 | int clear) { |
| 80 | int res; | 79 | int res; |
| 81 | handler h = lreset(); | 80 | handler h = lreset(); |
| @@ -86,45 +85,45 @@ static int ldo (int (*f)(lua_State *l, const l_char *), const l_char *name, | |||
| 86 | lua_settop(L, top); /* remove eventual results */ | 85 | lua_settop(L, top); /* remove eventual results */ |
| 87 | /* Lua gives no message in such cases, so lua.c provides one */ | 86 | /* Lua gives no message in such cases, so lua.c provides one */ |
| 88 | if (res == LUA_ERRMEM) { | 87 | if (res == LUA_ERRMEM) { |
| 89 | fprintf(stderr, LUA_PROGNAME l_s("memory allocation error\n")); | 88 | fprintf(stderr, LUA_PROGNAME "memory allocation error\n"); |
| 90 | } | 89 | } |
| 91 | else if (res == LUA_ERRERR) | 90 | else if (res == LUA_ERRERR) |
| 92 | fprintf(stderr, LUA_PROGNAME l_s("error in error message\n")); | 91 | fprintf(stderr, LUA_PROGNAME "error in error message\n"); |
| 93 | return res; | 92 | return res; |
| 94 | } | 93 | } |
| 95 | 94 | ||
| 96 | 95 | ||
| 97 | static void print_message (void) { | 96 | static void print_message (void) { |
| 98 | fprintf(stderr, | 97 | fprintf(stderr, |
| 99 | l_s("usage: lua [options]. Available options are:\n") | 98 | "usage: lua [options]. Available options are:\n" |
| 100 | l_s(" - execute stdin as a file\n") | 99 | " - execute stdin as a file\n" |
| 101 | l_s(" -c close Lua when exiting\n") | 100 | " -c close Lua when exiting\n" |
| 102 | l_s(" -e stat execute string `stat'\n") | 101 | " -e stat execute string `stat'\n" |
| 103 | l_s(" -f name execute file `name' with remaining arguments in table `arg'\n") | 102 | " -f name execute file `name' with remaining arguments in table `arg'\n" |
| 104 | l_s(" -i enter interactive mode with prompt\n") | 103 | " -i enter interactive mode with prompt\n" |
| 105 | l_s(" -q enter interactive mode without prompt\n") | 104 | " -q enter interactive mode without prompt\n" |
| 106 | l_s(" -sNUM set stack size to NUM (must be the first option)\n") | 105 | " -sNUM set stack size to NUM (must be the first option)\n" |
| 107 | l_s(" -v print version information\n") | 106 | " -v print version information\n" |
| 108 | l_s(" a=b set global `a' to string `b'\n") | 107 | " a=b set global `a' to string `b'\n" |
| 109 | l_s(" name execute file `name'\n") | 108 | " name execute file `name'\n" |
| 110 | ); | 109 | ); |
| 111 | } | 110 | } |
| 112 | 111 | ||
| 113 | 112 | ||
| 114 | static void print_version (void) { | 113 | static void print_version (void) { |
| 115 | printf(l_s("%.80s %.80s\n"), l_s(LUA_VERSION), l_s(LUA_COPYRIGHT)); | 114 | printf("%.80s %.80s\n", LUA_VERSION, LUA_COPYRIGHT); |
| 116 | } | 115 | } |
| 117 | 116 | ||
| 118 | 117 | ||
| 119 | static void assign (l_char *arg) { | 118 | static void assign (char *arg) { |
| 120 | l_char *eq = strchr(arg, l_c('=')); | 119 | char *eq = strchr(arg, '='); |
| 121 | *eq = l_c('\0'); /* spilt `arg' in two strings (name & value) */ | 120 | *eq = '\0'; /* spilt `arg' in two strings (name & value) */ |
| 122 | lua_pushstring(L, eq+1); | 121 | lua_pushstring(L, eq+1); |
| 123 | lua_setglobal(L, arg); | 122 | lua_setglobal(L, arg); |
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | 125 | ||
| 127 | static void getargs (l_char *argv[]) { | 126 | static void getargs (char *argv[]) { |
| 128 | int i; | 127 | int i; |
| 129 | lua_newtable(L); | 128 | lua_newtable(L); |
| 130 | for (i=0; argv[i]; i++) { | 129 | for (i=0; argv[i]; i++) { |
| @@ -134,24 +133,24 @@ static void getargs (l_char *argv[]) { | |||
| 134 | lua_settable(L, -3); | 133 | lua_settable(L, -3); |
| 135 | } | 134 | } |
| 136 | /* arg.n = maximum index in table `arg' */ | 135 | /* arg.n = maximum index in table `arg' */ |
| 137 | lua_pushliteral(L, l_s("n")); | 136 | lua_pushliteral(L, "n"); |
| 138 | lua_pushnumber(L, i-1); | 137 | lua_pushnumber(L, i-1); |
| 139 | lua_settable(L, -3); | 138 | lua_settable(L, -3); |
| 140 | } | 139 | } |
| 141 | 140 | ||
| 142 | 141 | ||
| 143 | static int l_getargs (lua_State *l) { | 142 | static int l_getargs (lua_State *l) { |
| 144 | l_char **argv = (l_char **)lua_touserdata(l, lua_upvalueindex(1)); | 143 | char **argv = (char **)lua_touserdata(l, lua_upvalueindex(1)); |
| 145 | getargs(argv); | 144 | getargs(argv); |
| 146 | return 1; | 145 | return 1; |
| 147 | } | 146 | } |
| 148 | 147 | ||
| 149 | 148 | ||
| 150 | static int file_input (const l_char *argv) { | 149 | static int file_input (const char *argv) { |
| 151 | int result = ldo(lua_dofile, argv, 1); | 150 | int result = ldo(lua_dofile, argv, 1); |
| 152 | if (result) { | 151 | if (result) { |
| 153 | if (result == LUA_ERRFILE) { | 152 | if (result == LUA_ERRFILE) { |
| 154 | fprintf(stderr, LUA_PROGNAME l_s("cannot execute file ")); | 153 | fprintf(stderr, LUA_PROGNAME "cannot execute file "); |
| 155 | perror(argv); | 154 | perror(argv); |
| 156 | } | 155 | } |
| 157 | return EXIT_FAILURE; | 156 | return EXIT_FAILURE; |
| @@ -167,12 +166,12 @@ static int file_input (const l_char *argv) { | |||
| 167 | #endif | 166 | #endif |
| 168 | 167 | ||
| 169 | 168 | ||
| 170 | static const l_char *get_prompt (int prompt) { | 169 | static const char *get_prompt (int prompt) { |
| 171 | if (!prompt) | 170 | if (!prompt) |
| 172 | return l_s(""); | 171 | return ""; |
| 173 | else { | 172 | else { |
| 174 | const l_char *s; | 173 | const char *s; |
| 175 | lua_getglobal(L, l_s("_PROMPT")); | 174 | lua_getglobal(L, "_PROMPT"); |
| 176 | s = lua_tostring(L, -1); | 175 | s = lua_tostring(L, -1); |
| 177 | if (!s) s = PROMPT; | 176 | if (!s) s = PROMPT; |
| 178 | lua_pop(L, 1); /* remove global */ | 177 | lua_pop(L, 1); /* remove global */ |
| @@ -188,20 +187,20 @@ static void manual_input (int version, int prompt) { | |||
| 188 | int toprint = 0; | 187 | int toprint = 0; |
| 189 | fputs(get_prompt(prompt), stdout); /* show prompt */ | 188 | fputs(get_prompt(prompt), stdout); /* show prompt */ |
| 190 | for(;;) { | 189 | for(;;) { |
| 191 | l_char buffer[MAXINPUT]; | 190 | char buffer[MAXINPUT]; |
| 192 | size_t l; | 191 | size_t l; |
| 193 | if (fgets(buffer, sizeof(buffer), stdin) == NULL) { | 192 | if (fgets(buffer, sizeof(buffer), stdin) == NULL) { |
| 194 | printf(l_s("\n")); | 193 | printf("\n"); |
| 195 | return; | 194 | return; |
| 196 | } | 195 | } |
| 197 | if (firstline && buffer[0] == l_c('=')) { | 196 | if (firstline && buffer[0] == '=') { |
| 198 | buffer[0] = l_c(' '); | 197 | buffer[0] = ' '; |
| 199 | lua_pushstring(L, l_s("return")); | 198 | lua_pushstring(L, "return"); |
| 200 | toprint = 1; | 199 | toprint = 1; |
| 201 | } | 200 | } |
| 202 | l = strlen(buffer); | 201 | l = strlen(buffer); |
| 203 | if (buffer[l-1] == l_c('\n') && buffer[l-2] == l_c('\\')) { | 202 | if (buffer[l-1] == '\n' && buffer[l-2] == '\\') { |
| 204 | buffer[l-2] = l_c('\n'); | 203 | buffer[l-2] = '\n'; |
| 205 | lua_pushlstring(L, buffer, l-1); | 204 | lua_pushlstring(L, buffer, l-1); |
| 206 | } | 205 | } |
| 207 | else { | 206 | else { |
| @@ -214,7 +213,7 @@ static void manual_input (int version, int prompt) { | |||
| 214 | ldo(lua_dostring, lua_tostring(L, 1), 0); | 213 | ldo(lua_dostring, lua_tostring(L, 1), 0); |
| 215 | lua_remove(L, 1); /* remove ran string */ | 214 | lua_remove(L, 1); /* remove ran string */ |
| 216 | if (toprint && lua_gettop(L) > 0) { /* any result to print? */ | 215 | if (toprint && lua_gettop(L) > 0) { /* any result to print? */ |
| 217 | lua_getglobal(L, l_s("print")); | 216 | lua_getglobal(L, "print"); |
| 218 | lua_insert(L, 1); | 217 | lua_insert(L, 1); |
| 219 | lua_call(L, lua_gettop(L)-1, 0); | 218 | lua_call(L, lua_gettop(L)-1, 0); |
| 220 | } | 219 | } |
| @@ -224,7 +223,7 @@ static void manual_input (int version, int prompt) { | |||
| 224 | } | 223 | } |
| 225 | 224 | ||
| 226 | 225 | ||
| 227 | static int handle_argv (l_char *argv[], int *toclose) { | 226 | static int handle_argv (char *argv[], int *toclose) { |
| 228 | if (*argv == NULL) { /* no more arguments? */ | 227 | if (*argv == NULL) { /* no more arguments? */ |
| 229 | if (isatty(0)) { | 228 | if (isatty(0)) { |
| 230 | manual_input(1, 1); | 229 | manual_input(1, 1); |
| @@ -235,8 +234,8 @@ static int handle_argv (l_char *argv[], int *toclose) { | |||
| 235 | else { /* other arguments; loop over them */ | 234 | else { /* other arguments; loop over them */ |
| 236 | int i; | 235 | int i; |
| 237 | for (i = 0; argv[i] != NULL; i++) { | 236 | for (i = 0; argv[i] != NULL; i++) { |
| 238 | if (argv[i][0] != l_c('-')) { /* not an option? */ | 237 | if (argv[i][0] != '-') { /* not an option? */ |
| 239 | if (strchr(argv[i], l_c('='))) | 238 | if (strchr(argv[i], '=')) |
| 240 | assign(argv[i]); | 239 | assign(argv[i]); |
| 241 | else | 240 | else |
| 242 | if (file_input(argv[i]) != EXIT_SUCCESS) | 241 | if (file_input(argv[i]) != EXIT_SUCCESS) |
| @@ -247,49 +246,49 @@ static int handle_argv (l_char *argv[], int *toclose) { | |||
| 247 | ldo(lua_dofile, NULL, 1); /* executes stdin as a file */ | 246 | ldo(lua_dofile, NULL, 1); /* executes stdin as a file */ |
| 248 | break; | 247 | break; |
| 249 | } | 248 | } |
| 250 | case l_c('i'): { | 249 | case 'i': { |
| 251 | manual_input(0, 1); | 250 | manual_input(0, 1); |
| 252 | break; | 251 | break; |
| 253 | } | 252 | } |
| 254 | case l_c('q'): { | 253 | case 'q': { |
| 255 | manual_input(0, 0); | 254 | manual_input(0, 0); |
| 256 | break; | 255 | break; |
| 257 | } | 256 | } |
| 258 | case l_c('c'): { | 257 | case 'c': { |
| 259 | *toclose = 1; | 258 | *toclose = 1; |
| 260 | break; | 259 | break; |
| 261 | } | 260 | } |
| 262 | case l_c('v'): { | 261 | case 'v': { |
| 263 | print_version(); | 262 | print_version(); |
| 264 | break; | 263 | break; |
| 265 | } | 264 | } |
| 266 | case l_c('e'): { | 265 | case 'e': { |
| 267 | i++; | 266 | i++; |
| 268 | if (argv[i] == NULL) { | 267 | if (argv[i] == NULL) { |
| 269 | print_message(); | 268 | print_message(); |
| 270 | return EXIT_FAILURE; | 269 | return EXIT_FAILURE; |
| 271 | } | 270 | } |
| 272 | if (ldo(lua_dostring, argv[i], 1) != 0) { | 271 | if (ldo(lua_dostring, argv[i], 1) != 0) { |
| 273 | fprintf(stderr, LUA_PROGNAME l_s("error running argument `%.99s'\n"), | 272 | fprintf(stderr, LUA_PROGNAME "error running argument `%.99s'\n", |
| 274 | argv[i]); | 273 | argv[i]); |
| 275 | return EXIT_FAILURE; | 274 | return EXIT_FAILURE; |
| 276 | } | 275 | } |
| 277 | break; | 276 | break; |
| 278 | } | 277 | } |
| 279 | case l_c('f'): { | 278 | case 'f': { |
| 280 | i++; | 279 | i++; |
| 281 | if (argv[i] == NULL) { | 280 | if (argv[i] == NULL) { |
| 282 | print_message(); | 281 | print_message(); |
| 283 | return EXIT_FAILURE; | 282 | return EXIT_FAILURE; |
| 284 | } | 283 | } |
| 285 | getargs(argv+i); /* collect remaining arguments */ | 284 | getargs(argv+i); /* collect remaining arguments */ |
| 286 | lua_setglobal(L, l_s("arg")); | 285 | lua_setglobal(L, "arg"); |
| 287 | return file_input(argv[i]); /* stop scanning arguments */ | 286 | return file_input(argv[i]); /* stop scanning arguments */ |
| 288 | } | 287 | } |
| 289 | case l_c('s'): { | 288 | case 's': { |
| 290 | if (i == 0) break; /* option already handled */ | 289 | if (i == 0) break; /* option already handled */ |
| 291 | fprintf(stderr, | 290 | fprintf(stderr, |
| 292 | LUA_PROGNAME l_s("stack size (`-s') must be the first option\n")); | 291 | LUA_PROGNAME "stack size (`-s') must be the first option\n"); |
| 293 | return EXIT_FAILURE; | 292 | return EXIT_FAILURE; |
| 294 | } | 293 | } |
| 295 | default: { | 294 | default: { |
| @@ -303,12 +302,12 @@ static int handle_argv (l_char *argv[], int *toclose) { | |||
| 303 | } | 302 | } |
| 304 | 303 | ||
| 305 | 304 | ||
| 306 | static int getstacksize (int argc, l_char *argv[]) { | 305 | static int getstacksize (int argc, char *argv[]) { |
| 307 | int stacksize = 0; | 306 | int stacksize = 0; |
| 308 | if (argc >= 2 && argv[1][0] == l_c('-') && argv[1][1] == l_c('s')) { | 307 | if (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 's') { |
| 309 | stacksize = strtol(&argv[1][2], NULL, 10); | 308 | stacksize = strtol(&argv[1][2], NULL, 10); |
| 310 | if (stacksize <= 0) { | 309 | if (stacksize <= 0) { |
| 311 | fprintf(stderr, LUA_PROGNAME l_s("invalid stack size ('%.20s')\n"), | 310 | fprintf(stderr, LUA_PROGNAME "invalid stack size ('%.20s')\n", |
| 312 | &argv[1][2]); | 311 | &argv[1][2]); |
| 313 | exit(EXIT_FAILURE); | 312 | exit(EXIT_FAILURE); |
| 314 | } | 313 | } |
| @@ -317,10 +316,10 @@ static int getstacksize (int argc, l_char *argv[]) { | |||
| 317 | } | 316 | } |
| 318 | 317 | ||
| 319 | 318 | ||
| 320 | static void register_getargs (l_char *argv[]) { | 319 | static void register_getargs (char *argv[]) { |
| 321 | lua_newuserdatabox(L, argv); | 320 | lua_newuserdatabox(L, argv); |
| 322 | lua_pushcclosure(L, l_getargs, 1); | 321 | lua_pushcclosure(L, l_getargs, 1); |
| 323 | lua_setglobal(L, l_s("getargs")); | 322 | lua_setglobal(L, "getargs"); |
| 324 | } | 323 | } |
| 325 | 324 | ||
| 326 | 325 | ||
| @@ -333,7 +332,7 @@ static void openstdlibs (lua_State *l) { | |||
| 333 | } | 332 | } |
| 334 | 333 | ||
| 335 | 334 | ||
| 336 | int main (int argc, l_char *argv[]) { | 335 | int main (int argc, char *argv[]) { |
| 337 | int status; | 336 | int status; |
| 338 | int toclose = 0; | 337 | int toclose = 0; |
| 339 | L = lua_open(getstacksize(argc, argv)); /* create state */ | 338 | L = lua_open(getstacksize(argc, argv)); /* create state */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.106 2001/10/31 19:40:14 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.107 2001/10/31 19:58:11 roberto Exp $ |
| 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: info@lua.org | 5 | ** e-mail: info@lua.org |
| @@ -91,12 +91,6 @@ typedef int (*lua_CFunction) (lua_State *L); | |||
| 91 | #endif | 91 | #endif |
| 92 | typedef LUA_NUMBER lua_Number; | 92 | typedef LUA_NUMBER lua_Number; |
| 93 | 93 | ||
| 94 | /* Lua character type */ | ||
| 95 | #ifndef L_CHAR | ||
| 96 | #define L_CHAR char | ||
| 97 | #endif | ||
| 98 | typedef L_CHAR lua_char; | ||
| 99 | |||
| 100 | 94 | ||
| 101 | /* mark for all API functions */ | 95 | /* mark for all API functions */ |
| 102 | #ifndef LUA_API | 96 | #ifndef LUA_API |
| @@ -126,7 +120,7 @@ LUA_API int lua_stackspace (lua_State *L); | |||
| 126 | ** access functions (stack -> C) | 120 | ** access functions (stack -> C) |
| 127 | */ | 121 | */ |
| 128 | 122 | ||
| 129 | LUA_API const lua_char *lua_type (lua_State *L, int index); | 123 | LUA_API const char *lua_type (lua_State *L, int index); |
| 130 | LUA_API int lua_isnumber (lua_State *L, int index); | 124 | LUA_API int lua_isnumber (lua_State *L, int index); |
| 131 | LUA_API int lua_isstring (lua_State *L, int index); | 125 | LUA_API int lua_isstring (lua_State *L, int index); |
| 132 | LUA_API int lua_iscfunction (lua_State *L, int index); | 126 | LUA_API int lua_iscfunction (lua_State *L, int index); |
| @@ -137,7 +131,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2); | |||
| 137 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2); | 131 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2); |
| 138 | 132 | ||
| 139 | LUA_API lua_Number lua_tonumber (lua_State *L, int index); | 133 | LUA_API lua_Number lua_tonumber (lua_State *L, int index); |
| 140 | LUA_API const lua_char *lua_tostring (lua_State *L, int index); | 134 | LUA_API const char *lua_tostring (lua_State *L, int index); |
| 141 | LUA_API size_t lua_strlen (lua_State *L, int index); | 135 | LUA_API size_t lua_strlen (lua_State *L, int index); |
| 142 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index); | 136 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index); |
| 143 | LUA_API void *lua_touserdata (lua_State *L, int index); | 137 | LUA_API void *lua_touserdata (lua_State *L, int index); |
| @@ -149,19 +143,19 @@ LUA_API const void *lua_topointer (lua_State *L, int index); | |||
| 149 | */ | 143 | */ |
| 150 | LUA_API void lua_pushnil (lua_State *L); | 144 | LUA_API void lua_pushnil (lua_State *L); |
| 151 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n); | 145 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n); |
| 152 | LUA_API void lua_pushlstring (lua_State *L, const lua_char *s, size_t len); | 146 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); |
| 153 | LUA_API void lua_pushstring (lua_State *L, const lua_char *s); | 147 | LUA_API void lua_pushstring (lua_State *L, const char *s); |
| 154 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); | 148 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
| 155 | 149 | ||
| 156 | 150 | ||
| 157 | /* | 151 | /* |
| 158 | ** get functions (Lua -> stack) | 152 | ** get functions (Lua -> stack) |
| 159 | */ | 153 | */ |
| 160 | LUA_API void lua_getglobal (lua_State *L, const lua_char *name); | 154 | LUA_API void lua_getglobal (lua_State *L, const char *name); |
| 161 | LUA_API void lua_gettable (lua_State *L, int index); | 155 | LUA_API void lua_gettable (lua_State *L, int index); |
| 162 | LUA_API void lua_rawget (lua_State *L, int index); | 156 | LUA_API void lua_rawget (lua_State *L, int index); |
| 163 | LUA_API void lua_rawgeti (lua_State *L, int index, int n); | 157 | LUA_API void lua_rawgeti (lua_State *L, int index, int n); |
| 164 | LUA_API void lua_gettagmethod (lua_State *L, int tag, const lua_char *event); | 158 | LUA_API void lua_gettagmethod (lua_State *L, int tag, const char *event); |
| 165 | LUA_API void lua_newtable (lua_State *L); | 159 | LUA_API void lua_newtable (lua_State *L); |
| 166 | LUA_API void lua_getweakregistry (lua_State *L); | 160 | LUA_API void lua_getweakregistry (lua_State *L); |
| 167 | 161 | ||
| @@ -169,12 +163,12 @@ LUA_API void lua_getweakregistry (lua_State *L); | |||
| 169 | /* | 163 | /* |
| 170 | ** set functions (stack -> Lua) | 164 | ** set functions (stack -> Lua) |
| 171 | */ | 165 | */ |
| 172 | LUA_API void lua_setglobal (lua_State *L, const lua_char *name); | 166 | LUA_API void lua_setglobal (lua_State *L, const char *name); |
| 173 | LUA_API void lua_settable (lua_State *L, int index); | 167 | LUA_API void lua_settable (lua_State *L, int index); |
| 174 | LUA_API void lua_rawset (lua_State *L, int index); | 168 | LUA_API void lua_rawset (lua_State *L, int index); |
| 175 | LUA_API void lua_rawseti (lua_State *L, int index, int n); | 169 | LUA_API void lua_rawseti (lua_State *L, int index, int n); |
| 176 | LUA_API void lua_setglobals (lua_State *L); | 170 | LUA_API void lua_setglobals (lua_State *L); |
| 177 | LUA_API void lua_settagmethod (lua_State *L, int tag, const lua_char *event); | 171 | LUA_API void lua_settagmethod (lua_State *L, int tag, const char *event); |
| 178 | 172 | ||
| 179 | 173 | ||
| 180 | /* | 174 | /* |
| @@ -182,13 +176,13 @@ LUA_API void lua_settagmethod (lua_State *L, int tag, const lua_char *event); | |||
| 182 | */ | 176 | */ |
| 183 | LUA_API int lua_call (lua_State *L, int nargs, int nresults); | 177 | LUA_API int lua_call (lua_State *L, int nargs, int nresults); |
| 184 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); | 178 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); |
| 185 | LUA_API int lua_loadfile (lua_State *L, const lua_char *filename); | 179 | LUA_API int lua_loadfile (lua_State *L, const char *filename); |
| 186 | LUA_API int lua_dofile (lua_State *L, const lua_char *filename); | 180 | LUA_API int lua_dofile (lua_State *L, const char *filename); |
| 187 | LUA_API int lua_dostring (lua_State *L, const lua_char *str); | 181 | LUA_API int lua_dostring (lua_State *L, const char *str); |
| 188 | LUA_API int lua_loadbuffer (lua_State *L, const lua_char *buff, size_t size, | 182 | LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size, |
| 189 | const lua_char *name); | 183 | const char *name); |
| 190 | LUA_API int lua_dobuffer (lua_State *L, const lua_char *buff, size_t size, | 184 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, |
| 191 | const lua_char *name); | 185 | const char *name); |
| 192 | 186 | ||
| 193 | /* | 187 | /* |
| 194 | ** Garbage-collection functions | 188 | ** Garbage-collection functions |
| @@ -200,13 +194,13 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold); | |||
| 200 | /* | 194 | /* |
| 201 | ** miscellaneous functions | 195 | ** miscellaneous functions |
| 202 | */ | 196 | */ |
| 203 | LUA_API int lua_newtype (lua_State *L, const lua_char *name, int basictype); | 197 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype); |
| 204 | LUA_API void lua_settag (lua_State *L, int tag); | 198 | LUA_API void lua_settag (lua_State *L, int tag); |
| 205 | 199 | ||
| 206 | LUA_API int lua_name2tag (lua_State *L, const lua_char *name); | 200 | LUA_API int lua_name2tag (lua_State *L, const char *name); |
| 207 | LUA_API const lua_char *lua_tag2name (lua_State *L, int tag); | 201 | LUA_API const char *lua_tag2name (lua_State *L, int tag); |
| 208 | 202 | ||
| 209 | LUA_API void lua_error (lua_State *L, const lua_char *s); | 203 | LUA_API void lua_error (lua_State *L, const char *s); |
| 210 | 204 | ||
| 211 | LUA_API int lua_next (lua_State *L, int index); | 205 | LUA_API int lua_next (lua_State *L, int index); |
| 212 | LUA_API int lua_getn (lua_State *L, int index); | 206 | LUA_API int lua_getn (lua_State *L, int index); |
| @@ -240,8 +234,8 @@ LUA_API int lua_getweakmode (lua_State *L, int index); | |||
| 240 | #define lua_isnil(L,n) (lua_rawtag(L,n) == LUA_TNIL) | 234 | #define lua_isnil(L,n) (lua_rawtag(L,n) == LUA_TNIL) |
| 241 | #define lua_isnull(L,n) (lua_rawtag(L,n) == LUA_TNONE) | 235 | #define lua_isnull(L,n) (lua_rawtag(L,n) == LUA_TNONE) |
| 242 | 236 | ||
| 243 | #define lua_pushliteral(L, s) lua_pushlstring(L, s, \ | 237 | #define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \ |
| 244 | (sizeof(s)/sizeof(lua_char))-1) | 238 | (sizeof(s)/sizeof(char))-1) |
| 245 | 239 | ||
| 246 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX); | 240 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX); |
| 247 | #define lua_getglobals(L) lua_pushvalue(L, LUA_GLOBALSINDEX); | 241 | #define lua_getglobals(L) lua_pushvalue(L, LUA_GLOBALSINDEX); |
| @@ -264,7 +258,7 @@ LUA_API void lua_pushupvalues (lua_State *L); | |||
| 264 | #define LUA_REFNIL (-1) | 258 | #define LUA_REFNIL (-1) |
| 265 | 259 | ||
| 266 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ | 260 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ |
| 267 | (lua_error(L, l_s("unlocked references are obsolete")), 0)) | 261 | (lua_error(L, "unlocked references are obsolete"), 0)) |
| 268 | 262 | ||
| 269 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) | 263 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) |
| 270 | 264 | ||
| @@ -277,43 +271,21 @@ LUA_API void lua_pushupvalues (lua_State *L); | |||
| 277 | /* | 271 | /* |
| 278 | ** {====================================================================== | 272 | ** {====================================================================== |
| 279 | ** useful definitions for Lua kernel and libraries | 273 | ** useful definitions for Lua kernel and libraries |
| 274 | ** ======================================================================= | ||
| 280 | */ | 275 | */ |
| 281 | #ifdef LUA_PRIVATE | ||
| 282 | |||
| 283 | #define l_char lua_char | ||
| 284 | |||
| 285 | /* macro to control type of literal strings */ | ||
| 286 | #ifndef l_s | ||
| 287 | #define l_s(x) x | ||
| 288 | #endif | ||
| 289 | |||
| 290 | /* macro to control type of literal chars */ | ||
| 291 | #ifndef l_c | ||
| 292 | #define l_c(x) x | ||
| 293 | #endif | ||
| 294 | |||
| 295 | /* macro to `unsign' a character */ | ||
| 296 | #ifndef uchar | ||
| 297 | #define uchar(c) ((unsigned char)(c)) | ||
| 298 | #endif | ||
| 299 | |||
| 300 | /* integer type to hold the result of fgetc */ | ||
| 301 | #ifndef l_charint | ||
| 302 | #define l_charint int | ||
| 303 | #endif | ||
| 304 | 276 | ||
| 305 | /* | 277 | /* formats for Lua numbers */ |
| 306 | ** formats for Lua numbers | ||
| 307 | */ | ||
| 308 | #ifndef LUA_NUMBER_SCAN | 278 | #ifndef LUA_NUMBER_SCAN |
| 309 | #define LUA_NUMBER_SCAN "%lf" | 279 | #define LUA_NUMBER_SCAN "%lf" |
| 310 | #endif | 280 | #endif |
| 281 | |||
| 311 | #ifndef LUA_NUMBER_FMT | 282 | #ifndef LUA_NUMBER_FMT |
| 312 | #define LUA_NUMBER_FMT "%.16g" | 283 | #define LUA_NUMBER_FMT "%.16g" |
| 313 | #endif | 284 | #endif |
| 285 | |||
| 314 | /* function to convert a lua_Number to a string */ | 286 | /* function to convert a lua_Number to a string */ |
| 315 | #ifndef lua_number2str | 287 | #ifndef lua_number2str |
| 316 | #define lua_number2str(s,n) sprintf((s), l_s(LUA_NUMBER_FMT), (n)) | 288 | #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) |
| 317 | #endif | 289 | #endif |
| 318 | 290 | ||
| 319 | /* function to convert a string to a lua_Number */ | 291 | /* function to convert a string to a lua_Number */ |
| @@ -321,7 +293,6 @@ LUA_API void lua_pushupvalues (lua_State *L); | |||
| 321 | #define lua_str2number(s,p) strtod((s), (p)) | 293 | #define lua_str2number(s,p) strtod((s), (p)) |
| 322 | #endif | 294 | #endif |
| 323 | 295 | ||
| 324 | #endif | ||
| 325 | /* }====================================================================== */ | 296 | /* }====================================================================== */ |
| 326 | 297 | ||
| 327 | 298 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luadebug.h,v 1.19 2001/03/07 18:09:25 roberto Exp roberto $ | 2 | ** $Id: luadebug.h,v 1.20 2001/04/06 21:17:37 roberto Exp $ |
| 3 | ** Debugging API | 3 | ** Debugging API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -18,9 +18,9 @@ typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); | 20 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); |
| 21 | LUA_API int lua_getinfo (lua_State *L, const lua_char *what, lua_Debug *ar); | 21 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); |
| 22 | LUA_API const lua_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); | 22 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); |
| 23 | LUA_API const lua_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); | 23 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); |
| 24 | 24 | ||
| 25 | LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); | 25 | LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); |
| 26 | LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); | 26 | LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); |
| @@ -29,15 +29,15 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); | |||
| 29 | #define LUA_IDSIZE 60 | 29 | #define LUA_IDSIZE 60 |
| 30 | 30 | ||
| 31 | struct lua_Debug { | 31 | struct lua_Debug { |
| 32 | const lua_char *event; /* `call', `return' */ | 32 | const char *event; /* `call', `return' */ |
| 33 | int currentline; /* (l) */ | 33 | int currentline; /* (l) */ |
| 34 | const lua_char *name; /* (n) */ | 34 | const char *name; /* (n) */ |
| 35 | const lua_char *namewhat; /* (n) `global', `tag method', `local', `field' */ | 35 | const char *namewhat; /* (n) `global', `tag method', `local', `field' */ |
| 36 | int nups; /* (u) number of upvalues */ | 36 | int nups; /* (u) number of upvalues */ |
| 37 | int linedefined; /* (S) */ | 37 | int linedefined; /* (S) */ |
| 38 | const lua_char *what; /* (S) `Lua' function, `C' function, Lua `main' */ | 38 | const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ |
| 39 | const lua_char *source; /* (S) */ | 39 | const char *source; /* (S) */ |
| 40 | lua_char short_src[LUA_IDSIZE]; /* (S) */ | 40 | char short_src[LUA_IDSIZE]; /* (S) */ |
| 41 | /* private part */ | 41 | /* private part */ |
| 42 | struct CallInfo *_ci; /* active function */ | 42 | struct CallInfo *_ci; /* active function */ |
| 43 | }; | 43 | }; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 1.36 2001/07/19 14:34:06 lhf Exp lhf $ | 2 | ** $Id: lundump.c,v 1.43 2001/07/24 21:57:19 roberto Exp $ |
| 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 | */ |
| @@ -7,7 +7,6 @@ | |||
| 7 | #include <stdio.h> | 7 | #include <stdio.h> |
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| 10 | #define LUA_PRIVATE | ||
| 11 | #include "lua.h" | 10 | #include "lua.h" |
| 12 | 11 | ||
| 13 | #include "ldebug.h" | 12 | #include "ldebug.h" |
| @@ -20,15 +19,15 @@ | |||
| 20 | #define LoadByte ezgetc | 19 | #define LoadByte ezgetc |
| 21 | #define LoadShort (short) LoadInt | 20 | #define LoadShort (short) LoadInt |
| 22 | 21 | ||
| 23 | static const l_char* ZNAME (ZIO* Z) | 22 | static const char* ZNAME (ZIO* Z) |
| 24 | { | 23 | { |
| 25 | const l_char* s=zname(Z); | 24 | const char* s=zname(Z); |
| 26 | return (*s==l_c('@')) ? s+1 : s; | 25 | return (*s=='@') ? s+1 : s; |
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | static void unexpectedEOZ (lua_State* L, ZIO* Z) | 28 | static void unexpectedEOZ (lua_State* L, ZIO* Z) |
| 30 | { | 29 | { |
| 31 | luaO_verror(L,l_s("unexpected end of file in `%.99s'"),ZNAME(Z)); | 30 | luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z)); |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | static int ezgetc (lua_State* L, ZIO* Z) | 33 | static int ezgetc (lua_State* L, ZIO* Z) |
| @@ -48,9 +47,9 @@ static void LoadBlock (lua_State* L, void* b, size_t size, ZIO* Z, int swap) | |||
| 48 | { | 47 | { |
| 49 | if (swap) | 48 | if (swap) |
| 50 | { | 49 | { |
| 51 | l_char *p=(l_char*) b+size-1; | 50 | char *p=(char*) b+size-1; |
| 52 | int n=size; | 51 | int n=size; |
| 53 | while (n--) *p--=(l_char)ezgetc(L,Z); | 52 | while (n--) *p--=(char)ezgetc(L,Z); |
| 54 | } | 53 | } |
| 55 | else | 54 | else |
| 56 | ezread(L,Z,b,size); | 55 | ezread(L,Z,b,size); |
| @@ -60,12 +59,12 @@ static void LoadVector (lua_State* L, void* b, int m, size_t size, ZIO* Z, int s | |||
| 60 | { | 59 | { |
| 61 | if (swap) | 60 | if (swap) |
| 62 | { | 61 | { |
| 63 | l_char *q=(l_char*) b; | 62 | char *q=(char*) b; |
| 64 | while (m--) | 63 | while (m--) |
| 65 | { | 64 | { |
| 66 | l_char *p=q+size-1; | 65 | char *p=q+size-1; |
| 67 | int n=size; | 66 | int n=size; |
| 68 | while (n--) *p--=(l_char)ezgetc(L,Z); | 67 | while (n--) *p--=(char)ezgetc(L,Z); |
| 69 | q+=size; | 68 | q+=size; |
| 70 | } | 69 | } |
| 71 | } | 70 | } |
| @@ -101,7 +100,7 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap) | |||
| 101 | return NULL; | 100 | return NULL; |
| 102 | else | 101 | else |
| 103 | { | 102 | { |
| 104 | l_char* s=luaO_openspace(L,size,l_char); | 103 | char* s=luaO_openspace(L,size,char); |
| 105 | LoadBlock(L,s,size,Z,0); | 104 | LoadBlock(L,s,size,Z,0); |
| 106 | return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ | 105 | return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ |
| 107 | } | 106 | } |
| @@ -159,7 +158,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap) | |||
| 159 | tsvalue(o)=LoadString(L,Z,swap); | 158 | tsvalue(o)=LoadString(L,Z,swap); |
| 160 | break; | 159 | break; |
| 161 | default: | 160 | default: |
| 162 | luaO_verror(L,l_s("bad constant type (%d) in `%.99s'"),ttype(o),ZNAME(Z)); | 161 | luaO_verror(L,"bad constant type (%d) in `%.99s'",ttype(o),ZNAME(Z)); |
| 163 | break; | 162 | break; |
| 164 | } | 163 | } |
| 165 | } | 164 | } |
| @@ -183,25 +182,25 @@ static Proto* LoadFunction (lua_State* L, TString* p, ZIO* Z, int swap) | |||
| 183 | LoadConstants(L,f,Z,swap); | 182 | LoadConstants(L,f,Z,swap); |
| 184 | LoadCode(L,f,Z,swap); | 183 | LoadCode(L,f,Z,swap); |
| 185 | #ifndef TRUST_BINARIES | 184 | #ifndef TRUST_BINARIES |
| 186 | if (!luaG_checkcode(f)) luaO_verror(L,l_s("bad code in `%.99s'"),ZNAME(Z)); | 185 | if (!luaG_checkcode(f)) luaO_verror(L,"bad code in `%.99s'",ZNAME(Z)); |
| 187 | #endif | 186 | #endif |
| 188 | return f; | 187 | return f; |
| 189 | } | 188 | } |
| 190 | 189 | ||
| 191 | static void LoadSignature (lua_State* L, ZIO* Z) | 190 | static void LoadSignature (lua_State* L, ZIO* Z) |
| 192 | { | 191 | { |
| 193 | const l_char* s=l_s(LUA_SIGNATURE); | 192 | const char* s=LUA_SIGNATURE; |
| 194 | while (*s!=0 && ezgetc(L,Z)==*s) | 193 | while (*s!=0 && ezgetc(L,Z)==*s) |
| 195 | ++s; | 194 | ++s; |
| 196 | if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z)); | 195 | if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z)); |
| 197 | } | 196 | } |
| 198 | 197 | ||
| 199 | static void TestSize (lua_State* L, int s, const l_char* what, ZIO* Z) | 198 | static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) |
| 200 | { | 199 | { |
| 201 | int r=LoadByte(L,Z); | 200 | int r=LoadByte(L,Z); |
| 202 | if (r!=s) | 201 | if (r!=s) |
| 203 | luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n") | 202 | luaO_verror(L,"virtual machine mismatch in `%.99s':\n" |
| 204 | l_s(" size of %.20s is %d but read %d"),ZNAME(Z),what,s,r); | 203 | " size of %.20s is %d but read %d",ZNAME(Z),what,s,r); |
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | #define TESTSIZE(s,w) TestSize(L,s,w,Z) | 206 | #define TESTSIZE(s,w) TestSize(L,s,w,Z) |
| @@ -214,26 +213,26 @@ static int LoadHeader (lua_State* L, ZIO* Z) | |||
| 214 | LoadSignature(L,Z); | 213 | LoadSignature(L,Z); |
| 215 | version=LoadByte(L,Z); | 214 | version=LoadByte(L,Z); |
| 216 | if (version>VERSION) | 215 | if (version>VERSION) |
| 217 | luaO_verror(L,l_s("`%.99s' too new:\n") | 216 | luaO_verror(L,"`%.99s' too new:\n" |
| 218 | l_s(" read version %d.%d; expected at most %d.%d"), | 217 | " read version %d.%d; expected at most %d.%d", |
| 219 | ZNAME(Z),V(version),V(VERSION)); | 218 | ZNAME(Z),V(version),V(VERSION)); |
| 220 | if (version<VERSION0) /* check last major change */ | 219 | if (version<VERSION0) /* check last major change */ |
| 221 | luaO_verror(L,l_s("`%.99s' too old:\n") | 220 | luaO_verror(L,"`%.99s' too old:\n" |
| 222 | l_s(" read version %d.%d; expected at least %d.%d"), | 221 | " read version %d.%d; expected at least %d.%d", |
| 223 | ZNAME(Z),V(version),V(VERSION)); | 222 | ZNAME(Z),V(version),V(VERSION)); |
| 224 | swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */ | 223 | swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */ |
| 225 | TESTSIZE(sizeof(int),l_s("int")); | 224 | TESTSIZE(sizeof(int),"int"); |
| 226 | TESTSIZE(sizeof(size_t), l_s("size_t")); | 225 | TESTSIZE(sizeof(size_t), "size_t"); |
| 227 | TESTSIZE(sizeof(Instruction), l_s("size_t")); | 226 | TESTSIZE(sizeof(Instruction), "size_t"); |
| 228 | TESTSIZE(SIZE_OP, l_s("OP")); | 227 | TESTSIZE(SIZE_OP, "OP"); |
| 229 | TESTSIZE(SIZE_A, l_s("A")); | 228 | TESTSIZE(SIZE_A, "A"); |
| 230 | TESTSIZE(SIZE_B, l_s("B")); | 229 | TESTSIZE(SIZE_B, "B"); |
| 231 | TESTSIZE(SIZE_C, l_s("C")); | 230 | TESTSIZE(SIZE_C, "C"); |
| 232 | TESTSIZE(sizeof(lua_Number), l_s("number")); | 231 | TESTSIZE(sizeof(lua_Number), "number"); |
| 233 | x=LoadNumber(L,Z,swap); | 232 | x=LoadNumber(L,Z,swap); |
| 234 | if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ | 233 | if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ |
| 235 | luaO_verror(L,l_s("unknown number format in `%.99s':\n") | 234 | luaO_verror(L,"unknown number format in `%.99s':\n" |
| 236 | l_s(" read ") l_s(LUA_NUMBER_FMT) l_s("; expected ") l_s(LUA_NUMBER_FMT), | 235 | " read " LUA_NUMBER_FMT "; expected " LUA_NUMBER_FMT, |
| 237 | ZNAME(Z),x,tx); | 236 | ZNAME(Z),x,tx); |
| 238 | return swap; | 237 | return swap; |
| 239 | } | 238 | } |
| @@ -250,7 +249,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
| 250 | { | 249 | { |
| 251 | Proto* f=LoadChunk(L,Z); | 250 | Proto* f=LoadChunk(L,Z); |
| 252 | if (zgetc(Z)!=EOZ) | 251 | if (zgetc(Z)!=EOZ) |
| 253 | luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z)); | 252 | luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z)); |
| 254 | return f; | 253 | return f; |
| 255 | } | 254 | } |
| 256 | 255 | ||
| @@ -260,5 +259,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
| 260 | int luaU_endianness (void) | 259 | int luaU_endianness (void) |
| 261 | { | 260 | { |
| 262 | int x=1; | 261 | int x=1; |
| 263 | return *(l_char*)&x; | 262 | return *(char*)&x; |
| 264 | } | 263 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.197 2001/10/31 19:58:11 roberto Exp $ | 2 | ** $Id: lvm.c,v 1.198 2001/11/06 21:41:53 roberto Exp $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| 12 | 12 | ||
| 13 | #define LUA_PRIVATE | ||
| 14 | #include "lua.h" | 13 | #include "lua.h" |
| 15 | 14 | ||
| 16 | #include "lapi.h" | 15 | #include "lapi.h" |
| @@ -54,7 +53,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { | |||
| 54 | if (ttype(obj) != LUA_TNUMBER) | 53 | if (ttype(obj) != LUA_TNUMBER) |
| 55 | return 1; | 54 | return 1; |
| 56 | else { | 55 | else { |
| 57 | l_char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ | 56 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ |
| 58 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ | 57 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ |
| 59 | setsvalue(obj, luaS_new(L, s)); | 58 | setsvalue(obj, luaS_new(L, s)); |
| 60 | return 0; | 59 | return 0; |
| @@ -86,7 +85,7 @@ static void traceexec (lua_State *L, lua_Hook linehook) { | |||
| 86 | /* maximum stack used by a call to a tag method (func + args) */ | 85 | /* maximum stack used by a call to a tag method (func + args) */ |
| 87 | #define MAXSTACK_TM 4 | 86 | #define MAXSTACK_TM 4 |
| 88 | 87 | ||
| 89 | static StkId callTM (lua_State *L, Closure *f, const l_char *fmt, ...) { | 88 | static StkId callTM (lua_State *L, Closure *f, const char *fmt, ...) { |
| 90 | va_list argp; | 89 | va_list argp; |
| 91 | StkId base = L->top; | 90 | StkId base = L->top; |
| 92 | lua_assert(strlen(fmt)+1 <= MAXSTACK_TM); | 91 | lua_assert(strlen(fmt)+1 <= MAXSTACK_TM); |
| @@ -95,11 +94,11 @@ static StkId callTM (lua_State *L, Closure *f, const l_char *fmt, ...) { | |||
| 95 | setclvalue(L->top, f); /* push function */ | 94 | setclvalue(L->top, f); /* push function */ |
| 96 | L->top++; | 95 | L->top++; |
| 97 | while (*fmt) { | 96 | while (*fmt) { |
| 98 | if (*fmt++ == l_c('o')) { | 97 | if (*fmt++ == 'o') { |
| 99 | setobj(L->top, va_arg(argp, TObject *)); | 98 | setobj(L->top, va_arg(argp, TObject *)); |
| 100 | } | 99 | } |
| 101 | else { | 100 | else { |
| 102 | lua_assert(*(fmt-1) == l_c('s')); | 101 | lua_assert(*(fmt-1) == 's'); |
| 103 | setsvalue(L->top, va_arg(argp, TString *)); | 102 | setsvalue(L->top, va_arg(argp, TString *)); |
| 104 | } | 103 | } |
| 105 | L->top++; | 104 | L->top++; |
| @@ -146,9 +145,9 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) { | |||
| 146 | } else { /* not a table; try a `gettable' tag method */ | 145 | } else { /* not a table; try a `gettable' tag method */ |
| 147 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); | 146 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); |
| 148 | if (tm == NULL) /* no tag method? */ | 147 | if (tm == NULL) /* no tag method? */ |
| 149 | luaG_typeerror(L, t, l_s("index")); | 148 | luaG_typeerror(L, t, "index"); |
| 150 | } | 149 | } |
| 151 | setTMresult(L, res, callTM(L, tm, l_s("oo"), t, key)); | 150 | setTMresult(L, res, callTM(L, tm, "oo", t, key)); |
| 152 | } | 151 | } |
| 153 | 152 | ||
| 154 | 153 | ||
| @@ -169,9 +168,9 @@ void luaV_settable (lua_State *L, StkId t, TObject *key, StkId val) { | |||
| 169 | } else { /* not a table; try a `settable' tag method */ | 168 | } else { /* not a table; try a `settable' tag method */ |
| 170 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); | 169 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); |
| 171 | if (tm == NULL) /* no tag method? */ | 170 | if (tm == NULL) /* no tag method? */ |
| 172 | luaG_typeerror(L, t, l_s("index")); | 171 | luaG_typeerror(L, t, "index"); |
| 173 | } | 172 | } |
| 174 | setTM(L, callTM(L, tm, l_s("ooo"), t, key, val)); | 173 | setTM(L, callTM(L, tm, "ooo", t, key, val)); |
| 175 | } | 174 | } |
| 176 | 175 | ||
| 177 | 176 | ||
| @@ -183,7 +182,7 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) { | |||
| 183 | setobj(res, value); /* default behavior */ | 182 | setobj(res, value); /* default behavior */ |
| 184 | } | 183 | } |
| 185 | else | 184 | else |
| 186 | setTMresult(L, res, callTM(L, tm, l_s("so"), name, value)); | 185 | setTMresult(L, res, callTM(L, tm, "so", name, value)); |
| 187 | } | 186 | } |
| 188 | 187 | ||
| 189 | 188 | ||
| @@ -198,7 +197,7 @@ void luaV_setglobal (lua_State *L, TString *name, StkId val) { | |||
| 198 | settableval(oldvalue, val); /* warning: tricky optimization! */ | 197 | settableval(oldvalue, val); /* warning: tricky optimization! */ |
| 199 | } | 198 | } |
| 200 | else | 199 | else |
| 201 | setTM(L, callTM(L, tm, l_s("soo"), name, oldvalue, val)); | 200 | setTM(L, callTM(L, tm, "soo", name, oldvalue, val)); |
| 202 | } | 201 | } |
| 203 | 202 | ||
| 204 | 203 | ||
| @@ -213,7 +212,7 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, | |||
| 213 | return 0; /* no tag method */ | 212 | return 0; /* no tag method */ |
| 214 | } | 213 | } |
| 215 | } | 214 | } |
| 216 | setTMresult(L, res, callTM(L, tm, l_s("oo"), p1, p2)); | 215 | setTMresult(L, res, callTM(L, tm, "oo", p1, p2)); |
| 217 | return 1; | 216 | return 1; |
| 218 | } | 217 | } |
| 219 | 218 | ||
| @@ -226,9 +225,9 @@ static void call_arith (lua_State *L, StkId p1, TObject *p2, | |||
| 226 | 225 | ||
| 227 | 226 | ||
| 228 | static int luaV_strlessthan (const TString *ls, const TString *rs) { | 227 | static int luaV_strlessthan (const TString *ls, const TString *rs) { |
| 229 | const l_char *l = getstr(ls); | 228 | const char *l = getstr(ls); |
| 230 | size_t ll = ls->tsv.len; | 229 | size_t ll = ls->tsv.len; |
| 231 | const l_char *r = getstr(rs); | 230 | const char *r = getstr(rs); |
| 232 | size_t lr = rs->tsv.len; | 231 | size_t lr = rs->tsv.len; |
| 233 | for (;;) { | 232 | for (;;) { |
| 234 | int temp = strcoll(l, r); | 233 | int temp = strcoll(l, r); |
| @@ -271,14 +270,14 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
| 271 | /* at least two string values; get as many as possible */ | 270 | /* at least two string values; get as many as possible */ |
| 272 | lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) + | 271 | lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) + |
| 273 | cast(lu_mem, tsvalue(top-2)->tsv.len); | 272 | cast(lu_mem, tsvalue(top-2)->tsv.len); |
| 274 | l_char *buffer; | 273 | char *buffer; |
| 275 | int i; | 274 | int i; |
| 276 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 275 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |
| 277 | tl += tsvalue(top-n-1)->tsv.len; | 276 | tl += tsvalue(top-n-1)->tsv.len; |
| 278 | n++; | 277 | n++; |
| 279 | } | 278 | } |
| 280 | if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow")); | 279 | if (tl > MAX_SIZET) luaD_error(L, "string size overflow"); |
| 281 | buffer = luaO_openspace(L, tl, l_char); | 280 | buffer = luaO_openspace(L, tl, char); |
| 282 | tl = 0; | 281 | tl = 0; |
| 283 | for (i=n; i>0; i--) { /* concat all strings */ | 282 | for (i=n; i>0; i--) { /* concat all strings */ |
| 284 | size_t l = tsvalue(top-i)->tsv.len; | 283 | size_t l = tsvalue(top-i)->tsv.len; |
| @@ -301,7 +300,7 @@ static void luaV_pack (lua_State *L, StkId firstelem) { | |||
| 301 | luaH_setnum(L, htab, i+1, firstelem+i); | 300 | luaH_setnum(L, htab, i+1, firstelem+i); |
| 302 | /* store counter in field `n' */ | 301 | /* store counter in field `n' */ |
| 303 | setnvalue(&n, i); | 302 | setnvalue(&n, i); |
| 304 | luaH_setstr(L, htab, luaS_newliteral(L, l_s("n")), &n); | 303 | luaH_setstr(L, htab, luaS_newliteral(L, "n"), &n); |
| 305 | L->top = firstelem; /* remove elements from the stack */ | 304 | L->top = firstelem; /* remove elements from the stack */ |
| 306 | sethvalue(L->top, htab); | 305 | sethvalue(L->top, htab); |
| 307 | incr_top; | 306 | incr_top; |
| @@ -567,11 +566,11 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 567 | } | 566 | } |
| 568 | case OP_FORPREP: { | 567 | case OP_FORPREP: { |
| 569 | if (luaV_tonumber(ra, ra) == NULL) | 568 | if (luaV_tonumber(ra, ra) == NULL) |
| 570 | luaD_error(L, l_s("`for' initial value must be a number")); | 569 | luaD_error(L, "`for' initial value must be a number"); |
| 571 | if (luaV_tonumber(ra+1, ra+1) == NULL) | 570 | if (luaV_tonumber(ra+1, ra+1) == NULL) |
| 572 | luaD_error(L, l_s("`for' limit must be a number")); | 571 | luaD_error(L, "`for' limit must be a number"); |
| 573 | if (luaV_tonumber(ra+2, ra+2) == NULL) | 572 | if (luaV_tonumber(ra+2, ra+2) == NULL) |
| 574 | luaD_error(L, l_s("`for' step must be a number")); | 573 | luaD_error(L, "`for' step must be a number"); |
| 575 | /* decrement index (to be incremented) */ | 574 | /* decrement index (to be incremented) */ |
| 576 | chgnvalue(ra, nvalue(ra) - nvalue(ra+2)); | 575 | chgnvalue(ra, nvalue(ra) - nvalue(ra+2)); |
| 577 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ | 576 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ |
| @@ -583,7 +582,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 583 | runtime_check(L, ttype(ra+1) == LUA_TNUMBER && | 582 | runtime_check(L, ttype(ra+1) == LUA_TNUMBER && |
| 584 | ttype(ra+2) == LUA_TNUMBER); | 583 | ttype(ra+2) == LUA_TNUMBER); |
| 585 | if (ttype(ra) != LUA_TNUMBER) | 584 | if (ttype(ra) != LUA_TNUMBER) |
| 586 | luaD_error(L, l_s("`for' index must be a number")); | 585 | luaD_error(L, "`for' index must be a number"); |
| 587 | chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */ | 586 | chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */ |
| 588 | if (nvalue(ra+1) >= 0) { | 587 | if (nvalue(ra+1) >= 0) { |
| 589 | chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */ | 588 | chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */ |
| @@ -593,7 +592,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
| 593 | } | 592 | } |
| 594 | case OP_TFORPREP: { | 593 | case OP_TFORPREP: { |
| 595 | if (ttype(ra) != LUA_TTABLE) | 594 | if (ttype(ra) != LUA_TTABLE) |
| 596 | luaD_error(L, l_s("`for' table must be a table")); | 595 | luaD_error(L, "`for' table must be a table"); |
| 597 | setnvalue(ra+1, -1); /* initial index */ | 596 | setnvalue(ra+1, -1); /* initial index */ |
| 598 | setnilvalue(ra+2); | 597 | setnilvalue(ra+2); |
| 599 | setnilvalue(ra+3); | 598 | setnilvalue(ra+3); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lzio.c,v 1.13 2000/06/12 13:52:05 roberto Exp roberto $ | 2 | ** $Id: lzio.c,v 1.14 2001/03/26 14:31:49 roberto Exp $ |
| 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 | */ |
| @@ -9,7 +9,6 @@ | |||
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | 11 | ||
| 12 | #define LUA_PRIVATE | ||
| 13 | #include "lua.h" | 12 | #include "lua.h" |
| 14 | 13 | ||
| 15 | #include "lzio.h" | 14 | #include "lzio.h" |
