diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-23 14:17:25 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-23 14:17:25 -0300 |
| commit | 39b79783297bee79db9853b63d199e120a009a8f (patch) | |
| tree | c738c621c4c28d8822c2f785400786301985273b | |
| parent | d164e2294f73d8e69f00d95a66014514b2dd0ec0 (diff) | |
| download | lua-39b79783297bee79db9853b63d199e120a009a8f.tar.gz lua-39b79783297bee79db9853b63d199e120a009a8f.tar.bz2 lua-39b79783297bee79db9853b63d199e120a009a8f.zip | |
first (big) step to support wide chars
| -rw-r--r-- | lapi.c | 50 | ||||
| -rw-r--r-- | lauxlib.c | 43 | ||||
| -rw-r--r-- | lauxlib.h | 30 | ||||
| -rw-r--r-- | lbaselib.c | 194 | ||||
| -rw-r--r-- | lcode.c | 16 | ||||
| -rw-r--r-- | lcode.h | 4 | ||||
| -rw-r--r-- | ldblib.c | 64 | ||||
| -rw-r--r-- | ldebug.c | 80 | ||||
| -rw-r--r-- | ldebug.h | 6 | ||||
| -rw-r--r-- | ldo.c | 44 | ||||
| -rw-r--r-- | ldo.h | 4 | ||||
| -rw-r--r-- | lfunc.c | 4 | ||||
| -rw-r--r-- | lfunc.h | 4 | ||||
| -rw-r--r-- | lgc.c | 4 | ||||
| -rw-r--r-- | liolib.c | 252 | ||||
| -rw-r--r-- | llex.c | 230 | ||||
| -rw-r--r-- | llex.h | 12 | ||||
| -rw-r--r-- | llimits.h | 22 | ||||
| -rw-r--r-- | lmathlib.c | 58 | ||||
| -rw-r--r-- | lmem.c | 6 | ||||
| -rw-r--r-- | lmem.h | 4 | ||||
| -rw-r--r-- | lobject.c | 42 | ||||
| -rw-r--r-- | lobject.h | 14 | ||||
| -rw-r--r-- | lparser.c | 184 | ||||
| -rw-r--r-- | lstate.c | 4 | ||||
| -rw-r--r-- | lstate.h | 8 | ||||
| -rw-r--r-- | lstring.c | 6 | ||||
| -rw-r--r-- | lstring.h | 10 | ||||
| -rw-r--r-- | lstrlib.c | 254 | ||||
| -rw-r--r-- | ltable.c | 12 | ||||
| -rw-r--r-- | ltests.c | 266 | ||||
| -rw-r--r-- | ltm.c | 42 | ||||
| -rw-r--r-- | ltm.h | 8 | ||||
| -rw-r--r-- | lua.c | 106 | ||||
| -rw-r--r-- | lua.h | 41 | ||||
| -rw-r--r-- | luadebug.h | 20 | ||||
| -rw-r--r-- | lualib.h | 12 | ||||
| -rw-r--r-- | lundump.c | 50 | ||||
| -rw-r--r-- | lundump.h | 8 | ||||
| -rw-r--r-- | lvm.c | 54 |
40 files changed, 1151 insertions, 1121 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.131 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.132 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -22,8 +22,8 @@ | |||
| 22 | #include "lvm.h" | 22 | #include "lvm.h" |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | 25 | const l_char lua_ident[] = l_s("$Lua: ") l_s(LUA_VERSION) l_s(" ") |
| 26 | "$Authors: " LUA_AUTHORS " $"; | 26 | l_s(LUA_COPYRIGHT) l_s(" $\n") l_s("$Authors: ") l_s(LUA_AUTHORS) l_s(" $"); |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | ||
| @@ -150,21 +150,21 @@ LUA_API int lua_type (lua_State *L, int index) { | |||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | LUA_API const char *lua_typename (lua_State *L, int t) { | 153 | LUA_API const l_char *lua_typename (lua_State *L, int t) { |
| 154 | const char *s; | 154 | const l_char *s; |
| 155 | LUA_LOCK(L); | 155 | LUA_LOCK(L); |
| 156 | s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t); | 156 | s = (t == LUA_TNONE) ? l_s("no value") : basictypename(G(L), t); |
| 157 | LUA_UNLOCK(L); | 157 | LUA_UNLOCK(L); |
| 158 | return s; | 158 | return s; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | 161 | ||
| 162 | LUA_API const char *lua_xtype (lua_State *L, int index) { | 162 | LUA_API const l_char *lua_xtype (lua_State *L, int index) { |
| 163 | StkId o; | 163 | StkId o; |
| 164 | const char *type; | 164 | const l_char *type; |
| 165 | LUA_LOCK(L); | 165 | LUA_LOCK(L); |
| 166 | o = luaA_indexAcceptable(L, index); | 166 | o = luaA_indexAcceptable(L, index); |
| 167 | type = (o == NULL) ? "no value" : luaT_typename(G(L), o); | 167 | type = (o == NULL) ? l_s("no value") : luaT_typename(G(L), o); |
| 168 | LUA_UNLOCK(L); | 168 | LUA_UNLOCK(L); |
| 169 | return type; | 169 | return type; |
| 170 | } | 170 | } |
| @@ -242,9 +242,9 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | |||
| 242 | return n; | 242 | return n; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | LUA_API const char *lua_tostring (lua_State *L, int index) { | 245 | LUA_API const l_char *lua_tostring (lua_State *L, int index) { |
| 246 | StkId o; | 246 | StkId o; |
| 247 | const char *s; | 247 | const l_char *s; |
| 248 | LUA_LOCK(L); | 248 | LUA_LOCK(L); |
| 249 | o = luaA_indexAcceptable(L, index); | 249 | o = luaA_indexAcceptable(L, index); |
| 250 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); | 250 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); |
| @@ -329,7 +329,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | 331 | ||
| 332 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 332 | LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { |
| 333 | LUA_LOCK(L); | 333 | LUA_LOCK(L); |
| 334 | setsvalue(L->top, luaS_newlstr(L, s, len)); | 334 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
| 335 | api_incr_top(L); | 335 | api_incr_top(L); |
| @@ -337,7 +337,7 @@ LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | |||
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | 339 | ||
| 340 | LUA_API void lua_pushstring (lua_State *L, const char *s) { | 340 | LUA_API void lua_pushstring (lua_State *L, const l_char *s) { |
| 341 | if (s == NULL) | 341 | if (s == NULL) |
| 342 | lua_pushnil(L); | 342 | lua_pushnil(L); |
| 343 | else | 343 | else |
| @@ -369,7 +369,7 @@ LUA_API int lua_pushuserdata (lua_State *L, void *u) { | |||
| 369 | */ | 369 | */ |
| 370 | 370 | ||
| 371 | 371 | ||
| 372 | LUA_API void lua_getglobal (lua_State *L, const char *name) { | 372 | LUA_API void lua_getglobal (lua_State *L, const l_char *name) { |
| 373 | LUA_LOCK(L); | 373 | LUA_LOCK(L); |
| 374 | luaV_getglobal(L, luaS_new(L, name), L->top); | 374 | luaV_getglobal(L, luaS_new(L, name), L->top); |
| 375 | api_incr_top(L); | 375 | api_incr_top(L); |
| @@ -450,7 +450,7 @@ LUA_API void lua_newtable (lua_State *L) { | |||
| 450 | */ | 450 | */ |
| 451 | 451 | ||
| 452 | 452 | ||
| 453 | LUA_API void lua_setglobal (lua_State *L, const char *name) { | 453 | LUA_API void lua_setglobal (lua_State *L, const l_char *name) { |
| 454 | LUA_LOCK(L); | 454 | LUA_LOCK(L); |
| 455 | api_checknelems(L, 1); | 455 | api_checknelems(L, 1); |
| 456 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); | 456 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); |
| @@ -518,7 +518,7 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
| 518 | } | 518 | } |
| 519 | else { /* no more free places */ | 519 | else { /* no more free places */ |
| 520 | luaM_growvector(L, G(L)->refArray, G(L)->nref, G(L)->sizeref, struct Ref, | 520 | luaM_growvector(L, G(L)->refArray, G(L)->nref, G(L)->sizeref, struct Ref, |
| 521 | MAX_INT, "reference table overflow"); | 521 | MAX_INT, l_s("reference table overflow")); |
| 522 | ref = G(L)->nref++; | 522 | ref = G(L)->nref++; |
| 523 | } | 523 | } |
| 524 | setobj(&G(L)->refArray[ref].o, L->top-1); | 524 | setobj(&G(L)->refArray[ref].o, L->top-1); |
| @@ -582,22 +582,22 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
| 582 | ** miscellaneous functions | 582 | ** miscellaneous functions |
| 583 | */ | 583 | */ |
| 584 | 584 | ||
| 585 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { | 585 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { |
| 586 | int tag; | 586 | int tag; |
| 587 | LUA_LOCK(L); | 587 | LUA_LOCK(L); |
| 588 | if (basictype != LUA_TNONE && | 588 | if (basictype != LUA_TNONE && |
| 589 | basictype != LUA_TTABLE && | 589 | basictype != LUA_TTABLE && |
| 590 | basictype != LUA_TUSERDATA) | 590 | basictype != LUA_TUSERDATA) |
| 591 | luaO_verror(L, "invalid basic type (%d) for new type", basictype); | 591 | luaO_verror(L, l_s("invalid basic type (%d) for new type"), basictype); |
| 592 | tag = luaT_newtag(L, name, basictype); | 592 | tag = luaT_newtag(L, name, basictype); |
| 593 | if (tag == LUA_TNONE) | 593 | if (tag == LUA_TNONE) |
| 594 | luaO_verror(L, "type name '%.30s' already exists", name); | 594 | luaO_verror(L, l_s("type name '%.30s' already exists"), name); |
| 595 | LUA_UNLOCK(L); | 595 | LUA_UNLOCK(L); |
| 596 | return tag; | 596 | return tag; |
| 597 | } | 597 | } |
| 598 | 598 | ||
| 599 | 599 | ||
| 600 | LUA_API int lua_type2tag (lua_State *L, const char *name) { | 600 | LUA_API int lua_type2tag (lua_State *L, const l_char *name) { |
| 601 | int tag; | 601 | int tag; |
| 602 | const TObject *v; | 602 | const TObject *v; |
| 603 | LUA_LOCK(L); | 603 | LUA_LOCK(L); |
| @@ -618,10 +618,10 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
| 618 | LUA_LOCK(L); | 618 | LUA_LOCK(L); |
| 619 | api_checknelems(L, 1); | 619 | api_checknelems(L, 1); |
| 620 | if (tag < 0 || tag >= G(L)->ntag) | 620 | if (tag < 0 || tag >= G(L)->ntag) |
| 621 | luaO_verror(L, "%d is not a valid tag", tag); | 621 | luaO_verror(L, l_s("%d is not a valid tag"), tag); |
| 622 | basictype = G(L)->TMtable[tag].basictype; | 622 | basictype = G(L)->TMtable[tag].basictype; |
| 623 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) | 623 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) |
| 624 | luaO_verror(L, "tag %d can only be used for type '%.20s'", tag, | 624 | luaO_verror(L, l_s("tag %d can only be used for type '%.20s'"), tag, |
| 625 | basictypename(G(L), basictype)); | 625 | basictypename(G(L), basictype)); |
| 626 | switch (ttype(L->top-1)) { | 626 | switch (ttype(L->top-1)) { |
| 627 | case LUA_TTABLE: | 627 | case LUA_TTABLE: |
| @@ -631,14 +631,14 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
| 631 | tsvalue(L->top-1)->u.d.tag = tag; | 631 | tsvalue(L->top-1)->u.d.tag = tag; |
| 632 | break; | 632 | break; |
| 633 | default: | 633 | default: |
| 634 | luaO_verror(L, "cannot change the tag of a %.20s", | 634 | luaO_verror(L, l_s("cannot change the tag of a %.20s"), |
| 635 | luaT_typename(G(L), L->top-1)); | 635 | luaT_typename(G(L), L->top-1)); |
| 636 | } | 636 | } |
| 637 | LUA_UNLOCK(L); | 637 | LUA_UNLOCK(L); |
| 638 | } | 638 | } |
| 639 | 639 | ||
| 640 | 640 | ||
| 641 | LUA_API void lua_error (lua_State *L, const char *s) { | 641 | LUA_API void lua_error (lua_State *L, const l_char *s) { |
| 642 | LUA_LOCK(L); | 642 | LUA_LOCK(L); |
| 643 | luaD_error(L, s); | 643 | luaD_error(L, s); |
| 644 | LUA_UNLOCK(L); | 644 | LUA_UNLOCK(L); |
| @@ -685,7 +685,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
| 685 | int n; | 685 | int n; |
| 686 | LUA_LOCK(L); | 686 | LUA_LOCK(L); |
| 687 | h = hvalue(luaA_index(L, index)); | 687 | h = hvalue(luaA_index(L, index)); |
| 688 | value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ | 688 | value = luaH_getstr(h, luaS_newliteral(L, l_s("n"))); /* = h.n */ |
| 689 | if (ttype(value) == LUA_TNUMBER) | 689 | if (ttype(value) == LUA_TNUMBER) |
| 690 | n = (int)nvalue(value); | 690 | n = (int)nvalue(value); |
| 691 | else { | 691 | else { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.46 2001/02/02 19:02:40 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.47 2001/02/14 17:04:11 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -18,10 +18,11 @@ | |||
| 18 | 18 | ||
| 19 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
| 20 | #include "luadebug.h" | 20 | #include "luadebug.h" |
| 21 | #include "lualib.h" | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | 25 | LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]) { |
| 25 | int i; | 26 | int i; |
| 26 | for (i=0; list[i]; i++) | 27 | for (i=0; list[i]; i++) |
| 27 | if (strcmp(list[i], name) == 0) | 28 | if (strcmp(list[i], name) == 0) |
| @@ -29,20 +30,20 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | |||
| 29 | return -1; /* name not found */ | 30 | return -1; /* name not found */ |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) { | 33 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const l_char *extramsg) { |
| 33 | lua_Debug ar; | 34 | lua_Debug ar; |
| 34 | lua_getstack(L, 0, &ar); | 35 | lua_getstack(L, 0, &ar); |
| 35 | lua_getinfo(L, "n", &ar); | 36 | lua_getinfo(L, l_s("n"), &ar); |
| 36 | if (ar.name == NULL) | 37 | if (ar.name == NULL) |
| 37 | ar.name = "?"; | 38 | ar.name = l_s("?"); |
| 38 | luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", | 39 | luaL_verror(L, l_s("bad argument #%d to `%.50s' (%.100s)"), |
| 39 | narg, ar.name, extramsg); | 40 | narg, ar.name, extramsg); |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | 43 | ||
| 43 | static void type_error (lua_State *L, int narg, const char *tname) { | 44 | static void type_error (lua_State *L, int narg, const l_char *tname) { |
| 44 | char buff[80]; | 45 | l_char buff[80]; |
| 45 | sprintf(buff, "%.25s expected, got %.25s", tname, lua_xtype(L, narg)); | 46 | sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtype(L, narg)); |
| 46 | luaL_argerror(L, narg, buff); | 47 | luaL_argerror(L, narg, buff); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| @@ -52,9 +53,9 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | 55 | ||
| 55 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { | 56 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *mes) { |
| 56 | if (space > lua_stackspace(L)) | 57 | if (space > lua_stackspace(L)) |
| 57 | luaL_verror(L, "stack overflow (%.30s)", mes); | 58 | luaL_verror(L, l_s("stack overflow (%.30s)"), mes); |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | 61 | ||
| @@ -66,27 +67,27 @@ LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) { | |||
| 66 | 67 | ||
| 67 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { | 68 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { |
| 68 | if (lua_type(L, narg) == LUA_TNONE) | 69 | if (lua_type(L, narg) == LUA_TNONE) |
| 69 | luaL_argerror(L, narg, "value expected"); | 70 | luaL_argerror(L, narg, l_s("value expected")); |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | 73 | ||
| 73 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, | 74 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, |
| 74 | const char *name) { | 75 | const l_char *name) { |
| 75 | if (strcmp(lua_xtype(L, narg), name) != 0) | 76 | if (strcmp(lua_xtype(L, narg), name) != 0) |
| 76 | type_error(L, narg, name); | 77 | type_error(L, narg, name); |
| 77 | return lua_touserdata(L, narg); | 78 | return lua_touserdata(L, narg); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | 81 | ||
| 81 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { | 82 | LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { |
| 82 | const char *s = lua_tostring(L, narg); | 83 | const l_char *s = lua_tostring(L, narg); |
| 83 | if (!s) tag_error(L, narg, LUA_TSTRING); | 84 | if (!s) tag_error(L, narg, LUA_TSTRING); |
| 84 | if (len) *len = lua_strlen(L, narg); | 85 | if (len) *len = lua_strlen(L, narg); |
| 85 | return s; | 86 | return s; |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | 89 | ||
| 89 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { | 90 | LUALIB_API const l_char *luaL_opt_lstr (lua_State *L, int narg, const l_char *def, size_t *len) { |
| 90 | if (lua_isnull(L, narg)) { | 91 | if (lua_isnull(L, narg)) { |
| 91 | if (len) | 92 | if (len) |
| 92 | *len = (def ? strlen(def) : 0); | 93 | *len = (def ? strlen(def) : 0); |
| @@ -117,8 +118,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n) { | |||
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | 120 | ||
| 120 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...) { | 121 | LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...) { |
| 121 | char buff[500]; | 122 | l_char buff[500]; |
| 122 | va_list argp; | 123 | va_list argp; |
| 123 | va_start(argp, fmt); | 124 | va_start(argp, fmt); |
| 124 | vsprintf(buff, fmt, argp); | 125 | vsprintf(buff, fmt, argp); |
| @@ -172,20 +173,20 @@ static void adjuststack (luaL_Buffer *B) { | |||
| 172 | } | 173 | } |
| 173 | 174 | ||
| 174 | 175 | ||
| 175 | LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { | 176 | LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B) { |
| 176 | if (emptybuffer(B)) | 177 | if (emptybuffer(B)) |
| 177 | adjuststack(B); | 178 | adjuststack(B); |
| 178 | return B->buffer; | 179 | return B->buffer; |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 181 | 182 | ||
| 182 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { | 183 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l) { |
| 183 | while (l--) | 184 | while (l--) |
| 184 | luaL_putchar(B, *s++); | 185 | luaL_putchar(B, *s++); |
| 185 | } | 186 | } |
| 186 | 187 | ||
| 187 | 188 | ||
| 188 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { | 189 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s) { |
| 189 | luaL_addlstring(B, s, strlen(s)); | 190 | luaL_addlstring(B, s, strlen(s)); |
| 190 | } | 191 | } |
| 191 | 192 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.32 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.33 2001/02/02 19:02:40 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -21,25 +21,25 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | typedef struct luaL_reg { | 23 | typedef struct luaL_reg { |
| 24 | const char *name; | 24 | const l_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_argerror (lua_State *L, int numarg, const char *extramsg); | 30 | LUALIB_API void luaL_argerror (lua_State *L, int numarg, const l_char *extramsg); |
| 31 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len); | 31 | LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int numArg, size_t *len); |
| 32 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, size_t *len); | 32 | LUALIB_API const l_char *luaL_opt_lstr (lua_State *L, int numArg, const l_char *def, size_t *len); |
| 33 | LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg); | 33 | LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg); |
| 34 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def); | 34 | LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def); |
| 35 | 35 | ||
| 36 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg); | 36 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *msg); |
| 37 | LUALIB_API void luaL_checktype (lua_State *L, int narg, int t); | 37 | LUALIB_API void luaL_checktype (lua_State *L, int narg, int t); |
| 38 | LUALIB_API void luaL_checkany (lua_State *L, int narg); | 38 | LUALIB_API void luaL_checkany (lua_State *L, int narg); |
| 39 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, const char *name); | 39 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, const l_char *name); |
| 40 | 40 | ||
| 41 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...); | 41 | LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...); |
| 42 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]); | 42 | LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]); |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | 45 | ||
| @@ -73,22 +73,22 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]); | |||
| 73 | 73 | ||
| 74 | 74 | ||
| 75 | typedef struct luaL_Buffer { | 75 | typedef struct luaL_Buffer { |
| 76 | char *p; /* current position in buffer */ | 76 | l_char *p; /* current position in buffer */ |
| 77 | int level; | 77 | int level; |
| 78 | lua_State *L; | 78 | lua_State *L; |
| 79 | char buffer[LUAL_BUFFERSIZE]; | 79 | l_char buffer[LUAL_BUFFERSIZE]; |
| 80 | } luaL_Buffer; | 80 | } luaL_Buffer; |
| 81 | 81 | ||
| 82 | #define luaL_putchar(B,c) \ | 82 | #define luaL_putchar(B,c) \ |
| 83 | ((void)((B)->p < &(B)->buffer[LUAL_BUFFERSIZE] || luaL_prepbuffer(B)), \ | 83 | ((void)((B)->p < &(B)->buffer[LUAL_BUFFERSIZE] || luaL_prepbuffer(B)), \ |
| 84 | (*(B)->p++ = (char)(c))) | 84 | (*(B)->p++ = (l_char)(c))) |
| 85 | 85 | ||
| 86 | #define luaL_addsize(B,n) ((B)->p += (n)) | 86 | #define luaL_addsize(B,n) ((B)->p += (n)) |
| 87 | 87 | ||
| 88 | LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B); | 88 | LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B); |
| 89 | LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B); | 89 | LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B); |
| 90 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l); | 90 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l); |
| 91 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s); | 91 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s); |
| 92 | LUALIB_API void luaL_addvalue (luaL_Buffer *B); | 92 | LUALIB_API void luaL_addvalue (luaL_Buffer *B); |
| 93 | LUALIB_API void luaL_pushresult (luaL_Buffer *B); | 93 | LUALIB_API void luaL_pushresult (luaL_Buffer *B); |
| 94 | 94 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.25 2001/02/22 17:15:18 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.26 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,21 +35,21 @@ static int luaB__ALERT (lua_State *L) { | |||
| 35 | */ | 35 | */ |
| 36 | static int luaB__ERRORMESSAGE (lua_State *L) { | 36 | static int luaB__ERRORMESSAGE (lua_State *L) { |
| 37 | luaL_checktype(L, 1, LUA_TSTRING); | 37 | luaL_checktype(L, 1, LUA_TSTRING); |
| 38 | lua_getglobal(L, LUA_ALERT); | 38 | lua_getglobal(L, l_s(LUA_ALERT)); |
| 39 | if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ | 39 | if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ |
| 40 | lua_Debug ar; | 40 | lua_Debug ar; |
| 41 | lua_pushliteral(L, "error: "); | 41 | lua_pushliteral(L, l_s("error: ")); |
| 42 | lua_pushvalue(L, 1); | 42 | lua_pushvalue(L, 1); |
| 43 | if (lua_getstack(L, 1, &ar)) { | 43 | if (lua_getstack(L, 1, &ar)) { |
| 44 | lua_getinfo(L, "Sl", &ar); | 44 | lua_getinfo(L, l_s("Sl"), &ar); |
| 45 | if (ar.source && ar.currentline > 0) { | 45 | if (ar.source && ar.currentline > 0) { |
| 46 | char buff[100]; | 46 | l_char buff[100]; |
| 47 | sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline); | 47 | sprintf(buff, l_s("\n <%.70s: line %d>"), ar.short_src, ar.currentline); |
| 48 | lua_pushstring(L, buff); | 48 | lua_pushstring(L, buff); |
| 49 | lua_concat(L, 2); | 49 | lua_concat(L, 2); |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | lua_pushliteral(L, "\n"); | 52 | lua_pushliteral(L, l_s("\n")); |
| 53 | lua_concat(L, 3); | 53 | lua_concat(L, 3); |
| 54 | lua_rawcall(L, 1, 0); | 54 | lua_rawcall(L, 1, 0); |
| 55 | } | 55 | } |
| @@ -66,20 +66,20 @@ static int luaB__ERRORMESSAGE (lua_State *L) { | |||
| 66 | static int luaB_print (lua_State *L) { | 66 | static int luaB_print (lua_State *L) { |
| 67 | int n = lua_gettop(L); /* number of arguments */ | 67 | int n = lua_gettop(L); /* number of arguments */ |
| 68 | int i; | 68 | int i; |
| 69 | lua_getglobal(L, "tostring"); | 69 | lua_getglobal(L, l_s("tostring")); |
| 70 | for (i=1; i<=n; i++) { | 70 | for (i=1; i<=n; i++) { |
| 71 | const char *s; | 71 | const l_char *s; |
| 72 | lua_pushvalue(L, -1); /* function to be called */ | 72 | lua_pushvalue(L, -1); /* function to be called */ |
| 73 | lua_pushvalue(L, i); /* value to print */ | 73 | lua_pushvalue(L, i); /* value to print */ |
| 74 | lua_rawcall(L, 1, 1); | 74 | lua_rawcall(L, 1, 1); |
| 75 | s = lua_tostring(L, -1); /* get result */ | 75 | s = lua_tostring(L, -1); /* get result */ |
| 76 | if (s == NULL) | 76 | if (s == NULL) |
| 77 | lua_error(L, "`tostring' must return a string to `print'"); | 77 | lua_error(L, l_s("`tostring' must return a string to `print'")); |
| 78 | if (i>1) fputs("\t", stdout); | 78 | if (i>1) fputs(l_s("\t"), stdout); |
| 79 | fputs(s, stdout); | 79 | fputs(s, stdout); |
| 80 | lua_pop(L, 1); /* pop result */ | 80 | lua_pop(L, 1); /* pop result */ |
| 81 | } | 81 | } |
| 82 | fputs("\n", stdout); | 82 | fputs(l_s("\n"), stdout); |
| 83 | return 0; | 83 | return 0; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| @@ -94,14 +94,14 @@ static int luaB_tonumber (lua_State *L) { | |||
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | else { | 96 | else { |
| 97 | const char *s1 = luaL_check_string(L, 1); | 97 | const l_char *s1 = luaL_check_string(L, 1); |
| 98 | char *s2; | 98 | l_char *s2; |
| 99 | unsigned long n; | 99 | unsigned long n; |
| 100 | luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range"); | 100 | luaL_arg_check(L, 2 <= base && base <= 36, 2, l_s("base out of range")); |
| 101 | n = strtoul(s1, &s2, base); | 101 | n = strtoul(s1, &s2, base); |
| 102 | if (s1 != s2) { /* at least one valid digit? */ | 102 | if (s1 != s2) { /* at least one valid digit? */ |
| 103 | while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */ | 103 | while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */ |
| 104 | if (*s2 == '\0') { /* no invalid trailing characters? */ | 104 | if (*s2 == l_c('\0')) { /* no invalid trailing characters? */ |
| 105 | lua_pushnumber(L, n); | 105 | lua_pushnumber(L, n); |
| 106 | return 1; | 106 | return 1; |
| 107 | } | 107 | } |
| @@ -135,14 +135,14 @@ static int gettag (lua_State *L, int narg) { | |||
| 135 | case LUA_TNUMBER: | 135 | case LUA_TNUMBER: |
| 136 | return (int)lua_tonumber(L, narg); | 136 | return (int)lua_tonumber(L, narg); |
| 137 | case LUA_TSTRING: { | 137 | case LUA_TSTRING: { |
| 138 | const char *name = lua_tostring(L, narg); | 138 | const l_char *name = lua_tostring(L, narg); |
| 139 | int tag = lua_type2tag(L, name); | 139 | int tag = lua_type2tag(L, name); |
| 140 | if (tag == LUA_TNONE) | 140 | if (tag == LUA_TNONE) |
| 141 | luaL_verror(L, "'%.30s' is not a valid type name", name); | 141 | luaL_verror(L, l_s("'%.30s' is not a valid type name"), name); |
| 142 | return tag; | 142 | return tag; |
| 143 | } | 143 | } |
| 144 | default: | 144 | default: |
| 145 | luaL_argerror(L, narg, "tag or type name expected"); | 145 | luaL_argerror(L, narg, l_s("tag or type name expected")); |
| 146 | return 0; /* to avoid warnings */ | 146 | return 0; /* to avoid warnings */ |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| @@ -162,7 +162,7 @@ static int luaB_settag (lua_State *L) { | |||
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | static int luaB_newtype (lua_State *L) { | 164 | static int luaB_newtype (lua_State *L) { |
| 165 | const char *name = luaL_opt_string(L, 1, NULL); | 165 | const l_char *name = luaL_opt_string(L, 1, NULL); |
| 166 | lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); | 166 | lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); |
| 167 | return 1; | 167 | return 1; |
| 168 | } | 168 | } |
| @@ -199,11 +199,11 @@ static int luaB_rawset (lua_State *L) { | |||
| 199 | 199 | ||
| 200 | static int luaB_settagmethod (lua_State *L) { | 200 | static int luaB_settagmethod (lua_State *L) { |
| 201 | int tag = gettag(L, 1); | 201 | int tag = gettag(L, 1); |
| 202 | const char *event = luaL_check_string(L, 2); | 202 | const l_char *event = luaL_check_string(L, 2); |
| 203 | luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, | 203 | luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, |
| 204 | "function or nil expected"); | 204 | l_s("function or nil expected")); |
| 205 | if (strcmp(event, "gc") == 0) | 205 | if (strcmp(event, l_s("gc")) == 0) |
| 206 | lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua"); | 206 | lua_error(L, l_s("deprecated use: cannot set the `gc' tag method from Lua")); |
| 207 | lua_gettagmethod(L, tag, event); | 207 | lua_gettagmethod(L, tag, event); |
| 208 | lua_pushvalue(L, 3); | 208 | lua_pushvalue(L, 3); |
| 209 | lua_settagmethod(L, tag, event); | 209 | lua_settagmethod(L, tag, event); |
| @@ -213,9 +213,9 @@ static int luaB_settagmethod (lua_State *L) { | |||
| 213 | 213 | ||
| 214 | static int luaB_gettagmethod (lua_State *L) { | 214 | static int luaB_gettagmethod (lua_State *L) { |
| 215 | int tag = gettag(L, 1); | 215 | int tag = gettag(L, 1); |
| 216 | const char *event = luaL_check_string(L, 2); | 216 | const l_char *event = luaL_check_string(L, 2); |
| 217 | if (strcmp(event, "gc") == 0) | 217 | if (strcmp(event, l_s("gc")) == 0) |
| 218 | lua_error(L, "deprecated use: cannot get the `gc' tag method from Lua"); | 218 | lua_error(L, l_s("deprecated use: cannot get the `gc' tag method from Lua")); |
| 219 | lua_gettagmethod(L, tag, event); | 219 | lua_gettagmethod(L, tag, event); |
| 220 | return 1; | 220 | return 1; |
| 221 | } | 221 | } |
| @@ -261,9 +261,9 @@ static int luaB_next (lua_State *L) { | |||
| 261 | 261 | ||
| 262 | 262 | ||
| 263 | static int passresults (lua_State *L, int status, int oldtop) { | 263 | static int passresults (lua_State *L, int status, int oldtop) { |
| 264 | static const char *const errornames[] = | 264 | static const l_char *const errornames[] = |
| 265 | {"ok", "run-time error", "file error", "syntax error", | 265 | {l_s("ok"), l_s("run-time error"), l_s("file error"), l_s("syntax error"), |
| 266 | "memory error", "error in error handling"}; | 266 | l_s("memory error"), l_s("error in error handling")}; |
| 267 | if (status == 0) { | 267 | if (status == 0) { |
| 268 | int nresults = lua_gettop(L) - oldtop; | 268 | int nresults = lua_gettop(L) - oldtop; |
| 269 | if (nresults > 0) | 269 | if (nresults > 0) |
| @@ -283,59 +283,59 @@ static int passresults (lua_State *L, int status, int oldtop) { | |||
| 283 | static int luaB_dostring (lua_State *L) { | 283 | static int luaB_dostring (lua_State *L) { |
| 284 | int oldtop = lua_gettop(L); | 284 | int oldtop = lua_gettop(L); |
| 285 | size_t l; | 285 | size_t l; |
| 286 | const char *s = luaL_check_lstr(L, 1, &l); | 286 | const l_char *s = luaL_check_lstr(L, 1, &l); |
| 287 | const char *chunkname = luaL_opt_string(L, 2, s); | 287 | const l_char *chunkname = luaL_opt_string(L, 2, s); |
| 288 | return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop); | 288 | return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop); |
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | 291 | ||
| 292 | static int luaB_dofile (lua_State *L) { | 292 | static int luaB_dofile (lua_State *L) { |
| 293 | int oldtop = lua_gettop(L); | 293 | int oldtop = lua_gettop(L); |
| 294 | const char *fname = luaL_opt_string(L, 1, NULL); | 294 | const l_char *fname = luaL_opt_string(L, 1, NULL); |
| 295 | return passresults(L, lua_dofile(L, fname), oldtop); | 295 | return passresults(L, lua_dofile(L, fname), oldtop); |
| 296 | } | 296 | } |
| 297 | 297 | ||
| 298 | 298 | ||
| 299 | static int luaB_call (lua_State *L) { | 299 | static int luaB_call (lua_State *L) { |
| 300 | int oldtop; | 300 | int oldtop; |
| 301 | const char *options = luaL_opt_string(L, 3, ""); | 301 | const l_char *options = luaL_opt_string(L, 3, l_s("")); |
| 302 | int err = 0; /* index of old error method */ | 302 | int err = 0; /* index of old error method */ |
| 303 | int i, status; | 303 | int i, status; |
| 304 | int n; | 304 | int n; |
| 305 | luaL_checktype(L, 2, LUA_TTABLE); | 305 | luaL_checktype(L, 2, LUA_TTABLE); |
| 306 | n = lua_getn(L, 2); | 306 | n = lua_getn(L, 2); |
| 307 | if (!lua_isnull(L, 4)) { /* set new error method */ | 307 | if (!lua_isnull(L, 4)) { /* set new error method */ |
| 308 | lua_getglobal(L, LUA_ERRORMESSAGE); | 308 | lua_getglobal(L, l_s(LUA_ERRORMESSAGE)); |
| 309 | err = lua_gettop(L); /* get index */ | 309 | err = lua_gettop(L); /* get index */ |
| 310 | lua_pushvalue(L, 4); | 310 | lua_pushvalue(L, 4); |
| 311 | lua_setglobal(L, LUA_ERRORMESSAGE); | 311 | lua_setglobal(L, l_s(LUA_ERRORMESSAGE)); |
| 312 | } | 312 | } |
| 313 | oldtop = lua_gettop(L); /* top before function-call preparation */ | 313 | oldtop = lua_gettop(L); /* top before function-call preparation */ |
| 314 | /* push function */ | 314 | /* push function */ |
| 315 | lua_pushvalue(L, 1); | 315 | lua_pushvalue(L, 1); |
| 316 | luaL_checkstack(L, n, "too many arguments"); | 316 | luaL_checkstack(L, n, l_s("too many arguments")); |
| 317 | for (i=0; i<n; i++) /* push arg[1...n] */ | 317 | for (i=0; i<n; i++) /* push arg[1...n] */ |
| 318 | lua_rawgeti(L, 2, i+1); | 318 | lua_rawgeti(L, 2, i+1); |
| 319 | status = lua_call(L, n, LUA_MULTRET); | 319 | status = lua_call(L, n, LUA_MULTRET); |
| 320 | if (err != 0) { /* restore old error method */ | 320 | if (err != 0) { /* restore old error method */ |
| 321 | lua_pushvalue(L, err); | 321 | lua_pushvalue(L, err); |
| 322 | lua_setglobal(L, LUA_ERRORMESSAGE); | 322 | lua_setglobal(L, l_s(LUA_ERRORMESSAGE)); |
| 323 | } | 323 | } |
| 324 | if (status != 0) { /* error in call? */ | 324 | if (status != 0) { /* error in call? */ |
| 325 | if (strchr(options, 'x')) | 325 | if (strchr(options, l_c('x'))) |
| 326 | lua_pushnil(L); /* return nil to signal the error */ | 326 | lua_pushnil(L); /* return nil to signal the error */ |
| 327 | else | 327 | else |
| 328 | lua_error(L, NULL); /* propagate error without additional messages */ | 328 | lua_error(L, NULL); /* propagate error without additional messages */ |
| 329 | return 1; | 329 | return 1; |
| 330 | } | 330 | } |
| 331 | if (strchr(options, 'p')) /* pack results? */ | 331 | if (strchr(options, l_c('p'))) /* pack results? */ |
| 332 | lua_error(L, "deprecated option `p' in `call'"); | 332 | lua_error(L, l_s("deprecated option `p' in `call'")); |
| 333 | return lua_gettop(L) - oldtop; /* results are already on the stack */ | 333 | return lua_gettop(L) - oldtop; /* results are already on the stack */ |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | 336 | ||
| 337 | static int luaB_tostring (lua_State *L) { | 337 | static int luaB_tostring (lua_State *L) { |
| 338 | char buff[64]; | 338 | l_char buff[64]; |
| 339 | switch (lua_type(L, 1)) { | 339 | switch (lua_type(L, 1)) { |
| 340 | case LUA_TNUMBER: | 340 | case LUA_TNUMBER: |
| 341 | lua_pushstring(L, lua_tostring(L, 1)); | 341 | lua_pushstring(L, lua_tostring(L, 1)); |
| @@ -344,24 +344,24 @@ static int luaB_tostring (lua_State *L) { | |||
| 344 | lua_pushvalue(L, 1); | 344 | lua_pushvalue(L, 1); |
| 345 | return 1; | 345 | return 1; |
| 346 | case LUA_TTABLE: | 346 | case LUA_TTABLE: |
| 347 | sprintf(buff, "%.40s: %p", lua_xtype(L, 1), lua_topointer(L, 1)); | 347 | sprintf(buff, l_s("%.40s: %p"), lua_xtype(L, 1), lua_topointer(L, 1)); |
| 348 | break; | 348 | break; |
| 349 | case LUA_TFUNCTION: | 349 | case LUA_TFUNCTION: |
| 350 | sprintf(buff, "function: %p", lua_topointer(L, 1)); | 350 | sprintf(buff, l_s("function: %p"), lua_topointer(L, 1)); |
| 351 | break; | 351 | break; |
| 352 | case LUA_TUSERDATA: { | 352 | case LUA_TUSERDATA: { |
| 353 | const char *t = lua_xtype(L, 1); | 353 | const l_char *t = lua_xtype(L, 1); |
| 354 | if (strcmp(t, "userdata") == 0) | 354 | if (strcmp(t, l_s("userdata")) == 0) |
| 355 | sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1)); | 355 | sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), lua_touserdata(L, 1)); |
| 356 | else | 356 | else |
| 357 | sprintf(buff, "%.40s: %p", t, lua_touserdata(L, 1)); | 357 | sprintf(buff, l_s("%.40s: %p"), t, lua_touserdata(L, 1)); |
| 358 | break; | 358 | break; |
| 359 | } | 359 | } |
| 360 | case LUA_TNIL: | 360 | case LUA_TNIL: |
| 361 | lua_pushliteral(L, "nil"); | 361 | lua_pushliteral(L, l_s("nil")); |
| 362 | return 1; | 362 | return 1; |
| 363 | default: | 363 | default: |
| 364 | luaL_argerror(L, 1, "value expected"); | 364 | luaL_argerror(L, 1, l_s("value expected")); |
| 365 | } | 365 | } |
| 366 | lua_pushstring(L, buff); | 366 | lua_pushstring(L, buff); |
| 367 | return 1; | 367 | return 1; |
| @@ -407,7 +407,7 @@ static int luaB_foreach (lua_State *L) { | |||
| 407 | static int luaB_assert (lua_State *L) { | 407 | static int luaB_assert (lua_State *L) { |
| 408 | luaL_checkany(L, 1); | 408 | luaL_checkany(L, 1); |
| 409 | if (lua_isnil(L, 1)) | 409 | if (lua_isnil(L, 1)) |
| 410 | luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); | 410 | luaL_verror(L, l_s("assertion failed! %.90s"), luaL_opt_string(L, 2, l_s(""))); |
| 411 | lua_settop(L, 1); | 411 | lua_settop(L, 1); |
| 412 | return 1; | 412 | return 1; |
| 413 | } | 413 | } |
| @@ -429,7 +429,7 @@ static int luaB_tinsert (lua_State *L) { | |||
| 429 | pos = n+1; | 429 | pos = n+1; |
| 430 | else | 430 | else |
| 431 | pos = luaL_check_int(L, 2); /* 2nd argument is the position */ | 431 | pos = luaL_check_int(L, 2); /* 2nd argument is the position */ |
| 432 | lua_pushliteral(L, "n"); | 432 | lua_pushliteral(L, l_s("n")); |
| 433 | lua_pushnumber(L, n+1); | 433 | lua_pushnumber(L, n+1); |
| 434 | lua_rawset(L, 1); /* t.n = n+1 */ | 434 | lua_rawset(L, 1); /* t.n = n+1 */ |
| 435 | for (; n>=pos; n--) { | 435 | for (; n>=pos; n--) { |
| @@ -453,7 +453,7 @@ static int luaB_tremove (lua_State *L) { | |||
| 453 | lua_rawgeti(L, 1, pos+1); | 453 | lua_rawgeti(L, 1, pos+1); |
| 454 | lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */ | 454 | lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */ |
| 455 | } | 455 | } |
| 456 | lua_pushliteral(L, "n"); | 456 | lua_pushliteral(L, l_s("n")); |
| 457 | lua_pushnumber(L, n-1); | 457 | lua_pushnumber(L, n-1); |
| 458 | lua_rawset(L, 1); /* t.n = n-1 */ | 458 | lua_rawset(L, 1); /* t.n = n-1 */ |
| 459 | lua_pushnil(L); | 459 | lua_pushnil(L); |
| @@ -527,12 +527,12 @@ static void auxsort (lua_State *L, int l, int u) { | |||
| 527 | for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ | 527 | for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ |
| 528 | /* repeat ++i until a[i] >= P */ | 528 | /* repeat ++i until a[i] >= P */ |
| 529 | while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { | 529 | while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { |
| 530 | if (i>u) lua_error(L, "invalid order function for sorting"); | 530 | if (i>u) lua_error(L, l_s("invalid order function for sorting")); |
| 531 | lua_pop(L, 1); /* remove a[i] */ | 531 | lua_pop(L, 1); /* remove a[i] */ |
| 532 | } | 532 | } |
| 533 | /* repeat --j until a[j] <= P */ | 533 | /* repeat --j until a[j] <= P */ |
| 534 | while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { | 534 | while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { |
| 535 | if (j<l) lua_error(L, "invalid order function for sorting"); | 535 | if (j<l) lua_error(L, l_s("invalid order function for sorting")); |
| 536 | lua_pop(L, 1); /* remove a[j] */ | 536 | lua_pop(L, 1); /* remove a[j] */ |
| 537 | } | 537 | } |
| 538 | if (j<i) { | 538 | if (j<i) { |
| @@ -581,10 +581,10 @@ static int luaB_sort (lua_State *L) { | |||
| 581 | #define num_deprecated 4 | 581 | #define num_deprecated 4 |
| 582 | 582 | ||
| 583 | static const luaL_reg deprecated_names [num_deprecated] = { | 583 | static const luaL_reg deprecated_names [num_deprecated] = { |
| 584 | {"foreachvar", luaB_foreach}, | 584 | {l_s("foreachvar"), luaB_foreach}, |
| 585 | {"nextvar", luaB_next}, | 585 | {l_s("nextvar"), luaB_next}, |
| 586 | {"rawgetglobal", luaB_rawget}, | 586 | {l_s("rawgetglobal"), luaB_rawget}, |
| 587 | {"rawsetglobal", luaB_rawset} | 587 | {l_s("rawsetglobal"), luaB_rawset} |
| 588 | }; | 588 | }; |
| 589 | 589 | ||
| 590 | 590 | ||
| @@ -618,7 +618,7 @@ static void deprecated_funcs (lua_State *L) { | |||
| 618 | ** gives an explicit error in any attempt to call a deprecated function | 618 | ** gives an explicit error in any attempt to call a deprecated function |
| 619 | */ | 619 | */ |
| 620 | static int deprecated_func (lua_State *L) { | 620 | static int deprecated_func (lua_State *L) { |
| 621 | luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1)); | 621 | luaL_verror(L, l_s("function `%.20s' is deprecated"), lua_tostring(L, -1)); |
| 622 | return 0; /* to avoid warnings */ | 622 | return 0; /* to avoid warnings */ |
| 623 | } | 623 | } |
| 624 | 624 | ||
| @@ -637,49 +637,49 @@ static void deprecated_funcs (lua_State *L) { | |||
| 637 | /* }====================================================== */ | 637 | /* }====================================================== */ |
| 638 | 638 | ||
| 639 | static const luaL_reg base_funcs[] = { | 639 | static const luaL_reg base_funcs[] = { |
| 640 | {LUA_ALERT, luaB__ALERT}, | 640 | {l_s(LUA_ALERT), luaB__ALERT}, |
| 641 | {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE}, | 641 | {l_s(LUA_ERRORMESSAGE), luaB__ERRORMESSAGE}, |
| 642 | {"call", luaB_call}, | 642 | {l_s("call"), luaB_call}, |
| 643 | {"collectgarbage", luaB_collectgarbage}, | 643 | {l_s("collectgarbage"), luaB_collectgarbage}, |
| 644 | {"copytagmethods", luaB_copytagmethods}, | 644 | {l_s("copytagmethods"), luaB_copytagmethods}, |
| 645 | {"dofile", luaB_dofile}, | 645 | {l_s("dofile"), luaB_dofile}, |
| 646 | {"dostring", luaB_dostring}, | 646 | {l_s("dostring"), luaB_dostring}, |
| 647 | {"error", luaB_error}, | 647 | {l_s("error"), luaB_error}, |
| 648 | {"foreach", luaB_foreach}, | 648 | {l_s("foreach"), luaB_foreach}, |
| 649 | {"foreachi", luaB_foreachi}, | 649 | {l_s("foreachi"), luaB_foreachi}, |
| 650 | {"gcinfo", luaB_gcinfo}, | 650 | {l_s("gcinfo"), luaB_gcinfo}, |
| 651 | {"getglobal", luaB_getglobal}, | 651 | {l_s("getglobal"), luaB_getglobal}, |
| 652 | {"gettagmethod", luaB_gettagmethod}, | 652 | {l_s("gettagmethod"), luaB_gettagmethod}, |
| 653 | {"globals", luaB_globals}, | 653 | {l_s("globals"), luaB_globals}, |
| 654 | {"newtype", luaB_newtype}, | 654 | {l_s("newtype"), luaB_newtype}, |
| 655 | {"newtag", luaB_newtype}, /* for compatibility 4.0 */ | 655 | {l_s("newtag"), luaB_newtype}, /* for compatibility 4.0 */ |
| 656 | {"next", luaB_next}, | 656 | {l_s("next"), luaB_next}, |
| 657 | {"print", luaB_print}, | 657 | {l_s("print"), luaB_print}, |
| 658 | {"rawget", luaB_rawget}, | 658 | {l_s("rawget"), luaB_rawget}, |
| 659 | {"rawset", luaB_rawset}, | 659 | {l_s("rawset"), luaB_rawset}, |
| 660 | {"rawgettable", luaB_rawget}, /* for compatibility 3.2 */ | 660 | {l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */ |
| 661 | {"rawsettable", luaB_rawset}, /* for compatibility 3.2 */ | 661 | {l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */ |
| 662 | {"setglobal", luaB_setglobal}, | 662 | {l_s("setglobal"), luaB_setglobal}, |
| 663 | {"settag", luaB_settag}, | 663 | {l_s("settag"), luaB_settag}, |
| 664 | {"settagmethod", luaB_settagmethod}, | 664 | {l_s("settagmethod"), luaB_settagmethod}, |
| 665 | {"tag", luaB_tag}, | 665 | {l_s("tag"), luaB_tag}, |
| 666 | {"tonumber", luaB_tonumber}, | 666 | {l_s("tonumber"), luaB_tonumber}, |
| 667 | {"tostring", luaB_tostring}, | 667 | {l_s("tostring"), luaB_tostring}, |
| 668 | {"type", luaB_type}, | 668 | {l_s("type"), luaB_type}, |
| 669 | {"assert", luaB_assert}, | 669 | {l_s("assert"), luaB_assert}, |
| 670 | {"getn", luaB_getn}, | 670 | {l_s("getn"), luaB_getn}, |
| 671 | {"sort", luaB_sort}, | 671 | {l_s("sort"), luaB_sort}, |
| 672 | {"tinsert", luaB_tinsert}, | 672 | {l_s("tinsert"), luaB_tinsert}, |
| 673 | {"tremove", luaB_tremove}, | 673 | {l_s("tremove"), luaB_tremove}, |
| 674 | {"xtype", luaB_xtype}, | 674 | {l_s("xtype"), luaB_xtype}, |
| 675 | }; | 675 | }; |
| 676 | 676 | ||
| 677 | 677 | ||
| 678 | 678 | ||
| 679 | LUALIB_API void lua_baselibopen (lua_State *L) { | 679 | LUALIB_API void lua_baselibopen (lua_State *L) { |
| 680 | luaL_openl(L, base_funcs); | 680 | luaL_openl(L, base_funcs); |
| 681 | lua_pushliteral(L, LUA_VERSION); | 681 | lua_pushliteral(L, l_s(LUA_VERSION)); |
| 682 | lua_setglobal(L, "_VERSION"); | 682 | lua_setglobal(L, l_s("_VERSION")); |
| 683 | deprecated_funcs(L); | 683 | deprecated_funcs(L); |
| 684 | } | 684 | } |
| 685 | 685 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.61 2001/02/08 11:19:10 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.62 2001/02/12 19:21:19 roberto Exp roberto $ |
| 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 | */ |
| @@ -18,7 +18,7 @@ | |||
| 18 | #include "lparser.h" | 18 | #include "lparser.h" |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | void luaK_error (LexState *ls, const char *msg) { | 21 | void luaK_error (LexState *ls, const l_char *msg) { |
| 22 | luaX_error(ls, msg, ls->t.token); | 22 | luaX_error(ls, msg, ls->t.token); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| @@ -53,7 +53,7 @@ static void luaK_fixjump (FuncState *fs, int pc, int dest) { | |||
| 53 | else { /* jump is relative to position following jump instruction */ | 53 | else { /* jump is relative to position following jump instruction */ |
| 54 | int offset = dest-(pc+1); | 54 | int offset = dest-(pc+1); |
| 55 | if (abs(offset) > MAXARG_S) | 55 | if (abs(offset) > MAXARG_S) |
| 56 | luaK_error(fs->ls, "control structure too long"); | 56 | luaK_error(fs->ls, l_s("control structure too long")); |
| 57 | SETARG_S(*jmp, offset); | 57 | SETARG_S(*jmp, offset); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| @@ -99,7 +99,7 @@ void luaK_deltastack (FuncState *fs, int delta) { | |||
| 99 | fs->stacklevel += delta; | 99 | fs->stacklevel += delta; |
| 100 | if (fs->stacklevel > fs->f->maxstacksize) { | 100 | if (fs->stacklevel > fs->f->maxstacksize) { |
| 101 | if (fs->stacklevel > MAXSTACK) | 101 | if (fs->stacklevel > MAXSTACK) |
| 102 | luaK_error(fs->ls, "function or expression too complex"); | 102 | luaK_error(fs->ls, l_s("function or expression too complex")); |
| 103 | fs->f->maxstacksize = (short)fs->stacklevel; | 103 | fs->f->maxstacksize = (short)fs->stacklevel; |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| @@ -119,7 +119,7 @@ static int number_constant (FuncState *fs, lua_Number r) { | |||
| 119 | if (f->knum[c] == r) return c; | 119 | if (f->knum[c] == r) return c; |
| 120 | /* not found; create a new entry */ | 120 | /* not found; create a new entry */ |
| 121 | luaM_growvector(fs->L, f->knum, fs->nknum, f->sizeknum, lua_Number, | 121 | luaM_growvector(fs->L, f->knum, fs->nknum, f->sizeknum, lua_Number, |
| 122 | MAXARG_U, "constant table overflow"); | 122 | MAXARG_U, l_s("constant table overflow")); |
| 123 | c = fs->nknum++; | 123 | c = fs->nknum++; |
| 124 | f->knum[c] = r; | 124 | f->knum[c] = r; |
| 125 | return c; | 125 | return c; |
| @@ -436,11 +436,11 @@ static void codelineinfo (FuncState *fs) { | |||
| 436 | if (ls->lastline > fs->lastline) { | 436 | if (ls->lastline > fs->lastline) { |
| 437 | if (ls->lastline > fs->lastline+1) { | 437 | if (ls->lastline > fs->lastline+1) { |
| 438 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, | 438 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, |
| 439 | MAX_INT, "line info overflow"); | 439 | MAX_INT, l_s("line info overflow")); |
| 440 | f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); | 440 | f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); |
| 441 | } | 441 | } |
| 442 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, | 442 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, |
| 443 | MAX_INT, "line info overflow"); | 443 | MAX_INT, l_s("line info overflow")); |
| 444 | f->lineinfo[fs->nlineinfo++] = fs->pc; | 444 | f->lineinfo[fs->nlineinfo++] = fs->pc; |
| 445 | fs->lastline = ls->lastline; | 445 | fs->lastline = ls->lastline; |
| 446 | } | 446 | } |
| @@ -660,7 +660,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { | |||
| 660 | codelineinfo(fs); | 660 | codelineinfo(fs); |
| 661 | /* put new instruction in code array */ | 661 | /* put new instruction in code array */ |
| 662 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | 662 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
| 663 | MAX_INT, "code size overflow"); | 663 | MAX_INT, l_s("code size overflow")); |
| 664 | f->code[fs->pc] = i; | 664 | f->code[fs->pc] = i; |
| 665 | return fs->pc++; | 665 | return fs->pc++; |
| 666 | } | 666 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.h,v 1.19 2001/01/29 15:26:40 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.20 2001/02/20 18:15:33 roberto Exp roberto $ |
| 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 | */ |
| @@ -47,7 +47,7 @@ typedef struct OpProperties { | |||
| 47 | extern const OpProperties luaK_opproperties[]; | 47 | extern const OpProperties luaK_opproperties[]; |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | void luaK_error (LexState *ls, const char *msg); | 50 | void luaK_error (LexState *ls, const l_char *msg); |
| 51 | int luaK_code0 (FuncState *fs, OpCode o); | 51 | int luaK_code0 (FuncState *fs, OpCode o); |
| 52 | int luaK_code1 (FuncState *fs, OpCode o, int arg1); | 52 | int luaK_code1 (FuncState *fs, OpCode o, int arg1); |
| 53 | int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2); | 53 | int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.31 2001/01/10 16:58:11 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.32 2001/02/02 19:02:40 roberto Exp roberto $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -17,14 +17,14 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | static void settabss (lua_State *L, const char *i, const char *v) { | 20 | static void settabss (lua_State *L, const l_char *i, const l_char *v) { |
| 21 | lua_pushstring(L, i); | 21 | lua_pushstring(L, i); |
| 22 | lua_pushstring(L, v); | 22 | lua_pushstring(L, v); |
| 23 | lua_settable(L, -3); | 23 | lua_settable(L, -3); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | static void settabsi (lua_State *L, const char *i, int v) { | 27 | static void settabsi (lua_State *L, const l_char *i, int v) { |
| 28 | lua_pushstring(L, i); | 28 | lua_pushstring(L, i); |
| 29 | lua_pushnumber(L, v); | 29 | lua_pushnumber(L, v); |
| 30 | lua_settable(L, -3); | 30 | lua_settable(L, -3); |
| @@ -33,8 +33,8 @@ static void settabsi (lua_State *L, const char *i, int v) { | |||
| 33 | 33 | ||
| 34 | static int getinfo (lua_State *L) { | 34 | static int getinfo (lua_State *L) { |
| 35 | lua_Debug ar; | 35 | lua_Debug ar; |
| 36 | const char *options = luaL_opt_string(L, 2, "flnSu"); | 36 | const l_char *options = luaL_opt_string(L, 2, l_s("flnSu")); |
| 37 | char buff[20]; | 37 | l_char buff[20]; |
| 38 | if (lua_isnumber(L, 1)) { | 38 | if (lua_isnumber(L, 1)) { |
| 39 | if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) { | 39 | if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) { |
| 40 | lua_pushnil(L); /* level out of range */ | 40 | lua_pushnil(L); /* level out of range */ |
| @@ -43,35 +43,35 @@ static int getinfo (lua_State *L) { | |||
| 43 | } | 43 | } |
| 44 | else if (lua_isfunction(L, 1)) { | 44 | else if (lua_isfunction(L, 1)) { |
| 45 | lua_pushvalue(L, 1); | 45 | lua_pushvalue(L, 1); |
| 46 | sprintf(buff, ">%.10s", options); | 46 | sprintf(buff, l_s(">%.10s"), options); |
| 47 | options = buff; | 47 | options = buff; |
| 48 | } | 48 | } |
| 49 | else | 49 | else |
| 50 | luaL_argerror(L, 1, "function or level expected"); | 50 | luaL_argerror(L, 1, l_s("function or level expected")); |
| 51 | if (!lua_getinfo(L, options, &ar)) | 51 | if (!lua_getinfo(L, options, &ar)) |
| 52 | luaL_argerror(L, 2, "invalid option"); | 52 | luaL_argerror(L, 2, l_s("invalid option")); |
| 53 | lua_newtable(L); | 53 | lua_newtable(L); |
| 54 | for (; *options; options++) { | 54 | for (; *options; options++) { |
| 55 | switch (*options) { | 55 | switch (*options) { |
| 56 | case 'S': | 56 | case l_c('S'): |
| 57 | settabss(L, "source", ar.source); | 57 | settabss(L, l_s("source"), ar.source); |
| 58 | if (ar.source) | 58 | if (ar.source) |
| 59 | settabss(L, "short_src", ar.short_src); | 59 | settabss(L, l_s("short_src"), ar.short_src); |
| 60 | settabsi(L, "linedefined", ar.linedefined); | 60 | settabsi(L, l_s("linedefined"), ar.linedefined); |
| 61 | settabss(L, "what", ar.what); | 61 | settabss(L, l_s("what"), ar.what); |
| 62 | break; | 62 | break; |
| 63 | case 'l': | 63 | case l_c('l'): |
| 64 | settabsi(L, "currentline", ar.currentline); | 64 | settabsi(L, l_s("currentline"), ar.currentline); |
| 65 | break; | 65 | break; |
| 66 | case 'u': | 66 | case l_c('u'): |
| 67 | settabsi(L, "nups", ar.nups); | 67 | settabsi(L, l_s("nups"), ar.nups); |
| 68 | break; | 68 | break; |
| 69 | case 'n': | 69 | case l_c('n'): |
| 70 | settabss(L, "name", ar.name); | 70 | settabss(L, l_s("name"), ar.name); |
| 71 | settabss(L, "namewhat", ar.namewhat); | 71 | settabss(L, l_s("namewhat"), ar.namewhat); |
| 72 | break; | 72 | break; |
| 73 | case 'f': | 73 | case l_c('f'): |
| 74 | lua_pushliteral(L, "func"); | 74 | lua_pushliteral(L, l_s("func")); |
| 75 | lua_pushvalue(L, -3); | 75 | lua_pushvalue(L, -3); |
| 76 | lua_settable(L, -3); | 76 | lua_settable(L, -3); |
| 77 | break; | 77 | break; |
| @@ -83,9 +83,9 @@ static int getinfo (lua_State *L) { | |||
| 83 | 83 | ||
| 84 | static int getlocal (lua_State *L) { | 84 | static int getlocal (lua_State *L) { |
| 85 | lua_Debug ar; | 85 | lua_Debug ar; |
| 86 | const char *name; | 86 | const l_char *name; |
| 87 | 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? */ |
| 88 | luaL_argerror(L, 1, "level out of range"); | 88 | luaL_argerror(L, 1, l_s("level out of range")); |
| 89 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); | 89 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); |
| 90 | if (name) { | 90 | if (name) { |
| 91 | lua_pushstring(L, name); | 91 | lua_pushstring(L, name); |
| @@ -102,7 +102,7 @@ static int getlocal (lua_State *L) { | |||
| 102 | static int setlocal (lua_State *L) { | 102 | static int setlocal (lua_State *L) { |
| 103 | lua_Debug ar; | 103 | lua_Debug ar; |
| 104 | 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? */ |
| 105 | luaL_argerror(L, 1, "level out of range"); | 105 | luaL_argerror(L, 1, l_s("level out of range")); |
| 106 | luaL_checkany(L, 3); | 106 | luaL_checkany(L, 3); |
| 107 | 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))); |
| 108 | return 1; | 108 | return 1; |
| @@ -111,7 +111,7 @@ static int setlocal (lua_State *L) { | |||
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | /* dummy variables (to define unique addresses) */ | 113 | /* dummy variables (to define unique addresses) */ |
| 114 | static const char key1[] = "ab"; | 114 | static const l_char key1[] = l_s("ab"); |
| 115 | #define KEY_CALLHOOK ((void *)key1) | 115 | #define KEY_CALLHOOK ((void *)key1) |
| 116 | #define KEY_LINEHOOK ((void *)(key1+1)) | 116 | #define KEY_LINEHOOK ((void *)(key1+1)) |
| 117 | 117 | ||
| @@ -150,7 +150,7 @@ static void sethook (lua_State *L, void *key, lua_Hook hook, | |||
| 150 | else if (lua_isfunction(L, 1)) | 150 | else if (lua_isfunction(L, 1)) |
| 151 | (*sethookf)(L, hook); | 151 | (*sethookf)(L, hook); |
| 152 | else | 152 | else |
| 153 | luaL_argerror(L, 1, "function expected"); | 153 | luaL_argerror(L, 1, l_s("function expected")); |
| 154 | lua_getregistry(L); | 154 | lua_getregistry(L); |
| 155 | lua_pushuserdata(L, key); | 155 | lua_pushuserdata(L, key); |
| 156 | lua_pushvalue(L, -1); /* dup key */ | 156 | lua_pushvalue(L, -1); /* dup key */ |
| @@ -174,11 +174,11 @@ static int setlinehook (lua_State *L) { | |||
| 174 | 174 | ||
| 175 | 175 | ||
| 176 | static const luaL_reg dblib[] = { | 176 | static const luaL_reg dblib[] = { |
| 177 | {"getlocal", getlocal}, | 177 | {l_s("getlocal"), getlocal}, |
| 178 | {"getinfo", getinfo}, | 178 | {l_s("getinfo"), getinfo}, |
| 179 | {"setcallhook", setcallhook}, | 179 | {l_s("setcallhook"), setcallhook}, |
| 180 | {"setlinehook", setlinehook}, | 180 | {l_s("setlinehook"), setlinehook}, |
| 181 | {"setlocal", setlocal} | 181 | {l_s("setlocal"), setlocal} |
| 182 | }; | 182 | }; |
| 183 | 183 | ||
| 184 | 184 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.67 2001/02/21 16:52:09 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.68 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -24,7 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | static const char *getfuncname (lua_State *L, StkId f, const char **name); | 27 | static const l_char *getfuncname (lua_State *L, StkId f, const l_char **name); |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | static void setnormalized (TObject *d, const TObject *s) { | 30 | static void setnormalized (TObject *d, const TObject *s) { |
| @@ -158,8 +158,8 @@ static Proto *getluaproto (StkId f) { | |||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | 160 | ||
| 161 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | 161 | LUA_API const l_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { |
| 162 | const char *name; | 162 | const l_char *name; |
| 163 | StkId f; | 163 | StkId f; |
| 164 | Proto *fp; | 164 | Proto *fp; |
| 165 | LUA_LOCK(L); | 165 | LUA_LOCK(L); |
| @@ -176,8 +176,8 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | 178 | ||
| 179 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | 179 | LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { |
| 180 | const char *name; | 180 | const l_char *name; |
| 181 | StkId f; | 181 | StkId f; |
| 182 | Proto *fp; | 182 | Proto *fp; |
| 183 | LUA_LOCK(L); | 183 | LUA_LOCK(L); |
| @@ -187,7 +187,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 187 | L->top--; /* pop new value */ | 187 | L->top--; /* pop new value */ |
| 188 | if (fp) { /* `f' is a Lua function? */ | 188 | if (fp) { /* `f' is a Lua function? */ |
| 189 | name = luaF_getlocalname(fp, n, currentpc(f)); | 189 | name = luaF_getlocalname(fp, n, currentpc(f)); |
| 190 | if (!name || name[0] == '(') /* `(' starts private locals */ | 190 | if (!name || name[0] == l_c('(')) /* `(' starts private locals */ |
| 191 | name = NULL; | 191 | name = NULL; |
| 192 | else | 192 | else |
| 193 | setobj((f+1)+(n-1), L->top); | 193 | setobj((f+1)+(n-1), L->top); |
| @@ -200,7 +200,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 200 | static void infoLproto (lua_Debug *ar, Proto *f) { | 200 | static void infoLproto (lua_Debug *ar, Proto *f) { |
| 201 | ar->source = getstr(f->source); | 201 | ar->source = getstr(f->source); |
| 202 | ar->linedefined = f->lineDefined; | 202 | ar->linedefined = f->lineDefined; |
| 203 | ar->what = "Lua"; | 203 | ar->what = l_s("Lua"); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | 206 | ||
| @@ -214,22 +214,22 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) { | |||
| 214 | cl = infovalue(func)->func; | 214 | cl = infovalue(func)->func; |
| 215 | break; | 215 | break; |
| 216 | default: | 216 | default: |
| 217 | luaD_error(L, "value for `lua_getinfo' is not a function"); | 217 | luaD_error(L, l_s("value for `lua_getinfo' is not a function")); |
| 218 | } | 218 | } |
| 219 | if (cl->isC) { | 219 | if (cl->isC) { |
| 220 | ar->source = "=C"; | 220 | ar->source = l_s("=C"); |
| 221 | ar->linedefined = -1; | 221 | ar->linedefined = -1; |
| 222 | ar->what = "C"; | 222 | ar->what = l_s("C"); |
| 223 | } | 223 | } |
| 224 | else | 224 | else |
| 225 | infoLproto(ar, cl->f.l); | 225 | infoLproto(ar, cl->f.l); |
| 226 | luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); | 226 | luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); |
| 227 | if (ar->linedefined == 0) | 227 | if (ar->linedefined == 0) |
| 228 | ar->what = "main"; | 228 | ar->what = l_s("main"); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | 231 | ||
| 232 | static const char *travtagmethods (global_State *G, const TObject *o) { | 232 | static const l_char *travtagmethods (global_State *G, const TObject *o) { |
| 233 | if (ttype(o) == LUA_TFUNCTION) { | 233 | if (ttype(o) == LUA_TFUNCTION) { |
| 234 | int e; | 234 | int e; |
| 235 | for (e=0; e<TM_N; e++) { | 235 | for (e=0; e<TM_N; e++) { |
| @@ -243,7 +243,7 @@ static const char *travtagmethods (global_State *G, const TObject *o) { | |||
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | 245 | ||
| 246 | static const char *travglobals (lua_State *L, const TObject *o) { | 246 | static const l_char *travglobals (lua_State *L, const TObject *o) { |
| 247 | Hash *g = L->gt; | 247 | Hash *g = L->gt; |
| 248 | int i; | 248 | int i; |
| 249 | for (i=0; i<g->size; i++) { | 249 | for (i=0; i<g->size; i++) { |
| @@ -260,20 +260,20 @@ static void getname (lua_State *L, StkId f, lua_Debug *ar) { | |||
| 260 | setnormalized(&o, f); | 260 | setnormalized(&o, f); |
| 261 | /* try to find a name for given function */ | 261 | /* try to find a name for given function */ |
| 262 | if ((ar->name = travglobals(L, &o)) != NULL) | 262 | if ((ar->name = travglobals(L, &o)) != NULL) |
| 263 | ar->namewhat = "global"; | 263 | ar->namewhat = l_s("global"); |
| 264 | /* not found: try tag methods */ | 264 | /* not found: try tag methods */ |
| 265 | else if ((ar->name = travtagmethods(G(L), &o)) != NULL) | 265 | else if ((ar->name = travtagmethods(G(L), &o)) != NULL) |
| 266 | ar->namewhat = "tag-method"; | 266 | ar->namewhat = l_s("tag-method"); |
| 267 | else ar->namewhat = ""; /* not found at all */ | 267 | else ar->namewhat = l_s(""); /* not found at all */ |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | 270 | ||
| 271 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | 271 | LUA_API int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar) { |
| 272 | StkId func; | 272 | StkId func; |
| 273 | int isactive; | 273 | int isactive; |
| 274 | int status = 1; | 274 | int status = 1; |
| 275 | LUA_LOCK(L); | 275 | LUA_LOCK(L); |
| 276 | isactive = (*what != '>'); | 276 | isactive = (*what != l_c('>')); |
| 277 | if (isactive) | 277 | if (isactive) |
| 278 | func = ar->_func; | 278 | func = ar->_func; |
| 279 | else { | 279 | else { |
| @@ -282,25 +282,25 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
| 282 | } | 282 | } |
| 283 | for (; *what; what++) { | 283 | for (; *what; what++) { |
| 284 | switch (*what) { | 284 | switch (*what) { |
| 285 | case 'S': { | 285 | case l_c('S'): { |
| 286 | funcinfo(L, ar, func); | 286 | funcinfo(L, ar, func); |
| 287 | break; | 287 | break; |
| 288 | } | 288 | } |
| 289 | case 'l': { | 289 | case l_c('l'): { |
| 290 | ar->currentline = currentline(func); | 290 | ar->currentline = currentline(func); |
| 291 | break; | 291 | break; |
| 292 | } | 292 | } |
| 293 | case 'u': { | 293 | case l_c('u'): { |
| 294 | ar->nups = nups(func); | 294 | ar->nups = nups(func); |
| 295 | break; | 295 | break; |
| 296 | } | 296 | } |
| 297 | case 'n': { | 297 | case l_c('n'): { |
| 298 | ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL; | 298 | ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL; |
| 299 | if (ar->namewhat == NULL) | 299 | if (ar->namewhat == NULL) |
| 300 | getname(L, func, ar); | 300 | getname(L, func, ar); |
| 301 | break; | 301 | break; |
| 302 | } | 302 | } |
| 303 | case 'f': { | 303 | case l_c('f'): { |
| 304 | setnormalized(L->top, func); | 304 | setnormalized(L->top, func); |
| 305 | incr_top; /* push function */ | 305 | incr_top; /* push function */ |
| 306 | break; | 306 | break; |
| @@ -543,7 +543,7 @@ int luaG_checkcode (lua_State *L, const Proto *pt) { | |||
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | 545 | ||
| 546 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { | 546 | static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) { |
| 547 | StkId func = aux_stackedfunction(L, 0, obj); | 547 | StkId func = aux_stackedfunction(L, 0, obj); |
| 548 | if (!isLmark(func)) | 548 | if (!isLmark(func)) |
| 549 | return NULL; /* not an active Lua function */ | 549 | return NULL; /* not an active Lua function */ |
| @@ -556,17 +556,17 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
| 556 | switch (GET_OPCODE(i)) { | 556 | switch (GET_OPCODE(i)) { |
| 557 | case OP_GETGLOBAL: { | 557 | case OP_GETGLOBAL: { |
| 558 | *name = getstr(p->kstr[GETARG_U(i)]); | 558 | *name = getstr(p->kstr[GETARG_U(i)]); |
| 559 | return "global"; | 559 | return l_s("global"); |
| 560 | } | 560 | } |
| 561 | case OP_GETLOCAL: { | 561 | case OP_GETLOCAL: { |
| 562 | *name = luaF_getlocalname(p, GETARG_U(i)+1, pc); | 562 | *name = luaF_getlocalname(p, GETARG_U(i)+1, pc); |
| 563 | lua_assert(*name); | 563 | lua_assert(*name); |
| 564 | return "local"; | 564 | return l_s("local"); |
| 565 | } | 565 | } |
| 566 | case OP_PUSHSELF: | 566 | case OP_PUSHSELF: |
| 567 | case OP_GETDOTTED: { | 567 | case OP_GETDOTTED: { |
| 568 | *name = getstr(p->kstr[GETARG_U(i)]); | 568 | *name = getstr(p->kstr[GETARG_U(i)]); |
| 569 | return "field"; | 569 | return l_s("field"); |
| 570 | } | 570 | } |
| 571 | default: | 571 | default: |
| 572 | return NULL; /* no useful name found */ | 572 | return NULL; /* no useful name found */ |
| @@ -575,7 +575,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
| 575 | } | 575 | } |
| 576 | 576 | ||
| 577 | 577 | ||
| 578 | static const char *getfuncname (lua_State *L, StkId f, const char **name) { | 578 | static const l_char *getfuncname (lua_State *L, StkId f, const l_char **name) { |
| 579 | StkId func = aux_stackedfunction(L, 0, f); /* calling function */ | 579 | StkId func = aux_stackedfunction(L, 0, f); /* calling function */ |
| 580 | if (!isLmark(func)) | 580 | if (!isLmark(func)) |
| 581 | return NULL; /* not an active Lua function */ | 581 | return NULL; /* not an active Lua function */ |
| @@ -595,19 +595,19 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) { | |||
| 595 | } | 595 | } |
| 596 | 596 | ||
| 597 | 597 | ||
| 598 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { | 598 | void luaG_typeerror (lua_State *L, StkId o, const l_char *op) { |
| 599 | const char *name; | 599 | const l_char *name; |
| 600 | const char *kind = getobjname(L, o, &name); | 600 | const l_char *kind = getobjname(L, o, &name); |
| 601 | const char *t = luaT_typename(G(L), o); | 601 | const l_char *t = luaT_typename(G(L), o); |
| 602 | if (kind) | 602 | if (kind) |
| 603 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", | 603 | luaO_verror(L, l_s("attempt to %.30s %.20s `%.40s' (a %.10s value)"), |
| 604 | op, kind, name, t); | 604 | op, kind, name, t); |
| 605 | else | 605 | else |
| 606 | luaO_verror(L, "attempt to %.30s a %.10s value", op, t); | 606 | luaO_verror(L, l_s("attempt to %.30s a %.10s value"), op, t); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | 609 | ||
| 610 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { | 610 | void luaG_binerror (lua_State *L, StkId p1, int t, const l_char *op) { |
| 611 | if (ttype(p1) == t) p1++; | 611 | if (ttype(p1) == t) p1++; |
| 612 | lua_assert(ttype(p1) != t); | 612 | lua_assert(ttype(p1) != t); |
| 613 | luaG_typeerror(L, p1, op); | 613 | luaG_typeerror(L, p1, op); |
| @@ -615,11 +615,11 @@ void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { | |||
| 615 | 615 | ||
| 616 | 616 | ||
| 617 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { | 617 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { |
| 618 | const char *t1 = luaT_typename(G(L), p1); | 618 | const l_char *t1 = luaT_typename(G(L), p1); |
| 619 | const char *t2 = luaT_typename(G(L), p2); | 619 | const l_char *t2 = luaT_typename(G(L), p2); |
| 620 | if (t1[2] == t2[2]) | 620 | if (t1[2] == t2[2]) |
| 621 | luaO_verror(L, "attempt to compare two %.10s values", t1); | 621 | luaO_verror(L, l_s("attempt to compare two %.10s values"), t1); |
| 622 | else | 622 | else |
| 623 | luaO_verror(L, "attempt to compare %.10s with %.10s", t1, t2); | 623 | luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2); |
| 624 | } | 624 | } |
| 625 | 625 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.h,v 1.9 2001/02/09 18:37:33 roberto Exp roberto $ | 2 | ** $Id: ldebug.h,v 1.10 2001/02/12 19:54:50 roberto Exp roberto $ |
| 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,8 +12,8 @@ | |||
| 12 | #include "luadebug.h" | 12 | #include "luadebug.h" |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | void luaG_typeerror (lua_State *L, StkId o, const char *op); | 15 | void luaG_typeerror (lua_State *L, StkId o, const l_char *op); |
| 16 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op); | 16 | void luaG_binerror (lua_State *L, StkId p1, int t, const l_char *op); |
| 17 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); | 17 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); |
| 18 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); | 18 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); |
| 19 | int luaG_checkcode (lua_State *L, const Proto *pt); | 19 | int luaG_checkcode (lua_State *L, const Proto *pt); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.126 2001/02/22 18:59:59 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.127 2001/02/23 13:38:56 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -56,7 +56,7 @@ void luaD_checkstack (lua_State *L, int n) { | |||
| 56 | else { | 56 | else { |
| 57 | L->stack_last += EXTRA_STACK; /* to be used by error message */ | 57 | L->stack_last += EXTRA_STACK; /* to be used by error message */ |
| 58 | lua_assert(L->stack_last == L->stack+L->stacksize-1); | 58 | lua_assert(L->stack_last == L->stack+L->stacksize-1); |
| 59 | luaD_error(L, "stack overflow"); | 59 | luaD_error(L, l_s("stack overflow")); |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| @@ -108,7 +108,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) { | |||
| 108 | if (L->allowhooks) { | 108 | if (L->allowhooks) { |
| 109 | lua_Debug ar; | 109 | lua_Debug ar; |
| 110 | ar._func = func; | 110 | ar._func = func; |
| 111 | ar.event = "line"; | 111 | ar.event = l_s("line"); |
| 112 | ar.currentline = line; | 112 | ar.currentline = line; |
| 113 | dohook(L, &ar, linehook); | 113 | dohook(L, &ar, linehook); |
| 114 | } | 114 | } |
| @@ -116,7 +116,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) { | |||
| 116 | 116 | ||
| 117 | 117 | ||
| 118 | static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, | 118 | static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, |
| 119 | const char *event) { | 119 | const l_char *event) { |
| 120 | if (L->allowhooks) { | 120 | if (L->allowhooks) { |
| 121 | lua_Debug ar; | 121 | lua_Debug ar; |
| 122 | ar._func = func; | 122 | ar._func = func; |
| @@ -159,7 +159,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
| 159 | /* `func' is not a function; check the `function' tag method */ | 159 | /* `func' is not a function; check the `function' tag method */ |
| 160 | Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); | 160 | Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); |
| 161 | if (tm == NULL) | 161 | if (tm == NULL) |
| 162 | luaG_typeerror(L, func, "call"); | 162 | luaG_typeerror(L, func, l_s("call")); |
| 163 | luaD_openstack(L, func); | 163 | luaD_openstack(L, func); |
| 164 | setclvalue(func, tm); /* tag method is the new function to be called */ | 164 | setclvalue(func, tm); /* tag method is the new function to be called */ |
| 165 | } | 165 | } |
| @@ -168,11 +168,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
| 168 | setivalue(func, &ci); | 168 | setivalue(func, &ci); |
| 169 | callhook = L->callhook; | 169 | callhook = L->callhook; |
| 170 | if (callhook) | 170 | if (callhook) |
| 171 | luaD_callHook(L, func, callhook, "call"); | 171 | luaD_callHook(L, func, callhook, l_s("call")); |
| 172 | firstResult = (cl->isC ? callCclosure(L, cl, func+1) : | 172 | firstResult = (cl->isC ? callCclosure(L, cl, func+1) : |
| 173 | luaV_execute(L, cl, func+1)); | 173 | luaV_execute(L, cl, func+1)); |
| 174 | if (callhook) /* same hook that was active at entry */ | 174 | if (callhook) /* same hook that was active at entry */ |
| 175 | luaD_callHook(L, func, callhook, "return"); | 175 | luaD_callHook(L, func, callhook, l_s("return")); |
| 176 | lua_assert(ttype(func) == LUA_TMARK); | 176 | lua_assert(ttype(func) == LUA_TMARK); |
| 177 | setnilvalue(func); /* remove callinfo from the stack */ | 177 | setnilvalue(func); /* remove callinfo from the stack */ |
| 178 | /* move results to `func' (to erase parameters and function) */ | 178 | /* move results to `func' (to erase parameters and function) */ |
| @@ -261,20 +261,20 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | 263 | ||
| 264 | static int parse_file (lua_State *L, const char *filename) { | 264 | static int parse_file (lua_State *L, const l_char *filename) { |
| 265 | ZIO z; | 265 | ZIO z; |
| 266 | int status; | 266 | int status; |
| 267 | int bin; /* flag for file mode */ | 267 | int bin; /* flag for file mode */ |
| 268 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | 268 | FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r")); |
| 269 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ | 269 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ |
| 270 | bin = (ungetc(fgetc(f), f) == ID_CHUNK); | 270 | bin = (ungetc(fgetc(f), f) == ID_CHUNK); |
| 271 | if (bin && f != stdin) { | 271 | if (bin && f != stdin) { |
| 272 | fclose(f); | 272 | fclose(f); |
| 273 | f = fopen(filename, "rb"); /* reopen in binary mode */ | 273 | f = fopen(filename, l_s("rb")); /* reopen in binary mode */ |
| 274 | if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ | 274 | if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ |
| 275 | } | 275 | } |
| 276 | lua_pushliteral(L, "@"); | 276 | lua_pushliteral(L, l_s("@")); |
| 277 | lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); | 277 | lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename); |
| 278 | lua_concat(L, 2); | 278 | lua_concat(L, 2); |
| 279 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ | 279 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ |
| 280 | luaZ_Fopen(&z, f, filename); | 280 | luaZ_Fopen(&z, f, filename); |
| @@ -286,7 +286,7 @@ static int parse_file (lua_State *L, const char *filename) { | |||
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | 288 | ||
| 289 | LUA_API int lua_dofile (lua_State *L, const char *filename) { | 289 | LUA_API int lua_dofile (lua_State *L, const l_char *filename) { |
| 290 | int status; | 290 | int status; |
| 291 | status = parse_file(L, filename); | 291 | status = parse_file(L, filename); |
| 292 | if (status == 0) /* parse OK? */ | 292 | if (status == 0) /* parse OK? */ |
| @@ -295,18 +295,18 @@ LUA_API int lua_dofile (lua_State *L, const char *filename) { | |||
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | 297 | ||
| 298 | static int parse_buffer (lua_State *L, const char *buff, size_t size, | 298 | static int parse_buffer (lua_State *L, const l_char *buff, size_t size, |
| 299 | const char *name) { | 299 | const l_char *name) { |
| 300 | ZIO z; | 300 | ZIO z; |
| 301 | int status; | 301 | int status; |
| 302 | if (!name) name = "?"; | 302 | if (!name) name = l_s("?"); |
| 303 | luaZ_mopen(&z, buff, size, name); | 303 | luaZ_mopen(&z, buff, size, name); |
| 304 | status = protectedparser(L, &z, buff[0]==ID_CHUNK); | 304 | status = protectedparser(L, &z, buff[0]==ID_CHUNK); |
| 305 | return status; | 305 | return status; |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | 308 | ||
| 309 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name) { | 309 | LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, const l_char *name) { |
| 310 | int status; | 310 | int status; |
| 311 | status = parse_buffer(L, buff, size, name); | 311 | status = parse_buffer(L, buff, size, name); |
| 312 | if (status == 0) /* parse OK? */ | 312 | if (status == 0) /* parse OK? */ |
| @@ -315,7 +315,7 @@ LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const cha | |||
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | 317 | ||
| 318 | LUA_API int lua_dostring (lua_State *L, const char *str) { | 318 | LUA_API int lua_dostring (lua_State *L, const l_char *str) { |
| 319 | return lua_dobuffer(L, str, strlen(str), str); | 319 | return lua_dobuffer(L, str, strlen(str), str); |
| 320 | } | 320 | } |
| 321 | 321 | ||
| @@ -334,8 +334,8 @@ struct lua_longjmp { | |||
| 334 | }; | 334 | }; |
| 335 | 335 | ||
| 336 | 336 | ||
| 337 | static void message (lua_State *L, const char *s) { | 337 | static void message (lua_State *L, const l_char *s) { |
| 338 | luaV_getglobal(L, luaS_newliteral(L, LUA_ERRORMESSAGE), L->top); | 338 | luaV_getglobal(L, luaS_newliteral(L, l_s(LUA_ERRORMESSAGE)), L->top); |
| 339 | if (ttype(L->top) == LUA_TFUNCTION) { | 339 | if (ttype(L->top) == LUA_TFUNCTION) { |
| 340 | incr_top; | 340 | incr_top; |
| 341 | setsvalue(L->top, luaS_new(L, s)); | 341 | setsvalue(L->top, luaS_new(L, s)); |
| @@ -348,7 +348,7 @@ static void message (lua_State *L, const char *s) { | |||
| 348 | /* | 348 | /* |
| 349 | ** Reports an error, and jumps up to the available recovery label | 349 | ** Reports an error, and jumps up to the available recovery label |
| 350 | */ | 350 | */ |
| 351 | void luaD_error (lua_State *L, const char *s) { | 351 | void luaD_error (lua_State *L, const l_char *s) { |
| 352 | if (s) message(L, s); | 352 | if (s) message(L, s); |
| 353 | luaD_breakrun(L, LUA_ERRRUN); | 353 | luaD_breakrun(L, LUA_ERRRUN); |
| 354 | } | 354 | } |
| @@ -361,7 +361,7 @@ void luaD_breakrun (lua_State *L, int errcode) { | |||
| 361 | } | 361 | } |
| 362 | else { | 362 | else { |
| 363 | if (errcode != LUA_ERRMEM) | 363 | if (errcode != LUA_ERRMEM) |
| 364 | message(L, "unable to recover; exiting\n"); | 364 | message(L, l_s("unable to recover; exiting\n")); |
| 365 | exit(EXIT_FAILURE); | 365 | exit(EXIT_FAILURE); |
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 1.29 2001/01/24 15:45:33 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.30 2001/02/07 18:13:49 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -25,7 +25,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook); | |||
| 25 | void luaD_call (lua_State *L, StkId func, int nResults); | 25 | void luaD_call (lua_State *L, StkId func, int nResults); |
| 26 | void luaD_checkstack (lua_State *L, int n); | 26 | void luaD_checkstack (lua_State *L, int n); |
| 27 | 27 | ||
| 28 | void luaD_error (lua_State *L, const char *s); | 28 | void luaD_error (lua_State *L, const l_char *s); |
| 29 | void luaD_breakrun (lua_State *L, int errcode); | 29 | void luaD_breakrun (lua_State *L, int errcode); |
| 30 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud); | 30 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud); |
| 31 | 31 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.40 2001/02/09 20:22:29 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.41 2001/02/20 18:28:11 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -74,7 +74,7 @@ void luaF_freeclosure (lua_State *L, Closure *c) { | |||
| 74 | ** Look for n-th local variable at line `line' in function `func'. | 74 | ** Look for n-th local variable at line `line' in function `func'. |
| 75 | ** Returns NULL if not found. | 75 | ** Returns NULL if not found. |
| 76 | */ | 76 | */ |
| 77 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { | 77 | const l_char *luaF_getlocalname (const Proto *f, int local_number, int pc) { |
| 78 | int i; | 78 | int i; |
| 79 | for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) { | 79 | for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) { |
| 80 | if (pc < f->locvars[i].endpc) { /* is variable active? */ | 80 | if (pc < f->locvars[i].endpc) { /* is variable active? */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.h,v 1.13 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lfunc.h,v 1.14 2000/12/28 12:55:41 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -17,7 +17,7 @@ Closure *luaF_newclosure (lua_State *L, int nelems); | |||
| 17 | void luaF_freeproto (lua_State *L, Proto *f); | 17 | void luaF_freeproto (lua_State *L, Proto *f); |
| 18 | void luaF_freeclosure (lua_State *L, Closure *c); | 18 | void luaF_freeclosure (lua_State *L, Closure *c); |
| 19 | 19 | ||
| 20 | const char *luaF_getlocalname (const Proto *func, int local_number, int pc); | 20 | const l_char *luaF_getlocalname (const Proto *func, int local_number, int pc); |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | #endif | 23 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.90 2001/02/20 18:28:11 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.91 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -331,7 +331,7 @@ static void collectudata (lua_State *L, int all) { | |||
| 331 | static void checkMbuffer (lua_State *L) { | 331 | static void checkMbuffer (lua_State *L) { |
| 332 | if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ | 332 | if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ |
| 333 | size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ | 333 | size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ |
| 334 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, char); | 334 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, l_char); |
| 335 | G(L)->Mbuffsize = newsize; | 335 | G(L)->Mbuffsize = newsize; |
| 336 | } | 336 | } |
| 337 | } | 337 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.106 2001/02/09 19:52:54 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.107 2001/02/22 17:15:18 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -47,10 +47,10 @@ int pclose(); */ | |||
| 47 | #define OUTFILE 1 | 47 | #define OUTFILE 1 |
| 48 | #define NOFILE 2 | 48 | #define NOFILE 2 |
| 49 | 49 | ||
| 50 | #define FILEHANDLE "FileHandle" | 50 | #define FILEHANDLE l_s("FileHandle") |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | static const char *const filenames[] = {"_INPUT", "_OUTPUT"}; | 53 | static const l_char *const filenames[] = {l_s("_INPUT"), l_s("_OUTPUT")}; |
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | static int pushresult (lua_State *L, int i) { | 56 | static int pushresult (lua_State *L, int i) { |
| @@ -81,10 +81,10 @@ static FILE *getopthandle (lua_State *L, int inout) { | |||
| 81 | FILE *p = (FILE *)lua_touserdata(L, 1); | 81 | FILE *p = (FILE *)lua_touserdata(L, 1); |
| 82 | if (p != NULL) { /* is it a userdata ? */ | 82 | if (p != NULL) { /* is it a userdata ? */ |
| 83 | if (!checkfile(L, 1)) { | 83 | if (!checkfile(L, 1)) { |
| 84 | if (strcmp(lua_xtype(L, 1), "ClosedFileHandle") == 0) | 84 | if (strcmp(lua_xtype(L, 1), l_s("ClosedFileHandle")) == 0) |
| 85 | luaL_argerror(L, 1, "file is closed"); | 85 | luaL_argerror(L, 1, l_s("file is closed")); |
| 86 | else | 86 | else |
| 87 | luaL_argerror(L, 1, "(invalid value)"); | 87 | luaL_argerror(L, 1, l_s("(invalid value)")); |
| 88 | } | 88 | } |
| 89 | /* move it to stack top */ | 89 | /* move it to stack top */ |
| 90 | lua_pushvalue(L, 1); lua_remove(L, 1); | 90 | lua_pushvalue(L, 1); lua_remove(L, 1); |
| @@ -92,7 +92,7 @@ static FILE *getopthandle (lua_State *L, int inout) { | |||
| 92 | else if (inout != NOFILE) { /* try global value */ | 92 | else if (inout != NOFILE) { /* try global value */ |
| 93 | lua_getglobal(L, filenames[inout]); | 93 | lua_getglobal(L, filenames[inout]); |
| 94 | if (!checkfile(L,-1)) | 94 | if (!checkfile(L,-1)) |
| 95 | luaL_verror(L, "global variable `%.10s' is not a valid file handle", | 95 | luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"), |
| 96 | filenames[inout]); | 96 | filenames[inout]); |
| 97 | p = (FILE *)lua_touserdata(L, -1); | 97 | p = (FILE *)lua_touserdata(L, -1); |
| 98 | } | 98 | } |
| @@ -105,7 +105,7 @@ static void pushfile (lua_State *L, FILE *f) { | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | static void setfilebyname (lua_State *L, FILE *f, const char *name) { | 108 | static void setfilebyname (lua_State *L, FILE *f, const l_char *name) { |
| 109 | pushfile(L, f); | 109 | pushfile(L, f); |
| 110 | lua_setglobal(L, name); | 110 | lua_setglobal(L, name); |
| 111 | } | 111 | } |
| @@ -131,7 +131,7 @@ static int closefile (lua_State *L, FILE *f) { | |||
| 131 | return 1; | 131 | return 1; |
| 132 | else { | 132 | else { |
| 133 | lua_pushuserdata(L, f); | 133 | lua_pushuserdata(L, f); |
| 134 | lua_settag(L, lua_type2tag(L, "ClosedFileHandle")); | 134 | lua_settag(L, lua_type2tag(L, l_s("ClosedFileHandle"))); |
| 135 | return (CLOSEFILE(L, f) == 0); | 135 | return (CLOSEFILE(L, f) == 0); |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| @@ -163,7 +163,7 @@ static int io_tmpfile (lua_State *L) { | |||
| 163 | 163 | ||
| 164 | 164 | ||
| 165 | 165 | ||
| 166 | static int io_fromto (lua_State *L, int inout, const char *mode) { | 166 | static int io_fromto (lua_State *L, int inout, const l_char *mode) { |
| 167 | FILE *current; | 167 | FILE *current; |
| 168 | if (lua_isnull(L, 1)) { | 168 | if (lua_isnull(L, 1)) { |
| 169 | closefile(L, getopthandle(L, inout)); | 169 | closefile(L, getopthandle(L, inout)); |
| @@ -172,25 +172,25 @@ static int io_fromto (lua_State *L, int inout, const char *mode) { | |||
| 172 | else if (checkfile(L, 1)) /* deprecated option */ | 172 | else if (checkfile(L, 1)) /* deprecated option */ |
| 173 | current = (FILE *)lua_touserdata(L, 1); | 173 | current = (FILE *)lua_touserdata(L, 1); |
| 174 | else { | 174 | else { |
| 175 | const char *s = luaL_check_string(L, 1); | 175 | const l_char *s = luaL_check_string(L, 1); |
| 176 | current = (*s == '|') ? popen(s+1, mode) : fopen(s, mode); | 176 | current = (*s == l_c('|')) ? popen(s+1, mode) : fopen(s, mode); |
| 177 | } | 177 | } |
| 178 | return setreturn(L, current, inout); | 178 | return setreturn(L, current, inout); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | 181 | ||
| 182 | static int io_readfrom (lua_State *L) { | 182 | static int io_readfrom (lua_State *L) { |
| 183 | return io_fromto(L, INFILE, "r"); | 183 | return io_fromto(L, INFILE, l_s("r")); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | 186 | ||
| 187 | static int io_writeto (lua_State *L) { | 187 | static int io_writeto (lua_State *L) { |
| 188 | return io_fromto(L, OUTFILE, "w"); | 188 | return io_fromto(L, OUTFILE, l_s("w")); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | 191 | ||
| 192 | static int io_appendto (lua_State *L) { | 192 | static int io_appendto (lua_State *L) { |
| 193 | FILE *current = fopen(luaL_check_string(L, 1), "a"); | 193 | FILE *current = fopen(luaL_check_string(L, 1), l_s("a")); |
| 194 | return setreturn(L, current, OUTFILE); | 194 | return setreturn(L, current, OUTFILE); |
| 195 | } | 195 | } |
| 196 | 196 | ||
| @@ -205,7 +205,7 @@ static int io_appendto (lua_State *L) { | |||
| 205 | 205 | ||
| 206 | static int read_number (lua_State *L, FILE *f) { | 206 | static int read_number (lua_State *L, FILE *f) { |
| 207 | double d; | 207 | double d; |
| 208 | if (fscanf(f, "%lf", &d) == 1) { | 208 | if (fscanf(f, l_s("%lf"), &d) == 1) { |
| 209 | lua_pushnumber(L, d); | 209 | lua_pushnumber(L, d); |
| 210 | return 1; | 210 | return 1; |
| 211 | } | 211 | } |
| @@ -233,11 +233,11 @@ static int read_line (lua_State *L, FILE *f) { | |||
| 233 | luaL_Buffer b; | 233 | luaL_Buffer b; |
| 234 | luaL_buffinit(L, &b); | 234 | luaL_buffinit(L, &b); |
| 235 | for (;;) { | 235 | for (;;) { |
| 236 | char *p = luaL_prepbuffer(&b); | 236 | l_char *p = luaL_prepbuffer(&b); |
| 237 | if (!fgets(p, LUAL_BUFFERSIZE, f)) /* read fails? */ | 237 | if (!fgets(p, LUAL_BUFFERSIZE, f)) /* read fails? */ |
| 238 | break; | 238 | break; |
| 239 | n = strlen(p); | 239 | n = strlen(p); |
| 240 | if (p[n-1] != '\n') | 240 | if (p[n-1] != l_c('\n')) |
| 241 | luaL_addsize(&b, n); | 241 | luaL_addsize(&b, n); |
| 242 | else { | 242 | else { |
| 243 | luaL_addsize(&b, n-1); /* do not add the `\n' */ | 243 | luaL_addsize(&b, n-1); /* do not add the `\n' */ |
| @@ -253,15 +253,15 @@ static void read_file (lua_State *L, FILE *f) { | |||
| 253 | size_t len = 0; | 253 | size_t len = 0; |
| 254 | size_t size = LUAL_BUFFERSIZE; | 254 | size_t size = LUAL_BUFFERSIZE; |
| 255 | size_t oldsize = 0; | 255 | size_t oldsize = 0; |
| 256 | char *buffer = NULL; | 256 | l_char *buffer = NULL; |
| 257 | for (;;) { | 257 | for (;;) { |
| 258 | char *newbuffer = (char *)l_realloc(buffer, oldsize, size); | 258 | l_char *newbuffer = (l_char *)l_realloc(buffer, oldsize, size); |
| 259 | if (newbuffer == NULL) { | 259 | if (newbuffer == NULL) { |
| 260 | l_free(buffer, oldsize); | 260 | l_free(buffer, oldsize); |
| 261 | lua_error(L, "not enough memory to read a file"); | 261 | lua_error(L, l_s("not enough memory to read a file")); |
| 262 | } | 262 | } |
| 263 | buffer = newbuffer; | 263 | buffer = newbuffer; |
| 264 | len += fread(buffer+len, sizeof(char), size-len, f); | 264 | len += fread(buffer+len, sizeof(l_char), size-len, f); |
| 265 | if (len < size) break; /* did not read all it could */ | 265 | if (len < size) break; /* did not read all it could */ |
| 266 | oldsize = size; | 266 | oldsize = size; |
| 267 | size *= 2; | 267 | size *= 2; |
| @@ -279,17 +279,17 @@ static int read_chars (lua_State *L, FILE *f, size_t n) { | |||
| 279 | return (c != EOF); | 279 | return (c != EOF); |
| 280 | } | 280 | } |
| 281 | else { | 281 | else { |
| 282 | char *buffer; | 282 | l_char *buffer; |
| 283 | size_t n1; | 283 | size_t n1; |
| 284 | char statbuff[LUAL_BUFFERSIZE]; | 284 | l_char statbuff[LUAL_BUFFERSIZE]; |
| 285 | if (n <= LUAL_BUFFERSIZE) | 285 | if (n <= LUAL_BUFFERSIZE) |
| 286 | buffer = statbuff; | 286 | buffer = statbuff; |
| 287 | else { | 287 | else { |
| 288 | buffer = (char *)l_malloc(n); | 288 | buffer = (l_char *)l_malloc(n); |
| 289 | if (buffer == NULL) | 289 | if (buffer == NULL) |
| 290 | lua_error(L, "not enough memory to read a file"); | 290 | lua_error(L, l_s("not enough memory to read a file")); |
| 291 | } | 291 | } |
| 292 | n1 = fread(buffer, sizeof(char), n, f); | 292 | n1 = fread(buffer, sizeof(l_char), n, f); |
| 293 | lua_pushlstring(L, buffer, n1); | 293 | lua_pushlstring(L, buffer, n1); |
| 294 | if (buffer != statbuff) l_free(buffer, n); | 294 | if (buffer != statbuff) l_free(buffer, n); |
| 295 | return (n1 > 0 || n == 0); | 295 | return (n1 > 0 || n == 0); |
| @@ -307,31 +307,31 @@ static int io_read (lua_State *L) { | |||
| 307 | n = 2; /* will return n-1 results */ | 307 | n = 2; /* will return n-1 results */ |
| 308 | } | 308 | } |
| 309 | else { /* ensure stack space for all results and for auxlib's buffer */ | 309 | else { /* ensure stack space for all results and for auxlib's buffer */ |
| 310 | luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); | 310 | luaL_checkstack(L, nargs+LUA_MINSTACK, l_s("too many arguments")); |
| 311 | success = 1; | 311 | success = 1; |
| 312 | for (n = 1; n<=nargs && success; n++) { | 312 | for (n = 1; n<=nargs && success; n++) { |
| 313 | if (lua_type(L, n) == LUA_TNUMBER) | 313 | if (lua_type(L, n) == LUA_TNUMBER) |
| 314 | success = read_chars(L, f, (size_t)lua_tonumber(L, n)); | 314 | success = read_chars(L, f, (size_t)lua_tonumber(L, n)); |
| 315 | else { | 315 | else { |
| 316 | const char *p = lua_tostring(L, n); | 316 | const l_char *p = lua_tostring(L, n); |
| 317 | if (!p || p[0] != '*') | 317 | if (!p || p[0] != l_c('*')) |
| 318 | lua_error(L, "invalid `read' option"); | 318 | lua_error(L, l_s("invalid `read' option")); |
| 319 | switch (p[1]) { | 319 | switch (p[1]) { |
| 320 | case 'n': /* number */ | 320 | case l_c('n'): /* number */ |
| 321 | success = read_number(L, f); | 321 | success = read_number(L, f); |
| 322 | break; | 322 | break; |
| 323 | case 'l': /* line */ | 323 | case l_c('l'): /* line */ |
| 324 | success = read_line(L, f); | 324 | success = read_line(L, f); |
| 325 | break; | 325 | break; |
| 326 | case 'a': /* file */ | 326 | case l_c('a'): /* file */ |
| 327 | read_file(L, f); | 327 | read_file(L, f); |
| 328 | success = 1; /* always success */ | 328 | success = 1; /* always success */ |
| 329 | break; | 329 | break; |
| 330 | case 'w': /* word */ | 330 | case l_c('w'): /* word */ |
| 331 | success = read_word(L, f); | 331 | success = read_word(L, f); |
| 332 | break; | 332 | break; |
| 333 | default: | 333 | default: |
| 334 | luaL_argerror(L, n, "invalid format"); | 334 | luaL_argerror(L, n, l_s("invalid format")); |
| 335 | success = 0; /* to avoid warnings */ | 335 | success = 0; /* to avoid warnings */ |
| 336 | } | 336 | } |
| 337 | } | 337 | } |
| @@ -355,12 +355,12 @@ static int io_write (lua_State *L) { | |||
| 355 | for (arg=1; arg<=nargs; arg++) { | 355 | for (arg=1; arg<=nargs; arg++) { |
| 356 | if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */ | 356 | if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */ |
| 357 | /* optimization: could be done exactly as for strings */ | 357 | /* optimization: could be done exactly as for strings */ |
| 358 | status = status && fprintf(f, "%.16g", lua_tonumber(L, arg)) > 0; | 358 | status = status && fprintf(f, l_s("%.16g"), lua_tonumber(L, arg)) > 0; |
| 359 | } | 359 | } |
| 360 | else { | 360 | else { |
| 361 | size_t l; | 361 | size_t l; |
| 362 | const char *s = luaL_check_lstr(L, arg, &l); | 362 | const l_char *s = luaL_check_lstr(L, arg, &l); |
| 363 | status = status && (fwrite(s, sizeof(char), l, f) == l); | 363 | status = status && (fwrite(s, sizeof(l_char), l, f) == l); |
| 364 | } | 364 | } |
| 365 | } | 365 | } |
| 366 | pushresult(L, status); | 366 | pushresult(L, status); |
| @@ -370,11 +370,11 @@ static int io_write (lua_State *L) { | |||
| 370 | 370 | ||
| 371 | static int io_seek (lua_State *L) { | 371 | static int io_seek (lua_State *L) { |
| 372 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | 372 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; |
| 373 | static const char *const modenames[] = {"set", "cur", "end", NULL}; | 373 | static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL}; |
| 374 | FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); | 374 | FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); |
| 375 | int op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames); | 375 | int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames); |
| 376 | long offset = luaL_opt_long(L, 3, 0); | 376 | long offset = luaL_opt_long(L, 3, 0); |
| 377 | luaL_arg_check(L, op != -1, 2, "invalid mode"); | 377 | luaL_arg_check(L, op != -1, 2, l_s("invalid mode")); |
| 378 | op = fseek(f, offset, mode[op]); | 378 | op = fseek(f, offset, mode[op]); |
| 379 | if (op) | 379 | if (op) |
| 380 | return pushresult(L, 0); /* error */ | 380 | return pushresult(L, 0); /* error */ |
| @@ -387,7 +387,7 @@ static int io_seek (lua_State *L) { | |||
| 387 | 387 | ||
| 388 | static int io_flush (lua_State *L) { | 388 | static int io_flush (lua_State *L) { |
| 389 | FILE *f = getopthandle(L, NOFILE); | 389 | FILE *f = getopthandle(L, NOFILE); |
| 390 | luaL_arg_check(L, f || lua_isnull(L, 1), 1, "invalid file handle"); | 390 | luaL_arg_check(L, f || lua_isnull(L, 1), 1, l_s("invalid file handle")); |
| 391 | return pushresult(L, fflush(f) == 0); | 391 | return pushresult(L, fflush(f) == 0); |
| 392 | } | 392 | } |
| 393 | 393 | ||
| @@ -418,9 +418,9 @@ static int io_rename (lua_State *L) { | |||
| 418 | 418 | ||
| 419 | 419 | ||
| 420 | static int io_tmpname (lua_State *L) { | 420 | static int io_tmpname (lua_State *L) { |
| 421 | char buff[L_tmpnam]; | 421 | l_char buff[L_tmpnam]; |
| 422 | if (tmpnam(buff) != buff) | 422 | if (tmpnam(buff) != buff) |
| 423 | lua_error(L, "unable to generate a unique filename"); | 423 | lua_error(L, l_s("unable to generate a unique filename")); |
| 424 | lua_pushstring(L, buff); | 424 | lua_pushstring(L, buff); |
| 425 | return 1; | 425 | return 1; |
| 426 | } | 426 | } |
| @@ -447,14 +447,14 @@ static int io_clock (lua_State *L) { | |||
| 447 | ** ======================================================= | 447 | ** ======================================================= |
| 448 | */ | 448 | */ |
| 449 | 449 | ||
| 450 | static void setfield (lua_State *L, const char *key, int value) { | 450 | static void setfield (lua_State *L, const l_char *key, int value) { |
| 451 | lua_pushstring(L, key); | 451 | lua_pushstring(L, key); |
| 452 | lua_pushnumber(L, value); | 452 | lua_pushnumber(L, value); |
| 453 | lua_rawset(L, -3); | 453 | lua_rawset(L, -3); |
| 454 | } | 454 | } |
| 455 | 455 | ||
| 456 | 456 | ||
| 457 | static int getfield (lua_State *L, const char *key, int d) { | 457 | static int getfield (lua_State *L, const l_char *key, int d) { |
| 458 | int res; | 458 | int res; |
| 459 | lua_pushstring(L, key); | 459 | lua_pushstring(L, key); |
| 460 | lua_rawget(L, -2); | 460 | lua_rawget(L, -2); |
| @@ -462,7 +462,7 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
| 462 | res = (int)lua_tonumber(L, -1); | 462 | res = (int)lua_tonumber(L, -1); |
| 463 | else { | 463 | else { |
| 464 | if (d == -2) | 464 | if (d == -2) |
| 465 | luaL_verror(L, "field `%.20s' missing in date table", key); | 465 | luaL_verror(L, l_s("field `%.20s' missing in date table"), key); |
| 466 | res = d; | 466 | res = d; |
| 467 | } | 467 | } |
| 468 | lua_pop(L, 1); | 468 | lua_pop(L, 1); |
| @@ -471,12 +471,12 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
| 471 | 471 | ||
| 472 | 472 | ||
| 473 | static int io_date (lua_State *L) { | 473 | static int io_date (lua_State *L) { |
| 474 | const char *s = luaL_opt_string(L, 1, "%c"); | 474 | const l_char *s = luaL_opt_string(L, 1, l_s("%c")); |
| 475 | time_t t = (time_t)luaL_opt_number(L, 2, -1); | 475 | time_t t = (time_t)luaL_opt_number(L, 2, -1); |
| 476 | struct tm *stm; | 476 | struct tm *stm; |
| 477 | if (t == (time_t)-1) /* no time given? */ | 477 | if (t == (time_t)-1) /* no time given? */ |
| 478 | t = time(NULL); /* use current time */ | 478 | t = time(NULL); /* use current time */ |
| 479 | if (*s == '!') { /* UTC? */ | 479 | if (*s == l_c('!')) { /* UTC? */ |
| 480 | stm = gmtime(&t); | 480 | stm = gmtime(&t); |
| 481 | s++; /* skip `!' */ | 481 | s++; /* skip `!' */ |
| 482 | } | 482 | } |
| @@ -484,24 +484,24 @@ static int io_date (lua_State *L) { | |||
| 484 | stm = localtime(&t); | 484 | stm = localtime(&t); |
| 485 | if (stm == NULL) /* invalid date? */ | 485 | if (stm == NULL) /* invalid date? */ |
| 486 | lua_pushnil(L); | 486 | lua_pushnil(L); |
| 487 | else if (strcmp(s, "*t") == 0) { | 487 | else if (strcmp(s, l_s("*t")) == 0) { |
| 488 | lua_newtable(L); | 488 | lua_newtable(L); |
| 489 | setfield(L, "sec", stm->tm_sec); | 489 | setfield(L, l_s("sec"), stm->tm_sec); |
| 490 | setfield(L, "min", stm->tm_min); | 490 | setfield(L, l_s("min"), stm->tm_min); |
| 491 | setfield(L, "hour", stm->tm_hour); | 491 | setfield(L, l_s("hour"), stm->tm_hour); |
| 492 | setfield(L, "day", stm->tm_mday); | 492 | setfield(L, l_s("day"), stm->tm_mday); |
| 493 | setfield(L, "month", stm->tm_mon+1); | 493 | setfield(L, l_s("month"), stm->tm_mon+1); |
| 494 | setfield(L, "year", stm->tm_year+1900); | 494 | setfield(L, l_s("year"), stm->tm_year+1900); |
| 495 | setfield(L, "wday", stm->tm_wday+1); | 495 | setfield(L, l_s("wday"), stm->tm_wday+1); |
| 496 | setfield(L, "yday", stm->tm_yday+1); | 496 | setfield(L, l_s("yday"), stm->tm_yday+1); |
| 497 | setfield(L, "isdst", stm->tm_isdst); | 497 | setfield(L, l_s("isdst"), stm->tm_isdst); |
| 498 | } | 498 | } |
| 499 | else { | 499 | else { |
| 500 | char b[256]; | 500 | l_char b[256]; |
| 501 | if (strftime(b, sizeof(b), s, stm)) | 501 | if (strftime(b, sizeof(b), s, stm)) |
| 502 | lua_pushstring(L, b); | 502 | lua_pushstring(L, b); |
| 503 | else | 503 | else |
| 504 | lua_error(L, "invalid `date' format"); | 504 | lua_error(L, l_s("invalid `date' format")); |
| 505 | } | 505 | } |
| 506 | return 1; | 506 | return 1; |
| 507 | } | 507 | } |
| @@ -515,13 +515,13 @@ static int io_time (lua_State *L) { | |||
| 515 | struct tm ts; | 515 | struct tm ts; |
| 516 | luaL_checktype(L, 1, LUA_TTABLE); | 516 | luaL_checktype(L, 1, LUA_TTABLE); |
| 517 | lua_settop(L, 1); /* make sure table is at the top */ | 517 | lua_settop(L, 1); /* make sure table is at the top */ |
| 518 | ts.tm_sec = getfield(L, "sec", 0); | 518 | ts.tm_sec = getfield(L, l_s("sec"), 0); |
| 519 | ts.tm_min = getfield(L, "min", 0); | 519 | ts.tm_min = getfield(L, l_s("min"), 0); |
| 520 | ts.tm_hour = getfield(L, "hour", 12); | 520 | ts.tm_hour = getfield(L, l_s("hour"), 12); |
| 521 | ts.tm_mday = getfield(L, "day", -2); | 521 | ts.tm_mday = getfield(L, l_s("day"), -2); |
| 522 | ts.tm_mon = getfield(L, "month", -2)-1; | 522 | ts.tm_mon = getfield(L, l_s("month"), -2)-1; |
| 523 | ts.tm_year = getfield(L, "year", -2)-1900; | 523 | ts.tm_year = getfield(L, l_s("year"), -2)-1900; |
| 524 | ts.tm_isdst = getfield(L, "isdst", -1); | 524 | ts.tm_isdst = getfield(L, l_s("isdst"), -1); |
| 525 | t = mktime(&ts); | 525 | t = mktime(&ts); |
| 526 | if (t == (time_t)-1) | 526 | if (t == (time_t)-1) |
| 527 | lua_pushnil(L); | 527 | lua_pushnil(L); |
| @@ -544,10 +544,10 @@ static int io_difftime (lua_State *L) { | |||
| 544 | static int io_setloc (lua_State *L) { | 544 | static int io_setloc (lua_State *L) { |
| 545 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, | 545 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, |
| 546 | LC_NUMERIC, LC_TIME}; | 546 | LC_NUMERIC, LC_TIME}; |
| 547 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", | 547 | static const l_char *const catnames[] = {l_s("all"), l_s("collate"), l_s("ctype"), l_s("monetary"), |
| 548 | "numeric", "time", NULL}; | 548 | l_s("numeric"), l_s("time"), NULL}; |
| 549 | int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames); | 549 | int op = luaL_findstring(luaL_opt_string(L, 2, l_s("all")), catnames); |
| 550 | luaL_arg_check(L, op != -1, 2, "invalid option"); | 550 | luaL_arg_check(L, op != -1, 2, l_s("invalid option")); |
| 551 | lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1))); | 551 | lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1))); |
| 552 | return 1; | 552 | return 1; |
| 553 | } | 553 | } |
| @@ -564,10 +564,10 @@ static int io_exit (lua_State *L) { | |||
| 564 | 564 | ||
| 565 | static int io_debug (lua_State *L) { | 565 | static int io_debug (lua_State *L) { |
| 566 | for (;;) { | 566 | for (;;) { |
| 567 | char buffer[250]; | 567 | l_char buffer[250]; |
| 568 | fprintf(stderr, "lua_debug> "); | 568 | fprintf(stderr, l_s("lua_debug> ")); |
| 569 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || | 569 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || |
| 570 | strcmp(buffer, "cont\n") == 0) | 570 | strcmp(buffer, l_s("cont\n")) == 0) |
| 571 | return 0; | 571 | return 0; |
| 572 | lua_dostring(L, buffer); | 572 | lua_dostring(L, buffer); |
| 573 | lua_settop(L, 0); /* remove eventual returns */ | 573 | lua_settop(L, 0); /* remove eventual returns */ |
| @@ -584,61 +584,61 @@ static int errorfb (lua_State *L) { | |||
| 584 | lua_Debug ar; | 584 | lua_Debug ar; |
| 585 | luaL_Buffer b; | 585 | luaL_Buffer b; |
| 586 | luaL_buffinit(L, &b); | 586 | luaL_buffinit(L, &b); |
| 587 | luaL_addstring(&b, "error: "); | 587 | luaL_addstring(&b, l_s("error: ")); |
| 588 | luaL_addstring(&b, luaL_check_string(L, 1)); | 588 | luaL_addstring(&b, luaL_check_string(L, 1)); |
| 589 | luaL_addstring(&b, "\n"); | 589 | luaL_addstring(&b, l_s("\n")); |
| 590 | while (lua_getstack(L, level++, &ar)) { | 590 | while (lua_getstack(L, level++, &ar)) { |
| 591 | char buff[120]; /* enough to fit following `sprintf's */ | 591 | l_char buff[120]; /* enough to fit following `sprintf's */ |
| 592 | if (level == 2) | 592 | if (level == 2) |
| 593 | luaL_addstring(&b, "stack traceback:\n"); | 593 | luaL_addstring(&b, l_s("stack traceback:\n")); |
| 594 | else if (level > LEVELS1 && firstpart) { | 594 | else if (level > LEVELS1 && firstpart) { |
| 595 | /* no more than `LEVELS2' more levels? */ | 595 | /* no more than `LEVELS2' more levels? */ |
| 596 | if (!lua_getstack(L, level+LEVELS2, &ar)) | 596 | if (!lua_getstack(L, level+LEVELS2, &ar)) |
| 597 | level--; /* keep going */ | 597 | level--; /* keep going */ |
| 598 | else { | 598 | else { |
| 599 | luaL_addstring(&b, " ...\n"); /* too many levels */ | 599 | luaL_addstring(&b, l_s(" ...\n")); /* too many levels */ |
| 600 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ | 600 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ |
| 601 | level++; | 601 | level++; |
| 602 | } | 602 | } |
| 603 | firstpart = 0; | 603 | firstpart = 0; |
| 604 | continue; | 604 | continue; |
| 605 | } | 605 | } |
| 606 | sprintf(buff, "%4d: ", level-1); | 606 | sprintf(buff, l_s("%4d: "), level-1); |
| 607 | luaL_addstring(&b, buff); | 607 | luaL_addstring(&b, buff); |
| 608 | lua_getinfo(L, "Snl", &ar); | 608 | lua_getinfo(L, l_s("Snl"), &ar); |
| 609 | switch (*ar.namewhat) { | 609 | switch (*ar.namewhat) { |
| 610 | case 'g': case 'l': /* global, local */ | 610 | case l_c('g'): case l_c('l'): /* global, local */ |
| 611 | sprintf(buff, "function `%.50s'", ar.name); | 611 | sprintf(buff, l_s("function `%.50s'"), ar.name); |
| 612 | break; | 612 | break; |
| 613 | case 'f': /* field */ | 613 | case l_c('f'): /* field */ |
| 614 | sprintf(buff, "method `%.50s'", ar.name); | 614 | sprintf(buff, l_s("method `%.50s'"), ar.name); |
| 615 | break; | 615 | break; |
| 616 | case 't': /* tag method */ | 616 | case l_c('t'): /* tag method */ |
| 617 | sprintf(buff, "`%.50s' tag method", ar.name); | 617 | sprintf(buff, l_s("`%.50s' tag method"), ar.name); |
| 618 | break; | 618 | break; |
| 619 | default: { | 619 | default: { |
| 620 | if (*ar.what == 'm') /* main? */ | 620 | if (*ar.what == l_c('m')) /* main? */ |
| 621 | sprintf(buff, "main of %.70s", ar.short_src); | 621 | sprintf(buff, l_s("main of %.70s"), ar.short_src); |
| 622 | else if (*ar.what == 'C') /* C function? */ | 622 | else if (*ar.what == l_c('C')) /* C function? */ |
| 623 | sprintf(buff, "%.70s", ar.short_src); | 623 | sprintf(buff, l_s("%.70s"), ar.short_src); |
| 624 | else | 624 | else |
| 625 | sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src); | 625 | sprintf(buff, l_s("function <%d:%.70s>"), ar.linedefined, ar.short_src); |
| 626 | ar.source = NULL; /* do not print source again */ | 626 | ar.source = NULL; /* do not print source again */ |
| 627 | } | 627 | } |
| 628 | } | 628 | } |
| 629 | luaL_addstring(&b, buff); | 629 | luaL_addstring(&b, buff); |
| 630 | if (ar.currentline > 0) { | 630 | if (ar.currentline > 0) { |
| 631 | sprintf(buff, " at line %d", ar.currentline); | 631 | sprintf(buff, l_s(" at line %d"), ar.currentline); |
| 632 | luaL_addstring(&b, buff); | 632 | luaL_addstring(&b, buff); |
| 633 | } | 633 | } |
| 634 | if (ar.source) { | 634 | if (ar.source) { |
| 635 | sprintf(buff, " [%.70s]", ar.short_src); | 635 | sprintf(buff, l_s(" [%.70s]"), ar.short_src); |
| 636 | luaL_addstring(&b, buff); | 636 | luaL_addstring(&b, buff); |
| 637 | } | 637 | } |
| 638 | luaL_addstring(&b, "\n"); | 638 | luaL_addstring(&b, l_s("\n")); |
| 639 | } | 639 | } |
| 640 | luaL_pushresult(&b); | 640 | luaL_pushresult(&b); |
| 641 | lua_getglobal(L, LUA_ALERT); | 641 | lua_getglobal(L, l_s(LUA_ALERT)); |
| 642 | if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ | 642 | if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ |
| 643 | lua_pushvalue(L, -2); /* error message */ | 643 | lua_pushvalue(L, -2); /* error message */ |
| 644 | lua_rawcall(L, 1, 0); | 644 | lua_rawcall(L, 1, 0); |
| @@ -649,44 +649,44 @@ static int errorfb (lua_State *L) { | |||
| 649 | 649 | ||
| 650 | 650 | ||
| 651 | static const luaL_reg iolib[] = { | 651 | static const luaL_reg iolib[] = { |
| 652 | {"appendto", io_appendto}, | 652 | {l_s("appendto"), io_appendto}, |
| 653 | {"clock", io_clock}, | 653 | {l_s("clock"), io_clock}, |
| 654 | {"closefile", io_close}, | 654 | {l_s("closefile"), io_close}, |
| 655 | {"date", io_date}, | 655 | {l_s("date"), io_date}, |
| 656 | {"debug", io_debug}, | 656 | {l_s("debug"), io_debug}, |
| 657 | {"difftime", io_difftime}, | 657 | {l_s("difftime"), io_difftime}, |
| 658 | {"execute", io_execute}, | 658 | {l_s("execute"), io_execute}, |
| 659 | {"exit", io_exit}, | 659 | {l_s("exit"), io_exit}, |
| 660 | {"flush", io_flush}, | 660 | {l_s("flush"), io_flush}, |
| 661 | {"getenv", io_getenv}, | 661 | {l_s("getenv"), io_getenv}, |
| 662 | {"openfile", io_open}, | 662 | {l_s("openfile"), io_open}, |
| 663 | {"read", io_read}, | 663 | {l_s("read"), io_read}, |
| 664 | {"readfrom", io_readfrom}, | 664 | {l_s("readfrom"), io_readfrom}, |
| 665 | {"remove", io_remove}, | 665 | {l_s("remove"), io_remove}, |
| 666 | {"rename", io_rename}, | 666 | {l_s("rename"), io_rename}, |
| 667 | {"seek", io_seek}, | 667 | {l_s("seek"), io_seek}, |
| 668 | {"setlocale", io_setloc}, | 668 | {l_s("setlocale"), io_setloc}, |
| 669 | {"time", io_time}, | 669 | {l_s("time"), io_time}, |
| 670 | {"tmpfile", io_tmpfile}, | 670 | {l_s("tmpfile"), io_tmpfile}, |
| 671 | {"tmpname", io_tmpname}, | 671 | {l_s("tmpname"), io_tmpname}, |
| 672 | {"write", io_write}, | 672 | {l_s("write"), io_write}, |
| 673 | {"writeto", io_writeto}, | 673 | {l_s("writeto"), io_writeto}, |
| 674 | {LUA_ERRORMESSAGE, errorfb} | 674 | {l_s(LUA_ERRORMESSAGE), errorfb} |
| 675 | }; | 675 | }; |
| 676 | 676 | ||
| 677 | 677 | ||
| 678 | LUALIB_API void lua_iolibopen (lua_State *L) { | 678 | LUALIB_API void lua_iolibopen (lua_State *L) { |
| 679 | int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA); | 679 | int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA); |
| 680 | lua_newtype(L, "ClosedFileHandle", LUA_TUSERDATA); | 680 | lua_newtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA); |
| 681 | luaL_openl(L, iolib); | 681 | luaL_openl(L, iolib); |
| 682 | /* predefined file handles */ | 682 | /* predefined file handles */ |
| 683 | setfile(L, stdin, INFILE); | 683 | setfile(L, stdin, INFILE); |
| 684 | setfile(L, stdout, OUTFILE); | 684 | setfile(L, stdout, OUTFILE); |
| 685 | setfilebyname(L, stdin, "_STDIN"); | 685 | setfilebyname(L, stdin, l_s("_STDIN")); |
| 686 | setfilebyname(L, stdout, "_STDOUT"); | 686 | setfilebyname(L, stdout, l_s("_STDOUT")); |
| 687 | setfilebyname(L, stderr, "_STDERR"); | 687 | setfilebyname(L, stderr, l_s("_STDERR")); |
| 688 | /* close files when collected */ | 688 | /* close files when collected */ |
| 689 | lua_pushcfunction(L, file_collect); | 689 | lua_pushcfunction(L, file_collect); |
| 690 | lua_settagmethod(L, iotag, "gc"); | 690 | lua_settagmethod(L, iotag, l_s("gc")); |
| 691 | } | 691 | } |
| 692 | 692 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.78 2001/02/22 17:15:18 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.79 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -25,10 +25,13 @@ | |||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | /* ORDER RESERVED */ | 27 | /* ORDER RESERVED */ |
| 28 | static const char *const token2string [] = { | 28 | static const l_char *const token2string [] = { |
| 29 | "and", "break", "do", "else", "elseif", "end", "for", | 29 | l_s("and"), l_s("break"), l_s("do"), l_s("else"), l_s("elseif"), |
| 30 | "function", "if", "local", "nil", "not", "or", "repeat", "return", "then", | 30 | l_s("end"), l_s("for"), l_s("function"), l_s("if"), l_s("local"), |
| 31 | "until", "while", "", "..", "...", "==", ">=", "<=", "~=", "", "", "<eof>"}; | 31 | l_s("nil"), l_s("not"), l_s("or"), l_s("repeat"), l_s("return"), |
| 32 | l_s("then"), l_s("until"), l_s("while"), l_s(""), l_s(".."), l_s("..."), | ||
| 33 | l_s("=="), l_s(">="), l_s("<="), l_s("~="), l_s(""), l_s(""), l_s("<eof>") | ||
| 34 | }; | ||
| 32 | 35 | ||
| 33 | 36 | ||
| 34 | void luaX_init (lua_State *L) { | 37 | void luaX_init (lua_State *L) { |
| @@ -44,37 +47,38 @@ void luaX_init (lua_State *L) { | |||
| 44 | #define MAXSRC 80 | 47 | #define MAXSRC 80 |
| 45 | 48 | ||
| 46 | 49 | ||
| 47 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { | 50 | void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg) { |
| 48 | if (val > limit) { | 51 | if (val > limit) { |
| 49 | char buff[90]; | 52 | l_char buff[90]; |
| 50 | sprintf(buff, "too many %.40s (limit=%d)", msg, limit); | 53 | sprintf(buff, l_s("too many %.40s (limit=%d)"), msg, limit); |
| 51 | luaX_error(ls, buff, ls->t.token); | 54 | luaX_error(ls, buff, ls->t.token); |
| 52 | } | 55 | } |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | 58 | ||
| 56 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { | 59 | void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token) { |
| 57 | char buff[MAXSRC]; | 60 | l_char buff[MAXSRC]; |
| 58 | luaO_chunkid(buff, getstr(ls->source), sizeof(buff)); | 61 | luaO_chunkid(buff, getstr(ls->source), sizeof(buff)); |
| 59 | luaO_verror(ls->L, "%.99s;\n last token read: `%.30s' at line %d in %.80s", | 62 | luaO_verror(ls->L, |
| 63 | l_s("%.99s;\n last token read: `%.30s' at line %d in %.80s"), | ||
| 60 | s, token, ls->linenumber, buff); | 64 | s, token, ls->linenumber, buff); |
| 61 | } | 65 | } |
| 62 | 66 | ||
| 63 | 67 | ||
| 64 | void luaX_error (LexState *ls, const char *s, int token) { | 68 | void luaX_error (LexState *ls, const l_char *s, int token) { |
| 65 | char buff[TOKEN_LEN]; | 69 | l_char buff[TOKEN_LEN]; |
| 66 | luaX_token2str(token, buff); | 70 | luaX_token2str(token, buff); |
| 67 | if (buff[0] == '\0') | 71 | if (buff[0] == l_c('\0')) |
| 68 | luaX_syntaxerror(ls, s, G(ls->L)->Mbuffer); | 72 | luaX_syntaxerror(ls, s, G(ls->L)->Mbuffer); |
| 69 | else | 73 | else |
| 70 | luaX_syntaxerror(ls, s, buff); | 74 | luaX_syntaxerror(ls, s, buff); |
| 71 | } | 75 | } |
| 72 | 76 | ||
| 73 | 77 | ||
| 74 | void luaX_token2str (int token, char *s) { | 78 | void luaX_token2str (int token, l_char *s) { |
| 75 | if (token < 256) { | 79 | if (token < 256) { |
| 76 | s[0] = (char)token; | 80 | s[0] = (l_char)token; |
| 77 | s[1] = '\0'; | 81 | s[1] = l_c('\0'); |
| 78 | } | 82 | } |
| 79 | else | 83 | else |
| 80 | strcpy(s, token2string[token-FIRST_RESERVED]); | 84 | strcpy(s, token2string[token-FIRST_RESERVED]); |
| @@ -82,16 +86,16 @@ void luaX_token2str (int token, char *s) { | |||
| 82 | 86 | ||
| 83 | 87 | ||
| 84 | static void luaX_invalidchar (LexState *ls, int c) { | 88 | static void luaX_invalidchar (LexState *ls, int c) { |
| 85 | char buff[8]; | 89 | l_char buff[8]; |
| 86 | sprintf(buff, "0x%02X", c); | 90 | sprintf(buff, l_s("0x%02X"), c); |
| 87 | luaX_syntaxerror(ls, "invalid control char", buff); | 91 | luaX_syntaxerror(ls, l_s("invalid control l_char"), buff); |
| 88 | } | 92 | } |
| 89 | 93 | ||
| 90 | 94 | ||
| 91 | static void inclinenumber (LexState *LS) { | 95 | static void inclinenumber (LexState *LS) { |
| 92 | next(LS); /* skip `\n' */ | 96 | next(LS); /* skip `\n' */ |
| 93 | ++LS->linenumber; | 97 | ++LS->linenumber; |
| 94 | luaX_checklimit(LS, LS->linenumber, MAX_INT, "lines in a chunk"); | 98 | luaX_checklimit(LS, LS->linenumber, MAX_INT, l_s("lines in a chunk")); |
| 95 | } | 99 | } |
| 96 | 100 | ||
| 97 | 101 | ||
| @@ -104,10 +108,10 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { | |||
| 104 | LS->lastline = 1; | 108 | LS->lastline = 1; |
| 105 | LS->source = source; | 109 | LS->source = source; |
| 106 | next(LS); /* read first char */ | 110 | next(LS); /* read first char */ |
| 107 | if (LS->current == '#') { | 111 | if (LS->current == l_c('#')) { |
| 108 | do { /* skip first line */ | 112 | do { /* skip first line */ |
| 109 | next(LS); | 113 | next(LS); |
| 110 | } while (LS->current != '\n' && LS->current != EOZ); | 114 | } while (LS->current != l_c('\n') && LS->current != EOZ); |
| 111 | } | 115 | } |
| 112 | } | 116 | } |
| 113 | 117 | ||
| @@ -126,7 +130,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { | |||
| 126 | #define checkbuffer(L, n, len) if ((len)+(n) > G(L)->Mbuffsize) \ | 130 | #define checkbuffer(L, n, len) if ((len)+(n) > G(L)->Mbuffsize) \ |
| 127 | luaO_openspace(L, (len)+(n)+EXTRABUFF) | 131 | luaO_openspace(L, (len)+(n)+EXTRABUFF) |
| 128 | 132 | ||
| 129 | #define save(L, c, l) (G(L)->Mbuffer[l++] = (char)c) | 133 | #define save(L, c, l) (G(L)->Mbuffer[l++] = (l_char)c) |
| 130 | #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) | 134 | #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) |
| 131 | 135 | ||
| 132 | 136 | ||
| @@ -137,8 +141,8 @@ static size_t readname (LexState *LS) { | |||
| 137 | do { | 141 | do { |
| 138 | checkbuffer(L, 10, l); | 142 | checkbuffer(L, 10, l); |
| 139 | save_and_next(L, LS, l); | 143 | save_and_next(L, LS, l); |
| 140 | } while (isalnum(LS->current) || LS->current == '_'); | 144 | } while (isalnum(LS->current) || LS->current == l_c('_')); |
| 141 | save(L, '\0', l); | 145 | save(L, l_c('\0'), l); |
| 142 | return l-1; | 146 | return l-1; |
| 143 | } | 147 | } |
| 144 | 148 | ||
| @@ -148,36 +152,37 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) { | |||
| 148 | lua_State *L = LS->L; | 152 | lua_State *L = LS->L; |
| 149 | size_t l = 0; | 153 | size_t l = 0; |
| 150 | checkbuffer(L, 10, l); | 154 | checkbuffer(L, 10, l); |
| 151 | if (comma) save(L, '.', l); | 155 | if (comma) save(L, l_c('.'), l); |
| 152 | while (isdigit(LS->current)) { | 156 | while (isdigit(LS->current)) { |
| 153 | checkbuffer(L, 10, l); | 157 | checkbuffer(L, 10, l); |
| 154 | save_and_next(L, LS, l); | 158 | save_and_next(L, LS, l); |
| 155 | } | 159 | } |
| 156 | if (LS->current == '.') { | 160 | if (LS->current == l_c('.')) { |
| 157 | save_and_next(L, LS, l); | 161 | save_and_next(L, LS, l); |
| 158 | if (LS->current == '.') { | 162 | if (LS->current == l_c('.')) { |
| 159 | save_and_next(L, LS, l); | 163 | save_and_next(L, LS, l); |
| 160 | save(L, '\0', l); | 164 | save(L, l_c('\0'), l); |
| 161 | luaX_error(LS, "ambiguous syntax" | 165 | luaX_error(LS, |
| 162 | " (decimal point x string concatenation)", TK_NUMBER); | 166 | l_s("ambiguous syntax (decimal point x string concatenation)"), |
| 167 | TK_NUMBER); | ||
| 163 | } | 168 | } |
| 164 | } | 169 | } |
| 165 | while (isdigit(LS->current)) { | 170 | while (isdigit(LS->current)) { |
| 166 | checkbuffer(L, 10, l); | 171 | checkbuffer(L, 10, l); |
| 167 | save_and_next(L, LS, l); | 172 | save_and_next(L, LS, l); |
| 168 | } | 173 | } |
| 169 | if (LS->current == 'e' || LS->current == 'E') { | 174 | if (LS->current == l_c('e') || LS->current == l_c('E')) { |
| 170 | save_and_next(L, LS, l); /* read `E' */ | 175 | save_and_next(L, LS, l); /* read `E' */ |
| 171 | if (LS->current == '+' || LS->current == '-') | 176 | if (LS->current == l_c('+') || LS->current == l_c('-')) |
| 172 | save_and_next(L, LS, l); /* optional exponent sign */ | 177 | save_and_next(L, LS, l); /* optional exponent sign */ |
| 173 | while (isdigit(LS->current)) { | 178 | while (isdigit(LS->current)) { |
| 174 | checkbuffer(L, 10, l); | 179 | checkbuffer(L, 10, l); |
| 175 | save_and_next(L, LS, l); | 180 | save_and_next(L, LS, l); |
| 176 | } | 181 | } |
| 177 | } | 182 | } |
| 178 | save(L, '\0', l); | 183 | save(L, l_c('\0'), l); |
| 179 | if (!luaO_str2d(G(L)->Mbuffer, &seminfo->r)) | 184 | if (!luaO_str2d(G(L)->Mbuffer, &seminfo->r)) |
| 180 | luaX_error(LS, "malformed number", TK_NUMBER); | 185 | luaX_error(LS, l_s("malformed number"), TK_NUMBER); |
| 181 | } | 186 | } |
| 182 | 187 | ||
| 183 | 188 | ||
| @@ -186,32 +191,32 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { | |||
| 186 | int cont = 0; | 191 | int cont = 0; |
| 187 | size_t l = 0; | 192 | size_t l = 0; |
| 188 | checkbuffer(L, 10, l); | 193 | checkbuffer(L, 10, l); |
| 189 | save(L, '[', l); /* save first `[' */ | 194 | save(L, l_c('['), l); /* save first `[' */ |
| 190 | save_and_next(L, LS, l); /* pass the second `[' */ | 195 | save_and_next(L, LS, l); /* pass the second `[' */ |
| 191 | for (;;) { | 196 | for (;;) { |
| 192 | checkbuffer(L, 10, l); | 197 | checkbuffer(L, 10, l); |
| 193 | switch (LS->current) { | 198 | switch (LS->current) { |
| 194 | case EOZ: | 199 | case EOZ: |
| 195 | save(L, '\0', l); | 200 | save(L, l_c('\0'), l); |
| 196 | luaX_error(LS, "unfinished long string", TK_STRING); | 201 | luaX_error(LS, l_s("unfinished long string"), TK_STRING); |
| 197 | break; /* to avoid warnings */ | 202 | break; /* to avoid warnings */ |
| 198 | case '[': | 203 | case l_c('['): |
| 199 | save_and_next(L, LS, l); | 204 | save_and_next(L, LS, l); |
| 200 | if (LS->current == '[') { | 205 | if (LS->current == l_c('[')) { |
| 201 | cont++; | 206 | cont++; |
| 202 | save_and_next(L, LS, l); | 207 | save_and_next(L, LS, l); |
| 203 | } | 208 | } |
| 204 | continue; | 209 | continue; |
| 205 | case ']': | 210 | case l_c(']'): |
| 206 | save_and_next(L, LS, l); | 211 | save_and_next(L, LS, l); |
| 207 | if (LS->current == ']') { | 212 | if (LS->current == l_c(']')) { |
| 208 | if (cont == 0) goto endloop; | 213 | if (cont == 0) goto endloop; |
| 209 | cont--; | 214 | cont--; |
| 210 | save_and_next(L, LS, l); | 215 | save_and_next(L, LS, l); |
| 211 | } | 216 | } |
| 212 | continue; | 217 | continue; |
| 213 | case '\n': | 218 | case l_c('\n'): |
| 214 | save(L, '\n', l); | 219 | save(L, l_c('\n'), l); |
| 215 | inclinenumber(LS); | 220 | inclinenumber(LS); |
| 216 | continue; | 221 | continue; |
| 217 | default: | 222 | default: |
| @@ -219,7 +224,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { | |||
| 219 | } | 224 | } |
| 220 | } endloop: | 225 | } endloop: |
| 221 | save_and_next(L, LS, l); /* skip the second `]' */ | 226 | save_and_next(L, LS, l); /* skip the second `]' */ |
| 222 | save(L, '\0', l); | 227 | save(L, l_c('\0'), l); |
| 223 | seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+2, l-5); | 228 | seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+2, l-5); |
| 224 | } | 229 | } |
| 225 | 230 | ||
| @@ -232,38 +237,38 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
| 232 | while (LS->current != del) { | 237 | while (LS->current != del) { |
| 233 | checkbuffer(L, 10, l); | 238 | checkbuffer(L, 10, l); |
| 234 | switch (LS->current) { | 239 | switch (LS->current) { |
| 235 | case EOZ: case '\n': | 240 | case EOZ: case l_c('\n'): |
| 236 | save(L, '\0', l); | 241 | save(L, l_c('\0'), l); |
| 237 | luaX_error(LS, "unfinished string", TK_STRING); | 242 | luaX_error(LS, l_s("unfinished string"), TK_STRING); |
| 238 | break; /* to avoid warnings */ | 243 | break; /* to avoid warnings */ |
| 239 | case '\\': | 244 | case l_c('\\'): |
| 240 | next(LS); /* do not save the `\' */ | 245 | next(LS); /* do not save the `\' */ |
| 241 | switch (LS->current) { | 246 | switch (LS->current) { |
| 242 | case 'a': save(L, '\a', l); next(LS); break; | 247 | case l_c('a'): save(L, l_c('\a'), l); next(LS); break; |
| 243 | case 'b': save(L, '\b', l); next(LS); break; | 248 | case l_c('b'): save(L, l_c('\b'), l); next(LS); break; |
| 244 | case 'f': save(L, '\f', l); next(LS); break; | 249 | case l_c('f'): save(L, l_c('\f'), l); next(LS); break; |
| 245 | case 'n': save(L, '\n', l); next(LS); break; | 250 | case l_c('n'): save(L, l_c('\n'), l); next(LS); break; |
| 246 | case 'r': save(L, '\r', l); next(LS); break; | 251 | case l_c('r'): save(L, l_c('\r'), l); next(LS); break; |
| 247 | case 't': save(L, '\t', l); next(LS); break; | 252 | case l_c('t'): save(L, l_c('\t'), l); next(LS); break; |
| 248 | case 'v': save(L, '\v', l); next(LS); break; | 253 | case l_c('v'): save(L, l_c('\v'), l); next(LS); break; |
| 249 | case '\n': save(L, '\n', l); inclinenumber(LS); break; | 254 | case l_c('\n'): save(L, l_c('\n'), l); inclinenumber(LS); break; |
| 250 | case '0': case '1': case '2': case '3': case '4': | 255 | default: { |
| 251 | case '5': case '6': case '7': case '8': case '9': { | 256 | if (!isdigit(LS->current)) |
| 252 | int c = 0; | 257 | save_and_next(L, LS, l); /* handles \\, \", \', and \? */ |
| 253 | int i = 0; | 258 | else { /* \xxx */ |
| 254 | do { | 259 | int c = 0; |
| 255 | c = 10*c + (LS->current-'0'); | 260 | int i = 0; |
| 256 | next(LS); | 261 | do { |
| 257 | } while (++i<3 && isdigit(LS->current)); | 262 | c = 10*c + (LS->current-l_c('0')); |
| 258 | if (c > UCHAR_MAX) { | 263 | next(LS); |
| 259 | save(L, '\0', l); | 264 | } while (++i<3 && isdigit(LS->current)); |
| 260 | luaX_error(LS, "escape sequence too large", TK_STRING); | 265 | if (c > UCHAR_MAX) { |
| 266 | save(L, l_c('\0'), l); | ||
| 267 | luaX_error(LS, l_s("escape sequence too large"), TK_STRING); | ||
| 268 | } | ||
| 269 | save(L, c, l); | ||
| 261 | } | 270 | } |
| 262 | save(L, c, l); | ||
| 263 | break; | ||
| 264 | } | 271 | } |
| 265 | default: /* handles \\, \", \', and \? */ | ||
| 266 | save_and_next(L, LS, l); | ||
| 267 | } | 272 | } |
| 268 | break; | 273 | break; |
| 269 | default: | 274 | default: |
| @@ -271,7 +276,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
| 271 | } | 276 | } |
| 272 | } | 277 | } |
| 273 | save_and_next(L, LS, l); /* skip delimiter */ | 278 | save_and_next(L, LS, l); /* skip delimiter */ |
| 274 | save(L, '\0', l); | 279 | save(L, l_c('\0'), l); |
| 275 | seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+1, l-3); | 280 | seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+1, l-3); |
| 276 | } | 281 | } |
| 277 | 282 | ||
| @@ -280,92 +285,85 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { | |||
| 280 | for (;;) { | 285 | for (;;) { |
| 281 | switch (LS->current) { | 286 | switch (LS->current) { |
| 282 | 287 | ||
| 283 | case ' ': case '\t': case '\r': /* `\r' to avoid problems with DOS */ | 288 | case l_c(' '): case l_c('\t'): case l_c('\r'): /* `\r' to avoid problems with DOS */ |
| 284 | next(LS); | 289 | next(LS); |
| 285 | continue; | 290 | continue; |
| 286 | 291 | ||
| 287 | case '\n': | 292 | case l_c('\n'): |
| 288 | inclinenumber(LS); | 293 | inclinenumber(LS); |
| 289 | continue; | 294 | continue; |
| 290 | 295 | ||
| 291 | case '$': | 296 | case l_c('$'): |
| 292 | luaX_error(LS, "unexpected `$' (pragmas are no longer supported)", '$'); | 297 | luaX_error(LS, |
| 298 | l_s("unexpected `$' (pragmas are no longer supported)"), | ||
| 299 | LS->current); | ||
| 293 | break; | 300 | break; |
| 294 | 301 | ||
| 295 | case '-': | 302 | case l_c('-'): |
| 296 | next(LS); | 303 | next(LS); |
| 297 | if (LS->current != '-') return '-'; | 304 | if (LS->current != l_c('-')) return l_c('-'); |
| 298 | do { next(LS); } while (LS->current != '\n' && LS->current != EOZ); | 305 | do { next(LS); } while (LS->current != l_c('\n') && LS->current != EOZ); |
| 299 | continue; | 306 | continue; |
| 300 | 307 | ||
| 301 | case '[': | 308 | case l_c('['): |
| 302 | next(LS); | 309 | next(LS); |
| 303 | if (LS->current != '[') return '['; | 310 | if (LS->current != l_c('[')) return l_c('['); |
| 304 | else { | 311 | else { |
| 305 | read_long_string(LS, seminfo); | 312 | read_long_string(LS, seminfo); |
| 306 | return TK_STRING; | 313 | return TK_STRING; |
| 307 | } | 314 | } |
| 308 | 315 | ||
| 309 | case '=': | 316 | case l_c('='): |
| 310 | next(LS); | 317 | next(LS); |
| 311 | if (LS->current != '=') return '='; | 318 | if (LS->current != l_c('=')) return l_c('='); |
| 312 | else { next(LS); return TK_EQ; } | 319 | else { next(LS); return TK_EQ; } |
| 313 | 320 | ||
| 314 | case '<': | 321 | case l_c('<'): |
| 315 | next(LS); | 322 | next(LS); |
| 316 | if (LS->current != '=') return '<'; | 323 | if (LS->current != l_c('=')) return l_c('<'); |
| 317 | else { next(LS); return TK_LE; } | 324 | else { next(LS); return TK_LE; } |
| 318 | 325 | ||
| 319 | case '>': | 326 | case l_c('>'): |
| 320 | next(LS); | 327 | next(LS); |
| 321 | if (LS->current != '=') return '>'; | 328 | if (LS->current != l_c('=')) return l_c('>'); |
| 322 | else { next(LS); return TK_GE; } | 329 | else { next(LS); return TK_GE; } |
| 323 | 330 | ||
| 324 | case '~': | 331 | case l_c('~'): |
| 325 | next(LS); | 332 | next(LS); |
| 326 | if (LS->current != '=') return '~'; | 333 | if (LS->current != l_c('=')) return l_c('~'); |
| 327 | else { next(LS); return TK_NE; } | 334 | else { next(LS); return TK_NE; } |
| 328 | 335 | ||
| 329 | case '"': | 336 | case l_c('"'): |
| 330 | case '\'': | 337 | case l_c('\''): |
| 331 | read_string(LS, LS->current, seminfo); | 338 | read_string(LS, LS->current, seminfo); |
| 332 | return TK_STRING; | 339 | return TK_STRING; |
| 333 | 340 | ||
| 334 | case '.': | 341 | case l_c('.'): |
| 335 | next(LS); | 342 | next(LS); |
| 336 | if (LS->current == '.') { | 343 | if (LS->current == l_c('.')) { |
| 337 | next(LS); | 344 | next(LS); |
| 338 | if (LS->current == '.') { | 345 | if (LS->current == l_c('.')) { |
| 339 | next(LS); | 346 | next(LS); |
| 340 | return TK_DOTS; /* ... */ | 347 | return TK_DOTS; /* ... */ |
| 341 | } | 348 | } |
| 342 | else return TK_CONCAT; /* .. */ | 349 | else return TK_CONCAT; /* .. */ |
| 343 | } | 350 | } |
| 344 | else if (!isdigit(LS->current)) return '.'; | 351 | else if (!isdigit(LS->current)) return l_c('.'); |
| 345 | else { | 352 | else { |
| 346 | read_number(LS, 1, seminfo); | 353 | read_number(LS, 1, seminfo); |
| 347 | return TK_NUMBER; | 354 | return TK_NUMBER; |
| 348 | } | 355 | } |
| 349 | 356 | ||
| 350 | case '0': case '1': case '2': case '3': case '4': | ||
| 351 | case '5': case '6': case '7': case '8': case '9': | ||
| 352 | read_number(LS, 0, seminfo); | ||
| 353 | return TK_NUMBER; | ||
| 354 | |||
| 355 | case EOZ: | 357 | case EOZ: |
| 356 | return TK_EOS; | 358 | return TK_EOS; |
| 357 | 359 | ||
| 358 | case '_': goto tname; | 360 | default: { |
| 359 | 361 | if (isdigit(LS->current)) { | |
| 360 | default: | 362 | read_number(LS, 0, seminfo); |
| 361 | if (!isalpha(LS->current)) { | 363 | return TK_NUMBER; |
| 362 | int c = LS->current; | ||
| 363 | if (iscntrl(c)) | ||
| 364 | luaX_invalidchar(LS, c); | ||
| 365 | next(LS); | ||
| 366 | return c; | ||
| 367 | } | 364 | } |
| 368 | tname: { /* identifier or reserved word */ | 365 | else if (isalpha(LS->current) || LS->current == l_c('_')) { |
| 366 | /* identifier or reserved word */ | ||
| 369 | size_t l = readname(LS); | 367 | size_t l = readname(LS); |
| 370 | TString *ts = luaS_newlstr(LS->L, G(LS->L)->Mbuffer, l); | 368 | TString *ts = luaS_newlstr(LS->L, G(LS->L)->Mbuffer, l); |
| 371 | if (ts->marked >= RESERVEDMARK) /* reserved word? */ | 369 | if (ts->marked >= RESERVEDMARK) /* reserved word? */ |
| @@ -373,6 +371,14 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { | |||
| 373 | seminfo->ts = ts; | 371 | seminfo->ts = ts; |
| 374 | return TK_NAME; | 372 | return TK_NAME; |
| 375 | } | 373 | } |
| 374 | else { | ||
| 375 | int c = LS->current; | ||
| 376 | if (iscntrl(c)) | ||
| 377 | luaX_invalidchar(LS, c); | ||
| 378 | next(LS); | ||
| 379 | return c; /* single-char tokens (+ - / ...) */ | ||
| 380 | } | ||
| 381 | } | ||
| 376 | } | 382 | } |
| 377 | } | 383 | } |
| 378 | } | 384 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.32 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.33 2001/01/10 16:40:56 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -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("function")) | 17 | #define TOKEN_LEN (sizeof(l_s("function"))) |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | /* | 20 | /* |
| @@ -63,10 +63,10 @@ typedef struct LexState { | |||
| 63 | void luaX_init (lua_State *L); | 63 | void luaX_init (lua_State *L); |
| 64 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); | 64 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); |
| 65 | int luaX_lex (LexState *LS, SemInfo *seminfo); | 65 | int luaX_lex (LexState *LS, SemInfo *seminfo); |
| 66 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); | 66 | void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg); |
| 67 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token); | 67 | void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token); |
| 68 | void luaX_error (LexState *ls, const char *s, int token); | 68 | void luaX_error (LexState *ls, const l_char *s, int token); |
| 69 | void luaX_token2str (int token, char *s); | 69 | void luaX_token2str (int token, l_char *s); |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | #endif | 72 | #endif |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.23 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.24 2001/02/22 17:15:18 roberto Exp roberto $ |
| 3 | ** Limits, basic types, and some other "installation-dependent" definitions | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| @@ -33,7 +33,7 @@ | |||
| 33 | 33 | ||
| 34 | /* function to convert a lua_Number to a string */ | 34 | /* function to convert a lua_Number to a string */ |
| 35 | #ifndef NUMBER_FMT | 35 | #ifndef NUMBER_FMT |
| 36 | #define NUMBER_FMT "%.16g" /* LUA_NUMBER */ | 36 | #define NUMBER_FMT l_s("%.16g") /* LUA_NUMBER */ |
| 37 | #endif | 37 | #endif |
| 38 | #ifndef lua_number2str | 38 | #ifndef lua_number2str |
| 39 | #define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n)) | 39 | #define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n)) |
| @@ -45,11 +45,21 @@ | |||
| 45 | #endif | 45 | #endif |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | /* macro to control type of literal strings */ | ||
| 49 | #ifndef l_s | ||
| 50 | #define l_s(x) x | ||
| 51 | #endif | ||
| 52 | |||
| 53 | /* macro to control type of literal chars */ | ||
| 54 | #ifndef l_c | ||
| 55 | #define l_c(x) x | ||
| 56 | #endif | ||
| 57 | |||
| 48 | 58 | ||
| 49 | /* | 59 | /* |
| 50 | ** the following types define integer types for values that may not | 60 | ** the following types define integer types for values that may not |
| 51 | ** fit in a "small int" (16 bits), but may waste space in a | 61 | ** fit in a `small int' (16 bits), but may waste space in a |
| 52 | ** "large long" (64 bits). The current definitions should work in | 62 | ** `large long' (64 bits). The current definitions should work in |
| 53 | ** any machine, but may not be optimal. | 63 | ** any machine, but may not be optimal. |
| 54 | */ | 64 | */ |
| 55 | 65 | ||
| @@ -88,7 +98,7 @@ typedef unsigned char lu_byte; | |||
| 88 | 98 | ||
| 89 | 99 | ||
| 90 | 100 | ||
| 91 | #define MINPOWER2 4 /* minimum size for "growing" vectors */ | 101 | #define MINPOWER2 4 /* minimum size for `growing' vectors */ |
| 92 | 102 | ||
| 93 | 103 | ||
| 94 | 104 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.34 2001/02/02 19:02:40 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.35 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -176,18 +176,18 @@ static int math_random (lua_State *L) { | |||
| 176 | } | 176 | } |
| 177 | case 1: { /* only upper limit */ | 177 | case 1: { /* only upper limit */ |
| 178 | int u = luaL_check_int(L, 1); | 178 | int u = luaL_check_int(L, 1); |
| 179 | luaL_arg_check(L, 1<=u, 1, "interval is empty"); | 179 | luaL_arg_check(L, 1<=u, 1, l_s("interval is empty")); |
| 180 | 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' */ |
| 181 | break; | 181 | break; |
| 182 | } | 182 | } |
| 183 | case 2: { /* lower and upper limits */ | 183 | case 2: { /* lower and upper limits */ |
| 184 | int l = luaL_check_int(L, 1); | 184 | int l = luaL_check_int(L, 1); |
| 185 | int u = luaL_check_int(L, 2); | 185 | int u = luaL_check_int(L, 2); |
| 186 | luaL_arg_check(L, l<=u, 2, "interval is empty"); | 186 | luaL_arg_check(L, l<=u, 2, l_s("interval is empty")); |
| 187 | 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' */ |
| 188 | break; | 188 | break; |
| 189 | } | 189 | } |
| 190 | default: lua_error(L, "wrong number of arguments"); | 190 | default: lua_error(L, l_s("wrong number of arguments")); |
| 191 | } | 191 | } |
| 192 | return 1; | 192 | return 1; |
| 193 | } | 193 | } |
| @@ -200,29 +200,29 @@ static int math_randomseed (lua_State *L) { | |||
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | static const luaL_reg mathlib[] = { | 202 | static const luaL_reg mathlib[] = { |
| 203 | {"abs", math_abs}, | 203 | {l_s("abs"), math_abs}, |
| 204 | {"sin", math_sin}, | 204 | {l_s("sin"), math_sin}, |
| 205 | {"cos", math_cos}, | 205 | {l_s("cos"), math_cos}, |
| 206 | {"tan", math_tan}, | 206 | {l_s("tan"), math_tan}, |
| 207 | {"asin", math_asin}, | 207 | {l_s("asin"), math_asin}, |
| 208 | {"acos", math_acos}, | 208 | {l_s("acos"), math_acos}, |
| 209 | {"atan", math_atan}, | 209 | {l_s("atan"), math_atan}, |
| 210 | {"atan2", math_atan2}, | 210 | {l_s("atan2"), math_atan2}, |
| 211 | {"ceil", math_ceil}, | 211 | {l_s("ceil"), math_ceil}, |
| 212 | {"floor", math_floor}, | 212 | {l_s("floor"), math_floor}, |
| 213 | {"mod", math_mod}, | 213 | {l_s("mod"), math_mod}, |
| 214 | {"frexp", math_frexp}, | 214 | {l_s("frexp"), math_frexp}, |
| 215 | {"ldexp", math_ldexp}, | 215 | {l_s("ldexp"), math_ldexp}, |
| 216 | {"sqrt", math_sqrt}, | 216 | {l_s("sqrt"), math_sqrt}, |
| 217 | {"min", math_min}, | 217 | {l_s("min"), math_min}, |
| 218 | {"max", math_max}, | 218 | {l_s("max"), math_max}, |
| 219 | {"log", math_log}, | 219 | {l_s("log"), math_log}, |
| 220 | {"log10", math_log10}, | 220 | {l_s("log10"), math_log10}, |
| 221 | {"exp", math_exp}, | 221 | {l_s("exp"), math_exp}, |
| 222 | {"deg", math_deg}, | 222 | {l_s("deg"), math_deg}, |
| 223 | {"rad", math_rad}, | 223 | {l_s("rad"), math_rad}, |
| 224 | {"random", math_random}, | 224 | {l_s("random"), math_random}, |
| 225 | {"randomseed", math_randomseed} | 225 | {l_s("randomseed"), math_randomseed} |
| 226 | }; | 226 | }; |
| 227 | 227 | ||
| 228 | /* | 228 | /* |
| @@ -231,8 +231,8 @@ static const luaL_reg mathlib[] = { | |||
| 231 | LUALIB_API void lua_mathlibopen (lua_State *L) { | 231 | LUALIB_API void lua_mathlibopen (lua_State *L) { |
| 232 | luaL_openl(L, mathlib); | 232 | luaL_openl(L, mathlib); |
| 233 | lua_pushcfunction(L, math_pow); | 233 | lua_pushcfunction(L, math_pow); |
| 234 | lua_settagmethod(L, LUA_TNUMBER, "pow"); | 234 | lua_settagmethod(L, LUA_TNUMBER, l_s("pow")); |
| 235 | lua_pushnumber(L, PI); | 235 | lua_pushnumber(L, PI); |
| 236 | lua_setglobal(L, "PI"); | 236 | lua_setglobal(L, l_s("PI")); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.46 2001/02/06 16:01:29 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.47 2001/02/20 18:15:33 roberto Exp roberto $ |
| 3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,7 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | 25 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, |
| 26 | int limit, const char *errormsg) { | 26 | int limit, const l_char *errormsg) { |
| 27 | void *newblock; | 27 | void *newblock; |
| 28 | int newsize = (*size)*2; | 28 | int newsize = (*size)*2; |
| 29 | if (newsize < MINPOWER2) | 29 | if (newsize < MINPOWER2) |
| @@ -49,7 +49,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { | |||
| 49 | block = NULL; | 49 | block = NULL; |
| 50 | } | 50 | } |
| 51 | else if (size >= MAX_SIZET) | 51 | else if (size >= MAX_SIZET) |
| 52 | luaD_error(L, "memory allocation error: block too big"); | 52 | luaD_error(L, l_s("memory allocation error: block too big")); |
| 53 | else { | 53 | else { |
| 54 | block = l_realloc(block, oldsize, size); | 54 | block = l_realloc(block, oldsize, size); |
| 55 | if (block == NULL) { | 55 | if (block == NULL) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.h,v 1.20 2001/02/02 15:13:05 roberto Exp roberto $ | 2 | ** $Id: lmem.h,v 1.21 2001/02/20 18:15:33 roberto Exp roberto $ |
| 3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -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 char *errormsg); | 19 | int limit, const l_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, t) luaM_realloc(L, (b), sizeof(t), 0) | 22 | #define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.65 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.66 2001/02/22 17:15:18 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,21 +35,21 @@ int luaO_equalObj (const TObject *t1, const TObject *t2) { | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | char *luaO_openspace (lua_State *L, size_t n) { | 38 | l_char *luaO_openspace (lua_State *L, size_t n) { |
| 39 | if (n > G(L)->Mbuffsize) { | 39 | if (n > G(L)->Mbuffsize) { |
| 40 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, n, char); | 40 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, n, l_char); |
| 41 | G(L)->Mbuffsize = n; | 41 | G(L)->Mbuffsize = n; |
| 42 | } | 42 | } |
| 43 | return G(L)->Mbuffer; | 43 | return G(L)->Mbuffer; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */ | 47 | int luaO_str2d (const l_char *s, lua_Number *result) { /* LUA_NUMBER */ |
| 48 | char *endptr; | 48 | l_char *endptr; |
| 49 | lua_Number res = lua_str2number(s, &endptr); | 49 | lua_Number res = lua_str2number(s, &endptr); |
| 50 | if (endptr == s) return 0; /* no conversion */ | 50 | if (endptr == s) return 0; /* no conversion */ |
| 51 | while (isspace(uchar(*endptr))) endptr++; | 51 | while (isspace(uchar(*endptr))) endptr++; |
| 52 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ | 52 | if (*endptr != l_c('\0')) return 0; /* invalid trailing characters? */ |
| 53 | *result = res; | 53 | *result = res; |
| 54 | return 1; | 54 | return 1; |
| 55 | } | 55 | } |
| @@ -59,9 +59,9 @@ int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */ | |||
| 59 | #define MAX_VERROR 280 | 59 | #define MAX_VERROR 280 |
| 60 | 60 | ||
| 61 | /* this function needs to handle only '%d' and '%.XXs' formats */ | 61 | /* this function needs to handle only '%d' and '%.XXs' formats */ |
| 62 | void luaO_verror (lua_State *L, const char *fmt, ...) { | 62 | void luaO_verror (lua_State *L, const l_char *fmt, ...) { |
| 63 | va_list argp; | 63 | va_list argp; |
| 64 | char buff[MAX_VERROR]; /* to hold formatted message */ | 64 | l_char buff[MAX_VERROR]; /* to hold formatted message */ |
| 65 | va_start(argp, fmt); | 65 | va_start(argp, fmt); |
| 66 | vsprintf(buff, fmt, argp); | 66 | vsprintf(buff, fmt, argp); |
| 67 | va_end(argp); | 67 | va_end(argp); |
| @@ -69,36 +69,36 @@ void luaO_verror (lua_State *L, const char *fmt, ...) { | |||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | void luaO_chunkid (char *out, const char *source, int bufflen) { | 72 | void luaO_chunkid (l_char *out, const l_char *source, int bufflen) { |
| 73 | if (*source == '=') { | 73 | if (*source == l_c('=')) { |
| 74 | strncpy(out, source+1, bufflen); /* remove first char */ | 74 | strncpy(out, source+1, bufflen); /* remove first char */ |
| 75 | out[bufflen-1] = '\0'; /* ensures null termination */ | 75 | out[bufflen-1] = l_c('\0'); /* ensures null termination */ |
| 76 | } | 76 | } |
| 77 | else { | 77 | else { |
| 78 | if (*source == '@') { | 78 | if (*source == l_c('@')) { |
| 79 | int l; | 79 | int l; |
| 80 | source++; /* skip the `@' */ | 80 | source++; /* skip the `@' */ |
| 81 | bufflen -= sizeof("file `...%s'"); | 81 | bufflen -= sizeof(l_s("file `...%s'")); |
| 82 | l = strlen(source); | 82 | l = strlen(source); |
| 83 | if (l>bufflen) { | 83 | if (l>bufflen) { |
| 84 | source += (l-bufflen); /* get last part of file name */ | 84 | source += (l-bufflen); /* get last part of file name */ |
| 85 | sprintf(out, "file `...%.99s'", source); | 85 | sprintf(out, l_s("file `...%.99s'"), source); |
| 86 | } | 86 | } |
| 87 | else | 87 | else |
| 88 | sprintf(out, "file `%.99s'", source); | 88 | sprintf(out, l_s("file `%.99s'"), source); |
| 89 | } | 89 | } |
| 90 | else { | 90 | else { |
| 91 | int len = strcspn(source, "\n"); /* stop at first newline */ | 91 | int len = strcspn(source, l_s("\n")); /* stop at first newline */ |
| 92 | bufflen -= sizeof("string \"%.*s...\""); | 92 | bufflen -= sizeof(l_s("string \"%.*s...\"")); |
| 93 | if (len > bufflen) len = bufflen; | 93 | if (len > bufflen) len = bufflen; |
| 94 | if (source[len] != '\0') { /* must truncate? */ | 94 | if (source[len] != l_c('\0')) { /* must truncate? */ |
| 95 | strcpy(out, "string \""); | 95 | strcpy(out, l_s("string \"")); |
| 96 | out += strlen(out); | 96 | out += strlen(out); |
| 97 | strncpy(out, source, len); | 97 | strncpy(out, source, len); |
| 98 | strcpy(out+len, "...\""); | 98 | strcpy(out+len, l_s("...\"")); |
| 99 | } | 99 | } |
| 100 | else | 100 | else |
| 101 | sprintf(out, "string \"%.99s\"", source); | 101 | sprintf(out, l_s("string \"%.99s\""), source); |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.96 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.97 2001/02/20 18:28:11 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -117,7 +117,7 @@ union L_UTString { | |||
| 117 | 117 | ||
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | #define getstr(ts) ((char *)(ts) + sizeof(union L_UTString)) | 120 | #define getstr(ts) ((l_char *)(ts) + sizeof(union L_UTString)) |
| 121 | #define svalue(o) getstr(tsvalue(o)) | 121 | #define svalue(o) getstr(tsvalue(o)) |
| 122 | 122 | ||
| 123 | 123 | ||
| @@ -200,7 +200,7 @@ typedef struct Hash { | |||
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | /* | 202 | /* |
| 203 | ** "module" operation for hashing (size is always a power of 2) | 203 | ** `module' operation for hashing (size is always a power of 2) |
| 204 | */ | 204 | */ |
| 205 | #define lmod(s,size) ((int)((s) & ((size)-1))) | 205 | #define lmod(s,size) ((int)((s) & ((size)-1))) |
| 206 | 206 | ||
| @@ -220,13 +220,13 @@ typedef struct CallInfo { | |||
| 220 | extern const TObject luaO_nilobject; | 220 | extern const TObject luaO_nilobject; |
| 221 | 221 | ||
| 222 | 222 | ||
| 223 | char *luaO_openspace (lua_State *L, size_t n); | 223 | l_char *luaO_openspace (lua_State *L, size_t n); |
| 224 | 224 | ||
| 225 | int luaO_equalObj (const TObject *t1, const TObject *t2); | 225 | int luaO_equalObj (const TObject *t1, const TObject *t2); |
| 226 | int luaO_str2d (const char *s, lua_Number *result); | 226 | int luaO_str2d (const l_char *s, lua_Number *result); |
| 227 | 227 | ||
| 228 | void luaO_verror (lua_State *L, const char *fmt, ...); | 228 | void luaO_verror (lua_State *L, const l_char *fmt, ...); |
| 229 | void luaO_chunkid (char *out, const char *source, int len); | 229 | void luaO_chunkid (l_char *out, const l_char *source, int len); |
| 230 | 230 | ||
| 231 | 231 | ||
| 232 | #endif | 232 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.137 2001/02/22 18:59:59 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.138 2001/02/23 13:38:56 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -72,9 +72,9 @@ static void lookahead (LexState *ls) { | |||
| 72 | 72 | ||
| 73 | 73 | ||
| 74 | static void error_expected (LexState *ls, int token) { | 74 | static void error_expected (LexState *ls, int token) { |
| 75 | char buff[30], t[TOKEN_LEN]; | 75 | l_char buff[30], t[TOKEN_LEN]; |
| 76 | luaX_token2str(token, t); | 76 | luaX_token2str(token, t); |
| 77 | sprintf(buff, "`%.10s' expected", t); | 77 | sprintf(buff, l_s("`%.10s' expected"), t); |
| 78 | luaK_error(ls, buff); | 78 | luaK_error(ls, buff); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| @@ -86,7 +86,7 @@ static void check (LexState *ls, int c) { | |||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | static void check_condition (LexState *ls, int c, const char *msg) { | 89 | static void check_condition (LexState *ls, int c, const l_char *msg) { |
| 90 | if (!c) luaK_error(ls, msg); | 90 | if (!c) luaK_error(ls, msg); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| @@ -105,11 +105,11 @@ static void check_match (LexState *ls, int what, int who, int where) { | |||
| 105 | if (where == ls->linenumber) | 105 | if (where == ls->linenumber) |
| 106 | error_expected(ls, what); | 106 | error_expected(ls, what); |
| 107 | else { | 107 | else { |
| 108 | char buff[70]; | 108 | l_char buff[70]; |
| 109 | char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; | 109 | l_char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; |
| 110 | luaX_token2str(what, t_what); | 110 | luaX_token2str(what, t_what); |
| 111 | luaX_token2str(who, t_who); | 111 | luaX_token2str(who, t_who); |
| 112 | sprintf(buff, "`%.10s' expected (to close `%.10s' at line %d)", | 112 | sprintf(buff, l_s("`%.10s' expected (to close `%.10s' at line %d)"), |
| 113 | t_what, t_who, where); | 113 | t_what, t_who, where); |
| 114 | luaK_error(ls, buff); | 114 | luaK_error(ls, buff); |
| 115 | } | 115 | } |
| @@ -123,7 +123,7 @@ static int string_constant (FuncState *fs, TString *s) { | |||
| 123 | int c = s->u.s.constindex; | 123 | int c = s->u.s.constindex; |
| 124 | if (c >= fs->nkstr || f->kstr[c] != s) { | 124 | if (c >= fs->nkstr || f->kstr[c] != s) { |
| 125 | luaM_growvector(fs->L, f->kstr, fs->nkstr, f->sizekstr, TString *, | 125 | luaM_growvector(fs->L, f->kstr, fs->nkstr, f->sizekstr, TString *, |
| 126 | MAXARG_U, "constant table overflow"); | 126 | MAXARG_U, l_s("constant table overflow")); |
| 127 | c = fs->nkstr++; | 127 | c = fs->nkstr++; |
| 128 | f->kstr[c] = s; | 128 | f->kstr[c] = s; |
| 129 | s->u.s.constindex = c; /* hint for next time */ | 129 | s->u.s.constindex = c; /* hint for next time */ |
| @@ -139,7 +139,7 @@ static void code_string (LexState *ls, TString *s) { | |||
| 139 | 139 | ||
| 140 | static TString *str_checkname (LexState *ls) { | 140 | static TString *str_checkname (LexState *ls) { |
| 141 | TString *ts; | 141 | TString *ts; |
| 142 | check_condition(ls, (ls->t.token == TK_NAME), "<name> expected"); | 142 | check_condition(ls, (ls->t.token == TK_NAME), l_s("<name> expected")); |
| 143 | ts = ls->t.seminfo.ts; | 143 | ts = ls->t.seminfo.ts; |
| 144 | next(ls); | 144 | next(ls); |
| 145 | return ts; | 145 | return ts; |
| @@ -155,7 +155,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 155 | FuncState *fs = ls->fs; | 155 | FuncState *fs = ls->fs; |
| 156 | Proto *f = fs->f; | 156 | Proto *f = fs->f; |
| 157 | luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, | 157 | luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, |
| 158 | LocVar, MAX_INT, ""); | 158 | LocVar, MAX_INT, l_s("")); |
| 159 | f->locvars[fs->nlocvars].varname = varname; | 159 | f->locvars[fs->nlocvars].varname = varname; |
| 160 | return fs->nlocvars++; | 160 | return fs->nlocvars++; |
| 161 | } | 161 | } |
| @@ -163,7 +163,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 163 | 163 | ||
| 164 | static void new_localvar (LexState *ls, TString *name, int n) { | 164 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 165 | FuncState *fs = ls->fs; | 165 | FuncState *fs = ls->fs; |
| 166 | luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, "local variables"); | 166 | luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, l_s("local variables")); |
| 167 | fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name); | 167 | fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| @@ -182,7 +182,7 @@ static void removelocalvars (LexState *ls, int nvars) { | |||
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | 184 | ||
| 185 | static void new_localvarstr (LexState *ls, const char *name, int n) { | 185 | static void new_localvarstr (LexState *ls, const l_char *name, int n) { |
| 186 | new_localvar(ls, luaS_new(ls->L, name), n); | 186 | new_localvar(ls, luaS_new(ls->L, name), n); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| @@ -209,7 +209,7 @@ static int search_local (LexState *ls, TString *n, expdesc *var) { | |||
| 209 | static void singlevar (LexState *ls, TString *n, expdesc *var) { | 209 | static void singlevar (LexState *ls, TString *n, expdesc *var) { |
| 210 | int level = search_local(ls, n, var); | 210 | int level = search_local(ls, n, var); |
| 211 | if (level >= 1) /* neither local (0) nor global (-1)? */ | 211 | if (level >= 1) /* neither local (0) nor global (-1)? */ |
| 212 | luaX_syntaxerror(ls, "cannot access a variable in outer function", | 212 | luaX_syntaxerror(ls, l_s("cannot access a variable in outer function"), |
| 213 | getstr(n)); | 213 | getstr(n)); |
| 214 | else if (level == -1) /* global? */ | 214 | else if (level == -1) /* global? */ |
| 215 | var->u.index = string_constant(ls->fs, n); | 215 | var->u.index = string_constant(ls->fs, n); |
| @@ -224,7 +224,7 @@ static int indexupvalue (LexState *ls, expdesc *v) { | |||
| 224 | return i; | 224 | return i; |
| 225 | } | 225 | } |
| 226 | /* new one */ | 226 | /* new one */ |
| 227 | luaX_checklimit(ls, fs->f->nupvalues+1, MAXUPVALUES, "upvalues"); | 227 | luaX_checklimit(ls, fs->f->nupvalues+1, MAXUPVALUES, l_s("upvalues")); |
| 228 | fs->upvalues[fs->f->nupvalues] = *v; | 228 | fs->upvalues[fs->f->nupvalues] = *v; |
| 229 | return fs->f->nupvalues++; | 229 | return fs->f->nupvalues++; |
| 230 | } | 230 | } |
| @@ -236,12 +236,12 @@ static void pushupvalue (LexState *ls, TString *n) { | |||
| 236 | int level = search_local(ls, n, &v); | 236 | int level = search_local(ls, n, &v); |
| 237 | if (level == -1) { /* global? */ | 237 | if (level == -1) { /* global? */ |
| 238 | if (fs->prev == NULL) | 238 | if (fs->prev == NULL) |
| 239 | luaX_syntaxerror(ls, "cannot access an upvalue at top level", getstr(n)); | 239 | luaX_syntaxerror(ls, l_s("cannot access an upvalue at top level"), getstr(n)); |
| 240 | v.u.index = string_constant(fs->prev, n); | 240 | v.u.index = string_constant(fs->prev, n); |
| 241 | } | 241 | } |
| 242 | else if (level != 1) { | 242 | else if (level != 1) { |
| 243 | luaX_syntaxerror(ls, | 243 | luaX_syntaxerror(ls, |
| 244 | "upvalue must be global or local to immediately outer function", getstr(n)); | 244 | l_s("upvalue must be global or local to immediately outer function"), getstr(n)); |
| 245 | } | 245 | } |
| 246 | luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, &v)); | 246 | luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, &v)); |
| 247 | } | 247 | } |
| @@ -267,11 +267,11 @@ static void adjust_mult_assign (LexState *ls, int nvars, int nexps) { | |||
| 267 | static void code_params (LexState *ls, int nparams, short dots) { | 267 | static void code_params (LexState *ls, int nparams, short dots) { |
| 268 | FuncState *fs = ls->fs; | 268 | FuncState *fs = ls->fs; |
| 269 | adjustlocalvars(ls, nparams); | 269 | adjustlocalvars(ls, nparams); |
| 270 | luaX_checklimit(ls, fs->nactloc, MAXPARAMS, "parameters"); | 270 | luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters")); |
| 271 | fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */ | 271 | fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */ |
| 272 | fs->f->is_vararg = dots; | 272 | fs->f->is_vararg = dots; |
| 273 | if (dots) { | 273 | if (dots) { |
| 274 | new_localvarstr(ls, "arg", 0); | 274 | new_localvarstr(ls, l_s("arg"), 0); |
| 275 | adjustlocalvars(ls, 1); | 275 | adjustlocalvars(ls, 1); |
| 276 | } | 276 | } |
| 277 | luaK_deltastack(fs, fs->nactloc); /* count parameters in the stack */ | 277 | luaK_deltastack(fs, fs->nactloc); /* count parameters in the stack */ |
| @@ -300,7 +300,7 @@ static void pushclosure (LexState *ls, FuncState *func) { | |||
| 300 | for (i=0; i<func->f->nupvalues; i++) | 300 | for (i=0; i<func->f->nupvalues; i++) |
| 301 | luaK_tostack(ls, &func->upvalues[i], 1); | 301 | luaK_tostack(ls, &func->upvalues[i], 1); |
| 302 | luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *, | 302 | luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *, |
| 303 | MAXARG_A, "constant table overflow"); | 303 | MAXARG_A, l_s("constant table overflow")); |
| 304 | f->kproto[fs->nkproto++] = func->f; | 304 | f->kproto[fs->nkproto++] = func->f; |
| 305 | luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->f->nupvalues); | 305 | luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->f->nupvalues); |
| 306 | } | 306 | } |
| @@ -366,7 +366,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z) { | |||
| 366 | open_func(&lexstate, &funcstate); | 366 | open_func(&lexstate, &funcstate); |
| 367 | next(&lexstate); /* read first token */ | 367 | next(&lexstate); /* read first token */ |
| 368 | chunk(&lexstate); | 368 | chunk(&lexstate); |
| 369 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); | 369 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), l_s("<eof> expected")); |
| 370 | close_func(&lexstate); | 370 | close_func(&lexstate); |
| 371 | lua_assert(funcstate.prev == NULL); | 371 | lua_assert(funcstate.prev == NULL); |
| 372 | lua_assert(funcstate.f->nupvalues == 0); | 372 | lua_assert(funcstate.f->nupvalues == 0); |
| @@ -385,7 +385,7 @@ static int explist1 (LexState *ls) { | |||
| 385 | int n = 1; /* at least one expression */ | 385 | int n = 1; /* at least one expression */ |
| 386 | expdesc v; | 386 | expdesc v; |
| 387 | expr(ls, &v); | 387 | expr(ls, &v); |
| 388 | while (ls->t.token == ',') { | 388 | while (ls->t.token == l_c(',')) { |
| 389 | next(ls); /* skip comma */ | 389 | next(ls); /* skip comma */ |
| 390 | luaK_tostack(ls, &v, 1); /* gets only 1 value from previous expression */ | 390 | luaK_tostack(ls, &v, 1); /* gets only 1 value from previous expression */ |
| 391 | expr(ls, &v); | 391 | expr(ls, &v); |
| @@ -400,13 +400,13 @@ static void funcargs (LexState *ls, int slf) { | |||
| 400 | FuncState *fs = ls->fs; | 400 | FuncState *fs = ls->fs; |
| 401 | int slevel = fs->stacklevel - slf - 1; /* where is func in the stack */ | 401 | int slevel = fs->stacklevel - slf - 1; /* where is func in the stack */ |
| 402 | switch (ls->t.token) { | 402 | switch (ls->t.token) { |
| 403 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ | 403 | case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */ |
| 404 | int line = ls->linenumber; | 404 | int line = ls->linenumber; |
| 405 | int nargs = 0; | 405 | int nargs = 0; |
| 406 | next(ls); | 406 | next(ls); |
| 407 | if (ls->t.token != ')') /* arg list not empty? */ | 407 | if (ls->t.token != l_c(')')) /* arg list not empty? */ |
| 408 | nargs = explist1(ls); | 408 | nargs = explist1(ls); |
| 409 | check_match(ls, ')', '(', line); | 409 | check_match(ls, l_c(')'), l_c('('), line); |
| 410 | #ifdef LUA_COMPAT_ARGRET | 410 | #ifdef LUA_COMPAT_ARGRET |
| 411 | if (nargs > 0) /* arg list is not empty? */ | 411 | if (nargs > 0) /* arg list is not empty? */ |
| 412 | luaK_setcallreturns(fs, 1); /* last call returns only 1 value */ | 412 | luaK_setcallreturns(fs, 1); /* last call returns only 1 value */ |
| @@ -415,7 +415,7 @@ static void funcargs (LexState *ls, int slf) { | |||
| 415 | #endif | 415 | #endif |
| 416 | break; | 416 | break; |
| 417 | } | 417 | } |
| 418 | case '{': { /* funcargs -> constructor */ | 418 | case l_c('{'): { /* funcargs -> constructor */ |
| 419 | constructor(ls); | 419 | constructor(ls); |
| 420 | break; | 420 | break; |
| 421 | } | 421 | } |
| @@ -425,7 +425,7 @@ static void funcargs (LexState *ls, int slf) { | |||
| 425 | break; | 425 | break; |
| 426 | } | 426 | } |
| 427 | default: { | 427 | default: { |
| 428 | luaK_error(ls, "function arguments expected"); | 428 | luaK_error(ls, l_s("function arguments expected")); |
| 429 | break; | 429 | break; |
| 430 | } | 430 | } |
| 431 | } | 431 | } |
| @@ -448,15 +448,15 @@ static void recfield (LexState *ls) { | |||
| 448 | luaK_kstr(ls, checkname(ls)); | 448 | luaK_kstr(ls, checkname(ls)); |
| 449 | break; | 449 | break; |
| 450 | } | 450 | } |
| 451 | case '[': { | 451 | case l_c('['): { |
| 452 | next(ls); | 452 | next(ls); |
| 453 | exp1(ls); | 453 | exp1(ls); |
| 454 | check(ls, ']'); | 454 | check(ls, l_c(']')); |
| 455 | break; | 455 | break; |
| 456 | } | 456 | } |
| 457 | default: luaK_error(ls, "<name> or `[' expected"); | 457 | default: luaK_error(ls, l_s("<name> or `[' expected")); |
| 458 | } | 458 | } |
| 459 | check(ls, '='); | 459 | check(ls, l_c('=')); |
| 460 | exp1(ls); | 460 | exp1(ls); |
| 461 | } | 461 | } |
| 462 | 462 | ||
| @@ -466,9 +466,9 @@ static int recfields (LexState *ls) { | |||
| 466 | FuncState *fs = ls->fs; | 466 | FuncState *fs = ls->fs; |
| 467 | int n = 1; /* at least one element */ | 467 | int n = 1; /* at least one element */ |
| 468 | recfield(ls); | 468 | recfield(ls); |
| 469 | while (ls->t.token == ',') { | 469 | while (ls->t.token == l_c(',')) { |
| 470 | next(ls); | 470 | next(ls); |
| 471 | if (ls->t.token == ';' || ls->t.token == '}') | 471 | if (ls->t.token == l_c(';') || ls->t.token == l_c('}')) |
| 472 | break; | 472 | break; |
| 473 | recfield(ls); | 473 | recfield(ls); |
| 474 | n++; | 474 | n++; |
| @@ -485,14 +485,14 @@ static int listfields (LexState *ls) { | |||
| 485 | FuncState *fs = ls->fs; | 485 | FuncState *fs = ls->fs; |
| 486 | int n = 1; /* at least one element */ | 486 | int n = 1; /* at least one element */ |
| 487 | exp1(ls); | 487 | exp1(ls); |
| 488 | while (ls->t.token == ',') { | 488 | while (ls->t.token == l_c(',')) { |
| 489 | next(ls); | 489 | next(ls); |
| 490 | if (ls->t.token == ';' || ls->t.token == '}') | 490 | if (ls->t.token == l_c(';') || ls->t.token == l_c('}')) |
| 491 | break; | 491 | break; |
| 492 | exp1(ls); | 492 | exp1(ls); |
| 493 | n++; | 493 | n++; |
| 494 | luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A, | 494 | luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A, |
| 495 | "`item groups' in a list initializer"); | 495 | l_s("`item groups' in a list initializer")); |
| 496 | if (n%LFIELDS_PER_FLUSH == 0) | 496 | if (n%LFIELDS_PER_FLUSH == 0) |
| 497 | luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); | 497 | luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); |
| 498 | } | 498 | } |
| @@ -504,18 +504,18 @@ static int listfields (LexState *ls) { | |||
| 504 | 504 | ||
| 505 | static void constructor_part (LexState *ls, Constdesc *cd) { | 505 | static void constructor_part (LexState *ls, Constdesc *cd) { |
| 506 | switch (ls->t.token) { | 506 | switch (ls->t.token) { |
| 507 | case ';': case '}': { /* constructor_part -> empty */ | 507 | case l_c(';'): case l_c('}'): { /* constructor_part -> empty */ |
| 508 | cd->n = 0; | 508 | cd->n = 0; |
| 509 | cd->k = ls->t.token; | 509 | cd->k = ls->t.token; |
| 510 | break; | 510 | break; |
| 511 | } | 511 | } |
| 512 | case TK_NAME: { /* may be listfields or recfields */ | 512 | case TK_NAME: { /* may be listfields or recfields */ |
| 513 | lookahead(ls); | 513 | lookahead(ls); |
| 514 | if (ls->lookahead.token != '=') /* expression? */ | 514 | if (ls->lookahead.token != l_c('=')) /* expression? */ |
| 515 | goto case_default; | 515 | goto case_default; |
| 516 | /* else go through to recfields */ | 516 | /* else go through to recfields */ |
| 517 | } | 517 | } |
| 518 | case '[': { /* constructor_part -> recfields */ | 518 | case l_c('['): { /* constructor_part -> recfields */ |
| 519 | cd->n = recfields(ls); | 519 | cd->n = recfields(ls); |
| 520 | cd->k = 1; /* record */ | 520 | cd->k = 1; /* record */ |
| 521 | break; | 521 | break; |
| @@ -537,17 +537,17 @@ static void constructor (LexState *ls) { | |||
| 537 | int pc = luaK_code1(fs, OP_CREATETABLE, 0); | 537 | int pc = luaK_code1(fs, OP_CREATETABLE, 0); |
| 538 | int nelems; | 538 | int nelems; |
| 539 | Constdesc cd; | 539 | Constdesc cd; |
| 540 | check(ls, '{'); | 540 | check(ls, l_c('{')); |
| 541 | constructor_part(ls, &cd); | 541 | constructor_part(ls, &cd); |
| 542 | nelems = cd.n; | 542 | nelems = cd.n; |
| 543 | if (optional(ls, ';')) { | 543 | if (optional(ls, l_c(';'))) { |
| 544 | Constdesc other_cd; | 544 | Constdesc other_cd; |
| 545 | constructor_part(ls, &other_cd); | 545 | constructor_part(ls, &other_cd); |
| 546 | check_condition(ls, (cd.k != other_cd.k), "invalid constructor syntax"); | 546 | check_condition(ls, (cd.k != other_cd.k), l_s("invalid constructor syntax")); |
| 547 | nelems += other_cd.n; | 547 | nelems += other_cd.n; |
| 548 | } | 548 | } |
| 549 | check_match(ls, '}', '{', line); | 549 | check_match(ls, l_c('}'), l_c('{'), line); |
| 550 | luaX_checklimit(ls, nelems, MAXARG_U, "elements in a table constructor"); | 550 | luaX_checklimit(ls, nelems, MAXARG_U, l_s("elements in a table constructor")); |
| 551 | SETARG_U(fs->f->code[pc], nelems); /* set initial table size */ | 551 | SETARG_U(fs->f->code[pc], nelems); /* set initial table size */ |
| 552 | } | 552 | } |
| 553 | 553 | ||
| @@ -581,7 +581,7 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
| 581 | next(ls); | 581 | next(ls); |
| 582 | break; | 582 | break; |
| 583 | } | 583 | } |
| 584 | case '{': { /* constructor */ | 584 | case l_c('{'): { /* constructor */ |
| 585 | constructor(ls); | 585 | constructor(ls); |
| 586 | break; | 586 | break; |
| 587 | } | 587 | } |
| @@ -590,23 +590,23 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
| 590 | body(ls, 0, ls->linenumber); | 590 | body(ls, 0, ls->linenumber); |
| 591 | break; | 591 | break; |
| 592 | } | 592 | } |
| 593 | case '(': { | 593 | case l_c('('): { |
| 594 | next(ls); | 594 | next(ls); |
| 595 | expr(ls, v); | 595 | expr(ls, v); |
| 596 | check(ls, ')'); | 596 | check(ls, l_c(')')); |
| 597 | return; | 597 | return; |
| 598 | } | 598 | } |
| 599 | case TK_NAME: { | 599 | case TK_NAME: { |
| 600 | singlevar(ls, str_checkname(ls), v); | 600 | singlevar(ls, str_checkname(ls), v); |
| 601 | return; | 601 | return; |
| 602 | } | 602 | } |
| 603 | case '%': { | 603 | case l_c('%'): { |
| 604 | next(ls); /* skip `%' */ | 604 | next(ls); /* skip `%' */ |
| 605 | pushupvalue(ls, str_checkname(ls)); | 605 | pushupvalue(ls, str_checkname(ls)); |
| 606 | break; | 606 | break; |
| 607 | } | 607 | } |
| 608 | default: { | 608 | default: { |
| 609 | luaK_error(ls, "unexpected symbol"); | 609 | luaK_error(ls, l_s("unexpected symbol")); |
| 610 | return; | 610 | return; |
| 611 | } | 611 | } |
| 612 | } | 612 | } |
| @@ -621,22 +621,22 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
| 621 | primaryexp(ls, v); | 621 | primaryexp(ls, v); |
| 622 | for (;;) { | 622 | for (;;) { |
| 623 | switch (ls->t.token) { | 623 | switch (ls->t.token) { |
| 624 | case '.': { /* `.' NAME */ | 624 | case l_c('.'): { /* `.' NAME */ |
| 625 | next(ls); | 625 | next(ls); |
| 626 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ | 626 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ |
| 627 | luaK_kstr(ls, checkname(ls)); | 627 | luaK_kstr(ls, checkname(ls)); |
| 628 | v->k = VINDEXED; | 628 | v->k = VINDEXED; |
| 629 | break; | 629 | break; |
| 630 | } | 630 | } |
| 631 | case '[': { /* `[' exp1 `]' */ | 631 | case l_c('['): { /* `[' exp1 `]' */ |
| 632 | next(ls); | 632 | next(ls); |
| 633 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ | 633 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ |
| 634 | v->k = VINDEXED; | 634 | v->k = VINDEXED; |
| 635 | exp1(ls); | 635 | exp1(ls); |
| 636 | check(ls, ']'); | 636 | check(ls, l_c(']')); |
| 637 | break; | 637 | break; |
| 638 | } | 638 | } |
| 639 | case ':': { /* `:' NAME funcargs */ | 639 | case l_c(':'): { /* `:' NAME funcargs */ |
| 640 | next(ls); | 640 | next(ls); |
| 641 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ | 641 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ |
| 642 | luaK_code1(ls->fs, OP_PUSHSELF, checkname(ls)); | 642 | luaK_code1(ls->fs, OP_PUSHSELF, checkname(ls)); |
| @@ -645,7 +645,7 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
| 645 | v->u.l.t = v->u.l.f = NO_JUMP; | 645 | v->u.l.t = v->u.l.f = NO_JUMP; |
| 646 | break; | 646 | break; |
| 647 | } | 647 | } |
| 648 | case '(': case TK_STRING: case '{': { /* funcargs */ | 648 | case l_c('('): case TK_STRING: case l_c('{'): { /* funcargs */ |
| 649 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ | 649 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ |
| 650 | funcargs(ls, 0); | 650 | funcargs(ls, 0); |
| 651 | v->k = VEXP; | 651 | v->k = VEXP; |
| @@ -661,7 +661,7 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
| 661 | static UnOpr getunopr (int op) { | 661 | static UnOpr getunopr (int op) { |
| 662 | switch (op) { | 662 | switch (op) { |
| 663 | case TK_NOT: return OPR_NOT; | 663 | case TK_NOT: return OPR_NOT; |
| 664 | case '-': return OPR_MINUS; | 664 | case l_c('-'): return OPR_MINUS; |
| 665 | default: return OPR_NOUNOPR; | 665 | default: return OPR_NOUNOPR; |
| 666 | } | 666 | } |
| 667 | } | 667 | } |
| @@ -669,17 +669,17 @@ static UnOpr getunopr (int op) { | |||
| 669 | 669 | ||
| 670 | static BinOpr getbinopr (int op) { | 670 | static BinOpr getbinopr (int op) { |
| 671 | switch (op) { | 671 | switch (op) { |
| 672 | case '+': return OPR_ADD; | 672 | case l_c('+'): return OPR_ADD; |
| 673 | case '-': return OPR_SUB; | 673 | case l_c('-'): return OPR_SUB; |
| 674 | case '*': return OPR_MULT; | 674 | case l_c('*'): return OPR_MULT; |
| 675 | case '/': return OPR_DIV; | 675 | case l_c('/'): return OPR_DIV; |
| 676 | case '^': return OPR_POW; | 676 | case l_c('^'): return OPR_POW; |
| 677 | case TK_CONCAT: return OPR_CONCAT; | 677 | case TK_CONCAT: return OPR_CONCAT; |
| 678 | case TK_NE: return OPR_NE; | 678 | case TK_NE: return OPR_NE; |
| 679 | case TK_EQ: return OPR_EQ; | 679 | case TK_EQ: return OPR_EQ; |
| 680 | case '<': return OPR_LT; | 680 | case l_c('<'): return OPR_LT; |
| 681 | case TK_LE: return OPR_LE; | 681 | case TK_LE: return OPR_LE; |
| 682 | case '>': return OPR_GT; | 682 | case l_c('>'): return OPR_GT; |
| 683 | case TK_GE: return OPR_GE; | 683 | case TK_GE: return OPR_GE; |
| 684 | case TK_AND: return OPR_AND; | 684 | case TK_AND: return OPR_AND; |
| 685 | case TK_OR: return OPR_OR; | 685 | case TK_OR: return OPR_OR; |
| @@ -774,17 +774,17 @@ static void block (LexState *ls) { | |||
| 774 | 774 | ||
| 775 | static int assignment (LexState *ls, expdesc *v, int nvars) { | 775 | static int assignment (LexState *ls, expdesc *v, int nvars) { |
| 776 | int left = 0; /* number of values left in the stack after assignment */ | 776 | int left = 0; /* number of values left in the stack after assignment */ |
| 777 | luaX_checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment"); | 777 | luaX_checklimit(ls, nvars, MAXVARSLH, l_s("variables in a multiple assignment")); |
| 778 | if (ls->t.token == ',') { /* assignment -> `,' simpleexp assignment */ | 778 | if (ls->t.token == l_c(',')) { /* assignment -> `,' simpleexp assignment */ |
| 779 | expdesc nv; | 779 | expdesc nv; |
| 780 | next(ls); | 780 | next(ls); |
| 781 | simpleexp(ls, &nv); | 781 | simpleexp(ls, &nv); |
| 782 | check_condition(ls, (nv.k != VEXP), "syntax error"); | 782 | check_condition(ls, (nv.k != VEXP), l_s("syntax error")); |
| 783 | left = assignment(ls, &nv, nvars+1); | 783 | left = assignment(ls, &nv, nvars+1); |
| 784 | } | 784 | } |
| 785 | else { /* assignment -> `=' explist1 */ | 785 | else { /* assignment -> `=' explist1 */ |
| 786 | int nexps; | 786 | int nexps; |
| 787 | check(ls, '='); | 787 | check(ls, l_c('=')); |
| 788 | nexps = explist1(ls); | 788 | nexps = explist1(ls); |
| 789 | adjust_mult_assign(ls, nvars, nexps); | 789 | adjust_mult_assign(ls, nvars, nexps); |
| 790 | } | 790 | } |
| @@ -856,17 +856,17 @@ static void forbody (LexState *ls, int nvar, OpCode prepfor, OpCode loopfor) { | |||
| 856 | static void fornum (LexState *ls, TString *varname) { | 856 | static void fornum (LexState *ls, TString *varname) { |
| 857 | /* fornum -> NAME = exp1,exp1[,exp1] forbody */ | 857 | /* fornum -> NAME = exp1,exp1[,exp1] forbody */ |
| 858 | FuncState *fs = ls->fs; | 858 | FuncState *fs = ls->fs; |
| 859 | check(ls, '='); | 859 | check(ls, l_c('=')); |
| 860 | exp1(ls); /* initial value */ | 860 | exp1(ls); /* initial value */ |
| 861 | check(ls, ','); | 861 | check(ls, l_c(',')); |
| 862 | exp1(ls); /* limit */ | 862 | exp1(ls); /* limit */ |
| 863 | if (optional(ls, ',')) | 863 | if (optional(ls, l_c(','))) |
| 864 | exp1(ls); /* optional step */ | 864 | exp1(ls); /* optional step */ |
| 865 | else | 865 | else |
| 866 | luaK_code1(fs, OP_PUSHINT, 1); /* default step */ | 866 | luaK_code1(fs, OP_PUSHINT, 1); /* default step */ |
| 867 | new_localvar(ls, varname, 0); | 867 | new_localvar(ls, varname, 0); |
| 868 | new_localvarstr(ls, "(limit)", 1); | 868 | new_localvarstr(ls, l_s("(limit)"), 1); |
| 869 | new_localvarstr(ls, "(step)", 2); | 869 | new_localvarstr(ls, l_s("(step)"), 2); |
| 870 | forbody(ls, 3, OP_FORPREP, OP_FORLOOP); | 870 | forbody(ls, 3, OP_FORPREP, OP_FORLOOP); |
| 871 | } | 871 | } |
| 872 | 872 | ||
| @@ -874,17 +874,17 @@ static void fornum (LexState *ls, TString *varname) { | |||
| 874 | static void forlist (LexState *ls, TString *indexname) { | 874 | static void forlist (LexState *ls, TString *indexname) { |
| 875 | /* forlist -> NAME,NAME IN exp1 forbody */ | 875 | /* forlist -> NAME,NAME IN exp1 forbody */ |
| 876 | TString *valname; | 876 | TString *valname; |
| 877 | check(ls, ','); | 877 | check(ls, l_c(',')); |
| 878 | valname = str_checkname(ls); | 878 | valname = str_checkname(ls); |
| 879 | /* next test is dirty, but avoids `in' being a reserved word */ | 879 | /* next test is dirty, but avoids `in' being a reserved word */ |
| 880 | check_condition(ls, | 880 | check_condition(ls, |
| 881 | (ls->t.token == TK_NAME && | 881 | (ls->t.token == TK_NAME && |
| 882 | ls->t.seminfo.ts == luaS_newliteral(ls->L, "in")), | 882 | ls->t.seminfo.ts == luaS_newliteral(ls->L, l_s("in"))), |
| 883 | "`in' expected"); | 883 | l_s("`in' expected")); |
| 884 | next(ls); /* skip `in' */ | 884 | next(ls); /* skip `in' */ |
| 885 | exp1(ls); /* table */ | 885 | exp1(ls); /* table */ |
| 886 | new_localvarstr(ls, "(table)", 0); | 886 | new_localvarstr(ls, l_s("(table)"), 0); |
| 887 | new_localvarstr(ls, "(index)", 1); | 887 | new_localvarstr(ls, l_s("(index)"), 1); |
| 888 | new_localvar(ls, indexname, 2); | 888 | new_localvar(ls, indexname, 2); |
| 889 | new_localvar(ls, valname, 3); | 889 | new_localvar(ls, valname, 3); |
| 890 | forbody(ls, 4, OP_LFORPREP, OP_LFORLOOP); | 890 | forbody(ls, 4, OP_LFORPREP, OP_LFORLOOP); |
| @@ -900,9 +900,9 @@ static void forstat (LexState *ls, int line) { | |||
| 900 | next(ls); /* skip `for' */ | 900 | next(ls); /* skip `for' */ |
| 901 | varname = str_checkname(ls); /* first variable name */ | 901 | varname = str_checkname(ls); /* first variable name */ |
| 902 | switch (ls->t.token) { | 902 | switch (ls->t.token) { |
| 903 | case '=': fornum(ls, varname); break; | 903 | case l_c('='): fornum(ls, varname); break; |
| 904 | case ',': forlist(ls, varname); break; | 904 | case l_c(','): forlist(ls, varname); break; |
| 905 | default: luaK_error(ls, "`=' or `,' expected"); | 905 | default: luaK_error(ls, l_s("`=' or `,' expected")); |
| 906 | } | 906 | } |
| 907 | check_match(ls, TK_END, TK_FOR, line); | 907 | check_match(ls, TK_END, TK_FOR, line); |
| 908 | leavebreak(fs, &bl); | 908 | leavebreak(fs, &bl); |
| @@ -949,8 +949,8 @@ static void localstat (LexState *ls) { | |||
| 949 | do { | 949 | do { |
| 950 | next(ls); /* skip LOCAL or `,' */ | 950 | next(ls); /* skip LOCAL or `,' */ |
| 951 | new_localvar(ls, str_checkname(ls), nvars++); | 951 | new_localvar(ls, str_checkname(ls), nvars++); |
| 952 | } while (ls->t.token == ','); | 952 | } while (ls->t.token == l_c(',')); |
| 953 | if (optional(ls, '=')) | 953 | if (optional(ls, l_c('='))) |
| 954 | nexps = explist1(ls); | 954 | nexps = explist1(ls); |
| 955 | else | 955 | else |
| 956 | nexps = 0; | 956 | nexps = 0; |
| @@ -963,13 +963,13 @@ static int funcname (LexState *ls, expdesc *v) { | |||
| 963 | /* funcname -> NAME {`.' NAME} [`:' NAME] */ | 963 | /* funcname -> NAME {`.' NAME} [`:' NAME] */ |
| 964 | int needself = 0; | 964 | int needself = 0; |
| 965 | singlevar(ls, str_checkname(ls), v); | 965 | singlevar(ls, str_checkname(ls), v); |
| 966 | while (ls->t.token == '.') { | 966 | while (ls->t.token == l_c('.')) { |
| 967 | next(ls); | 967 | next(ls); |
| 968 | luaK_tostack(ls, v, 1); | 968 | luaK_tostack(ls, v, 1); |
| 969 | luaK_kstr(ls, checkname(ls)); | 969 | luaK_kstr(ls, checkname(ls)); |
| 970 | v->k = VINDEXED; | 970 | v->k = VINDEXED; |
| 971 | } | 971 | } |
| 972 | if (ls->t.token == ':') { | 972 | if (ls->t.token == l_c(':')) { |
| 973 | needself = 1; | 973 | needself = 1; |
| 974 | next(ls); | 974 | next(ls); |
| 975 | luaK_tostack(ls, v, 1); | 975 | luaK_tostack(ls, v, 1); |
| @@ -997,7 +997,7 @@ static void namestat (LexState *ls) { | |||
| 997 | expdesc v; | 997 | expdesc v; |
| 998 | simpleexp(ls, &v); | 998 | simpleexp(ls, &v); |
| 999 | if (v.k == VEXP) { /* stat -> func */ | 999 | if (v.k == VEXP) { /* stat -> func */ |
| 1000 | check_condition(ls, luaK_lastisopen(fs), "syntax error"); /* an upvalue? */ | 1000 | check_condition(ls, luaK_lastisopen(fs), l_s("syntax error")); /* an upvalue? */ |
| 1001 | luaK_setcallreturns(fs, 0); /* call statement uses no results */ | 1001 | luaK_setcallreturns(fs, 0); /* call statement uses no results */ |
| 1002 | } | 1002 | } |
| 1003 | else { /* stat -> assignment */ | 1003 | else { /* stat -> assignment */ |
| @@ -1011,7 +1011,7 @@ static void retstat (LexState *ls) { | |||
| 1011 | /* stat -> RETURN explist */ | 1011 | /* stat -> RETURN explist */ |
| 1012 | FuncState *fs = ls->fs; | 1012 | FuncState *fs = ls->fs; |
| 1013 | next(ls); /* skip RETURN */ | 1013 | next(ls); /* skip RETURN */ |
| 1014 | if (!block_follow(ls->t.token) && ls->t.token != ';') | 1014 | if (!block_follow(ls->t.token) && ls->t.token != l_c(';')) |
| 1015 | explist1(ls); /* optional return values */ | 1015 | explist1(ls); /* optional return values */ |
| 1016 | luaK_code1(fs, OP_RETURN, ls->fs->nactloc); | 1016 | luaK_code1(fs, OP_RETURN, ls->fs->nactloc); |
| 1017 | fs->stacklevel = fs->nactloc; /* removes all temp values */ | 1017 | fs->stacklevel = fs->nactloc; /* removes all temp values */ |
| @@ -1024,7 +1024,7 @@ static void breakstat (LexState *ls) { | |||
| 1024 | int currentlevel = fs->stacklevel; | 1024 | int currentlevel = fs->stacklevel; |
| 1025 | Breaklabel *bl = fs->bl; | 1025 | Breaklabel *bl = fs->bl; |
| 1026 | if (!bl) | 1026 | if (!bl) |
| 1027 | luaK_error(ls, "no loop to break"); | 1027 | luaK_error(ls, l_s("no loop to break")); |
| 1028 | next(ls); /* skip BREAK */ | 1028 | next(ls); /* skip BREAK */ |
| 1029 | luaK_adjuststack(fs, currentlevel - bl->stacklevel); | 1029 | luaK_adjuststack(fs, currentlevel - bl->stacklevel); |
| 1030 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); | 1030 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); |
| @@ -1086,14 +1086,14 @@ static void parlist (LexState *ls) { | |||
| 1086 | /* parlist -> [ param { `,' param } ] */ | 1086 | /* parlist -> [ param { `,' param } ] */ |
| 1087 | int nparams = 0; | 1087 | int nparams = 0; |
| 1088 | short dots = 0; | 1088 | short dots = 0; |
| 1089 | if (ls->t.token != ')') { /* is `parlist' not empty? */ | 1089 | if (ls->t.token != l_c(')')) { /* is `parlist' not empty? */ |
| 1090 | do { | 1090 | do { |
| 1091 | switch (ls->t.token) { | 1091 | switch (ls->t.token) { |
| 1092 | case TK_DOTS: next(ls); dots = 1; break; | 1092 | case TK_DOTS: next(ls); dots = 1; break; |
| 1093 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; | 1093 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; |
| 1094 | default: luaK_error(ls, "<name> or `...' expected"); | 1094 | default: luaK_error(ls, l_s("<name> or `...' expected")); |
| 1095 | } | 1095 | } |
| 1096 | } while (!dots && optional(ls, ',')); | 1096 | } while (!dots && optional(ls, l_c(','))); |
| 1097 | } | 1097 | } |
| 1098 | code_params(ls, nparams, dots); | 1098 | code_params(ls, nparams, dots); |
| 1099 | } | 1099 | } |
| @@ -1104,13 +1104,13 @@ static void body (LexState *ls, int needself, int line) { | |||
| 1104 | FuncState new_fs; | 1104 | FuncState new_fs; |
| 1105 | open_func(ls, &new_fs); | 1105 | open_func(ls, &new_fs); |
| 1106 | new_fs.f->lineDefined = line; | 1106 | new_fs.f->lineDefined = line; |
| 1107 | check(ls, '('); | 1107 | check(ls, l_c('(')); |
| 1108 | if (needself) { | 1108 | if (needself) { |
| 1109 | new_localvarstr(ls, "self", 0); | 1109 | new_localvarstr(ls, l_s("self"), 0); |
| 1110 | adjustlocalvars(ls, 1); | 1110 | adjustlocalvars(ls, 1); |
| 1111 | } | 1111 | } |
| 1112 | parlist(ls); | 1112 | parlist(ls); |
| 1113 | check(ls, ')'); | 1113 | check(ls, l_c(')')); |
| 1114 | chunk(ls); | 1114 | chunk(ls); |
| 1115 | check_match(ls, TK_END, TK_FUNCTION, line); | 1115 | check_match(ls, TK_END, TK_FUNCTION, line); |
| 1116 | close_func(ls); | 1116 | close_func(ls); |
| @@ -1126,7 +1126,7 @@ static void chunk (LexState *ls) { | |||
| 1126 | int islast = 0; | 1126 | int islast = 0; |
| 1127 | while (!islast && !block_follow(ls->t.token)) { | 1127 | while (!islast && !block_follow(ls->t.token)) { |
| 1128 | islast = statement(ls); | 1128 | islast = statement(ls); |
| 1129 | optional(ls, ';'); | 1129 | optional(ls, l_c(';')); |
| 1130 | lua_assert(ls->fs->stacklevel == ls->fs->nactloc); | 1130 | lua_assert(ls->fs->stacklevel == ls->fs->nactloc); |
| 1131 | } | 1131 | } |
| 1132 | } | 1132 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 1.55 2001/01/26 11:45:51 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.56 2001/02/02 15:13:05 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -131,7 +131,7 @@ static void close_state (lua_State *L, lua_State *OL) { | |||
| 131 | luaS_freeall(L); | 131 | luaS_freeall(L); |
| 132 | luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM); | 132 | luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM); |
| 133 | luaM_freearray(L, G(L)->refArray, G(L)->sizeref, struct Ref); | 133 | luaM_freearray(L, G(L)->refArray, G(L)->sizeref, struct Ref); |
| 134 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); | 134 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, l_char); |
| 135 | luaM_freelem(NULL, L->G, global_State); | 135 | luaM_freelem(NULL, L->G, global_State); |
| 136 | } | 136 | } |
| 137 | luaM_freearray(OL, L->stack, L->stacksize, TObject); | 137 | luaM_freearray(OL, L->stack, L->stacksize, TObject); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 1.50 2001/02/02 15:13:05 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.51 2001/02/20 18:15:33 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -61,10 +61,10 @@ typedef struct stringtable { | |||
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | /* | 63 | /* |
| 64 | ** "global state", shared by all threads of this state | 64 | ** `global state', shared by all threads of this state |
| 65 | */ | 65 | */ |
| 66 | typedef struct global_State { | 66 | typedef struct global_State { |
| 67 | char *Mbuffer; /* global buffer */ | 67 | l_char *Mbuffer; /* global buffer */ |
| 68 | size_t Mbuffsize; /* size of Mbuffer */ | 68 | size_t Mbuffsize; /* size of Mbuffer */ |
| 69 | Proto *rootproto; /* list of all prototypes */ | 69 | Proto *rootproto; /* list of all prototypes */ |
| 70 | Closure *rootcl; /* list of all closures */ | 70 | Closure *rootcl; /* list of all closures */ |
| @@ -85,7 +85,7 @@ typedef struct global_State { | |||
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | /* | 87 | /* |
| 88 | ** "per thread" state | 88 | ** `per thread' state |
| 89 | */ | 89 | */ |
| 90 | struct lua_State { | 90 | struct lua_State { |
| 91 | LUA_USERSTATE | 91 | LUA_USERSTATE |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.59 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.60 2001/02/22 17:15:18 roberto Exp roberto $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -63,7 +63,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 66 | TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) { |
| 67 | TString *ts; | 67 | TString *ts; |
| 68 | lu_hash h = l; /* seed */ | 68 | lu_hash h = l; /* seed */ |
| 69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
| @@ -81,7 +81,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 81 | ts->len = l; | 81 | ts->len = l; |
| 82 | ts->u.s.hash = h; | 82 | ts->u.s.hash = h; |
| 83 | ts->u.s.constindex = 0; | 83 | ts->u.s.constindex = 0; |
| 84 | memcpy(getstr(ts), str, l*sizeof(char)); | 84 | memcpy(getstr(ts), str, l*sizeof(l_char)); |
| 85 | getstr(ts)[l] = 0; /* ending 0 */ | 85 | getstr(ts)[l] = 0; /* ending 0 */ |
| 86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ | 86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ |
| 87 | return ts; | 87 | return ts; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.h,v 1.29 2001/02/09 20:22:29 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.30 2001/02/20 18:15:33 roberto Exp roberto $ |
| 3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -22,20 +22,20 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | #define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \ | 24 | #define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \ |
| 25 | ((lu_mem)(l)+1)*sizeof(char)) | 25 | ((lu_mem)(l)+1)*sizeof(l_char)) |
| 26 | 26 | ||
| 27 | #define sizeudata(l) ((lu_mem)sizeof(union L_UTString)+(l)) | 27 | #define sizeudata(l) ((lu_mem)sizeof(union L_UTString)+(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, "" s, \ | 30 | #define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \ |
| 31 | (sizeof(s)/sizeof(char))-1)) | 31 | (sizeof(s)/sizeof(l_char))-1)) |
| 32 | 32 | ||
| 33 | void luaS_init (lua_State *L); | 33 | void luaS_init (lua_State *L); |
| 34 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); | 34 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); |
| 35 | TString *luaS_newudata (lua_State *L, size_t s, void *udata); | 35 | TString *luaS_newudata (lua_State *L, size_t s, void *udata); |
| 36 | int luaS_createudata (lua_State *L, void *udata, TObject *o); | 36 | int luaS_createudata (lua_State *L, void *udata, TObject *o); |
| 37 | void luaS_freeall (lua_State *L); | 37 | void luaS_freeall (lua_State *L); |
| 38 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | 38 | TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l); |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | #endif | 41 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.63 2001/02/22 17:15:18 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.64 2001/02/22 18:59:59 roberto Exp roberto $ |
| 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 | */ |
| @@ -36,14 +36,14 @@ static sint32 posrelat (sint32 pos, size_t len) { | |||
| 36 | 36 | ||
| 37 | static int str_sub (lua_State *L) { | 37 | static int str_sub (lua_State *L) { |
| 38 | size_t l; | 38 | size_t l; |
| 39 | const char *s = luaL_check_lstr(L, 1, &l); | 39 | const l_char *s = luaL_check_lstr(L, 1, &l); |
| 40 | sint32 start = posrelat(luaL_check_long(L, 2), l); | 40 | sint32 start = posrelat(luaL_check_long(L, 2), l); |
| 41 | sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); | 41 | sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); |
| 42 | if (start < 1) start = 1; | 42 | if (start < 1) start = 1; |
| 43 | if (end > (sint32)l) end = l; | 43 | if (end > (sint32)l) end = l; |
| 44 | if (start <= end) | 44 | if (start <= end) |
| 45 | lua_pushlstring(L, s+start-1, end-start+1); | 45 | lua_pushlstring(L, s+start-1, end-start+1); |
| 46 | else lua_pushliteral(L, ""); | 46 | else lua_pushliteral(L, l_s("")); |
| 47 | return 1; | 47 | return 1; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| @@ -52,7 +52,7 @@ static int str_lower (lua_State *L) { | |||
| 52 | size_t l; | 52 | size_t l; |
| 53 | size_t i; | 53 | size_t i; |
| 54 | luaL_Buffer b; | 54 | luaL_Buffer b; |
| 55 | const char *s = luaL_check_lstr(L, 1, &l); | 55 | const l_char *s = luaL_check_lstr(L, 1, &l); |
| 56 | luaL_buffinit(L, &b); | 56 | luaL_buffinit(L, &b); |
| 57 | for (i=0; i<l; i++) | 57 | for (i=0; i<l; i++) |
| 58 | luaL_putchar(&b, tolower(uchar(s[i]))); | 58 | luaL_putchar(&b, tolower(uchar(s[i]))); |
| @@ -65,7 +65,7 @@ static int str_upper (lua_State *L) { | |||
| 65 | size_t l; | 65 | size_t l; |
| 66 | size_t i; | 66 | size_t i; |
| 67 | luaL_Buffer b; | 67 | luaL_Buffer b; |
| 68 | const char *s = luaL_check_lstr(L, 1, &l); | 68 | const l_char *s = luaL_check_lstr(L, 1, &l); |
| 69 | luaL_buffinit(L, &b); | 69 | luaL_buffinit(L, &b); |
| 70 | for (i=0; i<l; i++) | 70 | for (i=0; i<l; i++) |
| 71 | luaL_putchar(&b, toupper(uchar(s[i]))); | 71 | luaL_putchar(&b, toupper(uchar(s[i]))); |
| @@ -76,7 +76,7 @@ static int str_upper (lua_State *L) { | |||
| 76 | static int str_rep (lua_State *L) { | 76 | static int str_rep (lua_State *L) { |
| 77 | size_t l; | 77 | size_t l; |
| 78 | luaL_Buffer b; | 78 | luaL_Buffer b; |
| 79 | const char *s = luaL_check_lstr(L, 1, &l); | 79 | const l_char *s = luaL_check_lstr(L, 1, &l); |
| 80 | int n = luaL_check_int(L, 2); | 80 | int n = luaL_check_int(L, 2); |
| 81 | luaL_buffinit(L, &b); | 81 | luaL_buffinit(L, &b); |
| 82 | while (n-- > 0) | 82 | while (n-- > 0) |
| @@ -88,9 +88,9 @@ static int str_rep (lua_State *L) { | |||
| 88 | 88 | ||
| 89 | static int str_byte (lua_State *L) { | 89 | static int str_byte (lua_State *L) { |
| 90 | size_t l; | 90 | size_t l; |
| 91 | const char *s = luaL_check_lstr(L, 1, &l); | 91 | const l_char *s = luaL_check_lstr(L, 1, &l); |
| 92 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); | 92 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); |
| 93 | luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range"); | 93 | luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, l_s("out of range")); |
| 94 | lua_pushnumber(L, uchar(s[pos-1])); | 94 | lua_pushnumber(L, uchar(s[pos-1])); |
| 95 | return 1; | 95 | return 1; |
| 96 | } | 96 | } |
| @@ -103,7 +103,7 @@ static int str_char (lua_State *L) { | |||
| 103 | luaL_buffinit(L, &b); | 103 | luaL_buffinit(L, &b); |
| 104 | for (i=1; i<=n; i++) { | 104 | for (i=1; i<=n; i++) { |
| 105 | int c = luaL_check_int(L, i); | 105 | int c = luaL_check_int(L, i); |
| 106 | luaL_arg_check(L, uchar(c) == c, i, "invalid value"); | 106 | luaL_arg_check(L, uchar(c) == c, i, l_s("invalid value")); |
| 107 | luaL_putchar(&b, uchar(c)); | 107 | luaL_putchar(&b, uchar(c)); |
| 108 | } | 108 | } |
| 109 | luaL_pushresult(&b); | 109 | luaL_pushresult(&b); |
| @@ -127,25 +127,25 @@ static int str_char (lua_State *L) { | |||
| 127 | #define CAP_POSITION (-2) | 127 | #define CAP_POSITION (-2) |
| 128 | 128 | ||
| 129 | typedef struct MatchState { | 129 | typedef struct MatchState { |
| 130 | const char *src_init; /* init of source string */ | 130 | const l_char *src_init; /* init of source string */ |
| 131 | const char *src_end; /* end (`\0') of source string */ | 131 | const l_char *src_end; /* end (`\0') of source string */ |
| 132 | int level; /* total number of captures (finished or unfinished) */ | 132 | int level; /* total number of captures (finished or unfinished) */ |
| 133 | struct { | 133 | struct { |
| 134 | const char *init; | 134 | const l_char *init; |
| 135 | sint32 len; | 135 | sint32 len; |
| 136 | } capture[MAX_CAPTURES]; | 136 | } capture[MAX_CAPTURES]; |
| 137 | lua_State *L; | 137 | lua_State *L; |
| 138 | } MatchState; | 138 | } MatchState; |
| 139 | 139 | ||
| 140 | 140 | ||
| 141 | #define ESC '%' | 141 | #define ESC l_c('%') |
| 142 | #define SPECIALS "^$*+?.([%-" | 142 | #define SPECIALS l_s("^$*+?.([%-") |
| 143 | 143 | ||
| 144 | 144 | ||
| 145 | static int check_capture (MatchState *ms, int l) { | 145 | static int check_capture (MatchState *ms, int l) { |
| 146 | l -= '1'; | 146 | l -= l_c('1'); |
| 147 | if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) | 147 | if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) |
| 148 | lua_error(ms->L, "invalid capture index"); | 148 | lua_error(ms->L, l_s("invalid capture index")); |
| 149 | return l; | 149 | return l; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| @@ -154,22 +154,22 @@ static int capture_to_close (MatchState *ms) { | |||
| 154 | int level = ms->level; | 154 | int level = ms->level; |
| 155 | for (level--; level>=0; level--) | 155 | for (level--; level>=0; level--) |
| 156 | if (ms->capture[level].len == CAP_UNFINISHED) return level; | 156 | if (ms->capture[level].len == CAP_UNFINISHED) return level; |
| 157 | lua_error(ms->L, "invalid pattern capture"); | 157 | lua_error(ms->L, l_s("invalid pattern capture")); |
| 158 | return 0; /* to avoid warnings */ | 158 | return 0; /* to avoid warnings */ |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | 161 | ||
| 162 | static const char *luaI_classend (MatchState *ms, const char *p) { | 162 | static const l_char *luaI_classend (MatchState *ms, const l_char *p) { |
| 163 | switch (*p++) { | 163 | switch (*p++) { |
| 164 | case ESC: | 164 | case ESC: |
| 165 | if (*p == '\0') lua_error(ms->L, "malformed pattern (ends with `%')"); | 165 | if (*p == l_c('\0')) lua_error(ms->L, l_s("malformed pattern (ends with `%')")); |
| 166 | return p+1; | 166 | return p+1; |
| 167 | case '[': | 167 | case l_c('['): |
| 168 | if (*p == '^') p++; | 168 | if (*p == l_c('^')) p++; |
| 169 | do { /* look for a `]' */ | 169 | do { /* look for a `]' */ |
| 170 | if (*p == '\0') lua_error(ms->L, "malformed pattern (missing `]')"); | 170 | if (*p == l_c('\0')) lua_error(ms->L, l_s("malformed pattern (missing `]')")); |
| 171 | if (*(p++) == ESC && *p != '\0') p++; /* skip escapes (e.g. `%]') */ | 171 | if (*(p++) == ESC && *p != l_c('\0')) p++; /* skip escapes (e.g. `%]') */ |
| 172 | } while (*p != ']'); | 172 | } while (*p != l_c(']')); |
| 173 | return p+1; | 173 | return p+1; |
| 174 | default: | 174 | default: |
| 175 | return p; | 175 | return p; |
| @@ -177,28 +177,28 @@ static const char *luaI_classend (MatchState *ms, const char *p) { | |||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | 179 | ||
| 180 | static int match_class (char c, char cl) { | 180 | static int match_class (l_char c, l_char cl) { |
| 181 | int res; | 181 | int res; |
| 182 | switch (tolower(uchar(cl))) { | 182 | switch (tolower(uchar(cl))) { |
| 183 | case 'a' : res = isalpha(uchar(c)); break; | 183 | case l_c('a') : res = isalpha(uchar(c)); break; |
| 184 | case 'c' : res = iscntrl(uchar(c)); break; | 184 | case l_c('c') : res = iscntrl(uchar(c)); break; |
| 185 | case 'd' : res = isdigit(uchar(c)); break; | 185 | case l_c('d') : res = isdigit(uchar(c)); break; |
| 186 | case 'l' : res = islower(uchar(c)); break; | 186 | case l_c('l') : res = islower(uchar(c)); break; |
| 187 | case 'p' : res = ispunct(uchar(c)); break; | 187 | case l_c('p') : res = ispunct(uchar(c)); break; |
| 188 | case 's' : res = isspace(uchar(c)); break; | 188 | case l_c('s') : res = isspace(uchar(c)); break; |
| 189 | case 'u' : res = isupper(uchar(c)); break; | 189 | case l_c('u') : res = isupper(uchar(c)); break; |
| 190 | case 'w' : res = isalnum(uchar(c)); break; | 190 | case l_c('w') : res = isalnum(uchar(c)); break; |
| 191 | case 'x' : res = isxdigit(uchar(c)); break; | 191 | case l_c('x') : res = isxdigit(uchar(c)); break; |
| 192 | case 'z' : res = (c == '\0'); break; | 192 | case l_c('z') : res = (c == l_c('\0')); break; |
| 193 | default: return (cl == c); | 193 | default: return (cl == c); |
| 194 | } | 194 | } |
| 195 | return (islower(uchar(cl)) ? res : !res); | 195 | return (islower(uchar(cl)) ? res : !res); |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | 198 | ||
| 199 | static int matchbracketclass (char c, const char *p, const char *endclass) { | 199 | static int matchbracketclass (l_char c, const l_char *p, const l_char *endclass) { |
| 200 | int sig = 1; | 200 | int sig = 1; |
| 201 | if (*(p+1) == '^') { | 201 | if (*(p+1) == l_c('^')) { |
| 202 | sig = 0; | 202 | sig = 0; |
| 203 | p++; /* skip the `^' */ | 203 | p++; /* skip the `^' */ |
| 204 | } | 204 | } |
| @@ -208,7 +208,7 @@ static int matchbracketclass (char c, const char *p, const char *endclass) { | |||
| 208 | if (match_class(c, *p)) | 208 | if (match_class(c, *p)) |
| 209 | return sig; | 209 | return sig; |
| 210 | } | 210 | } |
| 211 | else if ((*(p+1) == '-') && (p+2 < endclass)) { | 211 | else if ((*(p+1) == l_c('-')) && (p+2 < endclass)) { |
| 212 | p+=2; | 212 | p+=2; |
| 213 | if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p)) | 213 | if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p)) |
| 214 | return sig; | 214 | return sig; |
| @@ -219,13 +219,13 @@ static int matchbracketclass (char c, const char *p, const char *endclass) { | |||
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | 221 | ||
| 222 | static int luaI_singlematch (char c, const char *p, const char *ep) { | 222 | static int luaI_singlematch (l_char c, const l_char *p, const l_char *ep) { |
| 223 | switch (*p) { | 223 | switch (*p) { |
| 224 | case '.': /* matches any char */ | 224 | case l_c('.'): /* matches any char */ |
| 225 | return 1; | 225 | return 1; |
| 226 | case ESC: | 226 | case ESC: |
| 227 | return match_class(c, *(p+1)); | 227 | return match_class(c, *(p+1)); |
| 228 | case '[': | 228 | case l_c('['): |
| 229 | return matchbracketclass(c, p, ep-1); | 229 | return matchbracketclass(c, p, ep-1); |
| 230 | default: | 230 | default: |
| 231 | return (*p == c); | 231 | return (*p == c); |
| @@ -233,12 +233,12 @@ static int luaI_singlematch (char c, const char *p, const char *ep) { | |||
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | 235 | ||
| 236 | static const char *match (MatchState *ms, const char *s, const char *p); | 236 | static const l_char *match (MatchState *ms, const l_char *s, const l_char *p); |
| 237 | 237 | ||
| 238 | 238 | ||
| 239 | static const char *matchbalance (MatchState *ms, const char *s, const char *p) { | 239 | static const l_char *matchbalance (MatchState *ms, const l_char *s, const l_char *p) { |
| 240 | if (*p == 0 || *(p+1) == 0) | 240 | if (*p == 0 || *(p+1) == 0) |
| 241 | lua_error(ms->L, "unbalanced pattern"); | 241 | lua_error(ms->L, l_s("unbalanced pattern")); |
| 242 | if (*s != *p) return NULL; | 242 | if (*s != *p) return NULL; |
| 243 | else { | 243 | else { |
| 244 | int b = *p; | 244 | int b = *p; |
| @@ -255,14 +255,14 @@ static const char *matchbalance (MatchState *ms, const char *s, const char *p) { | |||
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | 257 | ||
| 258 | static const char *max_expand (MatchState *ms, const char *s, const char *p, | 258 | static const l_char *max_expand (MatchState *ms, const l_char *s, const l_char *p, |
| 259 | const char *ep) { | 259 | const l_char *ep) { |
| 260 | sint32 i = 0; /* counts maximum expand for item */ | 260 | sint32 i = 0; /* counts maximum expand for item */ |
| 261 | while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep)) | 261 | while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep)) |
| 262 | i++; | 262 | i++; |
| 263 | /* keeps trying to match with the maximum repetitions */ | 263 | /* keeps trying to match with the maximum repetitions */ |
| 264 | while (i>=0) { | 264 | while (i>=0) { |
| 265 | const char *res = match(ms, (s+i), ep+1); | 265 | const l_char *res = match(ms, (s+i), ep+1); |
| 266 | if (res) return res; | 266 | if (res) return res; |
| 267 | i--; /* else didn't match; reduce 1 repetition to try again */ | 267 | i--; /* else didn't match; reduce 1 repetition to try again */ |
| 268 | } | 268 | } |
| @@ -270,10 +270,10 @@ static const char *max_expand (MatchState *ms, const char *s, const char *p, | |||
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | 272 | ||
| 273 | static const char *min_expand (MatchState *ms, const char *s, const char *p, | 273 | static const l_char *min_expand (MatchState *ms, const l_char *s, const l_char *p, |
| 274 | const char *ep) { | 274 | const l_char *ep) { |
| 275 | for (;;) { | 275 | for (;;) { |
| 276 | const char *res = match(ms, s, ep+1); | 276 | const l_char *res = match(ms, s, ep+1); |
| 277 | if (res != NULL) | 277 | if (res != NULL) |
| 278 | return res; | 278 | return res; |
| 279 | else if (s<ms->src_end && luaI_singlematch(*s, p, ep)) | 279 | else if (s<ms->src_end && luaI_singlematch(*s, p, ep)) |
| @@ -283,11 +283,11 @@ static const char *min_expand (MatchState *ms, const char *s, const char *p, | |||
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | 285 | ||
| 286 | static const char *start_capture (MatchState *ms, const char *s, | 286 | static const l_char *start_capture (MatchState *ms, const l_char *s, |
| 287 | const char *p, int what) { | 287 | const l_char *p, int what) { |
| 288 | const char *res; | 288 | const l_char *res; |
| 289 | int level = ms->level; | 289 | int level = ms->level; |
| 290 | if (level >= MAX_CAPTURES) lua_error(ms->L, "too many captures"); | 290 | if (level >= MAX_CAPTURES) lua_error(ms->L, l_s("too many captures")); |
| 291 | ms->capture[level].init = s; | 291 | ms->capture[level].init = s; |
| 292 | ms->capture[level].len = what; | 292 | ms->capture[level].len = what; |
| 293 | ms->level = level+1; | 293 | ms->level = level+1; |
| @@ -297,9 +297,9 @@ static const char *start_capture (MatchState *ms, const char *s, | |||
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | 299 | ||
| 300 | static const char *end_capture (MatchState *ms, const char *s, const char *p) { | 300 | static const l_char *end_capture (MatchState *ms, const l_char *s, const l_char *p) { |
| 301 | int l = capture_to_close(ms); | 301 | int l = capture_to_close(ms); |
| 302 | const char *res; | 302 | const l_char *res; |
| 303 | ms->capture[l].len = s - ms->capture[l].init; /* close capture */ | 303 | ms->capture[l].len = s - ms->capture[l].init; /* close capture */ |
| 304 | if ((res = match(ms, s, p)) == NULL) /* match failed? */ | 304 | if ((res = match(ms, s, p)) == NULL) /* match failed? */ |
| 305 | ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ | 305 | ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ |
| @@ -307,7 +307,7 @@ static const char *end_capture (MatchState *ms, const char *s, const char *p) { | |||
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | 309 | ||
| 310 | static const char *match_capture (MatchState *ms, const char *s, int level) { | 310 | static const l_char *match_capture (MatchState *ms, const l_char *s, int level) { |
| 311 | int l = check_capture(ms, level); | 311 | int l = check_capture(ms, level); |
| 312 | size_t len = ms->capture[l].len; | 312 | size_t len = ms->capture[l].len; |
| 313 | if ((size_t)(ms->src_end-s) >= len && | 313 | if ((size_t)(ms->src_end-s) >= len && |
| @@ -317,15 +317,15 @@ static const char *match_capture (MatchState *ms, const char *s, int level) { | |||
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | 319 | ||
| 320 | static const char *match (MatchState *ms, const char *s, const char *p) { | 320 | static const l_char *match (MatchState *ms, const l_char *s, const l_char *p) { |
| 321 | init: /* using goto's to optimize tail recursion */ | 321 | init: /* using goto's to optimize tail recursion */ |
| 322 | switch (*p) { | 322 | switch (*p) { |
| 323 | case '(': /* start capture */ | 323 | case l_c('('): /* start capture */ |
| 324 | if (*(p+1) == ')') /* position capture? */ | 324 | if (*(p+1) == l_c(')')) /* position capture? */ |
| 325 | return start_capture(ms, s, p+2, CAP_POSITION); | 325 | return start_capture(ms, s, p+2, CAP_POSITION); |
| 326 | else | 326 | else |
| 327 | return start_capture(ms, s, p+1, CAP_UNFINISHED); | 327 | return start_capture(ms, s, p+1, CAP_UNFINISHED); |
| 328 | case ')': /* end capture */ | 328 | case l_c(')'): /* end capture */ |
| 329 | return end_capture(ms, s, p+1); | 329 | return end_capture(ms, s, p+1); |
| 330 | case ESC: /* may be %[0-9] or %b */ | 330 | case ESC: /* may be %[0-9] or %b */ |
| 331 | if (isdigit(uchar(*(p+1)))) { /* capture? */ | 331 | if (isdigit(uchar(*(p+1)))) { /* capture? */ |
| @@ -333,33 +333,33 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
| 333 | if (s == NULL) return NULL; | 333 | if (s == NULL) return NULL; |
| 334 | p+=2; goto init; /* else return match(ms, s, p+2) */ | 334 | p+=2; goto init; /* else return match(ms, s, p+2) */ |
| 335 | } | 335 | } |
| 336 | else if (*(p+1) == 'b') { /* balanced string? */ | 336 | else if (*(p+1) == l_c('b')) { /* balanced string? */ |
| 337 | s = matchbalance(ms, s, p+2); | 337 | s = matchbalance(ms, s, p+2); |
| 338 | if (s == NULL) return NULL; | 338 | if (s == NULL) return NULL; |
| 339 | p+=4; goto init; /* else return match(ms, s, p+4); */ | 339 | p+=4; goto init; /* else return match(ms, s, p+4); */ |
| 340 | } | 340 | } |
| 341 | else goto dflt; /* case default */ | 341 | else goto dflt; /* case default */ |
| 342 | case '\0': /* end of pattern */ | 342 | case l_c('\0'): /* end of pattern */ |
| 343 | return s; /* match succeeded */ | 343 | return s; /* match succeeded */ |
| 344 | case '$': | 344 | case l_c('$'): |
| 345 | if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ | 345 | if (*(p+1) == l_c('\0')) /* is the `$' the last char in pattern? */ |
| 346 | return (s == ms->src_end) ? s : NULL; /* check end of string */ | 346 | return (s == ms->src_end) ? s : NULL; /* check end of string */ |
| 347 | else goto dflt; | 347 | else goto dflt; |
| 348 | default: dflt: { /* it is a pattern item */ | 348 | default: dflt: { /* it is a pattern item */ |
| 349 | const char *ep = luaI_classend(ms, p); /* points to what is next */ | 349 | const l_char *ep = luaI_classend(ms, p); /* points to what is next */ |
| 350 | int m = s<ms->src_end && luaI_singlematch(*s, p, ep); | 350 | int m = s<ms->src_end && luaI_singlematch(*s, p, ep); |
| 351 | switch (*ep) { | 351 | switch (*ep) { |
| 352 | case '?': { /* optional */ | 352 | case l_c('?'): { /* optional */ |
| 353 | const char *res; | 353 | const l_char *res; |
| 354 | if (m && ((res=match(ms, s+1, ep+1)) != NULL)) | 354 | if (m && ((res=match(ms, s+1, ep+1)) != NULL)) |
| 355 | return res; | 355 | return res; |
| 356 | p=ep+1; goto init; /* else return match(ms, s, ep+1); */ | 356 | p=ep+1; goto init; /* else return match(ms, s, ep+1); */ |
| 357 | } | 357 | } |
| 358 | case '*': /* 0 or more repetitions */ | 358 | case l_c('*'): /* 0 or more repetitions */ |
| 359 | return max_expand(ms, s, p, ep); | 359 | return max_expand(ms, s, p, ep); |
| 360 | case '+': /* 1 or more repetitions */ | 360 | case l_c('+'): /* 1 or more repetitions */ |
| 361 | return (m ? max_expand(ms, s+1, p, ep) : NULL); | 361 | return (m ? max_expand(ms, s+1, p, ep) : NULL); |
| 362 | case '-': /* 0 or more repetitions (minimum) */ | 362 | case l_c('-'): /* 0 or more repetitions (minimum) */ |
| 363 | return min_expand(ms, s, p, ep); | 363 | return min_expand(ms, s, p, ep); |
| 364 | default: | 364 | default: |
| 365 | if (!m) return NULL; | 365 | if (!m) return NULL; |
| @@ -371,15 +371,15 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
| 371 | 371 | ||
| 372 | 372 | ||
| 373 | 373 | ||
| 374 | static const char *lmemfind (const char *s1, size_t l1, | 374 | static const l_char *lmemfind (const l_char *s1, size_t l1, |
| 375 | const char *s2, size_t l2) { | 375 | const l_char *s2, size_t l2) { |
| 376 | if (l2 == 0) return s1; /* empty strings are everywhere */ | 376 | if (l2 == 0) return s1; /* empty strings are everywhere */ |
| 377 | else if (l2 > l1) return NULL; /* avoids a negative `l1' */ | 377 | else if (l2 > l1) return NULL; /* avoids a negative `l1' */ |
| 378 | else { | 378 | else { |
| 379 | const char *init; /* to search for a `*s2' inside `s1' */ | 379 | const l_char *init; /* to search for a `*s2' inside `s1' */ |
| 380 | l2--; /* 1st char will be checked by `memchr' */ | 380 | l2--; /* 1st char will be checked by `memchr' */ |
| 381 | l1 = l1-l2; /* `s2' cannot be found after that */ | 381 | l1 = l1-l2; /* `s2' cannot be found after that */ |
| 382 | while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { | 382 | while (l1 > 0 && (init = (const l_char *)memchr(s1, *s2, l1)) != NULL) { |
| 383 | init++; /* 1st char is already checked */ | 383 | init++; /* 1st char is already checked */ |
| 384 | if (memcmp(init, s2+1, l2) == 0) | 384 | if (memcmp(init, s2+1, l2) == 0) |
| 385 | return init-1; | 385 | return init-1; |
| @@ -395,7 +395,7 @@ static const char *lmemfind (const char *s1, size_t l1, | |||
| 395 | 395 | ||
| 396 | static void push_onecapture (MatchState *ms, int i) { | 396 | static void push_onecapture (MatchState *ms, int i) { |
| 397 | int l = ms->capture[i].len; | 397 | int l = ms->capture[i].len; |
| 398 | if (l == CAP_UNFINISHED) lua_error(ms->L, "unfinished capture"); | 398 | if (l == CAP_UNFINISHED) lua_error(ms->L, l_s("unfinished capture")); |
| 399 | if (l == CAP_POSITION) | 399 | if (l == CAP_POSITION) |
| 400 | lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); | 400 | lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); |
| 401 | else | 401 | else |
| @@ -405,7 +405,7 @@ static void push_onecapture (MatchState *ms, int i) { | |||
| 405 | 405 | ||
| 406 | static int push_captures (MatchState *ms) { | 406 | static int push_captures (MatchState *ms) { |
| 407 | int i; | 407 | int i; |
| 408 | luaL_checkstack(ms->L, ms->level, "too many captures"); | 408 | luaL_checkstack(ms->L, ms->level, l_s("too many captures")); |
| 409 | for (i=0; i<ms->level; i++) | 409 | for (i=0; i<ms->level; i++) |
| 410 | push_onecapture(ms, i); | 410 | push_onecapture(ms, i); |
| 411 | return ms->level; /* number of strings pushed */ | 411 | return ms->level; /* number of strings pushed */ |
| @@ -414,13 +414,13 @@ static int push_captures (MatchState *ms) { | |||
| 414 | 414 | ||
| 415 | static int str_find (lua_State *L) { | 415 | static int str_find (lua_State *L) { |
| 416 | size_t l1, l2; | 416 | size_t l1, l2; |
| 417 | const char *s = luaL_check_lstr(L, 1, &l1); | 417 | const l_char *s = luaL_check_lstr(L, 1, &l1); |
| 418 | const char *p = luaL_check_lstr(L, 2, &l2); | 418 | const l_char *p = luaL_check_lstr(L, 2, &l2); |
| 419 | sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; | 419 | sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; |
| 420 | luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range"); | 420 | luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, l_s("out of range")); |
| 421 | if (lua_gettop(L) > 3 || /* extra argument? */ | 421 | if (lua_gettop(L) > 3 || /* extra argument? */ |
| 422 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ | 422 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ |
| 423 | const char *s2 = lmemfind(s+init, l1-init, p, l2); | 423 | const l_char *s2 = lmemfind(s+init, l1-init, p, l2); |
| 424 | if (s2) { | 424 | if (s2) { |
| 425 | lua_pushnumber(L, s2-s+1); | 425 | lua_pushnumber(L, s2-s+1); |
| 426 | lua_pushnumber(L, s2-s+l2); | 426 | lua_pushnumber(L, s2-s+l2); |
| @@ -429,13 +429,13 @@ static int str_find (lua_State *L) { | |||
| 429 | } | 429 | } |
| 430 | else { | 430 | else { |
| 431 | MatchState ms; | 431 | MatchState ms; |
| 432 | int anchor = (*p == '^') ? (p++, 1) : 0; | 432 | int anchor = (*p == l_c('^')) ? (p++, 1) : 0; |
| 433 | const char *s1=s+init; | 433 | const l_char *s1=s+init; |
| 434 | ms.L = L; | 434 | ms.L = L; |
| 435 | ms.src_init = s; | 435 | ms.src_init = s; |
| 436 | ms.src_end = s+l1; | 436 | ms.src_end = s+l1; |
| 437 | do { | 437 | do { |
| 438 | const char *res; | 438 | const l_char *res; |
| 439 | ms.level = 0; | 439 | ms.level = 0; |
| 440 | if ((res=match(&ms, s1, p)) != NULL) { | 440 | if ((res=match(&ms, s1, p)) != NULL) { |
| 441 | lua_pushnumber(L, s1-s+1); /* start */ | 441 | lua_pushnumber(L, s1-s+1); /* start */ |
| @@ -452,7 +452,7 @@ static int str_find (lua_State *L) { | |||
| 452 | static void add_s (MatchState *ms, luaL_Buffer *b) { | 452 | static void add_s (MatchState *ms, luaL_Buffer *b) { |
| 453 | lua_State *L = ms->L; | 453 | lua_State *L = ms->L; |
| 454 | if (lua_isstring(L, 3)) { | 454 | if (lua_isstring(L, 3)) { |
| 455 | const char *news = lua_tostring(L, 3); | 455 | const l_char *news = lua_tostring(L, 3); |
| 456 | size_t l = lua_strlen(L, 3); | 456 | size_t l = lua_strlen(L, 3); |
| 457 | size_t i; | 457 | size_t i; |
| 458 | for (i=0; i<l; i++) { | 458 | for (i=0; i<l; i++) { |
| @@ -485,22 +485,22 @@ static void add_s (MatchState *ms, luaL_Buffer *b) { | |||
| 485 | 485 | ||
| 486 | static int str_gsub (lua_State *L) { | 486 | static int str_gsub (lua_State *L) { |
| 487 | size_t srcl; | 487 | size_t srcl; |
| 488 | const char *src = luaL_check_lstr(L, 1, &srcl); | 488 | const l_char *src = luaL_check_lstr(L, 1, &srcl); |
| 489 | const char *p = luaL_check_string(L, 2); | 489 | const l_char *p = luaL_check_string(L, 2); |
| 490 | int max_s = luaL_opt_int(L, 4, srcl+1); | 490 | int max_s = luaL_opt_int(L, 4, srcl+1); |
| 491 | int anchor = (*p == '^') ? (p++, 1) : 0; | 491 | int anchor = (*p == l_c('^')) ? (p++, 1) : 0; |
| 492 | int n = 0; | 492 | int n = 0; |
| 493 | MatchState ms; | 493 | MatchState ms; |
| 494 | luaL_Buffer b; | 494 | luaL_Buffer b; |
| 495 | luaL_arg_check(L, | 495 | luaL_arg_check(L, |
| 496 | lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), | 496 | lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), |
| 497 | 3, "string or function expected"); | 497 | 3, l_s("string or function expected")); |
| 498 | luaL_buffinit(L, &b); | 498 | luaL_buffinit(L, &b); |
| 499 | ms.L = L; | 499 | ms.L = L; |
| 500 | ms.src_init = src; | 500 | ms.src_init = src; |
| 501 | ms.src_end = src+srcl; | 501 | ms.src_end = src+srcl; |
| 502 | while (n < max_s) { | 502 | while (n < max_s) { |
| 503 | const char *e; | 503 | const l_char *e; |
| 504 | ms.level = 0; | 504 | ms.level = 0; |
| 505 | e = match(&ms, src, p); | 505 | e = match(&ms, src, p); |
| 506 | if (e) { | 506 | if (e) { |
| @@ -531,40 +531,40 @@ static int str_gsub (lua_State *L) { | |||
| 531 | 531 | ||
| 532 | static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { | 532 | static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { |
| 533 | size_t l; | 533 | size_t l; |
| 534 | const char *s = luaL_check_lstr(L, arg, &l); | 534 | const l_char *s = luaL_check_lstr(L, arg, &l); |
| 535 | luaL_putchar(b, '"'); | 535 | luaL_putchar(b, l_c('"')); |
| 536 | while (l--) { | 536 | while (l--) { |
| 537 | switch (*s) { | 537 | switch (*s) { |
| 538 | case '"': case '\\': case '\n': | 538 | case l_c('"'): case l_c('\\'): case l_c('\n'): |
| 539 | luaL_putchar(b, '\\'); | 539 | luaL_putchar(b, l_c('\\')); |
| 540 | luaL_putchar(b, *s); | 540 | luaL_putchar(b, *s); |
| 541 | break; | 541 | break; |
| 542 | case '\0': luaL_addlstring(b, "\\000", 4); break; | 542 | case l_c('\0'): luaL_addlstring(b, l_s("\\000"), 4); break; |
| 543 | default: luaL_putchar(b, *s); | 543 | default: luaL_putchar(b, *s); |
| 544 | } | 544 | } |
| 545 | s++; | 545 | s++; |
| 546 | } | 546 | } |
| 547 | luaL_putchar(b, '"'); | 547 | luaL_putchar(b, l_c('"')); |
| 548 | } | 548 | } |
| 549 | 549 | ||
| 550 | 550 | ||
| 551 | static const char *scanformat (lua_State *L, const char *strfrmt, char *form, | 551 | static const l_char *scanformat (lua_State *L, const l_char *strfrmt, l_char *form, |
| 552 | int *hasprecision) { | 552 | int *hasprecision) { |
| 553 | const char *p = strfrmt; | 553 | const l_char *p = strfrmt; |
| 554 | while (strchr("-+ #0", *p)) p++; /* skip flags */ | 554 | while (strchr(l_s("-+ #0"), *p)) p++; /* skip flags */ |
| 555 | if (isdigit(uchar(*p))) p++; /* skip width */ | 555 | if (isdigit(uchar(*p))) p++; /* skip width */ |
| 556 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ | 556 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 557 | if (*p == '.') { | 557 | if (*p == l_c('.')) { |
| 558 | p++; | 558 | p++; |
| 559 | *hasprecision = 1; | 559 | *hasprecision = 1; |
| 560 | if (isdigit(uchar(*p))) p++; /* skip precision */ | 560 | if (isdigit(uchar(*p))) p++; /* skip precision */ |
| 561 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ | 561 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 562 | } | 562 | } |
| 563 | if (isdigit(uchar(*p))) | 563 | if (isdigit(uchar(*p))) |
| 564 | lua_error(L, "invalid format (width or precision too long)"); | 564 | lua_error(L, l_s("invalid format (width or precision too long)")); |
| 565 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ | 565 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ |
| 566 | lua_error(L, "invalid format (too long)"); | 566 | lua_error(L, l_s("invalid format (too long)")); |
| 567 | form[0] = '%'; | 567 | form[0] = l_c('%'); |
| 568 | strncpy(form+1, strfrmt, p-strfrmt+1); | 568 | strncpy(form+1, strfrmt, p-strfrmt+1); |
| 569 | form[p-strfrmt+2] = 0; | 569 | form[p-strfrmt+2] = 0; |
| 570 | return p; | 570 | return p; |
| @@ -573,38 +573,38 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form, | |||
| 573 | 573 | ||
| 574 | static int str_format (lua_State *L) { | 574 | static int str_format (lua_State *L) { |
| 575 | int arg = 1; | 575 | int arg = 1; |
| 576 | const char *strfrmt = luaL_check_string(L, arg); | 576 | const l_char *strfrmt = luaL_check_string(L, arg); |
| 577 | luaL_Buffer b; | 577 | luaL_Buffer b; |
| 578 | luaL_buffinit(L, &b); | 578 | luaL_buffinit(L, &b); |
| 579 | while (*strfrmt) { | 579 | while (*strfrmt) { |
| 580 | if (*strfrmt != '%') | 580 | if (*strfrmt != l_c('%')) |
| 581 | luaL_putchar(&b, *strfrmt++); | 581 | luaL_putchar(&b, *strfrmt++); |
| 582 | else if (*++strfrmt == '%') | 582 | else if (*++strfrmt == l_c('%')) |
| 583 | luaL_putchar(&b, *strfrmt++); /* %% */ | 583 | luaL_putchar(&b, *strfrmt++); /* %% */ |
| 584 | else { /* format item */ | 584 | else { /* format item */ |
| 585 | char form[MAX_FORMAT]; /* to store the format (`%...') */ | 585 | l_char form[MAX_FORMAT]; /* to store the format (`%...') */ |
| 586 | char buff[MAX_ITEM]; /* to store the formatted item */ | 586 | l_char buff[MAX_ITEM]; /* to store the formatted item */ |
| 587 | int hasprecision = 0; | 587 | int hasprecision = 0; |
| 588 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') | 588 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == l_c('$')) |
| 589 | lua_error(L, "obsolete `format' option (d$)"); | 589 | lua_error(L, l_s("obsolete `format' option (d$)")); |
| 590 | arg++; | 590 | arg++; |
| 591 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); | 591 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); |
| 592 | switch (*strfrmt++) { | 592 | switch (*strfrmt++) { |
| 593 | case 'c': case 'd': case 'i': | 593 | case l_c('c'): case l_c('d'): case l_c('i'): |
| 594 | sprintf(buff, form, luaL_check_int(L, arg)); | 594 | sprintf(buff, form, luaL_check_int(L, arg)); |
| 595 | break; | 595 | break; |
| 596 | case 'o': case 'u': case 'x': case 'X': | 596 | case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'): |
| 597 | sprintf(buff, form, (unsigned int)luaL_check_number(L, arg)); | 597 | sprintf(buff, form, (unsigned int)luaL_check_number(L, arg)); |
| 598 | break; | 598 | break; |
| 599 | case 'e': case 'E': case 'f': case 'g': case 'G': | 599 | case l_c('e'): case l_c('E'): case l_c('f'): case l_c('g'): case l_c('G'): |
| 600 | sprintf(buff, form, luaL_check_number(L, arg)); | 600 | sprintf(buff, form, luaL_check_number(L, arg)); |
| 601 | break; | 601 | break; |
| 602 | case 'q': | 602 | case l_c('q'): |
| 603 | luaI_addquoted(L, &b, arg); | 603 | luaI_addquoted(L, &b, arg); |
| 604 | continue; /* skip the `addsize' at the end */ | 604 | continue; /* skip the `addsize' at the end */ |
| 605 | case 's': { | 605 | case l_c('s'): { |
| 606 | size_t l; | 606 | size_t l; |
| 607 | const char *s = luaL_check_lstr(L, arg, &l); | 607 | const l_char *s = luaL_check_lstr(L, arg, &l); |
| 608 | if (!hasprecision && l >= 100) { | 608 | if (!hasprecision && l >= 100) { |
| 609 | /* no precision and string is too long to be formatted; | 609 | /* no precision and string is too long to be formatted; |
| 610 | keep original string */ | 610 | keep original string */ |
| @@ -618,7 +618,7 @@ static int str_format (lua_State *L) { | |||
| 618 | } | 618 | } |
| 619 | } | 619 | } |
| 620 | default: /* also treat cases `pnLlh' */ | 620 | default: /* also treat cases `pnLlh' */ |
| 621 | lua_error(L, "invalid option in `format'"); | 621 | lua_error(L, l_s("invalid option in `format'")); |
| 622 | } | 622 | } |
| 623 | luaL_addlstring(&b, buff, strlen(buff)); | 623 | luaL_addlstring(&b, buff, strlen(buff)); |
| 624 | } | 624 | } |
| @@ -629,16 +629,16 @@ static int str_format (lua_State *L) { | |||
| 629 | 629 | ||
| 630 | 630 | ||
| 631 | static const luaL_reg strlib[] = { | 631 | static const luaL_reg strlib[] = { |
| 632 | {"strlen", str_len}, | 632 | {l_s("strlen"), str_len}, |
| 633 | {"strsub", str_sub}, | 633 | {l_s("strsub"), str_sub}, |
| 634 | {"strlower", str_lower}, | 634 | {l_s("strlower"), str_lower}, |
| 635 | {"strupper", str_upper}, | 635 | {l_s("strupper"), str_upper}, |
| 636 | {"strchar", str_char}, | 636 | {l_s("strchar"), str_char}, |
| 637 | {"strrep", str_rep}, | 637 | {l_s("strrep"), str_rep}, |
| 638 | {"strbyte", str_byte}, | 638 | {l_s("strbyte"), str_byte}, |
| 639 | {"format", str_format}, | 639 | {l_s("format"), str_format}, |
| 640 | {"strfind", str_find}, | 640 | {l_s("strfind"), str_find}, |
| 641 | {"gsub", str_gsub} | 641 | {l_s("gsub"), str_gsub} |
| 642 | }; | 642 | }; |
| 643 | 643 | ||
| 644 | 644 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.75 2001/02/01 17:40:48 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.76 2001/02/20 18:15:33 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -59,9 +59,9 @@ Node *luaH_next (lua_State *L, Hash *t, const TObject *key) { | |||
| 59 | else { | 59 | else { |
| 60 | const TObject *v = luaH_get(t, key); | 60 | const TObject *v = luaH_get(t, key); |
| 61 | if (v == &luaO_nilobject) | 61 | if (v == &luaO_nilobject) |
| 62 | luaD_error(L, "invalid key for `next'"); | 62 | luaD_error(L, l_s("invalid key for `next'")); |
| 63 | i = (int)(((const char *)v - | 63 | i = (int)(((const l_char *)v - |
| 64 | (const char *)(&t->node[0].val)) / sizeof(Node)) + 1; | 64 | (const l_char *)(&t->node[0].val)) / sizeof(Node)) + 1; |
| 65 | } | 65 | } |
| 66 | for (; i<t->size; i++) { | 66 | for (; i<t->size; i++) { |
| 67 | Node *n = node(t, i); | 67 | Node *n = node(t, i); |
| @@ -82,7 +82,7 @@ int luaH_nexti (Hash *t, int i) { | |||
| 82 | 82 | ||
| 83 | 83 | ||
| 84 | #define check_grow(L, p, n) \ | 84 | #define check_grow(L, p, n) \ |
| 85 | if ((p) >= MAX_INT/(n)) luaD_error(L, "table overflow"); | 85 | if ((p) >= MAX_INT/(n)) luaD_error(L, l_s("table overflow")); |
| 86 | 86 | ||
| 87 | /* | 87 | /* |
| 88 | ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) | 88 | ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) |
| @@ -270,7 +270,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) { | |||
| 270 | case LUA_TNUMBER: return luaH_setnum(L, t, nvalue(key)); | 270 | case LUA_TNUMBER: return luaH_setnum(L, t, nvalue(key)); |
| 271 | case LUA_TSTRING: return luaH_setstr(L, t, tsvalue(key)); | 271 | case LUA_TSTRING: return luaH_setstr(L, t, tsvalue(key)); |
| 272 | case LUA_TNIL: | 272 | case LUA_TNIL: |
| 273 | if (L) luaD_error(L, "table index is nil"); | 273 | if (L) luaD_error(L, l_s("table index is nil")); |
| 274 | return (TObject *)&luaO_nilobject; /* get option */ | 274 | return (TObject *)&luaO_nilobject; /* get option */ |
| 275 | default: return luaH_setany(L, t, key); | 275 | default: return luaH_setany(L, t, key); |
| 276 | } | 276 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.70 2001/02/21 16:51:25 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.71 2001/02/22 18:59:59 roberto Exp roberto $ |
| 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 | */ |
| @@ -42,7 +42,7 @@ int islocked = 0; | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | static void setnameval (lua_State *L, const char *name, int val) { | 45 | static void setnameval (lua_State *L, const l_char *name, int val) { |
| 46 | lua_pushstring(L, name); | 46 | lua_pushstring(L, name); |
| 47 | lua_pushnumber(L, val); | 47 | lua_pushnumber(L, val); |
| 48 | lua_settable(L, -3); | 48 | lua_settable(L, -3); |
| @@ -63,7 +63,7 @@ static void setnameval (lua_State *L, const char *name, int val) { | |||
| 63 | #define MARK 0x55 /* 01010101 (a nice pattern) */ | 63 | #define MARK 0x55 /* 01010101 (a nice pattern) */ |
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | #define blocksize(b) ((size_t *)((char *)(b) - HEADER)) | 66 | #define blocksize(b) ((size_t *)((l_char *)(b) - HEADER)) |
| 67 | 67 | ||
| 68 | unsigned long memdebug_numblocks = 0; | 68 | unsigned long memdebug_numblocks = 0; |
| 69 | unsigned long memdebug_total = 0; | 69 | unsigned long memdebug_total = 0; |
| @@ -76,7 +76,7 @@ static void *checkblock (void *block) { | |||
| 76 | size_t size = *b; | 76 | size_t size = *b; |
| 77 | int i; | 77 | int i; |
| 78 | for (i=0;i<MARKSIZE;i++) | 78 | for (i=0;i<MARKSIZE;i++) |
| 79 | lua_assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ | 79 | lua_assert(*(((l_char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ |
| 80 | return b; | 80 | return b; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| @@ -102,11 +102,11 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) { | |||
| 102 | else if (memdebug_total+size-oldsize > memdebug_memlimit) | 102 | else if (memdebug_total+size-oldsize > memdebug_memlimit) |
| 103 | return NULL; /* to test memory allocation errors */ | 103 | return NULL; /* to test memory allocation errors */ |
| 104 | else { | 104 | else { |
| 105 | char *newblock; | 105 | l_char *newblock; |
| 106 | int i; | 106 | int i; |
| 107 | size_t realsize = HEADER+size+MARKSIZE; | 107 | size_t realsize = HEADER+size+MARKSIZE; |
| 108 | if (realsize < size) return NULL; /* overflow! */ | 108 | if (realsize < size) return NULL; /* overflow! */ |
| 109 | newblock = (char *)malloc(realsize); /* alloc a new block */ | 109 | newblock = (l_char *)malloc(realsize); /* alloc a new block */ |
| 110 | if (newblock == NULL) return NULL; | 110 | if (newblock == NULL) return NULL; |
| 111 | if (oldsize > size) oldsize = size; | 111 | if (oldsize > size) oldsize = size; |
| 112 | if (block) { | 112 | if (block) { |
| @@ -121,7 +121,7 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) { | |||
| 121 | memdebug_numblocks++; | 121 | memdebug_numblocks++; |
| 122 | *(size_t *)newblock = size; | 122 | *(size_t *)newblock = size; |
| 123 | for (i=0;i<MARKSIZE;i++) | 123 | for (i=0;i<MARKSIZE;i++) |
| 124 | *(newblock+HEADER+size+i) = (char)(MARK+i); | 124 | *(newblock+HEADER+size+i) = (l_char)(MARK+i); |
| 125 | return newblock+HEADER; | 125 | return newblock+HEADER; |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| @@ -138,36 +138,36 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) { | |||
| 138 | */ | 138 | */ |
| 139 | 139 | ||
| 140 | 140 | ||
| 141 | static const char *const instrname[NUM_OPCODES] = { | 141 | static const l_char *const instrname[NUM_OPCODES] = { |
| 142 | "RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT", | 142 | l_s("RETURN"), l_s("CALL"), l_s("TAILCALL"), l_s("PUSHNIL"), l_s("POP"), l_s("PUSHINT"), |
| 143 | "PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL", | 143 | l_s("PUSHSTRING"), l_s("PUSHNUM"), l_s("PUSHNEGNUM"), l_s("PUSHUPVALUE"), l_s("GETLOCAL"), |
| 144 | "GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF", | 144 | l_s("GETGLOBAL"), l_s("GETTABLE"), l_s("GETDOTTED"), l_s("GETINDEXED"), l_s("PUSHSELF"), |
| 145 | "CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP", | 145 | l_s("CREATETABLE"), l_s("SETLOCAL"), l_s("SETGLOBAL"), l_s("SETTABLE"), l_s("SETLIST"), l_s("SETMAP"), |
| 146 | "ADD", "ADDI", "SUB", "MULT", "DIV", "POW", "CONCAT", "MINUS", "NOT", | 146 | l_s("ADD"), l_s("ADDI"), l_s("SUB"), l_s("MULT"), l_s("DIV"), l_s("POW"), l_s("CONCAT"), l_s("MINUS"), l_s("NOT"), |
| 147 | "JMPNE", "JMPEQ", "JMPLT", "JMPLE", "JMPGT", "JMPGE", "JMPT", "JMPF", | 147 | l_s("JMPNE"), l_s("JMPEQ"), l_s("JMPLT"), l_s("JMPLE"), l_s("JMPGT"), l_s("JMPGE"), l_s("JMPT"), l_s("JMPF"), |
| 148 | "JMPONT", "JMPONF", "JMP", "PUSHNILJMP", "FORPREP", "FORLOOP", "LFORPREP", | 148 | l_s("JMPONT"), l_s("JMPONF"), l_s("JMP"), l_s("PUSHNILJMP"), l_s("FORPREP"), l_s("FORLOOP"), l_s("LFORPREP"), |
| 149 | "LFORLOOP", "CLOSURE" | 149 | l_s("LFORLOOP"), l_s("CLOSURE") |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | static void pushop (lua_State *L, Proto *p, int pc) { | 153 | static void pushop (lua_State *L, Proto *p, int pc) { |
| 154 | char buff[100]; | 154 | l_char buff[100]; |
| 155 | Instruction i = p->code[pc]; | 155 | Instruction i = p->code[pc]; |
| 156 | OpCode o = GET_OPCODE(i); | 156 | OpCode o = GET_OPCODE(i); |
| 157 | const char *name = instrname[o]; | 157 | const l_char *name = instrname[o]; |
| 158 | sprintf(buff, "%5d - ", luaG_getline(p->lineinfo, pc, 1, NULL)); | 158 | sprintf(buff, l_s("%5d - "), luaG_getline(p->lineinfo, pc, 1, NULL)); |
| 159 | switch ((enum Mode)luaK_opproperties[o].mode) { | 159 | switch ((enum Mode)luaK_opproperties[o].mode) { |
| 160 | case iO: | 160 | case iO: |
| 161 | sprintf(buff+8, "%-12s", name); | 161 | sprintf(buff+8, l_s("%-12s"), name); |
| 162 | break; | 162 | break; |
| 163 | case iU: | 163 | case iU: |
| 164 | sprintf(buff+8, "%-12s%4u", name, GETARG_U(i)); | 164 | sprintf(buff+8, l_s("%-12s%4u"), name, GETARG_U(i)); |
| 165 | break; | 165 | break; |
| 166 | case iS: | 166 | case iS: |
| 167 | sprintf(buff+8, "%-12s%4d", name, GETARG_S(i)); | 167 | sprintf(buff+8, l_s("%-12s%4d"), name, GETARG_S(i)); |
| 168 | break; | 168 | break; |
| 169 | case iAB: | 169 | case iAB: |
| 170 | sprintf(buff+8, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); | 170 | sprintf(buff+8, l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_B(i)); |
| 171 | break; | 171 | break; |
| 172 | } | 172 | } |
| 173 | lua_pushstring(L, buff); | 173 | lua_pushstring(L, buff); |
| @@ -178,11 +178,11 @@ static int listcode (lua_State *L) { | |||
| 178 | int pc; | 178 | int pc; |
| 179 | Proto *p; | 179 | Proto *p; |
| 180 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 180 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 181 | 1, "Lua function expected"); | 181 | 1, l_s("Lua function expected")); |
| 182 | p = clvalue(luaA_index(L, 1))->f.l; | 182 | p = clvalue(luaA_index(L, 1))->f.l; |
| 183 | lua_newtable(L); | 183 | lua_newtable(L); |
| 184 | setnameval(L, "maxstack", p->maxstacksize); | 184 | setnameval(L, l_s("maxstack"), p->maxstacksize); |
| 185 | setnameval(L, "numparams", p->numparams); | 185 | setnameval(L, l_s("numparams"), p->numparams); |
| 186 | for (pc=0; pc<p->sizecode; pc++) { | 186 | for (pc=0; pc<p->sizecode; pc++) { |
| 187 | lua_pushnumber(L, pc+1); | 187 | lua_pushnumber(L, pc+1); |
| 188 | pushop(L, p, pc); | 188 | pushop(L, p, pc); |
| @@ -196,7 +196,7 @@ static int liststrings (lua_State *L) { | |||
| 196 | Proto *p; | 196 | Proto *p; |
| 197 | int i; | 197 | int i; |
| 198 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 198 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 199 | 1, "Lua function expected"); | 199 | 1, l_s("Lua function expected")); |
| 200 | p = clvalue(luaA_index(L, 1))->f.l; | 200 | p = clvalue(luaA_index(L, 1))->f.l; |
| 201 | lua_newtable(L); | 201 | lua_newtable(L); |
| 202 | for (i=0; i<p->sizekstr; i++) { | 202 | for (i=0; i<p->sizekstr; i++) { |
| @@ -212,9 +212,9 @@ static int listlocals (lua_State *L) { | |||
| 212 | Proto *p; | 212 | Proto *p; |
| 213 | int pc = luaL_check_int(L, 2) - 1; | 213 | int pc = luaL_check_int(L, 2) - 1; |
| 214 | int i = 0; | 214 | int i = 0; |
| 215 | const char *name; | 215 | const l_char *name; |
| 216 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 216 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 217 | 1, "Lua function expected"); | 217 | 1, l_s("Lua function expected")); |
| 218 | p = clvalue(luaA_index(L, 1))->f.l; | 218 | p = clvalue(luaA_index(L, 1))->f.l; |
| 219 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) | 219 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
| 220 | lua_pushstring(L, name); | 220 | lua_pushstring(L, name); |
| @@ -234,22 +234,22 @@ static int pushbool (lua_State *L, int b) { | |||
| 234 | 234 | ||
| 235 | static int get_limits (lua_State *L) { | 235 | static int get_limits (lua_State *L) { |
| 236 | lua_newtable(L); | 236 | lua_newtable(L); |
| 237 | setnameval(L, "BITS_INT", BITS_INT); | 237 | setnameval(L, l_s("BITS_INT"), BITS_INT); |
| 238 | setnameval(L, "LFPF", LFIELDS_PER_FLUSH); | 238 | setnameval(L, l_s("LFPF"), LFIELDS_PER_FLUSH); |
| 239 | setnameval(L, "MAXARG_A", MAXARG_A); | 239 | setnameval(L, l_s("MAXARG_A"), MAXARG_A); |
| 240 | setnameval(L, "MAXARG_B", MAXARG_B); | 240 | setnameval(L, l_s("MAXARG_B"), MAXARG_B); |
| 241 | setnameval(L, "MAXARG_S", MAXARG_S); | 241 | setnameval(L, l_s("MAXARG_S"), MAXARG_S); |
| 242 | setnameval(L, "MAXARG_U", MAXARG_U); | 242 | setnameval(L, l_s("MAXARG_U"), MAXARG_U); |
| 243 | setnameval(L, "MAXLOCALS", MAXLOCALS); | 243 | setnameval(L, l_s("MAXLOCALS"), MAXLOCALS); |
| 244 | setnameval(L, "MAXPARAMS", MAXPARAMS); | 244 | setnameval(L, l_s("MAXPARAMS"), MAXPARAMS); |
| 245 | setnameval(L, "MAXSTACK", MAXSTACK); | 245 | setnameval(L, l_s("MAXSTACK"), MAXSTACK); |
| 246 | setnameval(L, "MAXUPVALUES", MAXUPVALUES); | 246 | setnameval(L, l_s("MAXUPVALUES"), MAXUPVALUES); |
| 247 | setnameval(L, "MAXVARSLH", MAXVARSLH); | 247 | setnameval(L, l_s("MAXVARSLH"), MAXVARSLH); |
| 248 | setnameval(L, "RFPF", RFIELDS_PER_FLUSH); | 248 | setnameval(L, l_s("RFPF"), RFIELDS_PER_FLUSH); |
| 249 | setnameval(L, "SIZE_A", SIZE_A); | 249 | setnameval(L, l_s("SIZE_A"), SIZE_A); |
| 250 | setnameval(L, "SIZE_B", SIZE_B); | 250 | setnameval(L, l_s("SIZE_B"), SIZE_B); |
| 251 | setnameval(L, "SIZE_OP", SIZE_OP); | 251 | setnameval(L, l_s("SIZE_OP"), SIZE_OP); |
| 252 | setnameval(L, "SIZE_U", SIZE_U); | 252 | setnameval(L, l_s("SIZE_U"), SIZE_U); |
| 253 | return 1; | 253 | return 1; |
| 254 | } | 254 | } |
| 255 | 255 | ||
| @@ -270,7 +270,7 @@ static int mem_query (lua_State *L) { | |||
| 270 | 270 | ||
| 271 | static int hash_query (lua_State *L) { | 271 | static int hash_query (lua_State *L) { |
| 272 | if (lua_isnull(L, 2)) { | 272 | if (lua_isnull(L, 2)) { |
| 273 | luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, "string expected"); | 273 | luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected")); |
| 274 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); | 274 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); |
| 275 | } | 275 | } |
| 276 | else { | 276 | else { |
| @@ -313,7 +313,7 @@ static int table_query (lua_State *L) { | |||
| 313 | 313 | ||
| 314 | 314 | ||
| 315 | static int string_query (lua_State *L) { | 315 | static int string_query (lua_State *L) { |
| 316 | stringtable *tb = (*luaL_check_string(L, 1) == 's') ? &G(L)->strt : | 316 | stringtable *tb = (*luaL_check_string(L, 1) == l_c('s')) ? &G(L)->strt : |
| 317 | &G(L)->udt; | 317 | &G(L)->udt; |
| 318 | int s = luaL_opt_int(L, 2, 0) - 1; | 318 | int s = luaL_opt_int(L, 2, 0) - 1; |
| 319 | if (s==-1) { | 319 | if (s==-1) { |
| @@ -364,8 +364,8 @@ static int newuserdata (lua_State *L) { | |||
| 364 | } | 364 | } |
| 365 | else { | 365 | else { |
| 366 | size_t size = luaL_check_int(L, 1); | 366 | size_t size = luaL_check_int(L, 1); |
| 367 | char *p = (char *)lua_newuserdata(L, size); | 367 | l_char *p = (l_char *)lua_newuserdata(L, size); |
| 368 | while (size--) *p++ = '\0'; | 368 | while (size--) *p++ = l_c('\0'); |
| 369 | return 1; | 369 | return 1; |
| 370 | } | 370 | } |
| 371 | } | 371 | } |
| @@ -400,7 +400,7 @@ static int s2d (lua_State *L) { | |||
| 400 | 400 | ||
| 401 | static int d2s (lua_State *L) { | 401 | static int d2s (lua_State *L) { |
| 402 | double d = luaL_check_number(L, 1); | 402 | double d = luaL_check_number(L, 1); |
| 403 | lua_pushlstring(L, (char *)&d, sizeof(d)); | 403 | lua_pushlstring(L, (l_char *)&d, sizeof(d)); |
| 404 | return 1; | 404 | return 1; |
| 405 | } | 405 | } |
| 406 | 406 | ||
| @@ -419,12 +419,12 @@ static int newstate (lua_State *L) { | |||
| 419 | static int loadlib (lua_State *L) { | 419 | static int loadlib (lua_State *L) { |
| 420 | lua_State *L1 = (lua_State *)lua_touserdata(L, 1); | 420 | lua_State *L1 = (lua_State *)lua_touserdata(L, 1); |
| 421 | switch (*luaL_check_string(L, 2)) { | 421 | switch (*luaL_check_string(L, 2)) { |
| 422 | case 'm': lua_mathlibopen(L1); break; | 422 | case l_c('m'): lua_mathlibopen(L1); break; |
| 423 | case 's': lua_strlibopen(L1); break; | 423 | case l_c('s'): lua_strlibopen(L1); break; |
| 424 | case 'i': lua_iolibopen(L1); break; | 424 | case l_c('i'): lua_iolibopen(L1); break; |
| 425 | case 'd': lua_dblibopen(L1); break; | 425 | case l_c('d'): lua_dblibopen(L1); break; |
| 426 | case 'b': lua_baselibopen(L1); break; | 426 | case l_c('b'): lua_baselibopen(L1); break; |
| 427 | default: luaL_argerror(L, 2, "invalid option"); | 427 | default: luaL_argerror(L, 2, l_s("invalid option")); |
| 428 | } | 428 | } |
| 429 | return 0; | 429 | return 0; |
| 430 | } | 430 | } |
| @@ -438,7 +438,7 @@ static int closestate (lua_State *L) { | |||
| 438 | 438 | ||
| 439 | static int doremote (lua_State *L) { | 439 | static int doremote (lua_State *L) { |
| 440 | lua_State *L1; | 440 | lua_State *L1; |
| 441 | const char *code = luaL_check_string(L, 2); | 441 | const l_char *code = luaL_check_string(L, 2); |
| 442 | int status; | 442 | int status; |
| 443 | L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); | 443 | L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); |
| 444 | status = lua_dostring(L1, code); | 444 | status = lua_dostring(L1, code); |
| @@ -457,7 +457,7 @@ static int doremote (lua_State *L) { | |||
| 457 | 457 | ||
| 458 | static int settagmethod (lua_State *L) { | 458 | static int settagmethod (lua_State *L) { |
| 459 | int tag = luaL_check_int(L, 1); | 459 | int tag = luaL_check_int(L, 1); |
| 460 | const char *event = luaL_check_string(L, 2); | 460 | const l_char *event = luaL_check_string(L, 2); |
| 461 | luaL_checkany(L, 3); | 461 | luaL_checkany(L, 3); |
| 462 | lua_gettagmethod(L, tag, event); | 462 | lua_gettagmethod(L, tag, event); |
| 463 | lua_pushvalue(L, 3); | 463 | lua_pushvalue(L, 3); |
| @@ -478,36 +478,36 @@ static int equal (lua_State *L) { | |||
| 478 | ** ======================================================= | 478 | ** ======================================================= |
| 479 | */ | 479 | */ |
| 480 | 480 | ||
| 481 | static const char *const delimits = " \t\n,;"; | 481 | static const l_char *const delimits = l_s(" \t\n,;"); |
| 482 | 482 | ||
| 483 | static void skip (const char **pc) { | 483 | static void skip (const l_char **pc) { |
| 484 | while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; | 484 | while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++; |
| 485 | } | 485 | } |
| 486 | 486 | ||
| 487 | static int getnum (lua_State *L, const char **pc) { | 487 | static int getnum (lua_State *L, const l_char **pc) { |
| 488 | int res = 0; | 488 | int res = 0; |
| 489 | int sig = 1; | 489 | int sig = 1; |
| 490 | skip(pc); | 490 | skip(pc); |
| 491 | if (**pc == '.') { | 491 | if (**pc == l_c('.')) { |
| 492 | res = (int)lua_tonumber(L, -1); | 492 | res = (int)lua_tonumber(L, -1); |
| 493 | lua_pop(L, 1); | 493 | lua_pop(L, 1); |
| 494 | (*pc)++; | 494 | (*pc)++; |
| 495 | return res; | 495 | return res; |
| 496 | } | 496 | } |
| 497 | else if (**pc == '-') { | 497 | else if (**pc == l_c('-')) { |
| 498 | sig = -1; | 498 | sig = -1; |
| 499 | (*pc)++; | 499 | (*pc)++; |
| 500 | } | 500 | } |
| 501 | while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0'; | 501 | while (isdigit(**pc)) res = res*10 + (*(*pc)++) - l_c('0'); |
| 502 | return sig*res; | 502 | return sig*res; |
| 503 | } | 503 | } |
| 504 | 504 | ||
| 505 | static const char *getname (char *buff, const char **pc) { | 505 | static const l_char *getname (l_char *buff, const l_char **pc) { |
| 506 | int i = 0; | 506 | int i = 0; |
| 507 | skip(pc); | 507 | skip(pc); |
| 508 | while (**pc != '\0' && !strchr(delimits, **pc)) | 508 | while (**pc != l_c('\0') && !strchr(delimits, **pc)) |
| 509 | buff[i++] = *(*pc)++; | 509 | buff[i++] = *(*pc)++; |
| 510 | buff[i] = '\0'; | 510 | buff[i] = l_c('\0'); |
| 511 | return buff; | 511 | return buff; |
| 512 | } | 512 | } |
| 513 | 513 | ||
| @@ -519,121 +519,121 @@ static const char *getname (char *buff, const char **pc) { | |||
| 519 | 519 | ||
| 520 | 520 | ||
| 521 | static int testC (lua_State *L) { | 521 | static int testC (lua_State *L) { |
| 522 | char buff[30]; | 522 | l_char buff[30]; |
| 523 | const char *pc = luaL_check_string(L, 1); | 523 | const l_char *pc = luaL_check_string(L, 1); |
| 524 | for (;;) { | 524 | for (;;) { |
| 525 | const char *inst = getname; | 525 | const l_char *inst = getname; |
| 526 | if EQ("") return 0; | 526 | if EQ(l_s("")) return 0; |
| 527 | else if EQ("isnumber") { | 527 | else if EQ(l_s("isnumber")) { |
| 528 | lua_pushnumber(L, lua_isnumber(L, getnum)); | 528 | lua_pushnumber(L, lua_isnumber(L, getnum)); |
| 529 | } | 529 | } |
| 530 | else if EQ("isstring") { | 530 | else if EQ(l_s("isstring")) { |
| 531 | lua_pushnumber(L, lua_isstring(L, getnum)); | 531 | lua_pushnumber(L, lua_isstring(L, getnum)); |
| 532 | } | 532 | } |
| 533 | else if EQ("istable") { | 533 | else if EQ(l_s("istable")) { |
| 534 | lua_pushnumber(L, lua_istable(L, getnum)); | 534 | lua_pushnumber(L, lua_istable(L, getnum)); |
| 535 | } | 535 | } |
| 536 | else if EQ("iscfunction") { | 536 | else if EQ(l_s("iscfunction")) { |
| 537 | lua_pushnumber(L, lua_iscfunction(L, getnum)); | 537 | lua_pushnumber(L, lua_iscfunction(L, getnum)); |
| 538 | } | 538 | } |
| 539 | else if EQ("isfunction") { | 539 | else if EQ(l_s("isfunction")) { |
| 540 | lua_pushnumber(L, lua_isfunction(L, getnum)); | 540 | lua_pushnumber(L, lua_isfunction(L, getnum)); |
| 541 | } | 541 | } |
| 542 | else if EQ("isuserdata") { | 542 | else if EQ(l_s("isuserdata")) { |
| 543 | lua_pushnumber(L, lua_isuserdata(L, getnum)); | 543 | lua_pushnumber(L, lua_isuserdata(L, getnum)); |
| 544 | } | 544 | } |
| 545 | else if EQ("isnil") { | 545 | else if EQ(l_s("isnil")) { |
| 546 | lua_pushnumber(L, lua_isnil(L, getnum)); | 546 | lua_pushnumber(L, lua_isnil(L, getnum)); |
| 547 | } | 547 | } |
| 548 | else if EQ("isnull") { | 548 | else if EQ(l_s("isnull")) { |
| 549 | lua_pushnumber(L, lua_isnull(L, getnum)); | 549 | lua_pushnumber(L, lua_isnull(L, getnum)); |
| 550 | } | 550 | } |
| 551 | else if EQ("tonumber") { | 551 | else if EQ(l_s("tonumber")) { |
| 552 | lua_pushnumber(L, lua_tonumber(L, getnum)); | 552 | lua_pushnumber(L, lua_tonumber(L, getnum)); |
| 553 | } | 553 | } |
| 554 | else if EQ("tostring") { | 554 | else if EQ(l_s("tostring")) { |
| 555 | const char *s = lua_tostring(L, getnum); | 555 | const l_char *s = lua_tostring(L, getnum); |
| 556 | lua_pushstring(L, s); | 556 | lua_pushstring(L, s); |
| 557 | } | 557 | } |
| 558 | else if EQ("tonumber") { | 558 | else if EQ(l_s("tonumber")) { |
| 559 | lua_pushnumber(L, lua_tonumber(L, getnum)); | 559 | lua_pushnumber(L, lua_tonumber(L, getnum)); |
| 560 | } | 560 | } |
| 561 | else if EQ("strlen") { | 561 | else if EQ(l_s("strlen")) { |
| 562 | lua_pushnumber(L, lua_strlen(L, getnum)); | 562 | lua_pushnumber(L, lua_strlen(L, getnum)); |
| 563 | } | 563 | } |
| 564 | else if EQ("tocfunction") { | 564 | else if EQ(l_s("tocfunction")) { |
| 565 | lua_pushcfunction(L, lua_tocfunction(L, getnum)); | 565 | lua_pushcfunction(L, lua_tocfunction(L, getnum)); |
| 566 | } | 566 | } |
| 567 | else if EQ("return") { | 567 | else if EQ(l_s("return")) { |
| 568 | return getnum; | 568 | return getnum; |
| 569 | } | 569 | } |
| 570 | else if EQ("gettop") { | 570 | else if EQ(l_s("gettop")) { |
| 571 | lua_pushnumber(L, lua_gettop(L)); | 571 | lua_pushnumber(L, lua_gettop(L)); |
| 572 | } | 572 | } |
| 573 | else if EQ("settop") { | 573 | else if EQ(l_s("settop")) { |
| 574 | lua_settop(L, getnum); | 574 | lua_settop(L, getnum); |
| 575 | } | 575 | } |
| 576 | else if EQ("pop") { | 576 | else if EQ(l_s("pop")) { |
| 577 | lua_pop(L, getnum); | 577 | lua_pop(L, getnum); |
| 578 | } | 578 | } |
| 579 | else if EQ("pushnum") { | 579 | else if EQ(l_s("pushnum")) { |
| 580 | lua_pushnumber(L, getnum); | 580 | lua_pushnumber(L, getnum); |
| 581 | } | 581 | } |
| 582 | else if EQ("pushvalue") { | 582 | else if EQ(l_s("pushvalue")) { |
| 583 | lua_pushvalue(L, getnum); | 583 | lua_pushvalue(L, getnum); |
| 584 | } | 584 | } |
| 585 | else if EQ("remove") { | 585 | else if EQ(l_s("remove")) { |
| 586 | lua_remove(L, getnum); | 586 | lua_remove(L, getnum); |
| 587 | } | 587 | } |
| 588 | else if EQ("insert") { | 588 | else if EQ(l_s("insert")) { |
| 589 | lua_insert(L, getnum); | 589 | lua_insert(L, getnum); |
| 590 | } | 590 | } |
| 591 | else if EQ("gettable") { | 591 | else if EQ(l_s("gettable")) { |
| 592 | lua_gettable(L, getnum); | 592 | lua_gettable(L, getnum); |
| 593 | } | 593 | } |
| 594 | else if EQ("settable") { | 594 | else if EQ(l_s("settable")) { |
| 595 | lua_settable(L, getnum); | 595 | lua_settable(L, getnum); |
| 596 | } | 596 | } |
| 597 | else if EQ("next") { | 597 | else if EQ(l_s("next")) { |
| 598 | lua_next(L, -2); | 598 | lua_next(L, -2); |
| 599 | } | 599 | } |
| 600 | else if EQ("concat") { | 600 | else if EQ(l_s("concat")) { |
| 601 | lua_concat(L, getnum); | 601 | lua_concat(L, getnum); |
| 602 | } | 602 | } |
| 603 | else if EQ("lessthan") { | 603 | else if EQ(l_s("lessthan")) { |
| 604 | int a = getnum; | 604 | int a = getnum; |
| 605 | if (lua_lessthan(L, a, getnum)) | 605 | if (lua_lessthan(L, a, getnum)) |
| 606 | lua_pushnumber(L, 1); | 606 | lua_pushnumber(L, 1); |
| 607 | else | 607 | else |
| 608 | lua_pushnil(L); | 608 | lua_pushnil(L); |
| 609 | } | 609 | } |
| 610 | else if EQ("rawcall") { | 610 | else if EQ(l_s("rawcall")) { |
| 611 | int narg = getnum; | 611 | int narg = getnum; |
| 612 | int nres = getnum; | 612 | int nres = getnum; |
| 613 | lua_rawcall(L, narg, nres); | 613 | lua_rawcall(L, narg, nres); |
| 614 | } | 614 | } |
| 615 | else if EQ("call") { | 615 | else if EQ(l_s("call")) { |
| 616 | int narg = getnum; | 616 | int narg = getnum; |
| 617 | int nres = getnum; | 617 | int nres = getnum; |
| 618 | lua_call(L, narg, nres); | 618 | lua_call(L, narg, nres); |
| 619 | } | 619 | } |
| 620 | else if EQ("dostring") { | 620 | else if EQ(l_s("dostring")) { |
| 621 | lua_dostring(L, luaL_check_string(L, getnum)); | 621 | lua_dostring(L, luaL_check_string(L, getnum)); |
| 622 | } | 622 | } |
| 623 | else if EQ("settagmethod") { | 623 | else if EQ(l_s("settagmethod")) { |
| 624 | int tag = getnum; | 624 | int tag = getnum; |
| 625 | const char *event = getname; | 625 | const l_char *event = getname; |
| 626 | lua_settagmethod(L, tag, event); | 626 | lua_settagmethod(L, tag, event); |
| 627 | } | 627 | } |
| 628 | else if EQ("gettagmethod") { | 628 | else if EQ(l_s("gettagmethod")) { |
| 629 | int tag = getnum; | 629 | int tag = getnum; |
| 630 | const char *event = getname; | 630 | const l_char *event = getname; |
| 631 | lua_gettagmethod(L, tag, event); | 631 | lua_gettagmethod(L, tag, event); |
| 632 | } | 632 | } |
| 633 | else if EQ("type") { | 633 | else if EQ(l_s("type")) { |
| 634 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); | 634 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); |
| 635 | } | 635 | } |
| 636 | else luaL_verror(L, "unknown instruction %.30s", buff); | 636 | else luaL_verror(L, l_s("unknown instruction %.30s"), buff); |
| 637 | } | 637 | } |
| 638 | return 0; | 638 | return 0; |
| 639 | } | 639 | } |
| @@ -643,30 +643,30 @@ static int testC (lua_State *L) { | |||
| 643 | 643 | ||
| 644 | 644 | ||
| 645 | static const struct luaL_reg tests_funcs[] = { | 645 | static const struct luaL_reg tests_funcs[] = { |
| 646 | {"hash", hash_query}, | 646 | {l_s("hash"), hash_query}, |
| 647 | {"limits", get_limits}, | 647 | {l_s("limits"), get_limits}, |
| 648 | {"listcode", listcode}, | 648 | {l_s("listcode"), listcode}, |
| 649 | {"liststrings", liststrings}, | 649 | {l_s("liststrings"), liststrings}, |
| 650 | {"listlocals", listlocals}, | 650 | {l_s("listlocals"), listlocals}, |
| 651 | {"loadlib", loadlib}, | 651 | {l_s("loadlib"), loadlib}, |
| 652 | {"querystr", string_query}, | 652 | {l_s("querystr"), string_query}, |
| 653 | {"querytab", table_query}, | 653 | {l_s("querytab"), table_query}, |
| 654 | {"testC", testC}, | 654 | {l_s("testC"), testC}, |
| 655 | {"ref", tref}, | 655 | {l_s("ref"), tref}, |
| 656 | {"getref", getref}, | 656 | {l_s("getref"), getref}, |
| 657 | {"unref", unref}, | 657 | {l_s("unref"), unref}, |
| 658 | {"d2s", d2s}, | 658 | {l_s("d2s"), d2s}, |
| 659 | {"s2d", s2d}, | 659 | {l_s("s2d"), s2d}, |
| 660 | {"newuserdata", newuserdata}, | 660 | {l_s("newuserdata"), newuserdata}, |
| 661 | {"udataval", udataval}, | 661 | {l_s("udataval"), udataval}, |
| 662 | {"newtag", newtag}, | 662 | {l_s("newtag"), newtag}, |
| 663 | {"doonnewstack", doonnewstack}, | 663 | {l_s("doonnewstack"), doonnewstack}, |
| 664 | {"newstate", newstate}, | 664 | {l_s("newstate"), newstate}, |
| 665 | {"closestate", closestate}, | 665 | {l_s("closestate"), closestate}, |
| 666 | {"doremote", doremote}, | 666 | {l_s("doremote"), doremote}, |
| 667 | {"settagmethod", settagmethod}, | 667 | {l_s("settagmethod"), settagmethod}, |
| 668 | {"equal", equal}, | 668 | {l_s("equal"), equal}, |
| 669 | {"totalmem", mem_query} | 669 | {l_s("totalmem"), mem_query} |
| 670 | }; | 670 | }; |
| 671 | 671 | ||
| 672 | 672 | ||
| @@ -680,7 +680,7 @@ void luaB_opentests (lua_State *L) { | |||
| 680 | lua_setglobals(L); | 680 | lua_setglobals(L); |
| 681 | luaL_openl(L, tests_funcs); /* open functions inside new table */ | 681 | luaL_openl(L, tests_funcs); /* open functions inside new table */ |
| 682 | lua_setglobals(L); /* restore old table of globals */ | 682 | lua_setglobals(L); /* restore old table of globals */ |
| 683 | lua_setglobal(L, "T"); /* set new table as global T */ | 683 | lua_setglobal(L, l_s("T")); /* set new table as global T */ |
| 684 | } | 684 | } |
| 685 | 685 | ||
| 686 | #endif | 686 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.67 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.68 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,15 +19,15 @@ | |||
| 19 | #include "ltm.h" | 19 | #include "ltm.h" |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | const char *const luaT_eventname[] = { /* ORDER TM */ | 22 | const l_char *const luaT_eventname[] = { /* ORDER TM */ |
| 23 | "gettable", "settable", "index", "getglobal", "setglobal", "add", "sub", | 23 | l_s("gettable"), l_s("settable"), l_s("index"), l_s("getglobal"), l_s("setglobal"), l_s("add"), l_s("sub"), |
| 24 | "mul", "div", "pow", "unm", "lt", "concat", "gc", "function", | 24 | l_s("mul"), l_s("div"), l_s("pow"), l_s("unm"), l_s("lt"), l_s("concat"), l_s("gc"), l_s("function"), |
| 25 | "le", "gt", "ge", /* deprecated options!! */ | 25 | l_s("le"), l_s("gt"), l_s("ge"), /* deprecated options!! */ |
| 26 | NULL | 26 | NULL |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | static int findevent (const char *name) { | 30 | static int findevent (const l_char *name) { |
| 31 | int i; | 31 | int i; |
| 32 | for (i=0; luaT_eventname[i]; i++) | 32 | for (i=0; luaT_eventname[i]; i++) |
| 33 | if (strcmp(luaT_eventname[i], name) == 0) | 33 | if (strcmp(luaT_eventname[i], name) == 0) |
| @@ -36,14 +36,14 @@ static int findevent (const char *name) { | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | static int luaI_checkevent (lua_State *L, const char *name, int t) { | 39 | static int luaI_checkevent (lua_State *L, const l_char *name, int t) { |
| 40 | int e = findevent(name); | 40 | int e = findevent(name); |
| 41 | if (e >= TM_N) | 41 | if (e >= TM_N) |
| 42 | luaO_verror(L, "event `%.50s' is deprecated", name); | 42 | luaO_verror(L, l_s("event `%.50s' is deprecated"), name); |
| 43 | if (e == TM_GC && t == LUA_TTABLE) | 43 | if (e == TM_GC && t == LUA_TTABLE) |
| 44 | luaO_verror(L, "event `gc' for tables is deprecated"); | 44 | luaO_verror(L, l_s("event `gc' for tables is deprecated")); |
| 45 | if (e < 0) | 45 | if (e < 0) |
| 46 | luaO_verror(L, "`%.50s' is not a valid event name", name); | 46 | luaO_verror(L, l_s("`%.50s' is not a valid event name"), name); |
| 47 | return e; | 47 | return e; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| @@ -68,8 +68,8 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | |||
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | void luaT_init (lua_State *L) { | 70 | void luaT_init (lua_State *L) { |
| 71 | static const char *const typenames[NUM_TAGS] = { | 71 | static const l_char *const typenames[NUM_TAGS] = { |
| 72 | "userdata", "nil", "number", "string", "table", "function" | 72 | l_s("userdata"), l_s("nil"), l_s("number"), l_s("string"), l_s("table"), l_s("function") |
| 73 | }; | 73 | }; |
| 74 | int i; | 74 | int i; |
| 75 | for (i=0; i<NUM_TAGS; i++) | 75 | for (i=0; i<NUM_TAGS; i++) |
| @@ -77,12 +77,12 @@ void luaT_init (lua_State *L) { | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | int luaT_newtag (lua_State *L, const char *name, int basictype) { | 80 | int luaT_newtag (lua_State *L, const l_char *name, int basictype) { |
| 81 | int tag; | 81 | int tag; |
| 82 | int i; | 82 | int i; |
| 83 | TString *ts; | 83 | TString *ts; |
| 84 | luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, | 84 | luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, |
| 85 | MAX_INT, "tag table overflow"); | 85 | MAX_INT, l_s("tag table overflow")); |
| 86 | tag = G(L)->ntag; | 86 | tag = G(L)->ntag; |
| 87 | if (name == NULL) | 87 | if (name == NULL) |
| 88 | ts = NULL; | 88 | ts = NULL; |
| @@ -105,7 +105,7 @@ int luaT_newtag (lua_State *L, const char *name, int basictype) { | |||
| 105 | 105 | ||
| 106 | static void checktag (lua_State *L, int tag) { | 106 | static void checktag (lua_State *L, int tag) { |
| 107 | if (!(0 <= tag && tag < G(L)->ntag)) | 107 | if (!(0 <= tag && tag < G(L)->ntag)) |
| 108 | luaO_verror(L, "%d is not a valid tag", tag); | 108 | luaO_verror(L, l_s("%d is not a valid tag"), tag); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | 111 | ||
| @@ -133,7 +133,7 @@ int luaT_tag (const TObject *o) { | |||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | 135 | ||
| 136 | const char *luaT_typename (global_State *G, const TObject *o) { | 136 | const l_char *luaT_typename (global_State *G, const TObject *o) { |
| 137 | int t = ttype(o); | 137 | int t = ttype(o); |
| 138 | int tag; | 138 | int tag; |
| 139 | TString *ts; | 139 | TString *ts; |
| @@ -154,7 +154,7 @@ const char *luaT_typename (global_State *G, const TObject *o) { | |||
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | 156 | ||
| 157 | LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | 157 | LUA_API void lua_gettagmethod (lua_State *L, int t, const l_char *event) { |
| 158 | int e; | 158 | int e; |
| 159 | LUA_LOCK(L); | 159 | LUA_LOCK(L); |
| 160 | e = luaI_checkevent(L, event, t); | 160 | e = luaI_checkevent(L, event, t); |
| @@ -169,16 +169,16 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | |||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | 171 | ||
| 172 | LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { | 172 | LUA_API void lua_settagmethod (lua_State *L, int t, const l_char *event) { |
| 173 | int e; | 173 | int e; |
| 174 | LUA_LOCK(L); | 174 | LUA_LOCK(L); |
| 175 | e = luaI_checkevent(L, event, t); | 175 | e = luaI_checkevent(L, event, t); |
| 176 | checktag(L, t); | 176 | checktag(L, t); |
| 177 | if (!luaT_validevent(t, e)) | 177 | if (!luaT_validevent(t, e)) |
| 178 | luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", | 178 | luaO_verror(L, l_s("cannot change `%.20s' tag method for type `%.20s'%.20s"), |
| 179 | luaT_eventname[e], basictypename(G(L), t), | 179 | luaT_eventname[e], basictypename(G(L), t), |
| 180 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? | 180 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? |
| 181 | " with default tag" : ""); | 181 | l_s(" with default tag") : l_s("")); |
| 182 | switch (ttype(L->top - 1)) { | 182 | switch (ttype(L->top - 1)) { |
| 183 | case LUA_TNIL: | 183 | case LUA_TNIL: |
| 184 | luaT_gettm(G(L), t, e) = NULL; | 184 | luaT_gettm(G(L), t, e) = NULL; |
| @@ -187,7 +187,7 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { | |||
| 187 | luaT_gettm(G(L), t, e) = clvalue(L->top - 1); | 187 | luaT_gettm(G(L), t, e) = clvalue(L->top - 1); |
| 188 | break; | 188 | break; |
| 189 | default: | 189 | default: |
| 190 | luaD_error(L, "tag method must be a function (or nil)"); | 190 | luaD_error(L, l_s("tag method must be a function (or nil)")); |
| 191 | } | 191 | } |
| 192 | L->top--; | 192 | L->top--; |
| 193 | LUA_UNLOCK(L); | 193 | LUA_UNLOCK(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 1.22 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.23 2001/02/09 20:22:29 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -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 char *const luaT_eventname[]; | 70 | extern const l_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 char *name, int basictype); | 74 | int luaT_newtag (lua_State *L, const l_char *name, int basictype); |
| 75 | const char *luaT_typename (global_State *G, const TObject *o); | 75 | const l_char *luaT_typename (global_State *G, const TObject *o); |
| 76 | int luaT_tag (const TObject *o); | 76 | int luaT_tag (const TObject *o); |
| 77 | int luaT_validevent (int t, int e); /* used by compatibility module */ | 77 | int luaT_validevent (int t, int e); /* used by compatibility module */ |
| 78 | 78 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.60 2001/02/14 17:19:01 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.61 2001/02/20 18:15:33 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -25,7 +25,7 @@ static int isatty (int x) { return x==0; } /* assume stdin is a tty */ | |||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | #ifndef PROMPT | 27 | #ifndef PROMPT |
| 28 | #define PROMPT "> " | 28 | #define PROMPT l_s("> ") |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | 31 | ||
| @@ -70,7 +70,7 @@ static void lstop (void) { | |||
| 70 | lua_setlinehook(L, old_linehook); | 70 | lua_setlinehook(L, old_linehook); |
| 71 | lua_setcallhook(L, old_callhook); | 71 | lua_setcallhook(L, old_callhook); |
| 72 | lreset(); | 72 | lreset(); |
| 73 | lua_error(L, "interrupted!"); | 73 | lua_error(L, l_s("interrupted!")); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | 76 | ||
| @@ -83,7 +83,7 @@ static void laction (int i) { | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | static int ldo (int (*f)(lua_State *l, const char *), const char *name) { | 86 | static int ldo (int (*f)(lua_State *l, const l_char *), const l_char *name) { |
| 87 | int res; | 87 | int res; |
| 88 | handler h = lreset(); | 88 | handler h = lreset(); |
| 89 | int top = lua_gettop(L); | 89 | int top = lua_gettop(L); |
| @@ -92,45 +92,45 @@ static int ldo (int (*f)(lua_State *l, const char *), const char *name) { | |||
| 92 | signal(SIGINT, h); /* restore old action */ | 92 | signal(SIGINT, h); /* restore old action */ |
| 93 | /* Lua gives no message in such cases, so lua.c provides one */ | 93 | /* Lua gives no message in such cases, so lua.c provides one */ |
| 94 | if (res == LUA_ERRMEM) { | 94 | if (res == LUA_ERRMEM) { |
| 95 | fprintf(stderr, "lua: memory allocation error\n"); | 95 | fprintf(stderr, l_s("lua: memory allocation error\n")); |
| 96 | } | 96 | } |
| 97 | else if (res == LUA_ERRERR) | 97 | else if (res == LUA_ERRERR) |
| 98 | fprintf(stderr, "lua: error in error message\n"); | 98 | fprintf(stderr, l_s("lua: error in error message\n")); |
| 99 | return res; | 99 | return res; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | static void print_message (void) { | 103 | static void print_message (void) { |
| 104 | fprintf(stderr, | 104 | fprintf(stderr, |
| 105 | "usage: lua [options]. Available options are:\n" | 105 | l_s("usage: lua [options]. Available options are:\n") |
| 106 | " - execute stdin as a file\n" | 106 | l_s(" - execute stdin as a file\n") |
| 107 | " -c close Lua when exiting\n" | 107 | l_s(" -c close Lua when exiting\n") |
| 108 | " -e stat execute string `stat'\n" | 108 | l_s(" -e stat execute string `stat'\n") |
| 109 | " -f name execute file `name' with remaining arguments in table `arg'\n" | 109 | l_s(" -f name execute file `name' with remaining arguments in table `arg'\n") |
| 110 | " -i enter interactive mode with prompt\n" | 110 | l_s(" -i enter interactive mode with prompt\n") |
| 111 | " -q enter interactive mode without prompt\n" | 111 | l_s(" -q enter interactive mode without prompt\n") |
| 112 | " -sNUM set stack size to NUM (must be the first option)\n" | 112 | l_s(" -sNUM set stack size to NUM (must be the first option)\n") |
| 113 | " -v print version information\n" | 113 | l_s(" -v print version information\n") |
| 114 | " a=b set global `a' to string `b'\n" | 114 | l_s(" a=b set global `a' to string `b'\n") |
| 115 | " name execute file `name'\n" | 115 | l_s(" name execute file `name'\n") |
| 116 | ); | 116 | ); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | static void print_version (void) { | 120 | static void print_version (void) { |
| 121 | printf("%.80s %.80s\n", LUA_VERSION, LUA_COPYRIGHT); | 121 | printf(l_s("%.80s %.80s\n"), l_s(LUA_VERSION), l_s(LUA_COPYRIGHT)); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | 124 | ||
| 125 | static void assign (char *arg) { | 125 | static void assign (l_char *arg) { |
| 126 | char *eq = strchr(arg, '='); | 126 | l_char *eq = strchr(arg, l_c('=')); |
| 127 | *eq = '\0'; /* spilt `arg' in two strings (name & value) */ | 127 | *eq = l_c('\0'); /* spilt `arg' in two strings (name & value) */ |
| 128 | lua_pushstring(L, eq+1); | 128 | lua_pushstring(L, eq+1); |
| 129 | lua_setglobal(L, arg); | 129 | lua_setglobal(L, arg); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | 132 | ||
| 133 | static void getargs (char *argv[]) { | 133 | static void getargs (l_char *argv[]) { |
| 134 | int i; | 134 | int i; |
| 135 | lua_newtable(L); | 135 | lua_newtable(L); |
| 136 | for (i=0; argv[i]; i++) { | 136 | for (i=0; argv[i]; i++) { |
| @@ -140,24 +140,24 @@ static void getargs (char *argv[]) { | |||
| 140 | lua_settable(L, -3); | 140 | lua_settable(L, -3); |
| 141 | } | 141 | } |
| 142 | /* arg.n = maximum index in table `arg' */ | 142 | /* arg.n = maximum index in table `arg' */ |
| 143 | lua_pushliteral(L, "n"); | 143 | lua_pushliteral(L, l_s("n")); |
| 144 | lua_pushnumber(L, i-1); | 144 | lua_pushnumber(L, i-1); |
| 145 | lua_settable(L, -3); | 145 | lua_settable(L, -3); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | 148 | ||
| 149 | static int l_getargs (lua_State *l) { | 149 | static int l_getargs (lua_State *l) { |
| 150 | char **argv = (char **)lua_touserdata(l, -1); | 150 | l_char **argv = (l_char **)lua_touserdata(l, -1); |
| 151 | getargs(argv); | 151 | getargs(argv); |
| 152 | return 1; | 152 | return 1; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | 155 | ||
| 156 | static int file_input (const char *argv) { | 156 | static int file_input (const l_char *argv) { |
| 157 | int result = ldo(lua_dofile, argv); | 157 | int result = ldo(lua_dofile, argv); |
| 158 | if (result) { | 158 | if (result) { |
| 159 | if (result == LUA_ERRFILE) { | 159 | if (result == LUA_ERRFILE) { |
| 160 | fprintf(stderr, "lua: cannot execute file "); | 160 | fprintf(stderr, l_s("lua: cannot execute file ")); |
| 161 | perror(argv); | 161 | perror(argv); |
| 162 | } | 162 | } |
| 163 | return EXIT_FAILURE; | 163 | return EXIT_FAILURE; |
| @@ -173,12 +173,12 @@ static int file_input (const char *argv) { | |||
| 173 | #endif | 173 | #endif |
| 174 | 174 | ||
| 175 | 175 | ||
| 176 | static const char *get_prompt (int prompt) { | 176 | static const l_char *get_prompt (int prompt) { |
| 177 | if (!prompt) | 177 | if (!prompt) |
| 178 | return ""; | 178 | return l_s(""); |
| 179 | else { | 179 | else { |
| 180 | const char *s; | 180 | const l_char *s; |
| 181 | lua_getglobal(L, "_PROMPT"); | 181 | lua_getglobal(L, l_s("_PROMPT")); |
| 182 | s = lua_tostring(L, -1); | 182 | s = lua_tostring(L, -1); |
| 183 | if (!s) s = PROMPT; | 183 | if (!s) s = PROMPT; |
| 184 | lua_pop(L, 1); /* remove global */ | 184 | lua_pop(L, 1); /* remove global */ |
| @@ -192,15 +192,15 @@ static void manual_input (int version, int prompt) { | |||
| 192 | for (;;) { | 192 | for (;;) { |
| 193 | fputs(get_prompt(prompt), stdout); /* show prompt */ | 193 | fputs(get_prompt(prompt), stdout); /* show prompt */ |
| 194 | for(;;) { | 194 | for(;;) { |
| 195 | char buffer[MAXINPUT]; | 195 | l_char buffer[MAXINPUT]; |
| 196 | size_t l; | 196 | size_t l; |
| 197 | if (fgets(buffer, sizeof(buffer), stdin) == NULL) { | 197 | if (fgets(buffer, sizeof(buffer), stdin) == NULL) { |
| 198 | printf("\n"); | 198 | printf(l_s("\n")); |
| 199 | return; | 199 | return; |
| 200 | } | 200 | } |
| 201 | l = strlen(buffer); | 201 | l = strlen(buffer); |
| 202 | if (buffer[l-1] == '\n' && buffer[l-2] == '\\') { | 202 | if (buffer[l-1] == l_c('\n') && buffer[l-2] == l_c('\\')) { |
| 203 | buffer[l-2] = '\n'; | 203 | buffer[l-2] = l_c('\n'); |
| 204 | lua_pushlstring(L, buffer, l-1); | 204 | lua_pushlstring(L, buffer, l-1); |
| 205 | } | 205 | } |
| 206 | else { | 206 | else { |
| @@ -215,7 +215,7 @@ static void manual_input (int version, int prompt) { | |||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | 217 | ||
| 218 | static int handle_argv (char *argv[], struct Options *opt) { | 218 | static int handle_argv (l_char *argv[], struct Options *opt) { |
| 219 | if (opt->stacksize > 0) argv++; /* skip option `-s' (if present) */ | 219 | if (opt->stacksize > 0) argv++; /* skip option `-s' (if present) */ |
| 220 | if (*argv == NULL) { /* no more arguments? */ | 220 | if (*argv == NULL) { /* no more arguments? */ |
| 221 | if (isatty(0)) { | 221 | if (isatty(0)) { |
| @@ -227,8 +227,8 @@ static int handle_argv (char *argv[], struct Options *opt) { | |||
| 227 | else { /* other arguments; loop over them */ | 227 | else { /* other arguments; loop over them */ |
| 228 | int i; | 228 | int i; |
| 229 | for (i = 0; argv[i] != NULL; i++) { | 229 | for (i = 0; argv[i] != NULL; i++) { |
| 230 | if (argv[i][0] != '-') { /* not an option? */ | 230 | if (argv[i][0] != l_c('-')) { /* not an option? */ |
| 231 | if (strchr(argv[i], '=')) | 231 | if (strchr(argv[i], l_c('='))) |
| 232 | assign(argv[i]); | 232 | assign(argv[i]); |
| 233 | else | 233 | else |
| 234 | if (file_input(argv[i]) != EXIT_SUCCESS) | 234 | if (file_input(argv[i]) != EXIT_SUCCESS) |
| @@ -239,46 +239,46 @@ static int handle_argv (char *argv[], struct Options *opt) { | |||
| 239 | ldo(lua_dofile, NULL); /* executes stdin as a file */ | 239 | ldo(lua_dofile, NULL); /* executes stdin as a file */ |
| 240 | break; | 240 | break; |
| 241 | } | 241 | } |
| 242 | case 'i': { | 242 | case l_c('i'): { |
| 243 | manual_input(0, 1); | 243 | manual_input(0, 1); |
| 244 | break; | 244 | break; |
| 245 | } | 245 | } |
| 246 | case 'q': { | 246 | case l_c('q'): { |
| 247 | manual_input(0, 0); | 247 | manual_input(0, 0); |
| 248 | break; | 248 | break; |
| 249 | } | 249 | } |
| 250 | case 'c': { | 250 | case l_c('c'): { |
| 251 | opt->toclose = 1; | 251 | opt->toclose = 1; |
| 252 | break; | 252 | break; |
| 253 | } | 253 | } |
| 254 | case 'v': { | 254 | case l_c('v'): { |
| 255 | print_version(); | 255 | print_version(); |
| 256 | break; | 256 | break; |
| 257 | } | 257 | } |
| 258 | case 'e': { | 258 | case l_c('e'): { |
| 259 | i++; | 259 | i++; |
| 260 | if (argv[i] == NULL) { | 260 | if (argv[i] == NULL) { |
| 261 | print_message(); | 261 | print_message(); |
| 262 | return EXIT_FAILURE; | 262 | return EXIT_FAILURE; |
| 263 | } | 263 | } |
| 264 | if (ldo(lua_dostring, argv[i]) != 0) { | 264 | if (ldo(lua_dostring, argv[i]) != 0) { |
| 265 | fprintf(stderr, "lua: error running argument `%.99s'\n", argv[i]); | 265 | fprintf(stderr, l_s("lua: error running argument `%.99s'\n"), argv[i]); |
| 266 | return EXIT_FAILURE; | 266 | return EXIT_FAILURE; |
| 267 | } | 267 | } |
| 268 | break; | 268 | break; |
| 269 | } | 269 | } |
| 270 | case 'f': { | 270 | case l_c('f'): { |
| 271 | i++; | 271 | i++; |
| 272 | if (argv[i] == NULL) { | 272 | if (argv[i] == NULL) { |
| 273 | print_message(); | 273 | print_message(); |
| 274 | return EXIT_FAILURE; | 274 | return EXIT_FAILURE; |
| 275 | } | 275 | } |
| 276 | getargs(argv+i); /* collect remaining arguments */ | 276 | getargs(argv+i); /* collect remaining arguments */ |
| 277 | lua_setglobal(L, "arg"); | 277 | lua_setglobal(L, l_s("arg")); |
| 278 | return file_input(argv[i]); /* stop scanning arguments */ | 278 | return file_input(argv[i]); /* stop scanning arguments */ |
| 279 | } | 279 | } |
| 280 | case 's': { | 280 | case l_c('s'): { |
| 281 | fprintf(stderr, "lua: stack size (`-s') must be the first option\n"); | 281 | fprintf(stderr, l_s("lua: stack size (`-s') must be the first option\n")); |
| 282 | return EXIT_FAILURE; | 282 | return EXIT_FAILURE; |
| 283 | } | 283 | } |
| 284 | default: { | 284 | default: { |
| @@ -292,11 +292,11 @@ static int handle_argv (char *argv[], struct Options *opt) { | |||
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | 294 | ||
| 295 | static void getstacksize (int argc, char *argv[], struct Options *opt) { | 295 | static void getstacksize (int argc, l_char *argv[], struct Options *opt) { |
| 296 | if (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 's') { | 296 | if (argc >= 2 && argv[1][0] == l_c('-') && argv[1][1] == l_c('s')) { |
| 297 | int stacksize = atoi(&argv[1][2]); | 297 | int stacksize = atoi(&argv[1][2]); |
| 298 | if (stacksize <= 0) { | 298 | if (stacksize <= 0) { |
| 299 | fprintf(stderr, "lua: invalid stack size ('%.20s')\n", &argv[1][2]); | 299 | fprintf(stderr, l_s("lua: invalid stack size ('%.20s')\n"), &argv[1][2]); |
| 300 | exit(EXIT_FAILURE); | 300 | exit(EXIT_FAILURE); |
| 301 | } | 301 | } |
| 302 | opt->stacksize = stacksize; | 302 | opt->stacksize = stacksize; |
| @@ -306,10 +306,10 @@ static void getstacksize (int argc, char *argv[], struct Options *opt) { | |||
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | 308 | ||
| 309 | static void register_getargs (char *argv[]) { | 309 | static void register_getargs (l_char *argv[]) { |
| 310 | lua_pushuserdata(L, argv); | 310 | lua_pushuserdata(L, argv); |
| 311 | lua_pushcclosure(L, l_getargs, 1); | 311 | lua_pushcclosure(L, l_getargs, 1); |
| 312 | lua_setglobal(L, "getargs"); | 312 | lua_setglobal(L, l_s("getargs")); |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | 315 | ||
| @@ -322,7 +322,7 @@ static void openstdlibs (lua_State *l) { | |||
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | 324 | ||
| 325 | int main (int argc, char *argv[]) { | 325 | int main (int argc, l_char *argv[]) { |
| 326 | struct Options opt; | 326 | struct Options opt; |
| 327 | int status; | 327 | int status; |
| 328 | opt.toclose = 0; | 328 | opt.toclose = 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.87 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.88 2001/02/22 17:15:18 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
| 5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
| @@ -79,6 +79,8 @@ typedef int (*lua_CFunction) (lua_State *L); | |||
| 79 | /* Lua numerical type */ | 79 | /* Lua numerical type */ |
| 80 | typedef double lua_Number; | 80 | typedef double lua_Number; |
| 81 | 81 | ||
| 82 | /* Lua character type */ | ||
| 83 | typedef char l_char; | ||
| 82 | 84 | ||
| 83 | 85 | ||
| 84 | /* mark for all API functions */ | 86 | /* mark for all API functions */ |
| @@ -111,8 +113,8 @@ LUA_API int lua_stackspace (lua_State *L); | |||
| 111 | */ | 113 | */ |
| 112 | 114 | ||
| 113 | LUA_API int lua_type (lua_State *L, int index); | 115 | LUA_API int lua_type (lua_State *L, int index); |
| 114 | LUA_API const char *lua_typename (lua_State *L, int t); | 116 | LUA_API const l_char *lua_typename (lua_State *L, int t); |
| 115 | LUA_API const char *lua_xtype (lua_State *L, int index); | 117 | LUA_API const l_char *lua_xtype (lua_State *L, int index); |
| 116 | LUA_API int lua_isnumber (lua_State *L, int index); | 118 | LUA_API int lua_isnumber (lua_State *L, int index); |
| 117 | LUA_API int lua_isstring (lua_State *L, int index); | 119 | LUA_API int lua_isstring (lua_State *L, int index); |
| 118 | LUA_API int lua_iscfunction (lua_State *L, int index); | 120 | LUA_API int lua_iscfunction (lua_State *L, int index); |
| @@ -122,7 +124,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2); | |||
| 122 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2); | 124 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2); |
| 123 | 125 | ||
| 124 | LUA_API lua_Number lua_tonumber (lua_State *L, int index); | 126 | LUA_API lua_Number lua_tonumber (lua_State *L, int index); |
| 125 | LUA_API const char *lua_tostring (lua_State *L, int index); | 127 | LUA_API const l_char *lua_tostring (lua_State *L, int index); |
| 126 | LUA_API size_t lua_strlen (lua_State *L, int index); | 128 | LUA_API size_t lua_strlen (lua_State *L, int index); |
| 127 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index); | 129 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index); |
| 128 | LUA_API void *lua_touserdata (lua_State *L, int index); | 130 | LUA_API void *lua_touserdata (lua_State *L, int index); |
| @@ -134,8 +136,8 @@ LUA_API const void *lua_topointer (lua_State *L, int index); | |||
| 134 | */ | 136 | */ |
| 135 | LUA_API void lua_pushnil (lua_State *L); | 137 | LUA_API void lua_pushnil (lua_State *L); |
| 136 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n); | 138 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n); |
| 137 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); | 139 | LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len); |
| 138 | LUA_API void lua_pushstring (lua_State *L, const char *s); | 140 | LUA_API void lua_pushstring (lua_State *L, const l_char *s); |
| 139 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); | 141 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
| 140 | LUA_API int lua_pushuserdata (lua_State *L, void *u); | 142 | LUA_API int lua_pushuserdata (lua_State *L, void *u); |
| 141 | 143 | ||
| @@ -143,12 +145,12 @@ LUA_API int lua_pushuserdata (lua_State *L, void *u); | |||
| 143 | /* | 145 | /* |
| 144 | ** get functions (Lua -> stack) | 146 | ** get functions (Lua -> stack) |
| 145 | */ | 147 | */ |
| 146 | LUA_API void lua_getglobal (lua_State *L, const char *name); | 148 | LUA_API void lua_getglobal (lua_State *L, const l_char *name); |
| 147 | LUA_API void lua_gettable (lua_State *L, int index); | 149 | LUA_API void lua_gettable (lua_State *L, int index); |
| 148 | LUA_API void lua_rawget (lua_State *L, int index); | 150 | LUA_API void lua_rawget (lua_State *L, int index); |
| 149 | LUA_API void lua_rawgeti (lua_State *L, int index, int n); | 151 | LUA_API void lua_rawgeti (lua_State *L, int index, int n); |
| 150 | LUA_API void lua_getglobals (lua_State *L); | 152 | LUA_API void lua_getglobals (lua_State *L); |
| 151 | LUA_API void lua_gettagmethod (lua_State *L, int tag, const char *event); | 153 | LUA_API void lua_gettagmethod (lua_State *L, int tag, const l_char *event); |
| 152 | LUA_API int lua_getref (lua_State *L, int ref); | 154 | LUA_API int lua_getref (lua_State *L, int ref); |
| 153 | LUA_API void lua_newtable (lua_State *L); | 155 | LUA_API void lua_newtable (lua_State *L); |
| 154 | 156 | ||
| @@ -156,23 +158,24 @@ LUA_API void lua_newtable (lua_State *L); | |||
| 156 | /* | 158 | /* |
| 157 | ** set functions (stack -> Lua) | 159 | ** set functions (stack -> Lua) |
| 158 | */ | 160 | */ |
| 159 | LUA_API void lua_setglobal (lua_State *L, const char *name); | 161 | LUA_API void lua_setglobal (lua_State *L, const l_char *name); |
| 160 | LUA_API void lua_settable (lua_State *L, int index); | 162 | LUA_API void lua_settable (lua_State *L, int index); |
| 161 | LUA_API void lua_rawset (lua_State *L, int index); | 163 | LUA_API void lua_rawset (lua_State *L, int index); |
| 162 | LUA_API void lua_rawseti (lua_State *L, int index, int n); | 164 | LUA_API void lua_rawseti (lua_State *L, int index, int n); |
| 163 | LUA_API void lua_setglobals (lua_State *L); | 165 | LUA_API void lua_setglobals (lua_State *L); |
| 164 | LUA_API void lua_settagmethod (lua_State *L, int tag, const char *event); | 166 | LUA_API void lua_settagmethod (lua_State *L, int tag, const l_char *event); |
| 165 | LUA_API int lua_ref (lua_State *L, int lock); | 167 | LUA_API int lua_ref (lua_State *L, int lock); |
| 166 | 168 | ||
| 167 | 169 | ||
| 168 | /* | 170 | /* |
| 169 | ** "do" functions (run Lua code) | 171 | ** `do' functions (run Lua code) |
| 170 | */ | 172 | */ |
| 171 | LUA_API int lua_call (lua_State *L, int nargs, int nresults); | 173 | LUA_API int lua_call (lua_State *L, int nargs, int nresults); |
| 172 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); | 174 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); |
| 173 | LUA_API int lua_dofile (lua_State *L, const char *filename); | 175 | LUA_API int lua_dofile (lua_State *L, const l_char *filename); |
| 174 | LUA_API int lua_dostring (lua_State *L, const char *str); | 176 | LUA_API int lua_dostring (lua_State *L, const l_char *str); |
| 175 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name); | 177 | LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, |
| 178 | const l_char *name); | ||
| 176 | 179 | ||
| 177 | /* | 180 | /* |
| 178 | ** Garbage-collection functions | 181 | ** Garbage-collection functions |
| @@ -184,12 +187,12 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold); | |||
| 184 | /* | 187 | /* |
| 185 | ** miscellaneous functions | 188 | ** miscellaneous functions |
| 186 | */ | 189 | */ |
| 187 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype); | 190 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype); |
| 188 | LUA_API int lua_type2tag (lua_State *L, const char *name); | 191 | LUA_API int lua_type2tag (lua_State *L, const l_char *name); |
| 189 | LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); | 192 | LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); |
| 190 | LUA_API void lua_settag (lua_State *L, int tag); | 193 | LUA_API void lua_settag (lua_State *L, int tag); |
| 191 | 194 | ||
| 192 | LUA_API void lua_error (lua_State *L, const char *s); | 195 | LUA_API void lua_error (lua_State *L, const l_char *s); |
| 193 | 196 | ||
| 194 | LUA_API void lua_unref (lua_State *L, int ref); | 197 | LUA_API void lua_unref (lua_State *L, int ref); |
| 195 | 198 | ||
| @@ -222,8 +225,8 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size); | |||
| 222 | 225 | ||
| 223 | #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY) | 226 | #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY) |
| 224 | 227 | ||
| 225 | #define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \ | 228 | #define lua_pushliteral(L, s) lua_pushlstring(L, l_s("") s, \ |
| 226 | (sizeof(s)/sizeof(char))-1) | 229 | (sizeof(s)/sizeof(l_char))-1) |
| 227 | 230 | ||
| 228 | 231 | ||
| 229 | 232 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luadebug.h,v 1.16 2000/10/20 16:39:03 roberto Exp roberto $ | 2 | ** $Id: luadebug.h,v 1.17 2000/10/30 12:38:50 roberto Exp roberto $ |
| 3 | ** Debugging API | 3 | ** Debugging API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -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 char *what, lua_Debug *ar); | 21 | LUA_API int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar); |
| 22 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); | 22 | LUA_API const l_char *lua_getlocal (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); | 23 | LUA_API const l_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 char *event; /* `call', `return' */ | 32 | const l_char *event; /* `call', `return' */ |
| 33 | int currentline; /* (l) */ | 33 | int currentline; /* (l) */ |
| 34 | const char *name; /* (n) */ | 34 | const l_char *name; /* (n) */ |
| 35 | const char *namewhat; /* (n) `global', `tag method', `local', `field' */ | 35 | const l_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 char *what; /* (S) `Lua' function, `C' function, Lua `main' */ | 38 | const l_char *what; /* (S) `Lua' function, `C' function, Lua `main' */ |
| 39 | const char *source; /* (S) */ | 39 | const l_char *source; /* (S) */ |
| 40 | char short_src[LUA_IDSIZE]; /* (S) */ | 40 | l_char short_src[LUA_IDSIZE]; /* (S) */ |
| 41 | /* private part */ | 41 | /* private part */ |
| 42 | struct lua_TObject *_func; /* active function */ | 42 | struct lua_TObject *_func; /* active function */ |
| 43 | }; | 43 | }; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lualib.h,v 1.15 2000/11/23 13:49:35 roberto Exp roberto $ | 2 | ** $Id: lualib.h,v 1.16 2001/02/22 17:15:18 roberto Exp roberto $ |
| 3 | ** Lua standard libraries | 3 | ** Lua standard libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -36,4 +36,14 @@ LUALIB_API void lua_dblibopen (lua_State *L); | |||
| 36 | /* integer type to hold the result of fgetc */ | 36 | /* integer type to hold the result of fgetc */ |
| 37 | typedef int l_charint; | 37 | typedef int l_charint; |
| 38 | 38 | ||
| 39 | /* macro to control type of literal strings */ | ||
| 40 | #ifndef l_s | ||
| 41 | #define l_s(x) x | ||
| 42 | #endif | ||
| 43 | |||
| 44 | /* macro to control type of literal chars */ | ||
| 45 | #ifndef l_c | ||
| 46 | #define l_c(x) x | ||
| 47 | #endif | ||
| 48 | |||
| 39 | #endif | 49 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 1.37 2000/12/28 12:59:41 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 1.38 2001/01/15 16:13:24 roberto Exp roberto $ |
| 3 | ** load bytecodes from files | 3 | ** load bytecodes from files |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -15,15 +15,15 @@ | |||
| 15 | 15 | ||
| 16 | #define LoadByte ezgetc | 16 | #define LoadByte ezgetc |
| 17 | 17 | ||
| 18 | static const char* ZNAME (ZIO* Z) | 18 | static const l_char* ZNAME (ZIO* Z) |
| 19 | { | 19 | { |
| 20 | const char* s=zname(Z); | 20 | const l_char* s=zname(Z); |
| 21 | return (*s=='@') ? s+1 : s; | 21 | return (*s==l_c('@')) ? s+1 : s; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | static void unexpectedEOZ (lua_State* L, ZIO* Z) | 24 | static void unexpectedEOZ (lua_State* L, ZIO* Z) |
| 25 | { | 25 | { |
| 26 | luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z)); | 26 | luaO_verror(L,l_s("unexpected end of file in `%.99s'"),ZNAME(Z)); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | static int ezgetc (lua_State* L, ZIO* Z) | 29 | static int ezgetc (lua_State* L, ZIO* Z) |
| @@ -43,9 +43,9 @@ static void LoadBlock (lua_State* L, void* b, size_t size, ZIO* Z, int swap) | |||
| 43 | { | 43 | { |
| 44 | if (swap) | 44 | if (swap) |
| 45 | { | 45 | { |
| 46 | char *p=(char *) b+size-1; | 46 | l_char *p=(l_char *) b+size-1; |
| 47 | int n=size; | 47 | int n=size; |
| 48 | while (n--) *p--=(char)ezgetc(L,Z); | 48 | while (n--) *p--=(l_char)ezgetc(L,Z); |
| 49 | } | 49 | } |
| 50 | else | 50 | else |
| 51 | ezread(L,Z,b,size); | 51 | ezread(L,Z,b,size); |
| @@ -55,12 +55,12 @@ static void LoadVector (lua_State* L, void* b, int m, size_t size, ZIO* Z, int s | |||
| 55 | { | 55 | { |
| 56 | if (swap) | 56 | if (swap) |
| 57 | { | 57 | { |
| 58 | char *q=(char *) b; | 58 | l_char *q=(l_char *) b; |
| 59 | while (m--) | 59 | while (m--) |
| 60 | { | 60 | { |
| 61 | char *p=q+size-1; | 61 | l_char *p=q+size-1; |
| 62 | int n=size; | 62 | int n=size; |
| 63 | while (n--) *p--=(char)ezgetc(L,Z); | 63 | while (n--) *p--=(l_char)ezgetc(L,Z); |
| 64 | q+=size; | 64 | q+=size; |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| @@ -96,9 +96,9 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap) | |||
| 96 | return NULL; | 96 | return NULL; |
| 97 | else | 97 | else |
| 98 | { | 98 | { |
| 99 | char* s=luaO_openspace(L,size); | 99 | l_char* s=luaO_openspace(L,size); |
| 100 | LoadBlock(L,s,size,Z,0); | 100 | LoadBlock(L,s,size,Z,0); |
| 101 | return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ | 101 | return luaS_newlstr(L,s,size-1); /* remove trailing l_c('\0') */ |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| @@ -171,18 +171,18 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap) | |||
| 171 | 171 | ||
| 172 | static void LoadSignature (lua_State* L, ZIO* Z) | 172 | static void LoadSignature (lua_State* L, ZIO* Z) |
| 173 | { | 173 | { |
| 174 | const char* s=SIGNATURE; | 174 | const l_char* s=SIGNATURE; |
| 175 | while (*s!=0 && ezgetc(L,Z)==*s) | 175 | while (*s!=0 && ezgetc(L,Z)==*s) |
| 176 | ++s; | 176 | ++s; |
| 177 | if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z)); | 177 | if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z)); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) | 180 | static void TestSize (lua_State* L, int s, const l_char* what, ZIO* Z) |
| 181 | { | 181 | { |
| 182 | int r=ezgetc(L,Z); | 182 | int r=ezgetc(L,Z); |
| 183 | if (r!=s) | 183 | if (r!=s) |
| 184 | luaO_verror(L,"virtual machine mismatch in `%.99s':\n" | 184 | luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n") |
| 185 | " %.20s is %d but read %d",ZNAME(Z),what,s,r); | 185 | l_s(" %.20s is %d but read %d"),ZNAME(Z),what,s,r); |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | #define TESTSIZE(s) TestSize(L,s,#s,Z) | 188 | #define TESTSIZE(s) TestSize(L,s,#s,Z) |
| @@ -195,12 +195,12 @@ static int LoadHeader (lua_State* L, ZIO* Z) | |||
| 195 | LoadSignature(L,Z); | 195 | LoadSignature(L,Z); |
| 196 | version=ezgetc(L,Z); | 196 | version=ezgetc(L,Z); |
| 197 | if (version>VERSION) | 197 | if (version>VERSION) |
| 198 | luaO_verror(L,"`%.99s' too new:\n" | 198 | luaO_verror(L,l_s("`%.99s' too new:\n") |
| 199 | " read version %d.%d; expected at most %d.%d", | 199 | l_s(" read version %d.%d; expected at most %d.%d"), |
| 200 | ZNAME(Z),V(version),V(VERSION)); | 200 | ZNAME(Z),V(version),V(VERSION)); |
| 201 | if (version<VERSION0) /* check last major change */ | 201 | if (version<VERSION0) /* check last major change */ |
| 202 | luaO_verror(L,"`%.99s' too old:\n" | 202 | luaO_verror(L,l_s("`%.99s' too old:\n") |
| 203 | " read version %d.%d; expected at least %d.%d", | 203 | l_s(" read version %d.%d; expected at least %d.%d"), |
| 204 | ZNAME(Z),V(version),V(VERSION)); | 204 | ZNAME(Z),V(version),V(VERSION)); |
| 205 | swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */ | 205 | swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */ |
| 206 | TESTSIZE(sizeof(int)); | 206 | TESTSIZE(sizeof(int)); |
| @@ -212,8 +212,8 @@ static int LoadHeader (lua_State* L, ZIO* Z) | |||
| 212 | TESTSIZE(sizeof(lua_Number)); | 212 | TESTSIZE(sizeof(lua_Number)); |
| 213 | f=LoadNumber(L,Z,swap); | 213 | f=LoadNumber(L,Z,swap); |
| 214 | if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ | 214 | if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ |
| 215 | luaO_verror(L,"unknown number format in `%.99s':\n" | 215 | luaO_verror(L,l_s("unknown number format in `%.99s':\n") |
| 216 | " read " NUMBER_FMT "; expected " NUMBER_FMT, ZNAME(Z),f,tf); | 216 | l_s(" read ") NUMBER_FMT l_s("; expected ") NUMBER_FMT, ZNAME(Z),f,tf); |
| 217 | return swap; | 217 | return swap; |
| 218 | } | 218 | } |
| 219 | 219 | ||
| @@ -234,7 +234,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
| 234 | tf=LoadChunk(L,Z); | 234 | tf=LoadChunk(L,Z); |
| 235 | c=zgetc(Z); | 235 | c=zgetc(Z); |
| 236 | if (c!=EOZ) | 236 | if (c!=EOZ) |
| 237 | luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z)); | 237 | luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z)); |
| 238 | return tf; | 238 | return tf; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| @@ -244,5 +244,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
| 244 | int luaU_endianess (void) | 244 | int luaU_endianess (void) |
| 245 | { | 245 | { |
| 246 | int x=1; | 246 | int x=1; |
| 247 | return *(char*)&x; | 247 | return *(l_char*)&x; |
| 248 | } | 248 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.h,v 1.21 2000/10/31 16:57:23 lhf Exp $ | 2 | ** $Id: lundump.h,v 1.19 2000/11/07 12:44:44 roberto Exp roberto $ |
| 3 | ** load pre-compiled Lua chunks | 3 | ** load pre-compiled Lua chunks |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -20,12 +20,12 @@ int luaU_endianess (void); | |||
| 20 | #define VERSION 0x40 /* last format change was in 4.0 */ | 20 | #define VERSION 0x40 /* last format change was in 4.0 */ |
| 21 | #define VERSION0 0x40 /* last major change was in 4.0 */ | 21 | #define VERSION0 0x40 /* last major change was in 4.0 */ |
| 22 | #define ID_CHUNK 27 /* binary files start with ESC... */ | 22 | #define ID_CHUNK 27 /* binary files start with ESC... */ |
| 23 | #define SIGNATURE "Lua" /* ...followed by this signature */ | 23 | #define SIGNATURE l_s("Lua") /* ...followed by this signature */ |
| 24 | 24 | ||
| 25 | /* formats for error messages */ | 25 | /* formats for error messages */ |
| 26 | #define SOURCE_FMT "<%d:%.99s>" | 26 | #define SOURCE_FMT l_s("<%d:%.99s>") |
| 27 | #define SOURCE tf->lineDefined,tf->source->str | 27 | #define SOURCE tf->lineDefined,tf->source->str |
| 28 | #define IN_FMT " in %p " SOURCE_FMT | 28 | #define IN_FMT l_s(" in %p ") SOURCE_FMT |
| 29 | #define IN tf,SOURCE | 29 | #define IN tf,SOURCE |
| 30 | 30 | ||
| 31 | /* a multiple of PI for testing native format */ | 31 | /* a multiple of PI for testing native format */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.170 2001/02/20 18:15:33 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.171 2001/02/22 18:59:59 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -43,7 +43,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ | |||
| 43 | if (ttype(obj) != LUA_TNUMBER) | 43 | if (ttype(obj) != LUA_TNUMBER) |
| 44 | return 1; | 44 | return 1; |
| 45 | else { | 45 | else { |
| 46 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ | 46 | l_char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ |
| 47 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ | 47 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ |
| 48 | setsvalue(obj, luaS_new(L, s)); | 48 | setsvalue(obj, luaS_new(L, s)); |
| 49 | return 0; | 49 | return 0; |
| @@ -96,23 +96,23 @@ void luaV_Lclosure (lua_State *L, Proto *l, int nelems) { | |||
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | static void callTM (lua_State *L, const char *fmt, ...) { | 99 | static void callTM (lua_State *L, const l_char *fmt, ...) { |
| 100 | va_list argp; | 100 | va_list argp; |
| 101 | StkId base = L->top; | 101 | StkId base = L->top; |
| 102 | int has_result = 0; | 102 | int has_result = 0; |
| 103 | va_start(argp, fmt); | 103 | va_start(argp, fmt); |
| 104 | while (*fmt) { | 104 | while (*fmt) { |
| 105 | switch (*fmt++) { | 105 | switch (*fmt++) { |
| 106 | case 'c': | 106 | case l_c('c'): |
| 107 | setclvalue(L->top, va_arg(argp, Closure *)); | 107 | setclvalue(L->top, va_arg(argp, Closure *)); |
| 108 | break; | 108 | break; |
| 109 | case 'o': | 109 | case l_c('o'): |
| 110 | setobj(L->top, va_arg(argp, TObject *)); | 110 | setobj(L->top, va_arg(argp, TObject *)); |
| 111 | break; | 111 | break; |
| 112 | case 's': | 112 | case l_c('s'): |
| 113 | setsvalue(L->top, va_arg(argp, TString *)); | 113 | setsvalue(L->top, va_arg(argp, TString *)); |
| 114 | break; | 114 | break; |
| 115 | case 'r': | 115 | case l_c('r'): |
| 116 | has_result = 1; | 116 | has_result = 1; |
| 117 | continue; | 117 | continue; |
| 118 | } | 118 | } |
| @@ -151,9 +151,9 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) { | |||
| 151 | else { /* not a table; try a `gettable' tag method */ | 151 | else { /* not a table; try a `gettable' tag method */ |
| 152 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); | 152 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); |
| 153 | if (tm == NULL) /* no tag method? */ | 153 | if (tm == NULL) /* no tag method? */ |
| 154 | luaG_typeerror(L, t, "index"); | 154 | luaG_typeerror(L, t, l_s("index")); |
| 155 | } | 155 | } |
| 156 | callTM(L, "coor", tm, t, key, res); | 156 | callTM(L, l_s("coor"), tm, t, key, res); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | 159 | ||
| @@ -175,9 +175,9 @@ void luaV_settable (lua_State *L, StkId t, StkId key, StkId val) { | |||
| 175 | else { /* not a table; try a `settable' tag method */ | 175 | else { /* not a table; try a `settable' tag method */ |
| 176 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); | 176 | tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); |
| 177 | if (tm == NULL) /* no tag method? */ | 177 | if (tm == NULL) /* no tag method? */ |
| 178 | luaG_typeerror(L, t, "index"); | 178 | luaG_typeerror(L, t, l_s("index")); |
| 179 | } | 179 | } |
| 180 | callTM(L, "cooo", tm, t, key, val); | 180 | callTM(L, l_s("cooo"), tm, t, key, val); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | 183 | ||
| @@ -189,7 +189,7 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) { | |||
| 189 | setobj(res, value); /* default behavior */ | 189 | setobj(res, value); /* default behavior */ |
| 190 | } | 190 | } |
| 191 | else | 191 | else |
| 192 | callTM(L, "csor", tm, name, value, res); | 192 | callTM(L, l_s("csor"), tm, name, value, res); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | 195 | ||
| @@ -201,7 +201,7 @@ void luaV_setglobal (lua_State *L, TString *name, StkId val) { | |||
| 201 | setobj(oldvalue, val); /* raw set */ | 201 | setobj(oldvalue, val); /* raw set */ |
| 202 | } | 202 | } |
| 203 | else | 203 | else |
| 204 | callTM(L, "csoo", tm, name, oldvalue, val); | 204 | callTM(L, l_s("csoo"), tm, name, oldvalue, val); |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | 207 | ||
| @@ -218,21 +218,21 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, | |||
| 218 | } | 218 | } |
| 219 | } | 219 | } |
| 220 | opname = luaS_new(L, luaT_eventname[event]); | 220 | opname = luaS_new(L, luaT_eventname[event]); |
| 221 | callTM(L, "coosr", tm, p1, p2, opname, res); | 221 | callTM(L, l_s("coosr"), tm, p1, p2, opname, res); |
| 222 | return 1; | 222 | return 1; |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | 225 | ||
| 226 | static void call_arith (lua_State *L, StkId p1, TMS event) { | 226 | static void call_arith (lua_State *L, StkId p1, TMS event) { |
| 227 | if (!call_binTM(L, p1, p1+1, p1, event)) | 227 | if (!call_binTM(L, p1, p1+1, p1, event)) |
| 228 | luaG_binerror(L, p1, LUA_TNUMBER, "perform arithmetic on"); | 228 | luaG_binerror(L, p1, LUA_TNUMBER, l_s("perform arithmetic on")); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | 231 | ||
| 232 | static int luaV_strlessthan (const TString *ls, const TString *rs) { | 232 | static int luaV_strlessthan (const TString *ls, const TString *rs) { |
| 233 | const char *l = getstr(ls); | 233 | const l_char *l = getstr(ls); |
| 234 | size_t ll = ls->len; | 234 | size_t ll = ls->len; |
| 235 | const char *r = getstr(rs); | 235 | const l_char *r = getstr(rs); |
| 236 | size_t lr = rs->len; | 236 | size_t lr = rs->len; |
| 237 | for (;;) { | 237 | for (;;) { |
| 238 | int temp = strcoll(l, r); | 238 | int temp = strcoll(l, r); |
| @@ -269,18 +269,18 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
| 269 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 269 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
| 270 | if (tostring(L, top-2) || tostring(L, top-1)) { | 270 | if (tostring(L, top-2) || tostring(L, top-1)) { |
| 271 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) | 271 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) |
| 272 | luaG_binerror(L, top-2, LUA_TSTRING, "concat"); | 272 | luaG_binerror(L, top-2, LUA_TSTRING, l_s("concat")); |
| 273 | } | 273 | } |
| 274 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ | 274 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
| 275 | /* at least two string values; get as many as possible */ | 275 | /* at least two string values; get as many as possible */ |
| 276 | lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len; | 276 | lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len; |
| 277 | char *buffer; | 277 | l_char *buffer; |
| 278 | int i; | 278 | int i; |
| 279 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 279 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |
| 280 | tl += tsvalue(top-n-1)->len; | 280 | tl += tsvalue(top-n-1)->len; |
| 281 | n++; | 281 | n++; |
| 282 | } | 282 | } |
| 283 | if (tl > MAX_SIZET) luaD_error(L, "string size overflow"); | 283 | if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow")); |
| 284 | buffer = luaO_openspace(L, tl); | 284 | buffer = luaO_openspace(L, tl); |
| 285 | tl = 0; | 285 | tl = 0; |
| 286 | for (i=n; i>0; i--) { /* concat all strings */ | 286 | for (i=n; i>0; i--) { /* concat all strings */ |
| @@ -303,7 +303,7 @@ static void luaV_pack (lua_State *L, StkId firstelem) { | |||
| 303 | for (i=0; firstelem+i<L->top; i++) | 303 | for (i=0; firstelem+i<L->top; i++) |
| 304 | setobj(luaH_setnum(L, htab, i+1), firstelem+i); | 304 | setobj(luaH_setnum(L, htab, i+1), firstelem+i); |
| 305 | /* store counter in field `n' */ | 305 | /* store counter in field `n' */ |
| 306 | n = luaH_setstr(L, htab, luaS_newliteral(L, "n")); | 306 | n = luaH_setstr(L, htab, luaS_newliteral(L, l_s("n"))); |
| 307 | setnvalue(n, i); | 307 | setnvalue(n, i); |
| 308 | L->top = firstelem; /* remove elements from the stack */ | 308 | L->top = firstelem; /* remove elements from the stack */ |
| 309 | sethvalue(L->top, htab); | 309 | sethvalue(L->top, htab); |
| @@ -509,7 +509,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 509 | } | 509 | } |
| 510 | case OP_POW: { | 510 | case OP_POW: { |
| 511 | if (!call_binTM(L, top-2, top-1, top-2, TM_POW)) | 511 | if (!call_binTM(L, top-2, top-1, top-2, TM_POW)) |
| 512 | luaD_error(L, "undefined operation"); | 512 | luaD_error(L, l_s("undefined operation")); |
| 513 | top--; | 513 | top--; |
| 514 | break; | 514 | break; |
| 515 | } | 515 | } |
| @@ -595,11 +595,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 595 | case OP_FORPREP: { | 595 | case OP_FORPREP: { |
| 596 | int jmp = GETARG_S(i); | 596 | int jmp = GETARG_S(i); |
| 597 | if (tonumber(top-1)) | 597 | if (tonumber(top-1)) |
| 598 | luaD_error(L, "`for' step must be a number"); | 598 | luaD_error(L, l_s("`for' step must be a number")); |
| 599 | if (tonumber(top-2)) | 599 | if (tonumber(top-2)) |
| 600 | luaD_error(L, "`for' limit must be a number"); | 600 | luaD_error(L, l_s("`for' limit must be a number")); |
| 601 | if (tonumber(top-3)) | 601 | if (tonumber(top-3)) |
| 602 | luaD_error(L, "`for' initial value must be a number"); | 602 | luaD_error(L, l_s("`for' initial value must be a number")); |
| 603 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ | 603 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ |
| 604 | goto forloop; /* do not increment index */ | 604 | goto forloop; /* do not increment index */ |
| 605 | } | 605 | } |
| @@ -607,7 +607,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 607 | lua_assert(ttype(top-1) == LUA_TNUMBER); | 607 | lua_assert(ttype(top-1) == LUA_TNUMBER); |
| 608 | lua_assert(ttype(top-2) == LUA_TNUMBER); | 608 | lua_assert(ttype(top-2) == LUA_TNUMBER); |
| 609 | if (ttype(top-3) != LUA_TNUMBER) | 609 | if (ttype(top-3) != LUA_TNUMBER) |
| 610 | luaD_error(L, "`for' index must be a number"); | 610 | luaD_error(L, l_s("`for' index must be a number")); |
| 611 | nvalue(top-3) += nvalue(top-1); /* increment index */ | 611 | nvalue(top-3) += nvalue(top-1); /* increment index */ |
| 612 | forloop: | 612 | forloop: |
| 613 | if (nvalue(top-1) > 0 ? | 613 | if (nvalue(top-1) > 0 ? |
| @@ -621,7 +621,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 621 | case OP_LFORPREP: { | 621 | case OP_LFORPREP: { |
| 622 | int jmp = GETARG_S(i); | 622 | int jmp = GETARG_S(i); |
| 623 | if (ttype(top-1) != LUA_TTABLE) | 623 | if (ttype(top-1) != LUA_TTABLE) |
| 624 | luaD_error(L, "`for' table must be a table"); | 624 | luaD_error(L, l_s("`for' table must be a table")); |
| 625 | top += 3; /* index,key,value */ | 625 | top += 3; /* index,key,value */ |
| 626 | setnvalue(top-3, -1); /* initial index */ | 626 | setnvalue(top-3, -1); /* initial index */ |
| 627 | setnilvalue(top-2); | 627 | setnilvalue(top-2); |
