first (big) step to support wide chars

This commit is contained in:
Roberto Ierusalimschy
2001-02-23 14:17:25 -03:00
parent d164e2294f
commit 39b7978329
40 changed files with 1151 additions and 1121 deletions

50
lapi.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 1.131 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lapi.c,v 1.132 2001/02/22 18:59:59 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -22,8 +22,8 @@
#include "lvm.h" #include "lvm.h"
const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" const l_char lua_ident[] = l_s("$Lua: ") l_s(LUA_VERSION) l_s(" ")
"$Authors: " LUA_AUTHORS " $"; l_s(LUA_COPYRIGHT) l_s(" $\n") l_s("$Authors: ") l_s(LUA_AUTHORS) l_s(" $");
@@ -150,21 +150,21 @@ LUA_API int lua_type (lua_State *L, int index) {
} }
LUA_API const char *lua_typename (lua_State *L, int t) { LUA_API const l_char *lua_typename (lua_State *L, int t) {
const char *s; const l_char *s;
LUA_LOCK(L); LUA_LOCK(L);
s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t); s = (t == LUA_TNONE) ? l_s("no value") : basictypename(G(L), t);
LUA_UNLOCK(L); LUA_UNLOCK(L);
return s; return s;
} }
LUA_API const char *lua_xtype (lua_State *L, int index) { LUA_API const l_char *lua_xtype (lua_State *L, int index) {
StkId o; StkId o;
const char *type; const l_char *type;
LUA_LOCK(L); LUA_LOCK(L);
o = luaA_indexAcceptable(L, index); o = luaA_indexAcceptable(L, index);
type = (o == NULL) ? "no value" : luaT_typename(G(L), o); type = (o == NULL) ? l_s("no value") : luaT_typename(G(L), o);
LUA_UNLOCK(L); LUA_UNLOCK(L);
return type; return type;
} }
@@ -242,9 +242,9 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
return n; return n;
} }
LUA_API const char *lua_tostring (lua_State *L, int index) { LUA_API const l_char *lua_tostring (lua_State *L, int index) {
StkId o; StkId o;
const char *s; const l_char *s;
LUA_LOCK(L); LUA_LOCK(L);
o = luaA_indexAcceptable(L, index); o = luaA_indexAcceptable(L, index);
s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); s = (o == NULL || tostring(L, o)) ? NULL : svalue(o);
@@ -329,7 +329,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
} }
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) {
LUA_LOCK(L); LUA_LOCK(L);
setsvalue(L->top, luaS_newlstr(L, s, len)); setsvalue(L->top, luaS_newlstr(L, s, len));
api_incr_top(L); api_incr_top(L);
@@ -337,7 +337,7 @@ LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
} }
LUA_API void lua_pushstring (lua_State *L, const char *s) { LUA_API void lua_pushstring (lua_State *L, const l_char *s) {
if (s == NULL) if (s == NULL)
lua_pushnil(L); lua_pushnil(L);
else else
@@ -369,7 +369,7 @@ LUA_API int lua_pushuserdata (lua_State *L, void *u) {
*/ */
LUA_API void lua_getglobal (lua_State *L, const char *name) { LUA_API void lua_getglobal (lua_State *L, const l_char *name) {
LUA_LOCK(L); LUA_LOCK(L);
luaV_getglobal(L, luaS_new(L, name), L->top); luaV_getglobal(L, luaS_new(L, name), L->top);
api_incr_top(L); api_incr_top(L);
@@ -450,7 +450,7 @@ LUA_API void lua_newtable (lua_State *L) {
*/ */
LUA_API void lua_setglobal (lua_State *L, const char *name) { LUA_API void lua_setglobal (lua_State *L, const l_char *name) {
LUA_LOCK(L); LUA_LOCK(L);
api_checknelems(L, 1); api_checknelems(L, 1);
luaV_setglobal(L, luaS_new(L, name), L->top - 1); luaV_setglobal(L, luaS_new(L, name), L->top - 1);
@@ -518,7 +518,7 @@ LUA_API int lua_ref (lua_State *L, int lock) {
} }
else { /* no more free places */ else { /* no more free places */
luaM_growvector(L, G(L)->refArray, G(L)->nref, G(L)->sizeref, struct Ref, luaM_growvector(L, G(L)->refArray, G(L)->nref, G(L)->sizeref, struct Ref,
MAX_INT, "reference table overflow"); MAX_INT, l_s("reference table overflow"));
ref = G(L)->nref++; ref = G(L)->nref++;
} }
setobj(&G(L)->refArray[ref].o, L->top-1); setobj(&G(L)->refArray[ref].o, L->top-1);
@@ -582,22 +582,22 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
** miscellaneous functions ** miscellaneous functions
*/ */
LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) {
int tag; int tag;
LUA_LOCK(L); LUA_LOCK(L);
if (basictype != LUA_TNONE && if (basictype != LUA_TNONE &&
basictype != LUA_TTABLE && basictype != LUA_TTABLE &&
basictype != LUA_TUSERDATA) basictype != LUA_TUSERDATA)
luaO_verror(L, "invalid basic type (%d) for new type", basictype); luaO_verror(L, l_s("invalid basic type (%d) for new type"), basictype);
tag = luaT_newtag(L, name, basictype); tag = luaT_newtag(L, name, basictype);
if (tag == LUA_TNONE) if (tag == LUA_TNONE)
luaO_verror(L, "type name '%.30s' already exists", name); luaO_verror(L, l_s("type name '%.30s' already exists"), name);
LUA_UNLOCK(L); LUA_UNLOCK(L);
return tag; return tag;
} }
LUA_API int lua_type2tag (lua_State *L, const char *name) { LUA_API int lua_type2tag (lua_State *L, const l_char *name) {
int tag; int tag;
const TObject *v; const TObject *v;
LUA_LOCK(L); LUA_LOCK(L);
@@ -618,10 +618,10 @@ LUA_API void lua_settag (lua_State *L, int tag) {
LUA_LOCK(L); LUA_LOCK(L);
api_checknelems(L, 1); api_checknelems(L, 1);
if (tag < 0 || tag >= G(L)->ntag) if (tag < 0 || tag >= G(L)->ntag)
luaO_verror(L, "%d is not a valid tag", tag); luaO_verror(L, l_s("%d is not a valid tag"), tag);
basictype = G(L)->TMtable[tag].basictype; basictype = G(L)->TMtable[tag].basictype;
if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) if (basictype != LUA_TNONE && basictype != ttype(L->top-1))
luaO_verror(L, "tag %d can only be used for type '%.20s'", tag, luaO_verror(L, l_s("tag %d can only be used for type '%.20s'"), tag,
basictypename(G(L), basictype)); basictypename(G(L), basictype));
switch (ttype(L->top-1)) { switch (ttype(L->top-1)) {
case LUA_TTABLE: case LUA_TTABLE:
@@ -631,14 +631,14 @@ LUA_API void lua_settag (lua_State *L, int tag) {
tsvalue(L->top-1)->u.d.tag = tag; tsvalue(L->top-1)->u.d.tag = tag;
break; break;
default: default:
luaO_verror(L, "cannot change the tag of a %.20s", luaO_verror(L, l_s("cannot change the tag of a %.20s"),
luaT_typename(G(L), L->top-1)); luaT_typename(G(L), L->top-1));
} }
LUA_UNLOCK(L); LUA_UNLOCK(L);
} }
LUA_API void lua_error (lua_State *L, const char *s) { LUA_API void lua_error (lua_State *L, const l_char *s) {
LUA_LOCK(L); LUA_LOCK(L);
luaD_error(L, s); luaD_error(L, s);
LUA_UNLOCK(L); LUA_UNLOCK(L);
@@ -685,7 +685,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
int n; int n;
LUA_LOCK(L); LUA_LOCK(L);
h = hvalue(luaA_index(L, index)); h = hvalue(luaA_index(L, index));
value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ value = luaH_getstr(h, luaS_newliteral(L, l_s("n"))); /* = h.n */
if (ttype(value) == LUA_TNUMBER) if (ttype(value) == LUA_TNUMBER)
n = (int)nvalue(value); n = (int)nvalue(value);
else { else {

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.46 2001/02/02 19:02:40 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.47 2001/02/14 17:04:11 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -18,10 +18,11 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "luadebug.h" #include "luadebug.h"
#include "lualib.h"
LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]) {
int i; int i;
for (i=0; list[i]; i++) for (i=0; list[i]; i++)
if (strcmp(list[i], name) == 0) if (strcmp(list[i], name) == 0)
@@ -29,20 +30,20 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]) {
return -1; /* name not found */ return -1; /* name not found */
} }
LUALIB_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) { LUALIB_API void luaL_argerror (lua_State *L, int narg, const l_char *extramsg) {
lua_Debug ar; lua_Debug ar;
lua_getstack(L, 0, &ar); lua_getstack(L, 0, &ar);
lua_getinfo(L, "n", &ar); lua_getinfo(L, l_s("n"), &ar);
if (ar.name == NULL) if (ar.name == NULL)
ar.name = "?"; ar.name = l_s("?");
luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", luaL_verror(L, l_s("bad argument #%d to `%.50s' (%.100s)"),
narg, ar.name, extramsg); narg, ar.name, extramsg);
} }
static void type_error (lua_State *L, int narg, const char *tname) { static void type_error (lua_State *L, int narg, const l_char *tname) {
char buff[80]; l_char buff[80];
sprintf(buff, "%.25s expected, got %.25s", tname, lua_xtype(L, narg)); sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtype(L, narg));
luaL_argerror(L, narg, buff); luaL_argerror(L, narg, buff);
} }
@@ -52,9 +53,9 @@ static void tag_error (lua_State *L, int narg, int tag) {
} }
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *mes) {
if (space > lua_stackspace(L)) if (space > lua_stackspace(L))
luaL_verror(L, "stack overflow (%.30s)", mes); luaL_verror(L, l_s("stack overflow (%.30s)"), mes);
} }
@@ -66,27 +67,27 @@ LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) {
LUALIB_API void luaL_checkany (lua_State *L, int narg) { LUALIB_API void luaL_checkany (lua_State *L, int narg) {
if (lua_type(L, narg) == LUA_TNONE) if (lua_type(L, narg) == LUA_TNONE)
luaL_argerror(L, narg, "value expected"); luaL_argerror(L, narg, l_s("value expected"));
} }
LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, LUALIB_API void *luaL_check_userdata (lua_State *L, int narg,
const char *name) { const l_char *name) {
if (strcmp(lua_xtype(L, narg), name) != 0) if (strcmp(lua_xtype(L, narg), name) != 0)
type_error(L, narg, name); type_error(L, narg, name);
return lua_touserdata(L, narg); return lua_touserdata(L, narg);
} }
LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
const char *s = lua_tostring(L, narg); const l_char *s = lua_tostring(L, narg);
if (!s) tag_error(L, narg, LUA_TSTRING); if (!s) tag_error(L, narg, LUA_TSTRING);
if (len) *len = lua_strlen(L, narg); if (len) *len = lua_strlen(L, narg);
return s; return s;
} }
LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { LUALIB_API const l_char *luaL_opt_lstr (lua_State *L, int narg, const l_char *def, size_t *len) {
if (lua_isnull(L, narg)) { if (lua_isnull(L, narg)) {
if (len) if (len)
*len = (def ? strlen(def) : 0); *len = (def ? strlen(def) : 0);
@@ -117,8 +118,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n) {
} }
LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...) { LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...) {
char buff[500]; l_char buff[500];
va_list argp; va_list argp;
va_start(argp, fmt); va_start(argp, fmt);
vsprintf(buff, fmt, argp); vsprintf(buff, fmt, argp);
@@ -172,20 +173,20 @@ static void adjuststack (luaL_Buffer *B) {
} }
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B) {
if (emptybuffer(B)) if (emptybuffer(B))
adjuststack(B); adjuststack(B);
return B->buffer; return B->buffer;
} }
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l) {
while (l--) while (l--)
luaL_putchar(B, *s++); luaL_putchar(B, *s++);
} }
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s) {
luaL_addlstring(B, s, strlen(s)); luaL_addlstring(B, s, strlen(s));
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.h,v 1.32 2001/01/25 16:45:36 roberto Exp roberto $ ** $Id: lauxlib.h,v 1.33 2001/02/02 19:02:40 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -21,25 +21,25 @@
typedef struct luaL_reg { typedef struct luaL_reg {
const char *name; const l_char *name;
lua_CFunction func; lua_CFunction func;
} luaL_reg; } luaL_reg;
LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n); LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n);
LUALIB_API void luaL_argerror (lua_State *L, int numarg, const char *extramsg); LUALIB_API void luaL_argerror (lua_State *L, int numarg, const l_char *extramsg);
LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len); LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, size_t *len); LUALIB_API const l_char *luaL_opt_lstr (lua_State *L, int numArg, const l_char *def, size_t *len);
LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg); LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg);
LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def); LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def);
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg); LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *msg);
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t); LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
LUALIB_API void luaL_checkany (lua_State *L, int narg); LUALIB_API void luaL_checkany (lua_State *L, int narg);
LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, const char *name); LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, const l_char *name);
LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...); LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...);
LUALIB_API int luaL_findstring (const char *name, const char *const list[]); LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]);
@@ -73,22 +73,22 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]);
typedef struct luaL_Buffer { typedef struct luaL_Buffer {
char *p; /* current position in buffer */ l_char *p; /* current position in buffer */
int level; int level;
lua_State *L; lua_State *L;
char buffer[LUAL_BUFFERSIZE]; l_char buffer[LUAL_BUFFERSIZE];
} luaL_Buffer; } luaL_Buffer;
#define luaL_putchar(B,c) \ #define luaL_putchar(B,c) \
((void)((B)->p < &(B)->buffer[LUAL_BUFFERSIZE] || luaL_prepbuffer(B)), \ ((void)((B)->p < &(B)->buffer[LUAL_BUFFERSIZE] || luaL_prepbuffer(B)), \
(*(B)->p++ = (char)(c))) (*(B)->p++ = (l_char)(c)))
#define luaL_addsize(B,n) ((B)->p += (n)) #define luaL_addsize(B,n) ((B)->p += (n))
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B); LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B);
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B); LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B);
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l); LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l);
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s); LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s);
LUALIB_API void luaL_addvalue (luaL_Buffer *B); LUALIB_API void luaL_addvalue (luaL_Buffer *B);
LUALIB_API void luaL_pushresult (luaL_Buffer *B); LUALIB_API void luaL_pushresult (luaL_Buffer *B);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lbaselib.c,v 1.25 2001/02/22 17:15:18 roberto Exp roberto $ ** $Id: lbaselib.c,v 1.26 2001/02/22 18:59:59 roberto Exp roberto $
** Basic library ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -35,21 +35,21 @@ static int luaB__ALERT (lua_State *L) {
*/ */
static int luaB__ERRORMESSAGE (lua_State *L) { static int luaB__ERRORMESSAGE (lua_State *L) {
luaL_checktype(L, 1, LUA_TSTRING); luaL_checktype(L, 1, LUA_TSTRING);
lua_getglobal(L, LUA_ALERT); lua_getglobal(L, l_s(LUA_ALERT));
if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
lua_Debug ar; lua_Debug ar;
lua_pushliteral(L, "error: "); lua_pushliteral(L, l_s("error: "));
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
if (lua_getstack(L, 1, &ar)) { if (lua_getstack(L, 1, &ar)) {
lua_getinfo(L, "Sl", &ar); lua_getinfo(L, l_s("Sl"), &ar);
if (ar.source && ar.currentline > 0) { if (ar.source && ar.currentline > 0) {
char buff[100]; l_char buff[100];
sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline); sprintf(buff, l_s("\n <%.70s: line %d>"), ar.short_src, ar.currentline);
lua_pushstring(L, buff); lua_pushstring(L, buff);
lua_concat(L, 2); lua_concat(L, 2);
} }
} }
lua_pushliteral(L, "\n"); lua_pushliteral(L, l_s("\n"));
lua_concat(L, 3); lua_concat(L, 3);
lua_rawcall(L, 1, 0); lua_rawcall(L, 1, 0);
} }
@@ -66,20 +66,20 @@ static int luaB__ERRORMESSAGE (lua_State *L) {
static int luaB_print (lua_State *L) { static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
int i; int i;
lua_getglobal(L, "tostring"); lua_getglobal(L, l_s("tostring"));
for (i=1; i<=n; i++) { for (i=1; i<=n; i++) {
const char *s; const l_char *s;
lua_pushvalue(L, -1); /* function to be called */ lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */ lua_pushvalue(L, i); /* value to print */
lua_rawcall(L, 1, 1); lua_rawcall(L, 1, 1);
s = lua_tostring(L, -1); /* get result */ s = lua_tostring(L, -1); /* get result */
if (s == NULL) if (s == NULL)
lua_error(L, "`tostring' must return a string to `print'"); lua_error(L, l_s("`tostring' must return a string to `print'"));
if (i>1) fputs("\t", stdout); if (i>1) fputs(l_s("\t"), stdout);
fputs(s, stdout); fputs(s, stdout);
lua_pop(L, 1); /* pop result */ lua_pop(L, 1); /* pop result */
} }
fputs("\n", stdout); fputs(l_s("\n"), stdout);
return 0; return 0;
} }
@@ -94,14 +94,14 @@ static int luaB_tonumber (lua_State *L) {
} }
} }
else { else {
const char *s1 = luaL_check_string(L, 1); const l_char *s1 = luaL_check_string(L, 1);
char *s2; l_char *s2;
unsigned long n; unsigned long n;
luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range"); luaL_arg_check(L, 2 <= base && base <= 36, 2, l_s("base out of range"));
n = strtoul(s1, &s2, base); n = strtoul(s1, &s2, base);
if (s1 != s2) { /* at least one valid digit? */ if (s1 != s2) { /* at least one valid digit? */
while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */ while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */
if (*s2 == '\0') { /* no invalid trailing characters? */ if (*s2 == l_c('\0')) { /* no invalid trailing characters? */
lua_pushnumber(L, n); lua_pushnumber(L, n);
return 1; return 1;
} }
@@ -135,14 +135,14 @@ static int gettag (lua_State *L, int narg) {
case LUA_TNUMBER: case LUA_TNUMBER:
return (int)lua_tonumber(L, narg); return (int)lua_tonumber(L, narg);
case LUA_TSTRING: { case LUA_TSTRING: {
const char *name = lua_tostring(L, narg); const l_char *name = lua_tostring(L, narg);
int tag = lua_type2tag(L, name); int tag = lua_type2tag(L, name);
if (tag == LUA_TNONE) if (tag == LUA_TNONE)
luaL_verror(L, "'%.30s' is not a valid type name", name); luaL_verror(L, l_s("'%.30s' is not a valid type name"), name);
return tag; return tag;
} }
default: default:
luaL_argerror(L, narg, "tag or type name expected"); luaL_argerror(L, narg, l_s("tag or type name expected"));
return 0; /* to avoid warnings */ return 0; /* to avoid warnings */
} }
} }
@@ -162,7 +162,7 @@ static int luaB_settag (lua_State *L) {
} }
static int luaB_newtype (lua_State *L) { static int luaB_newtype (lua_State *L) {
const char *name = luaL_opt_string(L, 1, NULL); const l_char *name = luaL_opt_string(L, 1, NULL);
lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE));
return 1; return 1;
} }
@@ -199,11 +199,11 @@ static int luaB_rawset (lua_State *L) {
static int luaB_settagmethod (lua_State *L) { static int luaB_settagmethod (lua_State *L) {
int tag = gettag(L, 1); int tag = gettag(L, 1);
const char *event = luaL_check_string(L, 2); const l_char *event = luaL_check_string(L, 2);
luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3,
"function or nil expected"); l_s("function or nil expected"));
if (strcmp(event, "gc") == 0) if (strcmp(event, l_s("gc")) == 0)
lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua"); lua_error(L, l_s("deprecated use: cannot set the `gc' tag method from Lua"));
lua_gettagmethod(L, tag, event); lua_gettagmethod(L, tag, event);
lua_pushvalue(L, 3); lua_pushvalue(L, 3);
lua_settagmethod(L, tag, event); lua_settagmethod(L, tag, event);
@@ -213,9 +213,9 @@ static int luaB_settagmethod (lua_State *L) {
static int luaB_gettagmethod (lua_State *L) { static int luaB_gettagmethod (lua_State *L) {
int tag = gettag(L, 1); int tag = gettag(L, 1);
const char *event = luaL_check_string(L, 2); const l_char *event = luaL_check_string(L, 2);
if (strcmp(event, "gc") == 0) if (strcmp(event, l_s("gc")) == 0)
lua_error(L, "deprecated use: cannot get the `gc' tag method from Lua"); lua_error(L, l_s("deprecated use: cannot get the `gc' tag method from Lua"));
lua_gettagmethod(L, tag, event); lua_gettagmethod(L, tag, event);
return 1; return 1;
} }
@@ -261,9 +261,9 @@ static int luaB_next (lua_State *L) {
static int passresults (lua_State *L, int status, int oldtop) { static int passresults (lua_State *L, int status, int oldtop) {
static const char *const errornames[] = static const l_char *const errornames[] =
{"ok", "run-time error", "file error", "syntax error", {l_s("ok"), l_s("run-time error"), l_s("file error"), l_s("syntax error"),
"memory error", "error in error handling"}; l_s("memory error"), l_s("error in error handling")};
if (status == 0) { if (status == 0) {
int nresults = lua_gettop(L) - oldtop; int nresults = lua_gettop(L) - oldtop;
if (nresults > 0) if (nresults > 0)
@@ -283,59 +283,59 @@ static int passresults (lua_State *L, int status, int oldtop) {
static int luaB_dostring (lua_State *L) { static int luaB_dostring (lua_State *L) {
int oldtop = lua_gettop(L); int oldtop = lua_gettop(L);
size_t l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
const char *chunkname = luaL_opt_string(L, 2, s); const l_char *chunkname = luaL_opt_string(L, 2, s);
return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop); return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop);
} }
static int luaB_dofile (lua_State *L) { static int luaB_dofile (lua_State *L) {
int oldtop = lua_gettop(L); int oldtop = lua_gettop(L);
const char *fname = luaL_opt_string(L, 1, NULL); const l_char *fname = luaL_opt_string(L, 1, NULL);
return passresults(L, lua_dofile(L, fname), oldtop); return passresults(L, lua_dofile(L, fname), oldtop);
} }
static int luaB_call (lua_State *L) { static int luaB_call (lua_State *L) {
int oldtop; int oldtop;
const char *options = luaL_opt_string(L, 3, ""); const l_char *options = luaL_opt_string(L, 3, l_s(""));
int err = 0; /* index of old error method */ int err = 0; /* index of old error method */
int i, status; int i, status;
int n; int n;
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
n = lua_getn(L, 2); n = lua_getn(L, 2);
if (!lua_isnull(L, 4)) { /* set new error method */ if (!lua_isnull(L, 4)) { /* set new error method */
lua_getglobal(L, LUA_ERRORMESSAGE); lua_getglobal(L, l_s(LUA_ERRORMESSAGE));
err = lua_gettop(L); /* get index */ err = lua_gettop(L); /* get index */
lua_pushvalue(L, 4); lua_pushvalue(L, 4);
lua_setglobal(L, LUA_ERRORMESSAGE); lua_setglobal(L, l_s(LUA_ERRORMESSAGE));
} }
oldtop = lua_gettop(L); /* top before function-call preparation */ oldtop = lua_gettop(L); /* top before function-call preparation */
/* push function */ /* push function */
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
luaL_checkstack(L, n, "too many arguments"); luaL_checkstack(L, n, l_s("too many arguments"));
for (i=0; i<n; i++) /* push arg[1...n] */ for (i=0; i<n; i++) /* push arg[1...n] */
lua_rawgeti(L, 2, i+1); lua_rawgeti(L, 2, i+1);
status = lua_call(L, n, LUA_MULTRET); status = lua_call(L, n, LUA_MULTRET);
if (err != 0) { /* restore old error method */ if (err != 0) { /* restore old error method */
lua_pushvalue(L, err); lua_pushvalue(L, err);
lua_setglobal(L, LUA_ERRORMESSAGE); lua_setglobal(L, l_s(LUA_ERRORMESSAGE));
} }
if (status != 0) { /* error in call? */ if (status != 0) { /* error in call? */
if (strchr(options, 'x')) if (strchr(options, l_c('x')))
lua_pushnil(L); /* return nil to signal the error */ lua_pushnil(L); /* return nil to signal the error */
else else
lua_error(L, NULL); /* propagate error without additional messages */ lua_error(L, NULL); /* propagate error without additional messages */
return 1; return 1;
} }
if (strchr(options, 'p')) /* pack results? */ if (strchr(options, l_c('p'))) /* pack results? */
lua_error(L, "deprecated option `p' in `call'"); lua_error(L, l_s("deprecated option `p' in `call'"));
return lua_gettop(L) - oldtop; /* results are already on the stack */ return lua_gettop(L) - oldtop; /* results are already on the stack */
} }
static int luaB_tostring (lua_State *L) { static int luaB_tostring (lua_State *L) {
char buff[64]; l_char buff[64];
switch (lua_type(L, 1)) { switch (lua_type(L, 1)) {
case LUA_TNUMBER: case LUA_TNUMBER:
lua_pushstring(L, lua_tostring(L, 1)); lua_pushstring(L, lua_tostring(L, 1));
@@ -344,24 +344,24 @@ static int luaB_tostring (lua_State *L) {
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
return 1; return 1;
case LUA_TTABLE: case LUA_TTABLE:
sprintf(buff, "%.40s: %p", lua_xtype(L, 1), lua_topointer(L, 1)); sprintf(buff, l_s("%.40s: %p"), lua_xtype(L, 1), lua_topointer(L, 1));
break; break;
case LUA_TFUNCTION: case LUA_TFUNCTION:
sprintf(buff, "function: %p", lua_topointer(L, 1)); sprintf(buff, l_s("function: %p"), lua_topointer(L, 1));
break; break;
case LUA_TUSERDATA: { case LUA_TUSERDATA: {
const char *t = lua_xtype(L, 1); const l_char *t = lua_xtype(L, 1);
if (strcmp(t, "userdata") == 0) if (strcmp(t, l_s("userdata")) == 0)
sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1)); sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), lua_touserdata(L, 1));
else else
sprintf(buff, "%.40s: %p", t, lua_touserdata(L, 1)); sprintf(buff, l_s("%.40s: %p"), t, lua_touserdata(L, 1));
break; break;
} }
case LUA_TNIL: case LUA_TNIL:
lua_pushliteral(L, "nil"); lua_pushliteral(L, l_s("nil"));
return 1; return 1;
default: default:
luaL_argerror(L, 1, "value expected"); luaL_argerror(L, 1, l_s("value expected"));
} }
lua_pushstring(L, buff); lua_pushstring(L, buff);
return 1; return 1;
@@ -407,7 +407,7 @@ static int luaB_foreach (lua_State *L) {
static int luaB_assert (lua_State *L) { static int luaB_assert (lua_State *L) {
luaL_checkany(L, 1); luaL_checkany(L, 1);
if (lua_isnil(L, 1)) if (lua_isnil(L, 1))
luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); luaL_verror(L, l_s("assertion failed! %.90s"), luaL_opt_string(L, 2, l_s("")));
lua_settop(L, 1); lua_settop(L, 1);
return 1; return 1;
} }
@@ -429,7 +429,7 @@ static int luaB_tinsert (lua_State *L) {
pos = n+1; pos = n+1;
else else
pos = luaL_check_int(L, 2); /* 2nd argument is the position */ pos = luaL_check_int(L, 2); /* 2nd argument is the position */
lua_pushliteral(L, "n"); lua_pushliteral(L, l_s("n"));
lua_pushnumber(L, n+1); lua_pushnumber(L, n+1);
lua_rawset(L, 1); /* t.n = n+1 */ lua_rawset(L, 1); /* t.n = n+1 */
for (; n>=pos; n--) { for (; n>=pos; n--) {
@@ -453,7 +453,7 @@ static int luaB_tremove (lua_State *L) {
lua_rawgeti(L, 1, pos+1); lua_rawgeti(L, 1, pos+1);
lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */ lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */
} }
lua_pushliteral(L, "n"); lua_pushliteral(L, l_s("n"));
lua_pushnumber(L, n-1); lua_pushnumber(L, n-1);
lua_rawset(L, 1); /* t.n = n-1 */ lua_rawset(L, 1); /* t.n = n-1 */
lua_pushnil(L); lua_pushnil(L);
@@ -527,12 +527,12 @@ static void auxsort (lua_State *L, int l, int u) {
for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
/* repeat ++i until a[i] >= P */ /* repeat ++i until a[i] >= P */
while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
if (i>u) lua_error(L, "invalid order function for sorting"); if (i>u) lua_error(L, l_s("invalid order function for sorting"));
lua_pop(L, 1); /* remove a[i] */ lua_pop(L, 1); /* remove a[i] */
} }
/* repeat --j until a[j] <= P */ /* repeat --j until a[j] <= P */
while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
if (j<l) lua_error(L, "invalid order function for sorting"); if (j<l) lua_error(L, l_s("invalid order function for sorting"));
lua_pop(L, 1); /* remove a[j] */ lua_pop(L, 1); /* remove a[j] */
} }
if (j<i) { if (j<i) {
@@ -581,10 +581,10 @@ static int luaB_sort (lua_State *L) {
#define num_deprecated 4 #define num_deprecated 4
static const luaL_reg deprecated_names [num_deprecated] = { static const luaL_reg deprecated_names [num_deprecated] = {
{"foreachvar", luaB_foreach}, {l_s("foreachvar"), luaB_foreach},
{"nextvar", luaB_next}, {l_s("nextvar"), luaB_next},
{"rawgetglobal", luaB_rawget}, {l_s("rawgetglobal"), luaB_rawget},
{"rawsetglobal", luaB_rawset} {l_s("rawsetglobal"), luaB_rawset}
}; };
@@ -618,7 +618,7 @@ static void deprecated_funcs (lua_State *L) {
** gives an explicit error in any attempt to call a deprecated function ** gives an explicit error in any attempt to call a deprecated function
*/ */
static int deprecated_func (lua_State *L) { static int deprecated_func (lua_State *L) {
luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1)); luaL_verror(L, l_s("function `%.20s' is deprecated"), lua_tostring(L, -1));
return 0; /* to avoid warnings */ return 0; /* to avoid warnings */
} }
@@ -637,49 +637,49 @@ static void deprecated_funcs (lua_State *L) {
/* }====================================================== */ /* }====================================================== */
static const luaL_reg base_funcs[] = { static const luaL_reg base_funcs[] = {
{LUA_ALERT, luaB__ALERT}, {l_s(LUA_ALERT), luaB__ALERT},
{LUA_ERRORMESSAGE, luaB__ERRORMESSAGE}, {l_s(LUA_ERRORMESSAGE), luaB__ERRORMESSAGE},
{"call", luaB_call}, {l_s("call"), luaB_call},
{"collectgarbage", luaB_collectgarbage}, {l_s("collectgarbage"), luaB_collectgarbage},
{"copytagmethods", luaB_copytagmethods}, {l_s("copytagmethods"), luaB_copytagmethods},
{"dofile", luaB_dofile}, {l_s("dofile"), luaB_dofile},
{"dostring", luaB_dostring}, {l_s("dostring"), luaB_dostring},
{"error", luaB_error}, {l_s("error"), luaB_error},
{"foreach", luaB_foreach}, {l_s("foreach"), luaB_foreach},
{"foreachi", luaB_foreachi}, {l_s("foreachi"), luaB_foreachi},
{"gcinfo", luaB_gcinfo}, {l_s("gcinfo"), luaB_gcinfo},
{"getglobal", luaB_getglobal}, {l_s("getglobal"), luaB_getglobal},
{"gettagmethod", luaB_gettagmethod}, {l_s("gettagmethod"), luaB_gettagmethod},
{"globals", luaB_globals}, {l_s("globals"), luaB_globals},
{"newtype", luaB_newtype}, {l_s("newtype"), luaB_newtype},
{"newtag", luaB_newtype}, /* for compatibility 4.0 */ {l_s("newtag"), luaB_newtype}, /* for compatibility 4.0 */
{"next", luaB_next}, {l_s("next"), luaB_next},
{"print", luaB_print}, {l_s("print"), luaB_print},
{"rawget", luaB_rawget}, {l_s("rawget"), luaB_rawget},
{"rawset", luaB_rawset}, {l_s("rawset"), luaB_rawset},
{"rawgettable", luaB_rawget}, /* for compatibility 3.2 */ {l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */
{"rawsettable", luaB_rawset}, /* for compatibility 3.2 */ {l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */
{"setglobal", luaB_setglobal}, {l_s("setglobal"), luaB_setglobal},
{"settag", luaB_settag}, {l_s("settag"), luaB_settag},
{"settagmethod", luaB_settagmethod}, {l_s("settagmethod"), luaB_settagmethod},
{"tag", luaB_tag}, {l_s("tag"), luaB_tag},
{"tonumber", luaB_tonumber}, {l_s("tonumber"), luaB_tonumber},
{"tostring", luaB_tostring}, {l_s("tostring"), luaB_tostring},
{"type", luaB_type}, {l_s("type"), luaB_type},
{"assert", luaB_assert}, {l_s("assert"), luaB_assert},
{"getn", luaB_getn}, {l_s("getn"), luaB_getn},
{"sort", luaB_sort}, {l_s("sort"), luaB_sort},
{"tinsert", luaB_tinsert}, {l_s("tinsert"), luaB_tinsert},
{"tremove", luaB_tremove}, {l_s("tremove"), luaB_tremove},
{"xtype", luaB_xtype}, {l_s("xtype"), luaB_xtype},
}; };
LUALIB_API void lua_baselibopen (lua_State *L) { LUALIB_API void lua_baselibopen (lua_State *L) {
luaL_openl(L, base_funcs); luaL_openl(L, base_funcs);
lua_pushliteral(L, LUA_VERSION); lua_pushliteral(L, l_s(LUA_VERSION));
lua_setglobal(L, "_VERSION"); lua_setglobal(L, l_s("_VERSION"));
deprecated_funcs(L); deprecated_funcs(L);
} }

16
lcode.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 1.61 2001/02/08 11:19:10 roberto Exp roberto $ ** $Id: lcode.c,v 1.62 2001/02/12 19:21:19 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -18,7 +18,7 @@
#include "lparser.h" #include "lparser.h"
void luaK_error (LexState *ls, const char *msg) { void luaK_error (LexState *ls, const l_char *msg) {
luaX_error(ls, msg, ls->t.token); luaX_error(ls, msg, ls->t.token);
} }
@@ -53,7 +53,7 @@ static void luaK_fixjump (FuncState *fs, int pc, int dest) {
else { /* jump is relative to position following jump instruction */ else { /* jump is relative to position following jump instruction */
int offset = dest-(pc+1); int offset = dest-(pc+1);
if (abs(offset) > MAXARG_S) if (abs(offset) > MAXARG_S)
luaK_error(fs->ls, "control structure too long"); luaK_error(fs->ls, l_s("control structure too long"));
SETARG_S(*jmp, offset); SETARG_S(*jmp, offset);
} }
} }
@@ -99,7 +99,7 @@ void luaK_deltastack (FuncState *fs, int delta) {
fs->stacklevel += delta; fs->stacklevel += delta;
if (fs->stacklevel > fs->f->maxstacksize) { if (fs->stacklevel > fs->f->maxstacksize) {
if (fs->stacklevel > MAXSTACK) if (fs->stacklevel > MAXSTACK)
luaK_error(fs->ls, "function or expression too complex"); luaK_error(fs->ls, l_s("function or expression too complex"));
fs->f->maxstacksize = (short)fs->stacklevel; fs->f->maxstacksize = (short)fs->stacklevel;
} }
} }
@@ -119,7 +119,7 @@ static int number_constant (FuncState *fs, lua_Number r) {
if (f->knum[c] == r) return c; if (f->knum[c] == r) return c;
/* not found; create a new entry */ /* not found; create a new entry */
luaM_growvector(fs->L, f->knum, fs->nknum, f->sizeknum, lua_Number, luaM_growvector(fs->L, f->knum, fs->nknum, f->sizeknum, lua_Number,
MAXARG_U, "constant table overflow"); MAXARG_U, l_s("constant table overflow"));
c = fs->nknum++; c = fs->nknum++;
f->knum[c] = r; f->knum[c] = r;
return c; return c;
@@ -436,11 +436,11 @@ static void codelineinfo (FuncState *fs) {
if (ls->lastline > fs->lastline) { if (ls->lastline > fs->lastline) {
if (ls->lastline > fs->lastline+1) { if (ls->lastline > fs->lastline+1) {
luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int,
MAX_INT, "line info overflow"); MAX_INT, l_s("line info overflow"));
f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1));
} }
luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int,
MAX_INT, "line info overflow"); MAX_INT, l_s("line info overflow"));
f->lineinfo[fs->nlineinfo++] = fs->pc; f->lineinfo[fs->nlineinfo++] = fs->pc;
fs->lastline = ls->lastline; fs->lastline = ls->lastline;
} }
@@ -660,7 +660,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
codelineinfo(fs); codelineinfo(fs);
/* put new instruction in code array */ /* put new instruction in code array */
luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
MAX_INT, "code size overflow"); MAX_INT, l_s("code size overflow"));
f->code[fs->pc] = i; f->code[fs->pc] = i;
return fs->pc++; return fs->pc++;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lcode.h,v 1.19 2001/01/29 15:26:40 roberto Exp roberto $ ** $Id: lcode.h,v 1.20 2001/02/20 18:15:33 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -47,7 +47,7 @@ typedef struct OpProperties {
extern const OpProperties luaK_opproperties[]; extern const OpProperties luaK_opproperties[];
void luaK_error (LexState *ls, const char *msg); void luaK_error (LexState *ls, const l_char *msg);
int luaK_code0 (FuncState *fs, OpCode o); int luaK_code0 (FuncState *fs, OpCode o);
int luaK_code1 (FuncState *fs, OpCode o, int arg1); int luaK_code1 (FuncState *fs, OpCode o, int arg1);
int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2); int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldblib.c,v 1.31 2001/01/10 16:58:11 roberto Exp roberto $ ** $Id: ldblib.c,v 1.32 2001/02/02 19:02:40 roberto Exp roberto $
** Interface from Lua to its debug API ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -17,14 +17,14 @@
static void settabss (lua_State *L, const char *i, const char *v) { static void settabss (lua_State *L, const l_char *i, const l_char *v) {
lua_pushstring(L, i); lua_pushstring(L, i);
lua_pushstring(L, v); lua_pushstring(L, v);
lua_settable(L, -3); lua_settable(L, -3);
} }
static void settabsi (lua_State *L, const char *i, int v) { static void settabsi (lua_State *L, const l_char *i, int v) {
lua_pushstring(L, i); lua_pushstring(L, i);
lua_pushnumber(L, v); lua_pushnumber(L, v);
lua_settable(L, -3); lua_settable(L, -3);
@@ -33,8 +33,8 @@ static void settabsi (lua_State *L, const char *i, int v) {
static int getinfo (lua_State *L) { static int getinfo (lua_State *L) {
lua_Debug ar; lua_Debug ar;
const char *options = luaL_opt_string(L, 2, "flnSu"); const l_char *options = luaL_opt_string(L, 2, l_s("flnSu"));
char buff[20]; l_char buff[20];
if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 1)) {
if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) { if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) {
lua_pushnil(L); /* level out of range */ lua_pushnil(L); /* level out of range */
@@ -43,35 +43,35 @@ static int getinfo (lua_State *L) {
} }
else if (lua_isfunction(L, 1)) { else if (lua_isfunction(L, 1)) {
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
sprintf(buff, ">%.10s", options); sprintf(buff, l_s(">%.10s"), options);
options = buff; options = buff;
} }
else else
luaL_argerror(L, 1, "function or level expected"); luaL_argerror(L, 1, l_s("function or level expected"));
if (!lua_getinfo(L, options, &ar)) if (!lua_getinfo(L, options, &ar))
luaL_argerror(L, 2, "invalid option"); luaL_argerror(L, 2, l_s("invalid option"));
lua_newtable(L); lua_newtable(L);
for (; *options; options++) { for (; *options; options++) {
switch (*options) { switch (*options) {
case 'S': case l_c('S'):
settabss(L, "source", ar.source); settabss(L, l_s("source"), ar.source);
if (ar.source) if (ar.source)
settabss(L, "short_src", ar.short_src); settabss(L, l_s("short_src"), ar.short_src);
settabsi(L, "linedefined", ar.linedefined); settabsi(L, l_s("linedefined"), ar.linedefined);
settabss(L, "what", ar.what); settabss(L, l_s("what"), ar.what);
break; break;
case 'l': case l_c('l'):
settabsi(L, "currentline", ar.currentline); settabsi(L, l_s("currentline"), ar.currentline);
break; break;
case 'u': case l_c('u'):
settabsi(L, "nups", ar.nups); settabsi(L, l_s("nups"), ar.nups);
break; break;
case 'n': case l_c('n'):
settabss(L, "name", ar.name); settabss(L, l_s("name"), ar.name);
settabss(L, "namewhat", ar.namewhat); settabss(L, l_s("namewhat"), ar.namewhat);
break; break;
case 'f': case l_c('f'):
lua_pushliteral(L, "func"); lua_pushliteral(L, l_s("func"));
lua_pushvalue(L, -3); lua_pushvalue(L, -3);
lua_settable(L, -3); lua_settable(L, -3);
break; break;
@@ -83,9 +83,9 @@ static int getinfo (lua_State *L) {
static int getlocal (lua_State *L) { static int getlocal (lua_State *L) {
lua_Debug ar; lua_Debug ar;
const char *name; const l_char *name;
if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */
luaL_argerror(L, 1, "level out of range"); luaL_argerror(L, 1, l_s("level out of range"));
name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); name = lua_getlocal(L, &ar, luaL_check_int(L, 2));
if (name) { if (name) {
lua_pushstring(L, name); lua_pushstring(L, name);
@@ -102,7 +102,7 @@ static int getlocal (lua_State *L) {
static int setlocal (lua_State *L) { static int setlocal (lua_State *L) {
lua_Debug ar; lua_Debug ar;
if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */
luaL_argerror(L, 1, "level out of range"); luaL_argerror(L, 1, l_s("level out of range"));
luaL_checkany(L, 3); luaL_checkany(L, 3);
lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2)));
return 1; return 1;
@@ -111,7 +111,7 @@ static int setlocal (lua_State *L) {
/* dummy variables (to define unique addresses) */ /* dummy variables (to define unique addresses) */
static const char key1[] = "ab"; static const l_char key1[] = l_s("ab");
#define KEY_CALLHOOK ((void *)key1) #define KEY_CALLHOOK ((void *)key1)
#define KEY_LINEHOOK ((void *)(key1+1)) #define KEY_LINEHOOK ((void *)(key1+1))
@@ -150,7 +150,7 @@ static void sethook (lua_State *L, void *key, lua_Hook hook,
else if (lua_isfunction(L, 1)) else if (lua_isfunction(L, 1))
(*sethookf)(L, hook); (*sethookf)(L, hook);
else else
luaL_argerror(L, 1, "function expected"); luaL_argerror(L, 1, l_s("function expected"));
lua_getregistry(L); lua_getregistry(L);
lua_pushuserdata(L, key); lua_pushuserdata(L, key);
lua_pushvalue(L, -1); /* dup key */ lua_pushvalue(L, -1); /* dup key */
@@ -174,11 +174,11 @@ static int setlinehook (lua_State *L) {
static const luaL_reg dblib[] = { static const luaL_reg dblib[] = {
{"getlocal", getlocal}, {l_s("getlocal"), getlocal},
{"getinfo", getinfo}, {l_s("getinfo"), getinfo},
{"setcallhook", setcallhook}, {l_s("setcallhook"), setcallhook},
{"setlinehook", setlinehook}, {l_s("setlinehook"), setlinehook},
{"setlocal", setlocal} {l_s("setlocal"), setlocal}
}; };

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 1.67 2001/02/21 16:52:09 roberto Exp roberto $ ** $Id: ldebug.c,v 1.68 2001/02/22 18:59:59 roberto Exp roberto $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -24,7 +24,7 @@
static const char *getfuncname (lua_State *L, StkId f, const char **name); static const l_char *getfuncname (lua_State *L, StkId f, const l_char **name);
static void setnormalized (TObject *d, const TObject *s) { static void setnormalized (TObject *d, const TObject *s) {
@@ -158,8 +158,8 @@ static Proto *getluaproto (StkId f) {
} }
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { LUA_API const l_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name; const l_char *name;
StkId f; StkId f;
Proto *fp; Proto *fp;
LUA_LOCK(L); LUA_LOCK(L);
@@ -176,8 +176,8 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
} }
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name; const l_char *name;
StkId f; StkId f;
Proto *fp; Proto *fp;
LUA_LOCK(L); LUA_LOCK(L);
@@ -187,7 +187,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
L->top--; /* pop new value */ L->top--; /* pop new value */
if (fp) { /* `f' is a Lua function? */ if (fp) { /* `f' is a Lua function? */
name = luaF_getlocalname(fp, n, currentpc(f)); name = luaF_getlocalname(fp, n, currentpc(f));
if (!name || name[0] == '(') /* `(' starts private locals */ if (!name || name[0] == l_c('(')) /* `(' starts private locals */
name = NULL; name = NULL;
else else
setobj((f+1)+(n-1), L->top); 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) {
static void infoLproto (lua_Debug *ar, Proto *f) { static void infoLproto (lua_Debug *ar, Proto *f) {
ar->source = getstr(f->source); ar->source = getstr(f->source);
ar->linedefined = f->lineDefined; ar->linedefined = f->lineDefined;
ar->what = "Lua"; ar->what = l_s("Lua");
} }
@@ -214,22 +214,22 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
cl = infovalue(func)->func; cl = infovalue(func)->func;
break; break;
default: default:
luaD_error(L, "value for `lua_getinfo' is not a function"); luaD_error(L, l_s("value for `lua_getinfo' is not a function"));
} }
if (cl->isC) { if (cl->isC) {
ar->source = "=C"; ar->source = l_s("=C");
ar->linedefined = -1; ar->linedefined = -1;
ar->what = "C"; ar->what = l_s("C");
} }
else else
infoLproto(ar, cl->f.l); infoLproto(ar, cl->f.l);
luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src));
if (ar->linedefined == 0) if (ar->linedefined == 0)
ar->what = "main"; ar->what = l_s("main");
} }
static const char *travtagmethods (global_State *G, const TObject *o) { static const l_char *travtagmethods (global_State *G, const TObject *o) {
if (ttype(o) == LUA_TFUNCTION) { if (ttype(o) == LUA_TFUNCTION) {
int e; int e;
for (e=0; e<TM_N; e++) { for (e=0; e<TM_N; e++) {
@@ -243,7 +243,7 @@ static const char *travtagmethods (global_State *G, const TObject *o) {
} }
static const char *travglobals (lua_State *L, const TObject *o) { static const l_char *travglobals (lua_State *L, const TObject *o) {
Hash *g = L->gt; Hash *g = L->gt;
int i; int i;
for (i=0; i<g->size; i++) { for (i=0; i<g->size; i++) {
@@ -260,20 +260,20 @@ static void getname (lua_State *L, StkId f, lua_Debug *ar) {
setnormalized(&o, f); setnormalized(&o, f);
/* try to find a name for given function */ /* try to find a name for given function */
if ((ar->name = travglobals(L, &o)) != NULL) if ((ar->name = travglobals(L, &o)) != NULL)
ar->namewhat = "global"; ar->namewhat = l_s("global");
/* not found: try tag methods */ /* not found: try tag methods */
else if ((ar->name = travtagmethods(G(L), &o)) != NULL) else if ((ar->name = travtagmethods(G(L), &o)) != NULL)
ar->namewhat = "tag-method"; ar->namewhat = l_s("tag-method");
else ar->namewhat = ""; /* not found at all */ else ar->namewhat = l_s(""); /* not found at all */
} }
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { LUA_API int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar) {
StkId func; StkId func;
int isactive; int isactive;
int status = 1; int status = 1;
LUA_LOCK(L); LUA_LOCK(L);
isactive = (*what != '>'); isactive = (*what != l_c('>'));
if (isactive) if (isactive)
func = ar->_func; func = ar->_func;
else { else {
@@ -282,25 +282,25 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
} }
for (; *what; what++) { for (; *what; what++) {
switch (*what) { switch (*what) {
case 'S': { case l_c('S'): {
funcinfo(L, ar, func); funcinfo(L, ar, func);
break; break;
} }
case 'l': { case l_c('l'): {
ar->currentline = currentline(func); ar->currentline = currentline(func);
break; break;
} }
case 'u': { case l_c('u'): {
ar->nups = nups(func); ar->nups = nups(func);
break; break;
} }
case 'n': { case l_c('n'): {
ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL; ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL;
if (ar->namewhat == NULL) if (ar->namewhat == NULL)
getname(L, func, ar); getname(L, func, ar);
break; break;
} }
case 'f': { case l_c('f'): {
setnormalized(L->top, func); setnormalized(L->top, func);
incr_top; /* push function */ incr_top; /* push function */
break; break;
@@ -543,7 +543,7 @@ int luaG_checkcode (lua_State *L, const Proto *pt) {
} }
static const char *getobjname (lua_State *L, StkId obj, const char **name) { static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) {
StkId func = aux_stackedfunction(L, 0, obj); StkId func = aux_stackedfunction(L, 0, obj);
if (!isLmark(func)) if (!isLmark(func))
return NULL; /* not an active Lua function */ return NULL; /* not an active Lua function */
@@ -556,17 +556,17 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) {
switch (GET_OPCODE(i)) { switch (GET_OPCODE(i)) {
case OP_GETGLOBAL: { case OP_GETGLOBAL: {
*name = getstr(p->kstr[GETARG_U(i)]); *name = getstr(p->kstr[GETARG_U(i)]);
return "global"; return l_s("global");
} }
case OP_GETLOCAL: { case OP_GETLOCAL: {
*name = luaF_getlocalname(p, GETARG_U(i)+1, pc); *name = luaF_getlocalname(p, GETARG_U(i)+1, pc);
lua_assert(*name); lua_assert(*name);
return "local"; return l_s("local");
} }
case OP_PUSHSELF: case OP_PUSHSELF:
case OP_GETDOTTED: { case OP_GETDOTTED: {
*name = getstr(p->kstr[GETARG_U(i)]); *name = getstr(p->kstr[GETARG_U(i)]);
return "field"; return l_s("field");
} }
default: default:
return NULL; /* no useful name found */ return NULL; /* no useful name found */
@@ -575,7 +575,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) {
} }
static const char *getfuncname (lua_State *L, StkId f, const char **name) { static const l_char *getfuncname (lua_State *L, StkId f, const l_char **name) {
StkId func = aux_stackedfunction(L, 0, f); /* calling function */ StkId func = aux_stackedfunction(L, 0, f); /* calling function */
if (!isLmark(func)) if (!isLmark(func))
return NULL; /* not an active Lua function */ return NULL; /* not an active Lua function */
@@ -595,19 +595,19 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) {
} }
void luaG_typeerror (lua_State *L, StkId o, const char *op) { void luaG_typeerror (lua_State *L, StkId o, const l_char *op) {
const char *name; const l_char *name;
const char *kind = getobjname(L, o, &name); const l_char *kind = getobjname(L, o, &name);
const char *t = luaT_typename(G(L), o); const l_char *t = luaT_typename(G(L), o);
if (kind) if (kind)
luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", luaO_verror(L, l_s("attempt to %.30s %.20s `%.40s' (a %.10s value)"),
op, kind, name, t); op, kind, name, t);
else else
luaO_verror(L, "attempt to %.30s a %.10s value", op, t); luaO_verror(L, l_s("attempt to %.30s a %.10s value"), op, t);
} }
void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { void luaG_binerror (lua_State *L, StkId p1, int t, const l_char *op) {
if (ttype(p1) == t) p1++; if (ttype(p1) == t) p1++;
lua_assert(ttype(p1) != t); lua_assert(ttype(p1) != t);
luaG_typeerror(L, p1, op); luaG_typeerror(L, p1, op);
@@ -615,11 +615,11 @@ void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) {
void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
const char *t1 = luaT_typename(G(L), p1); const l_char *t1 = luaT_typename(G(L), p1);
const char *t2 = luaT_typename(G(L), p2); const l_char *t2 = luaT_typename(G(L), p2);
if (t1[2] == t2[2]) if (t1[2] == t2[2])
luaO_verror(L, "attempt to compare two %.10s values", t1); luaO_verror(L, l_s("attempt to compare two %.10s values"), t1);
else else
luaO_verror(L, "attempt to compare %.10s with %.10s", t1, t2); luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2);
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.h,v 1.9 2001/02/09 18:37:33 roberto Exp roberto $ ** $Id: ldebug.h,v 1.10 2001/02/12 19:54:50 roberto Exp roberto $
** Auxiliary functions from Debug Interface module ** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -12,8 +12,8 @@
#include "luadebug.h" #include "luadebug.h"
void luaG_typeerror (lua_State *L, StkId o, const char *op); void luaG_typeerror (lua_State *L, StkId o, const l_char *op);
void luaG_binerror (lua_State *L, StkId p1, int t, const char *op); void luaG_binerror (lua_State *L, StkId p1, int t, const l_char *op);
int luaG_getline (int *lineinfo, int pc, int refline, int *refi); int luaG_getline (int *lineinfo, int pc, int refline, int *refi);
void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2);
int luaG_checkcode (lua_State *L, const Proto *pt); int luaG_checkcode (lua_State *L, const Proto *pt);

44
ldo.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 1.126 2001/02/22 18:59:59 roberto Exp roberto $ ** $Id: ldo.c,v 1.127 2001/02/23 13:38:56 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -56,7 +56,7 @@ void luaD_checkstack (lua_State *L, int n) {
else { else {
L->stack_last += EXTRA_STACK; /* to be used by error message */ L->stack_last += EXTRA_STACK; /* to be used by error message */
lua_assert(L->stack_last == L->stack+L->stacksize-1); lua_assert(L->stack_last == L->stack+L->stacksize-1);
luaD_error(L, "stack overflow"); luaD_error(L, l_s("stack overflow"));
} }
} }
} }
@@ -108,7 +108,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) {
if (L->allowhooks) { if (L->allowhooks) {
lua_Debug ar; lua_Debug ar;
ar._func = func; ar._func = func;
ar.event = "line"; ar.event = l_s("line");
ar.currentline = line; ar.currentline = line;
dohook(L, &ar, linehook); dohook(L, &ar, linehook);
} }
@@ -116,7 +116,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) {
static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook,
const char *event) { const l_char *event) {
if (L->allowhooks) { if (L->allowhooks) {
lua_Debug ar; lua_Debug ar;
ar._func = func; ar._func = func;
@@ -159,7 +159,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
/* `func' is not a function; check the `function' tag method */ /* `func' is not a function; check the `function' tag method */
Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION);
if (tm == NULL) if (tm == NULL)
luaG_typeerror(L, func, "call"); luaG_typeerror(L, func, l_s("call"));
luaD_openstack(L, func); luaD_openstack(L, func);
setclvalue(func, tm); /* tag method is the new function to be called */ setclvalue(func, tm); /* tag method is the new function to be called */
} }
@@ -168,11 +168,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
setivalue(func, &ci); setivalue(func, &ci);
callhook = L->callhook; callhook = L->callhook;
if (callhook) if (callhook)
luaD_callHook(L, func, callhook, "call"); luaD_callHook(L, func, callhook, l_s("call"));
firstResult = (cl->isC ? callCclosure(L, cl, func+1) : firstResult = (cl->isC ? callCclosure(L, cl, func+1) :
luaV_execute(L, cl, func+1)); luaV_execute(L, cl, func+1));
if (callhook) /* same hook that was active at entry */ if (callhook) /* same hook that was active at entry */
luaD_callHook(L, func, callhook, "return"); luaD_callHook(L, func, callhook, l_s("return"));
lua_assert(ttype(func) == LUA_TMARK); lua_assert(ttype(func) == LUA_TMARK);
setnilvalue(func); /* remove callinfo from the stack */ setnilvalue(func); /* remove callinfo from the stack */
/* move results to `func' (to erase parameters and function) */ /* move results to `func' (to erase parameters and function) */
@@ -261,20 +261,20 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
} }
static int parse_file (lua_State *L, const char *filename) { static int parse_file (lua_State *L, const l_char *filename) {
ZIO z; ZIO z;
int status; int status;
int bin; /* flag for file mode */ int bin; /* flag for file mode */
FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r"));
if (f == NULL) return LUA_ERRFILE; /* unable to open file */ if (f == NULL) return LUA_ERRFILE; /* unable to open file */
bin = (ungetc(fgetc(f), f) == ID_CHUNK); bin = (ungetc(fgetc(f), f) == ID_CHUNK);
if (bin && f != stdin) { if (bin && f != stdin) {
fclose(f); fclose(f);
f = fopen(filename, "rb"); /* reopen in binary mode */ f = fopen(filename, l_s("rb")); /* reopen in binary mode */
if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */
} }
lua_pushliteral(L, "@"); lua_pushliteral(L, l_s("@"));
lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename);
lua_concat(L, 2); lua_concat(L, 2);
filename = lua_tostring(L, -1); /* filename = `@'..filename */ filename = lua_tostring(L, -1); /* filename = `@'..filename */
luaZ_Fopen(&z, f, filename); luaZ_Fopen(&z, f, filename);
@@ -286,7 +286,7 @@ static int parse_file (lua_State *L, const char *filename) {
} }
LUA_API int lua_dofile (lua_State *L, const char *filename) { LUA_API int lua_dofile (lua_State *L, const l_char *filename) {
int status; int status;
status = parse_file(L, filename); status = parse_file(L, filename);
if (status == 0) /* parse OK? */ if (status == 0) /* parse OK? */
@@ -295,18 +295,18 @@ LUA_API int lua_dofile (lua_State *L, const char *filename) {
} }
static int parse_buffer (lua_State *L, const char *buff, size_t size, static int parse_buffer (lua_State *L, const l_char *buff, size_t size,
const char *name) { const l_char *name) {
ZIO z; ZIO z;
int status; int status;
if (!name) name = "?"; if (!name) name = l_s("?");
luaZ_mopen(&z, buff, size, name); luaZ_mopen(&z, buff, size, name);
status = protectedparser(L, &z, buff[0]==ID_CHUNK); status = protectedparser(L, &z, buff[0]==ID_CHUNK);
return status; return status;
} }
LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name) { LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, const l_char *name) {
int status; int status;
status = parse_buffer(L, buff, size, name); status = parse_buffer(L, buff, size, name);
if (status == 0) /* parse OK? */ 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
} }
LUA_API int lua_dostring (lua_State *L, const char *str) { LUA_API int lua_dostring (lua_State *L, const l_char *str) {
return lua_dobuffer(L, str, strlen(str), str); return lua_dobuffer(L, str, strlen(str), str);
} }
@@ -334,8 +334,8 @@ struct lua_longjmp {
}; };
static void message (lua_State *L, const char *s) { static void message (lua_State *L, const l_char *s) {
luaV_getglobal(L, luaS_newliteral(L, LUA_ERRORMESSAGE), L->top); luaV_getglobal(L, luaS_newliteral(L, l_s(LUA_ERRORMESSAGE)), L->top);
if (ttype(L->top) == LUA_TFUNCTION) { if (ttype(L->top) == LUA_TFUNCTION) {
incr_top; incr_top;
setsvalue(L->top, luaS_new(L, s)); setsvalue(L->top, luaS_new(L, s));
@@ -348,7 +348,7 @@ static void message (lua_State *L, const char *s) {
/* /*
** Reports an error, and jumps up to the available recovery label ** Reports an error, and jumps up to the available recovery label
*/ */
void luaD_error (lua_State *L, const char *s) { void luaD_error (lua_State *L, const l_char *s) {
if (s) message(L, s); if (s) message(L, s);
luaD_breakrun(L, LUA_ERRRUN); luaD_breakrun(L, LUA_ERRRUN);
} }
@@ -361,7 +361,7 @@ void luaD_breakrun (lua_State *L, int errcode) {
} }
else { else {
if (errcode != LUA_ERRMEM) if (errcode != LUA_ERRMEM)
message(L, "unable to recover; exiting\n"); message(L, l_s("unable to recover; exiting\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }

4
ldo.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldo.h,v 1.29 2001/01/24 15:45:33 roberto Exp roberto $ ** $Id: ldo.h,v 1.30 2001/02/07 18:13:49 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -25,7 +25,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook);
void luaD_call (lua_State *L, StkId func, int nResults); void luaD_call (lua_State *L, StkId func, int nResults);
void luaD_checkstack (lua_State *L, int n); void luaD_checkstack (lua_State *L, int n);
void luaD_error (lua_State *L, const char *s); void luaD_error (lua_State *L, const l_char *s);
void luaD_breakrun (lua_State *L, int errcode); void luaD_breakrun (lua_State *L, int errcode);
int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud); int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.c,v 1.40 2001/02/09 20:22:29 roberto Exp roberto $ ** $Id: lfunc.c,v 1.41 2001/02/20 18:28:11 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -74,7 +74,7 @@ void luaF_freeclosure (lua_State *L, Closure *c) {
** Look for n-th local variable at line `line' in function `func'. ** Look for n-th local variable at line `line' in function `func'.
** Returns NULL if not found. ** Returns NULL if not found.
*/ */
const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { const l_char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
int i; int i;
for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) { for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
if (pc < f->locvars[i].endpc) { /* is variable active? */ if (pc < f->locvars[i].endpc) { /* is variable active? */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.h,v 1.13 2000/09/29 12:42:13 roberto Exp roberto $ ** $Id: lfunc.h,v 1.14 2000/12/28 12:55:41 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -17,7 +17,7 @@ Closure *luaF_newclosure (lua_State *L, int nelems);
void luaF_freeproto (lua_State *L, Proto *f); void luaF_freeproto (lua_State *L, Proto *f);
void luaF_freeclosure (lua_State *L, Closure *c); void luaF_freeclosure (lua_State *L, Closure *c);
const char *luaF_getlocalname (const Proto *func, int local_number, int pc); const l_char *luaF_getlocalname (const Proto *func, int local_number, int pc);
#endif #endif

4
lgc.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.90 2001/02/20 18:28:11 roberto Exp roberto $ ** $Id: lgc.c,v 1.91 2001/02/22 18:59:59 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -331,7 +331,7 @@ static void collectudata (lua_State *L, int all) {
static void checkMbuffer (lua_State *L) { static void checkMbuffer (lua_State *L) {
if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */
size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */
luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, char); luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, l_char);
G(L)->Mbuffsize = newsize; G(L)->Mbuffsize = newsize;
} }
} }

252
liolib.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 1.106 2001/02/09 19:52:54 roberto Exp roberto $ ** $Id: liolib.c,v 1.107 2001/02/22 17:15:18 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -47,10 +47,10 @@ int pclose(); */
#define OUTFILE 1 #define OUTFILE 1
#define NOFILE 2 #define NOFILE 2
#define FILEHANDLE "FileHandle" #define FILEHANDLE l_s("FileHandle")
static const char *const filenames[] = {"_INPUT", "_OUTPUT"}; static const l_char *const filenames[] = {l_s("_INPUT"), l_s("_OUTPUT")};
static int pushresult (lua_State *L, int i) { static int pushresult (lua_State *L, int i) {
@@ -81,10 +81,10 @@ static FILE *getopthandle (lua_State *L, int inout) {
FILE *p = (FILE *)lua_touserdata(L, 1); FILE *p = (FILE *)lua_touserdata(L, 1);
if (p != NULL) { /* is it a userdata ? */ if (p != NULL) { /* is it a userdata ? */
if (!checkfile(L, 1)) { if (!checkfile(L, 1)) {
if (strcmp(lua_xtype(L, 1), "ClosedFileHandle") == 0) if (strcmp(lua_xtype(L, 1), l_s("ClosedFileHandle")) == 0)
luaL_argerror(L, 1, "file is closed"); luaL_argerror(L, 1, l_s("file is closed"));
else else
luaL_argerror(L, 1, "(invalid value)"); luaL_argerror(L, 1, l_s("(invalid value)"));
} }
/* move it to stack top */ /* move it to stack top */
lua_pushvalue(L, 1); lua_remove(L, 1); lua_pushvalue(L, 1); lua_remove(L, 1);
@@ -92,7 +92,7 @@ static FILE *getopthandle (lua_State *L, int inout) {
else if (inout != NOFILE) { /* try global value */ else if (inout != NOFILE) { /* try global value */
lua_getglobal(L, filenames[inout]); lua_getglobal(L, filenames[inout]);
if (!checkfile(L,-1)) if (!checkfile(L,-1))
luaL_verror(L, "global variable `%.10s' is not a valid file handle", luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"),
filenames[inout]); filenames[inout]);
p = (FILE *)lua_touserdata(L, -1); p = (FILE *)lua_touserdata(L, -1);
} }
@@ -105,7 +105,7 @@ static void pushfile (lua_State *L, FILE *f) {
} }
static void setfilebyname (lua_State *L, FILE *f, const char *name) { static void setfilebyname (lua_State *L, FILE *f, const l_char *name) {
pushfile(L, f); pushfile(L, f);
lua_setglobal(L, name); lua_setglobal(L, name);
} }
@@ -131,7 +131,7 @@ static int closefile (lua_State *L, FILE *f) {
return 1; return 1;
else { else {
lua_pushuserdata(L, f); lua_pushuserdata(L, f);
lua_settag(L, lua_type2tag(L, "ClosedFileHandle")); lua_settag(L, lua_type2tag(L, l_s("ClosedFileHandle")));
return (CLOSEFILE(L, f) == 0); return (CLOSEFILE(L, f) == 0);
} }
} }
@@ -163,7 +163,7 @@ static int io_tmpfile (lua_State *L) {
static int io_fromto (lua_State *L, int inout, const char *mode) { static int io_fromto (lua_State *L, int inout, const l_char *mode) {
FILE *current; FILE *current;
if (lua_isnull(L, 1)) { if (lua_isnull(L, 1)) {
closefile(L, getopthandle(L, inout)); closefile(L, getopthandle(L, inout));
@@ -172,25 +172,25 @@ static int io_fromto (lua_State *L, int inout, const char *mode) {
else if (checkfile(L, 1)) /* deprecated option */ else if (checkfile(L, 1)) /* deprecated option */
current = (FILE *)lua_touserdata(L, 1); current = (FILE *)lua_touserdata(L, 1);
else { else {
const char *s = luaL_check_string(L, 1); const l_char *s = luaL_check_string(L, 1);
current = (*s == '|') ? popen(s+1, mode) : fopen(s, mode); current = (*s == l_c('|')) ? popen(s+1, mode) : fopen(s, mode);
} }
return setreturn(L, current, inout); return setreturn(L, current, inout);
} }
static int io_readfrom (lua_State *L) { static int io_readfrom (lua_State *L) {
return io_fromto(L, INFILE, "r"); return io_fromto(L, INFILE, l_s("r"));
} }
static int io_writeto (lua_State *L) { static int io_writeto (lua_State *L) {
return io_fromto(L, OUTFILE, "w"); return io_fromto(L, OUTFILE, l_s("w"));
} }
static int io_appendto (lua_State *L) { static int io_appendto (lua_State *L) {
FILE *current = fopen(luaL_check_string(L, 1), "a"); FILE *current = fopen(luaL_check_string(L, 1), l_s("a"));
return setreturn(L, current, OUTFILE); return setreturn(L, current, OUTFILE);
} }
@@ -205,7 +205,7 @@ static int io_appendto (lua_State *L) {
static int read_number (lua_State *L, FILE *f) { static int read_number (lua_State *L, FILE *f) {
double d; double d;
if (fscanf(f, "%lf", &d) == 1) { if (fscanf(f, l_s("%lf"), &d) == 1) {
lua_pushnumber(L, d); lua_pushnumber(L, d);
return 1; return 1;
} }
@@ -233,11 +233,11 @@ static int read_line (lua_State *L, FILE *f) {
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (;;) { for (;;) {
char *p = luaL_prepbuffer(&b); l_char *p = luaL_prepbuffer(&b);
if (!fgets(p, LUAL_BUFFERSIZE, f)) /* read fails? */ if (!fgets(p, LUAL_BUFFERSIZE, f)) /* read fails? */
break; break;
n = strlen(p); n = strlen(p);
if (p[n-1] != '\n') if (p[n-1] != l_c('\n'))
luaL_addsize(&b, n); luaL_addsize(&b, n);
else { else {
luaL_addsize(&b, n-1); /* do not add the `\n' */ luaL_addsize(&b, n-1); /* do not add the `\n' */
@@ -253,15 +253,15 @@ static void read_file (lua_State *L, FILE *f) {
size_t len = 0; size_t len = 0;
size_t size = LUAL_BUFFERSIZE; size_t size = LUAL_BUFFERSIZE;
size_t oldsize = 0; size_t oldsize = 0;
char *buffer = NULL; l_char *buffer = NULL;
for (;;) { for (;;) {
char *newbuffer = (char *)l_realloc(buffer, oldsize, size); l_char *newbuffer = (l_char *)l_realloc(buffer, oldsize, size);
if (newbuffer == NULL) { if (newbuffer == NULL) {
l_free(buffer, oldsize); l_free(buffer, oldsize);
lua_error(L, "not enough memory to read a file"); lua_error(L, l_s("not enough memory to read a file"));
} }
buffer = newbuffer; buffer = newbuffer;
len += fread(buffer+len, sizeof(char), size-len, f); len += fread(buffer+len, sizeof(l_char), size-len, f);
if (len < size) break; /* did not read all it could */ if (len < size) break; /* did not read all it could */
oldsize = size; oldsize = size;
size *= 2; size *= 2;
@@ -279,17 +279,17 @@ static int read_chars (lua_State *L, FILE *f, size_t n) {
return (c != EOF); return (c != EOF);
} }
else { else {
char *buffer; l_char *buffer;
size_t n1; size_t n1;
char statbuff[LUAL_BUFFERSIZE]; l_char statbuff[LUAL_BUFFERSIZE];
if (n <= LUAL_BUFFERSIZE) if (n <= LUAL_BUFFERSIZE)
buffer = statbuff; buffer = statbuff;
else { else {
buffer = (char *)l_malloc(n); buffer = (l_char *)l_malloc(n);
if (buffer == NULL) if (buffer == NULL)
lua_error(L, "not enough memory to read a file"); lua_error(L, l_s("not enough memory to read a file"));
} }
n1 = fread(buffer, sizeof(char), n, f); n1 = fread(buffer, sizeof(l_char), n, f);
lua_pushlstring(L, buffer, n1); lua_pushlstring(L, buffer, n1);
if (buffer != statbuff) l_free(buffer, n); if (buffer != statbuff) l_free(buffer, n);
return (n1 > 0 || n == 0); return (n1 > 0 || n == 0);
@@ -307,31 +307,31 @@ static int io_read (lua_State *L) {
n = 2; /* will return n-1 results */ n = 2; /* will return n-1 results */
} }
else { /* ensure stack space for all results and for auxlib's buffer */ else { /* ensure stack space for all results and for auxlib's buffer */
luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); luaL_checkstack(L, nargs+LUA_MINSTACK, l_s("too many arguments"));
success = 1; success = 1;
for (n = 1; n<=nargs && success; n++) { for (n = 1; n<=nargs && success; n++) {
if (lua_type(L, n) == LUA_TNUMBER) if (lua_type(L, n) == LUA_TNUMBER)
success = read_chars(L, f, (size_t)lua_tonumber(L, n)); success = read_chars(L, f, (size_t)lua_tonumber(L, n));
else { else {
const char *p = lua_tostring(L, n); const l_char *p = lua_tostring(L, n);
if (!p || p[0] != '*') if (!p || p[0] != l_c('*'))
lua_error(L, "invalid `read' option"); lua_error(L, l_s("invalid `read' option"));
switch (p[1]) { switch (p[1]) {
case 'n': /* number */ case l_c('n'): /* number */
success = read_number(L, f); success = read_number(L, f);
break; break;
case 'l': /* line */ case l_c('l'): /* line */
success = read_line(L, f); success = read_line(L, f);
break; break;
case 'a': /* file */ case l_c('a'): /* file */
read_file(L, f); read_file(L, f);
success = 1; /* always success */ success = 1; /* always success */
break; break;
case 'w': /* word */ case l_c('w'): /* word */
success = read_word(L, f); success = read_word(L, f);
break; break;
default: default:
luaL_argerror(L, n, "invalid format"); luaL_argerror(L, n, l_s("invalid format"));
success = 0; /* to avoid warnings */ success = 0; /* to avoid warnings */
} }
} }
@@ -355,12 +355,12 @@ static int io_write (lua_State *L) {
for (arg=1; arg<=nargs; arg++) { for (arg=1; arg<=nargs; arg++) {
if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */ if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */
/* optimization: could be done exactly as for strings */ /* optimization: could be done exactly as for strings */
status = status && fprintf(f, "%.16g", lua_tonumber(L, arg)) > 0; status = status && fprintf(f, l_s("%.16g"), lua_tonumber(L, arg)) > 0;
} }
else { else {
size_t l; size_t l;
const char *s = luaL_check_lstr(L, arg, &l); const l_char *s = luaL_check_lstr(L, arg, &l);
status = status && (fwrite(s, sizeof(char), l, f) == l); status = status && (fwrite(s, sizeof(l_char), l, f) == l);
} }
} }
pushresult(L, status); pushresult(L, status);
@@ -370,11 +370,11 @@ static int io_write (lua_State *L) {
static int io_seek (lua_State *L) { static int io_seek (lua_State *L) {
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL}; static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL};
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE);
int op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames); int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames);
long offset = luaL_opt_long(L, 3, 0); long offset = luaL_opt_long(L, 3, 0);
luaL_arg_check(L, op != -1, 2, "invalid mode"); luaL_arg_check(L, op != -1, 2, l_s("invalid mode"));
op = fseek(f, offset, mode[op]); op = fseek(f, offset, mode[op]);
if (op) if (op)
return pushresult(L, 0); /* error */ return pushresult(L, 0); /* error */
@@ -387,7 +387,7 @@ static int io_seek (lua_State *L) {
static int io_flush (lua_State *L) { static int io_flush (lua_State *L) {
FILE *f = getopthandle(L, NOFILE); FILE *f = getopthandle(L, NOFILE);
luaL_arg_check(L, f || lua_isnull(L, 1), 1, "invalid file handle"); luaL_arg_check(L, f || lua_isnull(L, 1), 1, l_s("invalid file handle"));
return pushresult(L, fflush(f) == 0); return pushresult(L, fflush(f) == 0);
} }
@@ -418,9 +418,9 @@ static int io_rename (lua_State *L) {
static int io_tmpname (lua_State *L) { static int io_tmpname (lua_State *L) {
char buff[L_tmpnam]; l_char buff[L_tmpnam];
if (tmpnam(buff) != buff) if (tmpnam(buff) != buff)
lua_error(L, "unable to generate a unique filename"); lua_error(L, l_s("unable to generate a unique filename"));
lua_pushstring(L, buff); lua_pushstring(L, buff);
return 1; return 1;
} }
@@ -447,14 +447,14 @@ static int io_clock (lua_State *L) {
** ======================================================= ** =======================================================
*/ */
static void setfield (lua_State *L, const char *key, int value) { static void setfield (lua_State *L, const l_char *key, int value) {
lua_pushstring(L, key); lua_pushstring(L, key);
lua_pushnumber(L, value); lua_pushnumber(L, value);
lua_rawset(L, -3); lua_rawset(L, -3);
} }
static int getfield (lua_State *L, const char *key, int d) { static int getfield (lua_State *L, const l_char *key, int d) {
int res; int res;
lua_pushstring(L, key); lua_pushstring(L, key);
lua_rawget(L, -2); lua_rawget(L, -2);
@@ -462,7 +462,7 @@ static int getfield (lua_State *L, const char *key, int d) {
res = (int)lua_tonumber(L, -1); res = (int)lua_tonumber(L, -1);
else { else {
if (d == -2) if (d == -2)
luaL_verror(L, "field `%.20s' missing in date table", key); luaL_verror(L, l_s("field `%.20s' missing in date table"), key);
res = d; res = d;
} }
lua_pop(L, 1); lua_pop(L, 1);
@@ -471,12 +471,12 @@ static int getfield (lua_State *L, const char *key, int d) {
static int io_date (lua_State *L) { static int io_date (lua_State *L) {
const char *s = luaL_opt_string(L, 1, "%c"); const l_char *s = luaL_opt_string(L, 1, l_s("%c"));
time_t t = (time_t)luaL_opt_number(L, 2, -1); time_t t = (time_t)luaL_opt_number(L, 2, -1);
struct tm *stm; struct tm *stm;
if (t == (time_t)-1) /* no time given? */ if (t == (time_t)-1) /* no time given? */
t = time(NULL); /* use current time */ t = time(NULL); /* use current time */
if (*s == '!') { /* UTC? */ if (*s == l_c('!')) { /* UTC? */
stm = gmtime(&t); stm = gmtime(&t);
s++; /* skip `!' */ s++; /* skip `!' */
} }
@@ -484,24 +484,24 @@ static int io_date (lua_State *L) {
stm = localtime(&t); stm = localtime(&t);
if (stm == NULL) /* invalid date? */ if (stm == NULL) /* invalid date? */
lua_pushnil(L); lua_pushnil(L);
else if (strcmp(s, "*t") == 0) { else if (strcmp(s, l_s("*t")) == 0) {
lua_newtable(L); lua_newtable(L);
setfield(L, "sec", stm->tm_sec); setfield(L, l_s("sec"), stm->tm_sec);
setfield(L, "min", stm->tm_min); setfield(L, l_s("min"), stm->tm_min);
setfield(L, "hour", stm->tm_hour); setfield(L, l_s("hour"), stm->tm_hour);
setfield(L, "day", stm->tm_mday); setfield(L, l_s("day"), stm->tm_mday);
setfield(L, "month", stm->tm_mon+1); setfield(L, l_s("month"), stm->tm_mon+1);
setfield(L, "year", stm->tm_year+1900); setfield(L, l_s("year"), stm->tm_year+1900);
setfield(L, "wday", stm->tm_wday+1); setfield(L, l_s("wday"), stm->tm_wday+1);
setfield(L, "yday", stm->tm_yday+1); setfield(L, l_s("yday"), stm->tm_yday+1);
setfield(L, "isdst", stm->tm_isdst); setfield(L, l_s("isdst"), stm->tm_isdst);
} }
else { else {
char b[256]; l_char b[256];
if (strftime(b, sizeof(b), s, stm)) if (strftime(b, sizeof(b), s, stm))
lua_pushstring(L, b); lua_pushstring(L, b);
else else
lua_error(L, "invalid `date' format"); lua_error(L, l_s("invalid `date' format"));
} }
return 1; return 1;
} }
@@ -515,13 +515,13 @@ static int io_time (lua_State *L) {
struct tm ts; struct tm ts;
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
lua_settop(L, 1); /* make sure table is at the top */ lua_settop(L, 1); /* make sure table is at the top */
ts.tm_sec = getfield(L, "sec", 0); ts.tm_sec = getfield(L, l_s("sec"), 0);
ts.tm_min = getfield(L, "min", 0); ts.tm_min = getfield(L, l_s("min"), 0);
ts.tm_hour = getfield(L, "hour", 12); ts.tm_hour = getfield(L, l_s("hour"), 12);
ts.tm_mday = getfield(L, "day", -2); ts.tm_mday = getfield(L, l_s("day"), -2);
ts.tm_mon = getfield(L, "month", -2)-1; ts.tm_mon = getfield(L, l_s("month"), -2)-1;
ts.tm_year = getfield(L, "year", -2)-1900; ts.tm_year = getfield(L, l_s("year"), -2)-1900;
ts.tm_isdst = getfield(L, "isdst", -1); ts.tm_isdst = getfield(L, l_s("isdst"), -1);
t = mktime(&ts); t = mktime(&ts);
if (t == (time_t)-1) if (t == (time_t)-1)
lua_pushnil(L); lua_pushnil(L);
@@ -544,10 +544,10 @@ static int io_difftime (lua_State *L) {
static int io_setloc (lua_State *L) { static int io_setloc (lua_State *L) {
static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
LC_NUMERIC, LC_TIME}; LC_NUMERIC, LC_TIME};
static const char *const catnames[] = {"all", "collate", "ctype", "monetary", static const l_char *const catnames[] = {l_s("all"), l_s("collate"), l_s("ctype"), l_s("monetary"),
"numeric", "time", NULL}; l_s("numeric"), l_s("time"), NULL};
int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames); int op = luaL_findstring(luaL_opt_string(L, 2, l_s("all")), catnames);
luaL_arg_check(L, op != -1, 2, "invalid option"); luaL_arg_check(L, op != -1, 2, l_s("invalid option"));
lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1))); lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1)));
return 1; return 1;
} }
@@ -564,10 +564,10 @@ static int io_exit (lua_State *L) {
static int io_debug (lua_State *L) { static int io_debug (lua_State *L) {
for (;;) { for (;;) {
char buffer[250]; l_char buffer[250];
fprintf(stderr, "lua_debug> "); fprintf(stderr, l_s("lua_debug> "));
if (fgets(buffer, sizeof(buffer), stdin) == 0 || if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
strcmp(buffer, "cont\n") == 0) strcmp(buffer, l_s("cont\n")) == 0)
return 0; return 0;
lua_dostring(L, buffer); lua_dostring(L, buffer);
lua_settop(L, 0); /* remove eventual returns */ lua_settop(L, 0); /* remove eventual returns */
@@ -584,61 +584,61 @@ static int errorfb (lua_State *L) {
lua_Debug ar; lua_Debug ar;
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
luaL_addstring(&b, "error: "); luaL_addstring(&b, l_s("error: "));
luaL_addstring(&b, luaL_check_string(L, 1)); luaL_addstring(&b, luaL_check_string(L, 1));
luaL_addstring(&b, "\n"); luaL_addstring(&b, l_s("\n"));
while (lua_getstack(L, level++, &ar)) { while (lua_getstack(L, level++, &ar)) {
char buff[120]; /* enough to fit following `sprintf's */ l_char buff[120]; /* enough to fit following `sprintf's */
if (level == 2) if (level == 2)
luaL_addstring(&b, "stack traceback:\n"); luaL_addstring(&b, l_s("stack traceback:\n"));
else if (level > LEVELS1 && firstpart) { else if (level > LEVELS1 && firstpart) {
/* no more than `LEVELS2' more levels? */ /* no more than `LEVELS2' more levels? */
if (!lua_getstack(L, level+LEVELS2, &ar)) if (!lua_getstack(L, level+LEVELS2, &ar))
level--; /* keep going */ level--; /* keep going */
else { else {
luaL_addstring(&b, " ...\n"); /* too many levels */ luaL_addstring(&b, l_s(" ...\n")); /* too many levels */
while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */
level++; level++;
} }
firstpart = 0; firstpart = 0;
continue; continue;
} }
sprintf(buff, "%4d: ", level-1); sprintf(buff, l_s("%4d: "), level-1);
luaL_addstring(&b, buff); luaL_addstring(&b, buff);
lua_getinfo(L, "Snl", &ar); lua_getinfo(L, l_s("Snl"), &ar);
switch (*ar.namewhat) { switch (*ar.namewhat) {
case 'g': case 'l': /* global, local */ case l_c('g'): case l_c('l'): /* global, local */
sprintf(buff, "function `%.50s'", ar.name); sprintf(buff, l_s("function `%.50s'"), ar.name);
break; break;
case 'f': /* field */ case l_c('f'): /* field */
sprintf(buff, "method `%.50s'", ar.name); sprintf(buff, l_s("method `%.50s'"), ar.name);
break; break;
case 't': /* tag method */ case l_c('t'): /* tag method */
sprintf(buff, "`%.50s' tag method", ar.name); sprintf(buff, l_s("`%.50s' tag method"), ar.name);
break; break;
default: { default: {
if (*ar.what == 'm') /* main? */ if (*ar.what == l_c('m')) /* main? */
sprintf(buff, "main of %.70s", ar.short_src); sprintf(buff, l_s("main of %.70s"), ar.short_src);
else if (*ar.what == 'C') /* C function? */ else if (*ar.what == l_c('C')) /* C function? */
sprintf(buff, "%.70s", ar.short_src); sprintf(buff, l_s("%.70s"), ar.short_src);
else else
sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src); sprintf(buff, l_s("function <%d:%.70s>"), ar.linedefined, ar.short_src);
ar.source = NULL; /* do not print source again */ ar.source = NULL; /* do not print source again */
} }
} }
luaL_addstring(&b, buff); luaL_addstring(&b, buff);
if (ar.currentline > 0) { if (ar.currentline > 0) {
sprintf(buff, " at line %d", ar.currentline); sprintf(buff, l_s(" at line %d"), ar.currentline);
luaL_addstring(&b, buff); luaL_addstring(&b, buff);
} }
if (ar.source) { if (ar.source) {
sprintf(buff, " [%.70s]", ar.short_src); sprintf(buff, l_s(" [%.70s]"), ar.short_src);
luaL_addstring(&b, buff); luaL_addstring(&b, buff);
} }
luaL_addstring(&b, "\n"); luaL_addstring(&b, l_s("\n"));
} }
luaL_pushresult(&b); luaL_pushresult(&b);
lua_getglobal(L, LUA_ALERT); lua_getglobal(L, l_s(LUA_ALERT));
if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */
lua_pushvalue(L, -2); /* error message */ lua_pushvalue(L, -2); /* error message */
lua_rawcall(L, 1, 0); lua_rawcall(L, 1, 0);
@@ -649,44 +649,44 @@ static int errorfb (lua_State *L) {
static const luaL_reg iolib[] = { static const luaL_reg iolib[] = {
{"appendto", io_appendto}, {l_s("appendto"), io_appendto},
{"clock", io_clock}, {l_s("clock"), io_clock},
{"closefile", io_close}, {l_s("closefile"), io_close},
{"date", io_date}, {l_s("date"), io_date},
{"debug", io_debug}, {l_s("debug"), io_debug},
{"difftime", io_difftime}, {l_s("difftime"), io_difftime},
{"execute", io_execute}, {l_s("execute"), io_execute},
{"exit", io_exit}, {l_s("exit"), io_exit},
{"flush", io_flush}, {l_s("flush"), io_flush},
{"getenv", io_getenv}, {l_s("getenv"), io_getenv},
{"openfile", io_open}, {l_s("openfile"), io_open},
{"read", io_read}, {l_s("read"), io_read},
{"readfrom", io_readfrom}, {l_s("readfrom"), io_readfrom},
{"remove", io_remove}, {l_s("remove"), io_remove},
{"rename", io_rename}, {l_s("rename"), io_rename},
{"seek", io_seek}, {l_s("seek"), io_seek},
{"setlocale", io_setloc}, {l_s("setlocale"), io_setloc},
{"time", io_time}, {l_s("time"), io_time},
{"tmpfile", io_tmpfile}, {l_s("tmpfile"), io_tmpfile},
{"tmpname", io_tmpname}, {l_s("tmpname"), io_tmpname},
{"write", io_write}, {l_s("write"), io_write},
{"writeto", io_writeto}, {l_s("writeto"), io_writeto},
{LUA_ERRORMESSAGE, errorfb} {l_s(LUA_ERRORMESSAGE), errorfb}
}; };
LUALIB_API void lua_iolibopen (lua_State *L) { LUALIB_API void lua_iolibopen (lua_State *L) {
int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA); int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA);
lua_newtype(L, "ClosedFileHandle", LUA_TUSERDATA); lua_newtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA);
luaL_openl(L, iolib); luaL_openl(L, iolib);
/* predefined file handles */ /* predefined file handles */
setfile(L, stdin, INFILE); setfile(L, stdin, INFILE);
setfile(L, stdout, OUTFILE); setfile(L, stdout, OUTFILE);
setfilebyname(L, stdin, "_STDIN"); setfilebyname(L, stdin, l_s("_STDIN"));
setfilebyname(L, stdout, "_STDOUT"); setfilebyname(L, stdout, l_s("_STDOUT"));
setfilebyname(L, stderr, "_STDERR"); setfilebyname(L, stderr, l_s("_STDERR"));
/* close files when collected */ /* close files when collected */
lua_pushcfunction(L, file_collect); lua_pushcfunction(L, file_collect);
lua_settagmethod(L, iotag, "gc"); lua_settagmethod(L, iotag, l_s("gc"));
} }

230
llex.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 1.78 2001/02/22 17:15:18 roberto Exp roberto $ ** $Id: llex.c,v 1.79 2001/02/22 18:59:59 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -25,10 +25,13 @@
/* ORDER RESERVED */ /* ORDER RESERVED */
static const char *const token2string [] = { static const l_char *const token2string [] = {
"and", "break", "do", "else", "elseif", "end", "for", l_s("and"), l_s("break"), l_s("do"), l_s("else"), l_s("elseif"),
"function", "if", "local", "nil", "not", "or", "repeat", "return", "then", l_s("end"), l_s("for"), l_s("function"), l_s("if"), l_s("local"),
"until", "while", "", "..", "...", "==", ">=", "<=", "~=", "", "", "<eof>"}; l_s("nil"), l_s("not"), l_s("or"), l_s("repeat"), l_s("return"),
l_s("then"), l_s("until"), l_s("while"), l_s(""), l_s(".."), l_s("..."),
l_s("=="), l_s(">="), l_s("<="), l_s("~="), l_s(""), l_s(""), l_s("<eof>")
};
void luaX_init (lua_State *L) { void luaX_init (lua_State *L) {
@@ -44,37 +47,38 @@ void luaX_init (lua_State *L) {
#define MAXSRC 80 #define MAXSRC 80
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg) {
if (val > limit) { if (val > limit) {
char buff[90]; l_char buff[90];
sprintf(buff, "too many %.40s (limit=%d)", msg, limit); sprintf(buff, l_s("too many %.40s (limit=%d)"), msg, limit);
luaX_error(ls, buff, ls->t.token); luaX_error(ls, buff, ls->t.token);
} }
} }
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token) {
char buff[MAXSRC]; l_char buff[MAXSRC];
luaO_chunkid(buff, getstr(ls->source), sizeof(buff)); luaO_chunkid(buff, getstr(ls->source), sizeof(buff));
luaO_verror(ls->L, "%.99s;\n last token read: `%.30s' at line %d in %.80s", luaO_verror(ls->L,
l_s("%.99s;\n last token read: `%.30s' at line %d in %.80s"),
s, token, ls->linenumber, buff); s, token, ls->linenumber, buff);
} }
void luaX_error (LexState *ls, const char *s, int token) { void luaX_error (LexState *ls, const l_char *s, int token) {
char buff[TOKEN_LEN]; l_char buff[TOKEN_LEN];
luaX_token2str(token, buff); luaX_token2str(token, buff);
if (buff[0] == '\0') if (buff[0] == l_c('\0'))
luaX_syntaxerror(ls, s, G(ls->L)->Mbuffer); luaX_syntaxerror(ls, s, G(ls->L)->Mbuffer);
else else
luaX_syntaxerror(ls, s, buff); luaX_syntaxerror(ls, s, buff);
} }
void luaX_token2str (int token, char *s) { void luaX_token2str (int token, l_char *s) {
if (token < 256) { if (token < 256) {
s[0] = (char)token; s[0] = (l_char)token;
s[1] = '\0'; s[1] = l_c('\0');
} }
else else
strcpy(s, token2string[token-FIRST_RESERVED]); strcpy(s, token2string[token-FIRST_RESERVED]);
@@ -82,16 +86,16 @@ void luaX_token2str (int token, char *s) {
static void luaX_invalidchar (LexState *ls, int c) { static void luaX_invalidchar (LexState *ls, int c) {
char buff[8]; l_char buff[8];
sprintf(buff, "0x%02X", c); sprintf(buff, l_s("0x%02X"), c);
luaX_syntaxerror(ls, "invalid control char", buff); luaX_syntaxerror(ls, l_s("invalid control l_char"), buff);
} }
static void inclinenumber (LexState *LS) { static void inclinenumber (LexState *LS) {
next(LS); /* skip `\n' */ next(LS); /* skip `\n' */
++LS->linenumber; ++LS->linenumber;
luaX_checklimit(LS, LS->linenumber, MAX_INT, "lines in a chunk"); luaX_checklimit(LS, LS->linenumber, MAX_INT, l_s("lines in a chunk"));
} }
@@ -104,10 +108,10 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
LS->lastline = 1; LS->lastline = 1;
LS->source = source; LS->source = source;
next(LS); /* read first char */ next(LS); /* read first char */
if (LS->current == '#') { if (LS->current == l_c('#')) {
do { /* skip first line */ do { /* skip first line */
next(LS); next(LS);
} while (LS->current != '\n' && LS->current != EOZ); } while (LS->current != l_c('\n') && LS->current != EOZ);
} }
} }
@@ -126,7 +130,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
#define checkbuffer(L, n, len) if ((len)+(n) > G(L)->Mbuffsize) \ #define checkbuffer(L, n, len) if ((len)+(n) > G(L)->Mbuffsize) \
luaO_openspace(L, (len)+(n)+EXTRABUFF) luaO_openspace(L, (len)+(n)+EXTRABUFF)
#define save(L, c, l) (G(L)->Mbuffer[l++] = (char)c) #define save(L, c, l) (G(L)->Mbuffer[l++] = (l_char)c)
#define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS))
@@ -137,8 +141,8 @@ static size_t readname (LexState *LS) {
do { do {
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
save_and_next(L, LS, l); save_and_next(L, LS, l);
} while (isalnum(LS->current) || LS->current == '_'); } while (isalnum(LS->current) || LS->current == l_c('_'));
save(L, '\0', l); save(L, l_c('\0'), l);
return l-1; return l-1;
} }
@@ -148,36 +152,37 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) {
lua_State *L = LS->L; lua_State *L = LS->L;
size_t l = 0; size_t l = 0;
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
if (comma) save(L, '.', l); if (comma) save(L, l_c('.'), l);
while (isdigit(LS->current)) { while (isdigit(LS->current)) {
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
save_and_next(L, LS, l); save_and_next(L, LS, l);
} }
if (LS->current == '.') { if (LS->current == l_c('.')) {
save_and_next(L, LS, l); save_and_next(L, LS, l);
if (LS->current == '.') { if (LS->current == l_c('.')) {
save_and_next(L, LS, l); save_and_next(L, LS, l);
save(L, '\0', l); save(L, l_c('\0'), l);
luaX_error(LS, "ambiguous syntax" luaX_error(LS,
" (decimal point x string concatenation)", TK_NUMBER); l_s("ambiguous syntax (decimal point x string concatenation)"),
TK_NUMBER);
} }
} }
while (isdigit(LS->current)) { while (isdigit(LS->current)) {
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
save_and_next(L, LS, l); save_and_next(L, LS, l);
} }
if (LS->current == 'e' || LS->current == 'E') { if (LS->current == l_c('e') || LS->current == l_c('E')) {
save_and_next(L, LS, l); /* read `E' */ save_and_next(L, LS, l); /* read `E' */
if (LS->current == '+' || LS->current == '-') if (LS->current == l_c('+') || LS->current == l_c('-'))
save_and_next(L, LS, l); /* optional exponent sign */ save_and_next(L, LS, l); /* optional exponent sign */
while (isdigit(LS->current)) { while (isdigit(LS->current)) {
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
save_and_next(L, LS, l); save_and_next(L, LS, l);
} }
} }
save(L, '\0', l); save(L, l_c('\0'), l);
if (!luaO_str2d(G(L)->Mbuffer, &seminfo->r)) if (!luaO_str2d(G(L)->Mbuffer, &seminfo->r))
luaX_error(LS, "malformed number", TK_NUMBER); luaX_error(LS, l_s("malformed number"), TK_NUMBER);
} }
@@ -186,32 +191,32 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) {
int cont = 0; int cont = 0;
size_t l = 0; size_t l = 0;
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
save(L, '[', l); /* save first `[' */ save(L, l_c('['), l); /* save first `[' */
save_and_next(L, LS, l); /* pass the second `[' */ save_and_next(L, LS, l); /* pass the second `[' */
for (;;) { for (;;) {
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
switch (LS->current) { switch (LS->current) {
case EOZ: case EOZ:
save(L, '\0', l); save(L, l_c('\0'), l);
luaX_error(LS, "unfinished long string", TK_STRING); luaX_error(LS, l_s("unfinished long string"), TK_STRING);
break; /* to avoid warnings */ break; /* to avoid warnings */
case '[': case l_c('['):
save_and_next(L, LS, l); save_and_next(L, LS, l);
if (LS->current == '[') { if (LS->current == l_c('[')) {
cont++; cont++;
save_and_next(L, LS, l); save_and_next(L, LS, l);
} }
continue; continue;
case ']': case l_c(']'):
save_and_next(L, LS, l); save_and_next(L, LS, l);
if (LS->current == ']') { if (LS->current == l_c(']')) {
if (cont == 0) goto endloop; if (cont == 0) goto endloop;
cont--; cont--;
save_and_next(L, LS, l); save_and_next(L, LS, l);
} }
continue; continue;
case '\n': case l_c('\n'):
save(L, '\n', l); save(L, l_c('\n'), l);
inclinenumber(LS); inclinenumber(LS);
continue; continue;
default: default:
@@ -219,7 +224,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) {
} }
} endloop: } endloop:
save_and_next(L, LS, l); /* skip the second `]' */ save_and_next(L, LS, l); /* skip the second `]' */
save(L, '\0', l); save(L, l_c('\0'), l);
seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+2, l-5); seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+2, l-5);
} }
@@ -232,38 +237,38 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
while (LS->current != del) { while (LS->current != del) {
checkbuffer(L, 10, l); checkbuffer(L, 10, l);
switch (LS->current) { switch (LS->current) {
case EOZ: case '\n': case EOZ: case l_c('\n'):
save(L, '\0', l); save(L, l_c('\0'), l);
luaX_error(LS, "unfinished string", TK_STRING); luaX_error(LS, l_s("unfinished string"), TK_STRING);
break; /* to avoid warnings */ break; /* to avoid warnings */
case '\\': case l_c('\\'):
next(LS); /* do not save the `\' */ next(LS); /* do not save the `\' */
switch (LS->current) { switch (LS->current) {
case 'a': save(L, '\a', l); next(LS); break; case l_c('a'): save(L, l_c('\a'), l); next(LS); break;
case 'b': save(L, '\b', l); next(LS); break; case l_c('b'): save(L, l_c('\b'), l); next(LS); break;
case 'f': save(L, '\f', l); next(LS); break; case l_c('f'): save(L, l_c('\f'), l); next(LS); break;
case 'n': save(L, '\n', l); next(LS); break; case l_c('n'): save(L, l_c('\n'), l); next(LS); break;
case 'r': save(L, '\r', l); next(LS); break; case l_c('r'): save(L, l_c('\r'), l); next(LS); break;
case 't': save(L, '\t', l); next(LS); break; case l_c('t'): save(L, l_c('\t'), l); next(LS); break;
case 'v': save(L, '\v', l); next(LS); break; case l_c('v'): save(L, l_c('\v'), l); next(LS); break;
case '\n': save(L, '\n', l); inclinenumber(LS); break; case l_c('\n'): save(L, l_c('\n'), l); inclinenumber(LS); break;
case '0': case '1': case '2': case '3': case '4': default: {
case '5': case '6': case '7': case '8': case '9': { if (!isdigit(LS->current))
int c = 0; save_and_next(L, LS, l); /* handles \\, \", \', and \? */
int i = 0; else { /* \xxx */
do { int c = 0;
c = 10*c + (LS->current-'0'); int i = 0;
next(LS); do {
} while (++i<3 && isdigit(LS->current)); c = 10*c + (LS->current-l_c('0'));
if (c > UCHAR_MAX) { next(LS);
save(L, '\0', l); } while (++i<3 && isdigit(LS->current));
luaX_error(LS, "escape sequence too large", TK_STRING); if (c > UCHAR_MAX) {
save(L, l_c('\0'), l);
luaX_error(LS, l_s("escape sequence too large"), TK_STRING);
}
save(L, c, l);
} }
save(L, c, l);
break;
} }
default: /* handles \\, \", \', and \? */
save_and_next(L, LS, l);
} }
break; break;
default: default:
@@ -271,7 +276,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
} }
} }
save_and_next(L, LS, l); /* skip delimiter */ save_and_next(L, LS, l); /* skip delimiter */
save(L, '\0', l); save(L, l_c('\0'), l);
seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+1, l-3); seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+1, l-3);
} }
@@ -280,92 +285,85 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
for (;;) { for (;;) {
switch (LS->current) { switch (LS->current) {
case ' ': case '\t': case '\r': /* `\r' to avoid problems with DOS */ case l_c(' '): case l_c('\t'): case l_c('\r'): /* `\r' to avoid problems with DOS */
next(LS); next(LS);
continue; continue;
case '\n': case l_c('\n'):
inclinenumber(LS); inclinenumber(LS);
continue; continue;
case '$': case l_c('$'):
luaX_error(LS, "unexpected `$' (pragmas are no longer supported)", '$'); luaX_error(LS,
l_s("unexpected `$' (pragmas are no longer supported)"),
LS->current);
break; break;
case '-': case l_c('-'):
next(LS); next(LS);
if (LS->current != '-') return '-'; if (LS->current != l_c('-')) return l_c('-');
do { next(LS); } while (LS->current != '\n' && LS->current != EOZ); do { next(LS); } while (LS->current != l_c('\n') && LS->current != EOZ);
continue; continue;
case '[': case l_c('['):
next(LS); next(LS);
if (LS->current != '[') return '['; if (LS->current != l_c('[')) return l_c('[');
else { else {
read_long_string(LS, seminfo); read_long_string(LS, seminfo);
return TK_STRING; return TK_STRING;
} }
case '=': case l_c('='):
next(LS); next(LS);
if (LS->current != '=') return '='; if (LS->current != l_c('=')) return l_c('=');
else { next(LS); return TK_EQ; } else { next(LS); return TK_EQ; }
case '<': case l_c('<'):
next(LS); next(LS);
if (LS->current != '=') return '<'; if (LS->current != l_c('=')) return l_c('<');
else { next(LS); return TK_LE; } else { next(LS); return TK_LE; }
case '>': case l_c('>'):
next(LS); next(LS);
if (LS->current != '=') return '>'; if (LS->current != l_c('=')) return l_c('>');
else { next(LS); return TK_GE; } else { next(LS); return TK_GE; }
case '~': case l_c('~'):
next(LS); next(LS);
if (LS->current != '=') return '~'; if (LS->current != l_c('=')) return l_c('~');
else { next(LS); return TK_NE; } else { next(LS); return TK_NE; }
case '"': case l_c('"'):
case '\'': case l_c('\''):
read_string(LS, LS->current, seminfo); read_string(LS, LS->current, seminfo);
return TK_STRING; return TK_STRING;
case '.': case l_c('.'):
next(LS); next(LS);
if (LS->current == '.') { if (LS->current == l_c('.')) {
next(LS); next(LS);
if (LS->current == '.') { if (LS->current == l_c('.')) {
next(LS); next(LS);
return TK_DOTS; /* ... */ return TK_DOTS; /* ... */
} }
else return TK_CONCAT; /* .. */ else return TK_CONCAT; /* .. */
} }
else if (!isdigit(LS->current)) return '.'; else if (!isdigit(LS->current)) return l_c('.');
else { else {
read_number(LS, 1, seminfo); read_number(LS, 1, seminfo);
return TK_NUMBER; return TK_NUMBER;
} }
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
read_number(LS, 0, seminfo);
return TK_NUMBER;
case EOZ: case EOZ:
return TK_EOS; return TK_EOS;
case '_': goto tname; default: {
if (isdigit(LS->current)) {
default: read_number(LS, 0, seminfo);
if (!isalpha(LS->current)) { return TK_NUMBER;
int c = LS->current;
if (iscntrl(c))
luaX_invalidchar(LS, c);
next(LS);
return c;
} }
tname: { /* identifier or reserved word */ else if (isalpha(LS->current) || LS->current == l_c('_')) {
/* identifier or reserved word */
size_t l = readname(LS); size_t l = readname(LS);
TString *ts = luaS_newlstr(LS->L, G(LS->L)->Mbuffer, l); TString *ts = luaS_newlstr(LS->L, G(LS->L)->Mbuffer, l);
if (ts->marked >= RESERVEDMARK) /* reserved word? */ if (ts->marked >= RESERVEDMARK) /* reserved word? */
@@ -373,6 +371,14 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
seminfo->ts = ts; seminfo->ts = ts;
return TK_NAME; return TK_NAME;
} }
else {
int c = LS->current;
if (iscntrl(c))
luaX_invalidchar(LS, c);
next(LS);
return c; /* single-char tokens (+ - / ...) */
}
}
} }
} }
} }

12
llex.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.32 2000/12/04 18:33:40 roberto Exp roberto $ ** $Id: llex.h,v 1.33 2001/01/10 16:40:56 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -14,7 +14,7 @@
#define FIRST_RESERVED 257 #define FIRST_RESERVED 257
/* maximum length of a reserved word */ /* maximum length of a reserved word */
#define TOKEN_LEN (sizeof("function")) #define TOKEN_LEN (sizeof(l_s("function")))
/* /*
@@ -63,10 +63,10 @@ typedef struct LexState {
void luaX_init (lua_State *L); void luaX_init (lua_State *L);
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
int luaX_lex (LexState *LS, SemInfo *seminfo); int luaX_lex (LexState *LS, SemInfo *seminfo);
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg);
void luaX_syntaxerror (LexState *ls, const char *s, const char *token); void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token);
void luaX_error (LexState *ls, const char *s, int token); void luaX_error (LexState *ls, const l_char *s, int token);
void luaX_token2str (int token, char *s); void luaX_token2str (int token, l_char *s);
#endif #endif

View File

@@ -1,6 +1,6 @@
/* /*
** $Id: llimits.h,v 1.23 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: llimits.h,v 1.24 2001/02/22 17:15:18 roberto Exp roberto $
** Limits, basic types, and some other "installation-dependent" definitions ** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -33,7 +33,7 @@
/* function to convert a lua_Number to a string */ /* function to convert a lua_Number to a string */
#ifndef NUMBER_FMT #ifndef NUMBER_FMT
#define NUMBER_FMT "%.16g" /* LUA_NUMBER */ #define NUMBER_FMT l_s("%.16g") /* LUA_NUMBER */
#endif #endif
#ifndef lua_number2str #ifndef lua_number2str
#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n)) #define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n))
@@ -45,11 +45,21 @@
#endif #endif
/* macro to control type of literal strings */
#ifndef l_s
#define l_s(x) x
#endif
/* macro to control type of literal chars */
#ifndef l_c
#define l_c(x) x
#endif
/* /*
** the following types define integer types for values that may not ** the following types define integer types for values that may not
** fit in a "small int" (16 bits), but may waste space in a ** fit in a `small int' (16 bits), but may waste space in a
** "large long" (64 bits). The current definitions should work in ** `large long' (64 bits). The current definitions should work in
** any machine, but may not be optimal. ** any machine, but may not be optimal.
*/ */
@@ -88,7 +98,7 @@ typedef unsigned char lu_byte;
#define MINPOWER2 4 /* minimum size for "growing" vectors */ #define MINPOWER2 4 /* minimum size for `growing' vectors */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmathlib.c,v 1.34 2001/02/02 19:02:40 roberto Exp roberto $ ** $Id: lmathlib.c,v 1.35 2001/02/22 18:59:59 roberto Exp roberto $
** Standard mathematical library ** Standard mathematical library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -176,18 +176,18 @@ static int math_random (lua_State *L) {
} }
case 1: { /* only upper limit */ case 1: { /* only upper limit */
int u = luaL_check_int(L, 1); int u = luaL_check_int(L, 1);
luaL_arg_check(L, 1<=u, 1, "interval is empty"); luaL_arg_check(L, 1<=u, 1, l_s("interval is empty"));
lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */ lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */
break; break;
} }
case 2: { /* lower and upper limits */ case 2: { /* lower and upper limits */
int l = luaL_check_int(L, 1); int l = luaL_check_int(L, 1);
int u = luaL_check_int(L, 2); int u = luaL_check_int(L, 2);
luaL_arg_check(L, l<=u, 2, "interval is empty"); luaL_arg_check(L, l<=u, 2, l_s("interval is empty"));
lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */
break; break;
} }
default: lua_error(L, "wrong number of arguments"); default: lua_error(L, l_s("wrong number of arguments"));
} }
return 1; return 1;
} }
@@ -200,29 +200,29 @@ static int math_randomseed (lua_State *L) {
static const luaL_reg mathlib[] = { static const luaL_reg mathlib[] = {
{"abs", math_abs}, {l_s("abs"), math_abs},
{"sin", math_sin}, {l_s("sin"), math_sin},
{"cos", math_cos}, {l_s("cos"), math_cos},
{"tan", math_tan}, {l_s("tan"), math_tan},
{"asin", math_asin}, {l_s("asin"), math_asin},
{"acos", math_acos}, {l_s("acos"), math_acos},
{"atan", math_atan}, {l_s("atan"), math_atan},
{"atan2", math_atan2}, {l_s("atan2"), math_atan2},
{"ceil", math_ceil}, {l_s("ceil"), math_ceil},
{"floor", math_floor}, {l_s("floor"), math_floor},
{"mod", math_mod}, {l_s("mod"), math_mod},
{"frexp", math_frexp}, {l_s("frexp"), math_frexp},
{"ldexp", math_ldexp}, {l_s("ldexp"), math_ldexp},
{"sqrt", math_sqrt}, {l_s("sqrt"), math_sqrt},
{"min", math_min}, {l_s("min"), math_min},
{"max", math_max}, {l_s("max"), math_max},
{"log", math_log}, {l_s("log"), math_log},
{"log10", math_log10}, {l_s("log10"), math_log10},
{"exp", math_exp}, {l_s("exp"), math_exp},
{"deg", math_deg}, {l_s("deg"), math_deg},
{"rad", math_rad}, {l_s("rad"), math_rad},
{"random", math_random}, {l_s("random"), math_random},
{"randomseed", math_randomseed} {l_s("randomseed"), math_randomseed}
}; };
/* /*
@@ -231,8 +231,8 @@ static const luaL_reg mathlib[] = {
LUALIB_API void lua_mathlibopen (lua_State *L) { LUALIB_API void lua_mathlibopen (lua_State *L) {
luaL_openl(L, mathlib); luaL_openl(L, mathlib);
lua_pushcfunction(L, math_pow); lua_pushcfunction(L, math_pow);
lua_settagmethod(L, LUA_TNUMBER, "pow"); lua_settagmethod(L, LUA_TNUMBER, l_s("pow"));
lua_pushnumber(L, PI); lua_pushnumber(L, PI);
lua_setglobal(L, "PI"); lua_setglobal(L, l_s("PI"));
} }

6
lmem.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmem.c,v 1.46 2001/02/06 16:01:29 roberto Exp roberto $ ** $Id: lmem.c,v 1.47 2001/02/20 18:15:33 roberto Exp roberto $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -23,7 +23,7 @@
void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
int limit, const char *errormsg) { int limit, const l_char *errormsg) {
void *newblock; void *newblock;
int newsize = (*size)*2; int newsize = (*size)*2;
if (newsize < MINPOWER2) if (newsize < MINPOWER2)
@@ -49,7 +49,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
block = NULL; block = NULL;
} }
else if (size >= MAX_SIZET) else if (size >= MAX_SIZET)
luaD_error(L, "memory allocation error: block too big"); luaD_error(L, l_s("memory allocation error: block too big"));
else { else {
block = l_realloc(block, oldsize, size); block = l_realloc(block, oldsize, size);
if (block == NULL) { if (block == NULL) {

4
lmem.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmem.h,v 1.20 2001/02/02 15:13:05 roberto Exp roberto $ ** $Id: lmem.h,v 1.21 2001/02/20 18:15:33 roberto Exp roberto $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -16,7 +16,7 @@
void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size);
void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
int limit, const char *errormsg); int limit, const l_char *errormsg);
#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
#define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0) #define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0)

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 1.65 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lobject.c,v 1.66 2001/02/22 17:15:18 roberto Exp roberto $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -35,21 +35,21 @@ int luaO_equalObj (const TObject *t1, const TObject *t2) {
} }
char *luaO_openspace (lua_State *L, size_t n) { l_char *luaO_openspace (lua_State *L, size_t n) {
if (n > G(L)->Mbuffsize) { if (n > G(L)->Mbuffsize) {
luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, n, char); luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, n, l_char);
G(L)->Mbuffsize = n; G(L)->Mbuffsize = n;
} }
return G(L)->Mbuffer; return G(L)->Mbuffer;
} }
int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */ int luaO_str2d (const l_char *s, lua_Number *result) { /* LUA_NUMBER */
char *endptr; l_char *endptr;
lua_Number res = lua_str2number(s, &endptr); lua_Number res = lua_str2number(s, &endptr);
if (endptr == s) return 0; /* no conversion */ if (endptr == s) return 0; /* no conversion */
while (isspace(uchar(*endptr))) endptr++; while (isspace(uchar(*endptr))) endptr++;
if (*endptr != '\0') return 0; /* invalid trailing characters? */ if (*endptr != l_c('\0')) return 0; /* invalid trailing characters? */
*result = res; *result = res;
return 1; return 1;
} }
@@ -59,9 +59,9 @@ int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */
#define MAX_VERROR 280 #define MAX_VERROR 280
/* this function needs to handle only '%d' and '%.XXs' formats */ /* this function needs to handle only '%d' and '%.XXs' formats */
void luaO_verror (lua_State *L, const char *fmt, ...) { void luaO_verror (lua_State *L, const l_char *fmt, ...) {
va_list argp; va_list argp;
char buff[MAX_VERROR]; /* to hold formatted message */ l_char buff[MAX_VERROR]; /* to hold formatted message */
va_start(argp, fmt); va_start(argp, fmt);
vsprintf(buff, fmt, argp); vsprintf(buff, fmt, argp);
va_end(argp); va_end(argp);
@@ -69,36 +69,36 @@ void luaO_verror (lua_State *L, const char *fmt, ...) {
} }
void luaO_chunkid (char *out, const char *source, int bufflen) { void luaO_chunkid (l_char *out, const l_char *source, int bufflen) {
if (*source == '=') { if (*source == l_c('=')) {
strncpy(out, source+1, bufflen); /* remove first char */ strncpy(out, source+1, bufflen); /* remove first char */
out[bufflen-1] = '\0'; /* ensures null termination */ out[bufflen-1] = l_c('\0'); /* ensures null termination */
} }
else { else {
if (*source == '@') { if (*source == l_c('@')) {
int l; int l;
source++; /* skip the `@' */ source++; /* skip the `@' */
bufflen -= sizeof("file `...%s'"); bufflen -= sizeof(l_s("file `...%s'"));
l = strlen(source); l = strlen(source);
if (l>bufflen) { if (l>bufflen) {
source += (l-bufflen); /* get last part of file name */ source += (l-bufflen); /* get last part of file name */
sprintf(out, "file `...%.99s'", source); sprintf(out, l_s("file `...%.99s'"), source);
} }
else else
sprintf(out, "file `%.99s'", source); sprintf(out, l_s("file `%.99s'"), source);
} }
else { else {
int len = strcspn(source, "\n"); /* stop at first newline */ int len = strcspn(source, l_s("\n")); /* stop at first newline */
bufflen -= sizeof("string \"%.*s...\""); bufflen -= sizeof(l_s("string \"%.*s...\""));
if (len > bufflen) len = bufflen; if (len > bufflen) len = bufflen;
if (source[len] != '\0') { /* must truncate? */ if (source[len] != l_c('\0')) { /* must truncate? */
strcpy(out, "string \""); strcpy(out, l_s("string \""));
out += strlen(out); out += strlen(out);
strncpy(out, source, len); strncpy(out, source, len);
strcpy(out+len, "...\""); strcpy(out+len, l_s("...\""));
} }
else else
sprintf(out, "string \"%.99s\"", source); sprintf(out, l_s("string \"%.99s\""), source);
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 1.96 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lobject.h,v 1.97 2001/02/20 18:28:11 roberto Exp roberto $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -117,7 +117,7 @@ union L_UTString {
#define getstr(ts) ((char *)(ts) + sizeof(union L_UTString)) #define getstr(ts) ((l_char *)(ts) + sizeof(union L_UTString))
#define svalue(o) getstr(tsvalue(o)) #define svalue(o) getstr(tsvalue(o))
@@ -200,7 +200,7 @@ typedef struct Hash {
/* /*
** "module" operation for hashing (size is always a power of 2) ** `module' operation for hashing (size is always a power of 2)
*/ */
#define lmod(s,size) ((int)((s) & ((size)-1))) #define lmod(s,size) ((int)((s) & ((size)-1)))
@@ -220,13 +220,13 @@ typedef struct CallInfo {
extern const TObject luaO_nilobject; extern const TObject luaO_nilobject;
char *luaO_openspace (lua_State *L, size_t n); l_char *luaO_openspace (lua_State *L, size_t n);
int luaO_equalObj (const TObject *t1, const TObject *t2); int luaO_equalObj (const TObject *t1, const TObject *t2);
int luaO_str2d (const char *s, lua_Number *result); int luaO_str2d (const l_char *s, lua_Number *result);
void luaO_verror (lua_State *L, const char *fmt, ...); void luaO_verror (lua_State *L, const l_char *fmt, ...);
void luaO_chunkid (char *out, const char *source, int len); void luaO_chunkid (l_char *out, const l_char *source, int len);
#endif #endif

184
lparser.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.137 2001/02/22 18:59:59 roberto Exp roberto $ ** $Id: lparser.c,v 1.138 2001/02/23 13:38:56 roberto Exp roberto $
** LL(1) Parser and code generator for Lua ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -72,9 +72,9 @@ static void lookahead (LexState *ls) {
static void error_expected (LexState *ls, int token) { static void error_expected (LexState *ls, int token) {
char buff[30], t[TOKEN_LEN]; l_char buff[30], t[TOKEN_LEN];
luaX_token2str(token, t); luaX_token2str(token, t);
sprintf(buff, "`%.10s' expected", t); sprintf(buff, l_s("`%.10s' expected"), t);
luaK_error(ls, buff); luaK_error(ls, buff);
} }
@@ -86,7 +86,7 @@ static void check (LexState *ls, int c) {
} }
static void check_condition (LexState *ls, int c, const char *msg) { static void check_condition (LexState *ls, int c, const l_char *msg) {
if (!c) luaK_error(ls, msg); if (!c) luaK_error(ls, msg);
} }
@@ -105,11 +105,11 @@ static void check_match (LexState *ls, int what, int who, int where) {
if (where == ls->linenumber) if (where == ls->linenumber)
error_expected(ls, what); error_expected(ls, what);
else { else {
char buff[70]; l_char buff[70];
char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; l_char t_what[TOKEN_LEN], t_who[TOKEN_LEN];
luaX_token2str(what, t_what); luaX_token2str(what, t_what);
luaX_token2str(who, t_who); luaX_token2str(who, t_who);
sprintf(buff, "`%.10s' expected (to close `%.10s' at line %d)", sprintf(buff, l_s("`%.10s' expected (to close `%.10s' at line %d)"),
t_what, t_who, where); t_what, t_who, where);
luaK_error(ls, buff); luaK_error(ls, buff);
} }
@@ -123,7 +123,7 @@ static int string_constant (FuncState *fs, TString *s) {
int c = s->u.s.constindex; int c = s->u.s.constindex;
if (c >= fs->nkstr || f->kstr[c] != s) { if (c >= fs->nkstr || f->kstr[c] != s) {
luaM_growvector(fs->L, f->kstr, fs->nkstr, f->sizekstr, TString *, luaM_growvector(fs->L, f->kstr, fs->nkstr, f->sizekstr, TString *,
MAXARG_U, "constant table overflow"); MAXARG_U, l_s("constant table overflow"));
c = fs->nkstr++; c = fs->nkstr++;
f->kstr[c] = s; f->kstr[c] = s;
s->u.s.constindex = c; /* hint for next time */ s->u.s.constindex = c; /* hint for next time */
@@ -139,7 +139,7 @@ static void code_string (LexState *ls, TString *s) {
static TString *str_checkname (LexState *ls) { static TString *str_checkname (LexState *ls) {
TString *ts; TString *ts;
check_condition(ls, (ls->t.token == TK_NAME), "<name> expected"); check_condition(ls, (ls->t.token == TK_NAME), l_s("<name> expected"));
ts = ls->t.seminfo.ts; ts = ls->t.seminfo.ts;
next(ls); next(ls);
return ts; return ts;
@@ -155,7 +155,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
Proto *f = fs->f; Proto *f = fs->f;
luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
LocVar, MAX_INT, ""); LocVar, MAX_INT, l_s(""));
f->locvars[fs->nlocvars].varname = varname; f->locvars[fs->nlocvars].varname = varname;
return fs->nlocvars++; return fs->nlocvars++;
} }
@@ -163,7 +163,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
static void new_localvar (LexState *ls, TString *name, int n) { static void new_localvar (LexState *ls, TString *name, int n) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, "local variables"); luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, l_s("local variables"));
fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name); fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name);
} }
@@ -182,7 +182,7 @@ static void removelocalvars (LexState *ls, int nvars) {
} }
static void new_localvarstr (LexState *ls, const char *name, int n) { static void new_localvarstr (LexState *ls, const l_char *name, int n) {
new_localvar(ls, luaS_new(ls->L, name), n); new_localvar(ls, luaS_new(ls->L, name), n);
} }
@@ -209,7 +209,7 @@ static int search_local (LexState *ls, TString *n, expdesc *var) {
static void singlevar (LexState *ls, TString *n, expdesc *var) { static void singlevar (LexState *ls, TString *n, expdesc *var) {
int level = search_local(ls, n, var); int level = search_local(ls, n, var);
if (level >= 1) /* neither local (0) nor global (-1)? */ if (level >= 1) /* neither local (0) nor global (-1)? */
luaX_syntaxerror(ls, "cannot access a variable in outer function", luaX_syntaxerror(ls, l_s("cannot access a variable in outer function"),
getstr(n)); getstr(n));
else if (level == -1) /* global? */ else if (level == -1) /* global? */
var->u.index = string_constant(ls->fs, n); var->u.index = string_constant(ls->fs, n);
@@ -224,7 +224,7 @@ static int indexupvalue (LexState *ls, expdesc *v) {
return i; return i;
} }
/* new one */ /* new one */
luaX_checklimit(ls, fs->f->nupvalues+1, MAXUPVALUES, "upvalues"); luaX_checklimit(ls, fs->f->nupvalues+1, MAXUPVALUES, l_s("upvalues"));
fs->upvalues[fs->f->nupvalues] = *v; fs->upvalues[fs->f->nupvalues] = *v;
return fs->f->nupvalues++; return fs->f->nupvalues++;
} }
@@ -236,12 +236,12 @@ static void pushupvalue (LexState *ls, TString *n) {
int level = search_local(ls, n, &v); int level = search_local(ls, n, &v);
if (level == -1) { /* global? */ if (level == -1) { /* global? */
if (fs->prev == NULL) if (fs->prev == NULL)
luaX_syntaxerror(ls, "cannot access an upvalue at top level", getstr(n)); luaX_syntaxerror(ls, l_s("cannot access an upvalue at top level"), getstr(n));
v.u.index = string_constant(fs->prev, n); v.u.index = string_constant(fs->prev, n);
} }
else if (level != 1) { else if (level != 1) {
luaX_syntaxerror(ls, luaX_syntaxerror(ls,
"upvalue must be global or local to immediately outer function", getstr(n)); l_s("upvalue must be global or local to immediately outer function"), getstr(n));
} }
luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, &v)); luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, &v));
} }
@@ -267,11 +267,11 @@ static void adjust_mult_assign (LexState *ls, int nvars, int nexps) {
static void code_params (LexState *ls, int nparams, short dots) { static void code_params (LexState *ls, int nparams, short dots) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
adjustlocalvars(ls, nparams); adjustlocalvars(ls, nparams);
luaX_checklimit(ls, fs->nactloc, MAXPARAMS, "parameters"); luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters"));
fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */ fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */
fs->f->is_vararg = dots; fs->f->is_vararg = dots;
if (dots) { if (dots) {
new_localvarstr(ls, "arg", 0); new_localvarstr(ls, l_s("arg"), 0);
adjustlocalvars(ls, 1); adjustlocalvars(ls, 1);
} }
luaK_deltastack(fs, fs->nactloc); /* count parameters in the stack */ luaK_deltastack(fs, fs->nactloc); /* count parameters in the stack */
@@ -300,7 +300,7 @@ static void pushclosure (LexState *ls, FuncState *func) {
for (i=0; i<func->f->nupvalues; i++) for (i=0; i<func->f->nupvalues; i++)
luaK_tostack(ls, &func->upvalues[i], 1); luaK_tostack(ls, &func->upvalues[i], 1);
luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *, luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *,
MAXARG_A, "constant table overflow"); MAXARG_A, l_s("constant table overflow"));
f->kproto[fs->nkproto++] = func->f; f->kproto[fs->nkproto++] = func->f;
luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->f->nupvalues); luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->f->nupvalues);
} }
@@ -366,7 +366,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z) {
open_func(&lexstate, &funcstate); open_func(&lexstate, &funcstate);
next(&lexstate); /* read first token */ next(&lexstate); /* read first token */
chunk(&lexstate); chunk(&lexstate);
check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); check_condition(&lexstate, (lexstate.t.token == TK_EOS), l_s("<eof> expected"));
close_func(&lexstate); close_func(&lexstate);
lua_assert(funcstate.prev == NULL); lua_assert(funcstate.prev == NULL);
lua_assert(funcstate.f->nupvalues == 0); lua_assert(funcstate.f->nupvalues == 0);
@@ -385,7 +385,7 @@ static int explist1 (LexState *ls) {
int n = 1; /* at least one expression */ int n = 1; /* at least one expression */
expdesc v; expdesc v;
expr(ls, &v); expr(ls, &v);
while (ls->t.token == ',') { while (ls->t.token == l_c(',')) {
next(ls); /* skip comma */ next(ls); /* skip comma */
luaK_tostack(ls, &v, 1); /* gets only 1 value from previous expression */ luaK_tostack(ls, &v, 1); /* gets only 1 value from previous expression */
expr(ls, &v); expr(ls, &v);
@@ -400,13 +400,13 @@ static void funcargs (LexState *ls, int slf) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
int slevel = fs->stacklevel - slf - 1; /* where is func in the stack */ int slevel = fs->stacklevel - slf - 1; /* where is func in the stack */
switch (ls->t.token) { switch (ls->t.token) {
case '(': { /* funcargs -> `(' [ explist1 ] `)' */ case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */
int line = ls->linenumber; int line = ls->linenumber;
int nargs = 0; int nargs = 0;
next(ls); next(ls);
if (ls->t.token != ')') /* arg list not empty? */ if (ls->t.token != l_c(')')) /* arg list not empty? */
nargs = explist1(ls); nargs = explist1(ls);
check_match(ls, ')', '(', line); check_match(ls, l_c(')'), l_c('('), line);
#ifdef LUA_COMPAT_ARGRET #ifdef LUA_COMPAT_ARGRET
if (nargs > 0) /* arg list is not empty? */ if (nargs > 0) /* arg list is not empty? */
luaK_setcallreturns(fs, 1); /* last call returns only 1 value */ luaK_setcallreturns(fs, 1); /* last call returns only 1 value */
@@ -415,7 +415,7 @@ static void funcargs (LexState *ls, int slf) {
#endif #endif
break; break;
} }
case '{': { /* funcargs -> constructor */ case l_c('{'): { /* funcargs -> constructor */
constructor(ls); constructor(ls);
break; break;
} }
@@ -425,7 +425,7 @@ static void funcargs (LexState *ls, int slf) {
break; break;
} }
default: { default: {
luaK_error(ls, "function arguments expected"); luaK_error(ls, l_s("function arguments expected"));
break; break;
} }
} }
@@ -448,15 +448,15 @@ static void recfield (LexState *ls) {
luaK_kstr(ls, checkname(ls)); luaK_kstr(ls, checkname(ls));
break; break;
} }
case '[': { case l_c('['): {
next(ls); next(ls);
exp1(ls); exp1(ls);
check(ls, ']'); check(ls, l_c(']'));
break; break;
} }
default: luaK_error(ls, "<name> or `[' expected"); default: luaK_error(ls, l_s("<name> or `[' expected"));
} }
check(ls, '='); check(ls, l_c('='));
exp1(ls); exp1(ls);
} }
@@ -466,9 +466,9 @@ static int recfields (LexState *ls) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
int n = 1; /* at least one element */ int n = 1; /* at least one element */
recfield(ls); recfield(ls);
while (ls->t.token == ',') { while (ls->t.token == l_c(',')) {
next(ls); next(ls);
if (ls->t.token == ';' || ls->t.token == '}') if (ls->t.token == l_c(';') || ls->t.token == l_c('}'))
break; break;
recfield(ls); recfield(ls);
n++; n++;
@@ -485,14 +485,14 @@ static int listfields (LexState *ls) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
int n = 1; /* at least one element */ int n = 1; /* at least one element */
exp1(ls); exp1(ls);
while (ls->t.token == ',') { while (ls->t.token == l_c(',')) {
next(ls); next(ls);
if (ls->t.token == ';' || ls->t.token == '}') if (ls->t.token == l_c(';') || ls->t.token == l_c('}'))
break; break;
exp1(ls); exp1(ls);
n++; n++;
luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A, luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A,
"`item groups' in a list initializer"); l_s("`item groups' in a list initializer"));
if (n%LFIELDS_PER_FLUSH == 0) if (n%LFIELDS_PER_FLUSH == 0)
luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH);
} }
@@ -504,18 +504,18 @@ static int listfields (LexState *ls) {
static void constructor_part (LexState *ls, Constdesc *cd) { static void constructor_part (LexState *ls, Constdesc *cd) {
switch (ls->t.token) { switch (ls->t.token) {
case ';': case '}': { /* constructor_part -> empty */ case l_c(';'): case l_c('}'): { /* constructor_part -> empty */
cd->n = 0; cd->n = 0;
cd->k = ls->t.token; cd->k = ls->t.token;
break; break;
} }
case TK_NAME: { /* may be listfields or recfields */ case TK_NAME: { /* may be listfields or recfields */
lookahead(ls); lookahead(ls);
if (ls->lookahead.token != '=') /* expression? */ if (ls->lookahead.token != l_c('=')) /* expression? */
goto case_default; goto case_default;
/* else go through to recfields */ /* else go through to recfields */
} }
case '[': { /* constructor_part -> recfields */ case l_c('['): { /* constructor_part -> recfields */
cd->n = recfields(ls); cd->n = recfields(ls);
cd->k = 1; /* record */ cd->k = 1; /* record */
break; break;
@@ -537,17 +537,17 @@ static void constructor (LexState *ls) {
int pc = luaK_code1(fs, OP_CREATETABLE, 0); int pc = luaK_code1(fs, OP_CREATETABLE, 0);
int nelems; int nelems;
Constdesc cd; Constdesc cd;
check(ls, '{'); check(ls, l_c('{'));
constructor_part(ls, &cd); constructor_part(ls, &cd);
nelems = cd.n; nelems = cd.n;
if (optional(ls, ';')) { if (optional(ls, l_c(';'))) {
Constdesc other_cd; Constdesc other_cd;
constructor_part(ls, &other_cd); constructor_part(ls, &other_cd);
check_condition(ls, (cd.k != other_cd.k), "invalid constructor syntax"); check_condition(ls, (cd.k != other_cd.k), l_s("invalid constructor syntax"));
nelems += other_cd.n; nelems += other_cd.n;
} }
check_match(ls, '}', '{', line); check_match(ls, l_c('}'), l_c('{'), line);
luaX_checklimit(ls, nelems, MAXARG_U, "elements in a table constructor"); luaX_checklimit(ls, nelems, MAXARG_U, l_s("elements in a table constructor"));
SETARG_U(fs->f->code[pc], nelems); /* set initial table size */ SETARG_U(fs->f->code[pc], nelems); /* set initial table size */
} }
@@ -581,7 +581,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
next(ls); next(ls);
break; break;
} }
case '{': { /* constructor */ case l_c('{'): { /* constructor */
constructor(ls); constructor(ls);
break; break;
} }
@@ -590,23 +590,23 @@ static void primaryexp (LexState *ls, expdesc *v) {
body(ls, 0, ls->linenumber); body(ls, 0, ls->linenumber);
break; break;
} }
case '(': { case l_c('('): {
next(ls); next(ls);
expr(ls, v); expr(ls, v);
check(ls, ')'); check(ls, l_c(')'));
return; return;
} }
case TK_NAME: { case TK_NAME: {
singlevar(ls, str_checkname(ls), v); singlevar(ls, str_checkname(ls), v);
return; return;
} }
case '%': { case l_c('%'): {
next(ls); /* skip `%' */ next(ls); /* skip `%' */
pushupvalue(ls, str_checkname(ls)); pushupvalue(ls, str_checkname(ls));
break; break;
} }
default: { default: {
luaK_error(ls, "unexpected symbol"); luaK_error(ls, l_s("unexpected symbol"));
return; return;
} }
} }
@@ -621,22 +621,22 @@ static void simpleexp (LexState *ls, expdesc *v) {
primaryexp(ls, v); primaryexp(ls, v);
for (;;) { for (;;) {
switch (ls->t.token) { switch (ls->t.token) {
case '.': { /* `.' NAME */ case l_c('.'): { /* `.' NAME */
next(ls); next(ls);
luaK_tostack(ls, v, 1); /* `v' must be on stack */ luaK_tostack(ls, v, 1); /* `v' must be on stack */
luaK_kstr(ls, checkname(ls)); luaK_kstr(ls, checkname(ls));
v->k = VINDEXED; v->k = VINDEXED;
break; break;
} }
case '[': { /* `[' exp1 `]' */ case l_c('['): { /* `[' exp1 `]' */
next(ls); next(ls);
luaK_tostack(ls, v, 1); /* `v' must be on stack */ luaK_tostack(ls, v, 1); /* `v' must be on stack */
v->k = VINDEXED; v->k = VINDEXED;
exp1(ls); exp1(ls);
check(ls, ']'); check(ls, l_c(']'));
break; break;
} }
case ':': { /* `:' NAME funcargs */ case l_c(':'): { /* `:' NAME funcargs */
next(ls); next(ls);
luaK_tostack(ls, v, 1); /* `v' must be on stack */ luaK_tostack(ls, v, 1); /* `v' must be on stack */
luaK_code1(ls->fs, OP_PUSHSELF, checkname(ls)); luaK_code1(ls->fs, OP_PUSHSELF, checkname(ls));
@@ -645,7 +645,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
v->u.l.t = v->u.l.f = NO_JUMP; v->u.l.t = v->u.l.f = NO_JUMP;
break; break;
} }
case '(': case TK_STRING: case '{': { /* funcargs */ case l_c('('): case TK_STRING: case l_c('{'): { /* funcargs */
luaK_tostack(ls, v, 1); /* `v' must be on stack */ luaK_tostack(ls, v, 1); /* `v' must be on stack */
funcargs(ls, 0); funcargs(ls, 0);
v->k = VEXP; v->k = VEXP;
@@ -661,7 +661,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
static UnOpr getunopr (int op) { static UnOpr getunopr (int op) {
switch (op) { switch (op) {
case TK_NOT: return OPR_NOT; case TK_NOT: return OPR_NOT;
case '-': return OPR_MINUS; case l_c('-'): return OPR_MINUS;
default: return OPR_NOUNOPR; default: return OPR_NOUNOPR;
} }
} }
@@ -669,17 +669,17 @@ static UnOpr getunopr (int op) {
static BinOpr getbinopr (int op) { static BinOpr getbinopr (int op) {
switch (op) { switch (op) {
case '+': return OPR_ADD; case l_c('+'): return OPR_ADD;
case '-': return OPR_SUB; case l_c('-'): return OPR_SUB;
case '*': return OPR_MULT; case l_c('*'): return OPR_MULT;
case '/': return OPR_DIV; case l_c('/'): return OPR_DIV;
case '^': return OPR_POW; case l_c('^'): return OPR_POW;
case TK_CONCAT: return OPR_CONCAT; case TK_CONCAT: return OPR_CONCAT;
case TK_NE: return OPR_NE; case TK_NE: return OPR_NE;
case TK_EQ: return OPR_EQ; case TK_EQ: return OPR_EQ;
case '<': return OPR_LT; case l_c('<'): return OPR_LT;
case TK_LE: return OPR_LE; case TK_LE: return OPR_LE;
case '>': return OPR_GT; case l_c('>'): return OPR_GT;
case TK_GE: return OPR_GE; case TK_GE: return OPR_GE;
case TK_AND: return OPR_AND; case TK_AND: return OPR_AND;
case TK_OR: return OPR_OR; case TK_OR: return OPR_OR;
@@ -774,17 +774,17 @@ static void block (LexState *ls) {
static int assignment (LexState *ls, expdesc *v, int nvars) { static int assignment (LexState *ls, expdesc *v, int nvars) {
int left = 0; /* number of values left in the stack after assignment */ int left = 0; /* number of values left in the stack after assignment */
luaX_checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment"); luaX_checklimit(ls, nvars, MAXVARSLH, l_s("variables in a multiple assignment"));
if (ls->t.token == ',') { /* assignment -> `,' simpleexp assignment */ if (ls->t.token == l_c(',')) { /* assignment -> `,' simpleexp assignment */
expdesc nv; expdesc nv;
next(ls); next(ls);
simpleexp(ls, &nv); simpleexp(ls, &nv);
check_condition(ls, (nv.k != VEXP), "syntax error"); check_condition(ls, (nv.k != VEXP), l_s("syntax error"));
left = assignment(ls, &nv, nvars+1); left = assignment(ls, &nv, nvars+1);
} }
else { /* assignment -> `=' explist1 */ else { /* assignment -> `=' explist1 */
int nexps; int nexps;
check(ls, '='); check(ls, l_c('='));
nexps = explist1(ls); nexps = explist1(ls);
adjust_mult_assign(ls, nvars, nexps); adjust_mult_assign(ls, nvars, nexps);
} }
@@ -856,17 +856,17 @@ static void forbody (LexState *ls, int nvar, OpCode prepfor, OpCode loopfor) {
static void fornum (LexState *ls, TString *varname) { static void fornum (LexState *ls, TString *varname) {
/* fornum -> NAME = exp1,exp1[,exp1] forbody */ /* fornum -> NAME = exp1,exp1[,exp1] forbody */
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
check(ls, '='); check(ls, l_c('='));
exp1(ls); /* initial value */ exp1(ls); /* initial value */
check(ls, ','); check(ls, l_c(','));
exp1(ls); /* limit */ exp1(ls); /* limit */
if (optional(ls, ',')) if (optional(ls, l_c(',')))
exp1(ls); /* optional step */ exp1(ls); /* optional step */
else else
luaK_code1(fs, OP_PUSHINT, 1); /* default step */ luaK_code1(fs, OP_PUSHINT, 1); /* default step */
new_localvar(ls, varname, 0); new_localvar(ls, varname, 0);
new_localvarstr(ls, "(limit)", 1); new_localvarstr(ls, l_s("(limit)"), 1);
new_localvarstr(ls, "(step)", 2); new_localvarstr(ls, l_s("(step)"), 2);
forbody(ls, 3, OP_FORPREP, OP_FORLOOP); forbody(ls, 3, OP_FORPREP, OP_FORLOOP);
} }
@@ -874,17 +874,17 @@ static void fornum (LexState *ls, TString *varname) {
static void forlist (LexState *ls, TString *indexname) { static void forlist (LexState *ls, TString *indexname) {
/* forlist -> NAME,NAME IN exp1 forbody */ /* forlist -> NAME,NAME IN exp1 forbody */
TString *valname; TString *valname;
check(ls, ','); check(ls, l_c(','));
valname = str_checkname(ls); valname = str_checkname(ls);
/* next test is dirty, but avoids `in' being a reserved word */ /* next test is dirty, but avoids `in' being a reserved word */
check_condition(ls, check_condition(ls,
(ls->t.token == TK_NAME && (ls->t.token == TK_NAME &&
ls->t.seminfo.ts == luaS_newliteral(ls->L, "in")), ls->t.seminfo.ts == luaS_newliteral(ls->L, l_s("in"))),
"`in' expected"); l_s("`in' expected"));
next(ls); /* skip `in' */ next(ls); /* skip `in' */
exp1(ls); /* table */ exp1(ls); /* table */
new_localvarstr(ls, "(table)", 0); new_localvarstr(ls, l_s("(table)"), 0);
new_localvarstr(ls, "(index)", 1); new_localvarstr(ls, l_s("(index)"), 1);
new_localvar(ls, indexname, 2); new_localvar(ls, indexname, 2);
new_localvar(ls, valname, 3); new_localvar(ls, valname, 3);
forbody(ls, 4, OP_LFORPREP, OP_LFORLOOP); forbody(ls, 4, OP_LFORPREP, OP_LFORLOOP);
@@ -900,9 +900,9 @@ static void forstat (LexState *ls, int line) {
next(ls); /* skip `for' */ next(ls); /* skip `for' */
varname = str_checkname(ls); /* first variable name */ varname = str_checkname(ls); /* first variable name */
switch (ls->t.token) { switch (ls->t.token) {
case '=': fornum(ls, varname); break; case l_c('='): fornum(ls, varname); break;
case ',': forlist(ls, varname); break; case l_c(','): forlist(ls, varname); break;
default: luaK_error(ls, "`=' or `,' expected"); default: luaK_error(ls, l_s("`=' or `,' expected"));
} }
check_match(ls, TK_END, TK_FOR, line); check_match(ls, TK_END, TK_FOR, line);
leavebreak(fs, &bl); leavebreak(fs, &bl);
@@ -949,8 +949,8 @@ static void localstat (LexState *ls) {
do { do {
next(ls); /* skip LOCAL or `,' */ next(ls); /* skip LOCAL or `,' */
new_localvar(ls, str_checkname(ls), nvars++); new_localvar(ls, str_checkname(ls), nvars++);
} while (ls->t.token == ','); } while (ls->t.token == l_c(','));
if (optional(ls, '=')) if (optional(ls, l_c('=')))
nexps = explist1(ls); nexps = explist1(ls);
else else
nexps = 0; nexps = 0;
@@ -963,13 +963,13 @@ static int funcname (LexState *ls, expdesc *v) {
/* funcname -> NAME {`.' NAME} [`:' NAME] */ /* funcname -> NAME {`.' NAME} [`:' NAME] */
int needself = 0; int needself = 0;
singlevar(ls, str_checkname(ls), v); singlevar(ls, str_checkname(ls), v);
while (ls->t.token == '.') { while (ls->t.token == l_c('.')) {
next(ls); next(ls);
luaK_tostack(ls, v, 1); luaK_tostack(ls, v, 1);
luaK_kstr(ls, checkname(ls)); luaK_kstr(ls, checkname(ls));
v->k = VINDEXED; v->k = VINDEXED;
} }
if (ls->t.token == ':') { if (ls->t.token == l_c(':')) {
needself = 1; needself = 1;
next(ls); next(ls);
luaK_tostack(ls, v, 1); luaK_tostack(ls, v, 1);
@@ -997,7 +997,7 @@ static void namestat (LexState *ls) {
expdesc v; expdesc v;
simpleexp(ls, &v); simpleexp(ls, &v);
if (v.k == VEXP) { /* stat -> func */ if (v.k == VEXP) { /* stat -> func */
check_condition(ls, luaK_lastisopen(fs), "syntax error"); /* an upvalue? */ check_condition(ls, luaK_lastisopen(fs), l_s("syntax error")); /* an upvalue? */
luaK_setcallreturns(fs, 0); /* call statement uses no results */ luaK_setcallreturns(fs, 0); /* call statement uses no results */
} }
else { /* stat -> assignment */ else { /* stat -> assignment */
@@ -1011,7 +1011,7 @@ static void retstat (LexState *ls) {
/* stat -> RETURN explist */ /* stat -> RETURN explist */
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
next(ls); /* skip RETURN */ next(ls); /* skip RETURN */
if (!block_follow(ls->t.token) && ls->t.token != ';') if (!block_follow(ls->t.token) && ls->t.token != l_c(';'))
explist1(ls); /* optional return values */ explist1(ls); /* optional return values */
luaK_code1(fs, OP_RETURN, ls->fs->nactloc); luaK_code1(fs, OP_RETURN, ls->fs->nactloc);
fs->stacklevel = fs->nactloc; /* removes all temp values */ fs->stacklevel = fs->nactloc; /* removes all temp values */
@@ -1024,7 +1024,7 @@ static void breakstat (LexState *ls) {
int currentlevel = fs->stacklevel; int currentlevel = fs->stacklevel;
Breaklabel *bl = fs->bl; Breaklabel *bl = fs->bl;
if (!bl) if (!bl)
luaK_error(ls, "no loop to break"); luaK_error(ls, l_s("no loop to break"));
next(ls); /* skip BREAK */ next(ls); /* skip BREAK */
luaK_adjuststack(fs, currentlevel - bl->stacklevel); luaK_adjuststack(fs, currentlevel - bl->stacklevel);
luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
@@ -1086,14 +1086,14 @@ static void parlist (LexState *ls) {
/* parlist -> [ param { `,' param } ] */ /* parlist -> [ param { `,' param } ] */
int nparams = 0; int nparams = 0;
short dots = 0; short dots = 0;
if (ls->t.token != ')') { /* is `parlist' not empty? */ if (ls->t.token != l_c(')')) { /* is `parlist' not empty? */
do { do {
switch (ls->t.token) { switch (ls->t.token) {
case TK_DOTS: next(ls); dots = 1; break; case TK_DOTS: next(ls); dots = 1; break;
case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break;
default: luaK_error(ls, "<name> or `...' expected"); default: luaK_error(ls, l_s("<name> or `...' expected"));
} }
} while (!dots && optional(ls, ',')); } while (!dots && optional(ls, l_c(',')));
} }
code_params(ls, nparams, dots); code_params(ls, nparams, dots);
} }
@@ -1104,13 +1104,13 @@ static void body (LexState *ls, int needself, int line) {
FuncState new_fs; FuncState new_fs;
open_func(ls, &new_fs); open_func(ls, &new_fs);
new_fs.f->lineDefined = line; new_fs.f->lineDefined = line;
check(ls, '('); check(ls, l_c('('));
if (needself) { if (needself) {
new_localvarstr(ls, "self", 0); new_localvarstr(ls, l_s("self"), 0);
adjustlocalvars(ls, 1); adjustlocalvars(ls, 1);
} }
parlist(ls); parlist(ls);
check(ls, ')'); check(ls, l_c(')'));
chunk(ls); chunk(ls);
check_match(ls, TK_END, TK_FUNCTION, line); check_match(ls, TK_END, TK_FUNCTION, line);
close_func(ls); close_func(ls);
@@ -1126,7 +1126,7 @@ static void chunk (LexState *ls) {
int islast = 0; int islast = 0;
while (!islast && !block_follow(ls->t.token)) { while (!islast && !block_follow(ls->t.token)) {
islast = statement(ls); islast = statement(ls);
optional(ls, ';'); optional(ls, l_c(';'));
lua_assert(ls->fs->stacklevel == ls->fs->nactloc); lua_assert(ls->fs->stacklevel == ls->fs->nactloc);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 1.55 2001/01/26 11:45:51 roberto Exp roberto $ ** $Id: lstate.c,v 1.56 2001/02/02 15:13:05 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -131,7 +131,7 @@ static void close_state (lua_State *L, lua_State *OL) {
luaS_freeall(L); luaS_freeall(L);
luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM); luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM);
luaM_freearray(L, G(L)->refArray, G(L)->sizeref, struct Ref); luaM_freearray(L, G(L)->refArray, G(L)->sizeref, struct Ref);
luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, l_char);
luaM_freelem(NULL, L->G, global_State); luaM_freelem(NULL, L->G, global_State);
} }
luaM_freearray(OL, L->stack, L->stacksize, TObject); luaM_freearray(OL, L->stack, L->stacksize, TObject);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 1.50 2001/02/02 15:13:05 roberto Exp roberto $ ** $Id: lstate.h,v 1.51 2001/02/20 18:15:33 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -61,10 +61,10 @@ typedef struct stringtable {
/* /*
** "global state", shared by all threads of this state ** `global state', shared by all threads of this state
*/ */
typedef struct global_State { typedef struct global_State {
char *Mbuffer; /* global buffer */ l_char *Mbuffer; /* global buffer */
size_t Mbuffsize; /* size of Mbuffer */ size_t Mbuffsize; /* size of Mbuffer */
Proto *rootproto; /* list of all prototypes */ Proto *rootproto; /* list of all prototypes */
Closure *rootcl; /* list of all closures */ Closure *rootcl; /* list of all closures */
@@ -85,7 +85,7 @@ typedef struct global_State {
/* /*
** "per thread" state ** `per thread' state
*/ */
struct lua_State { struct lua_State {
LUA_USERSTATE LUA_USERSTATE

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstring.c,v 1.59 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lstring.c,v 1.60 2001/02/22 17:15:18 roberto Exp roberto $
** String table (keeps all strings handled by Lua) ** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -63,7 +63,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) {
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) {
TString *ts; TString *ts;
lu_hash h = l; /* seed */ lu_hash h = l; /* seed */
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ 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) {
ts->len = l; ts->len = l;
ts->u.s.hash = h; ts->u.s.hash = h;
ts->u.s.constindex = 0; ts->u.s.constindex = 0;
memcpy(getstr(ts), str, l*sizeof(char)); memcpy(getstr(ts), str, l*sizeof(l_char));
getstr(ts)[l] = 0; /* ending 0 */ getstr(ts)[l] = 0; /* ending 0 */
newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */
return ts; return ts;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstring.h,v 1.29 2001/02/09 20:22:29 roberto Exp roberto $ ** $Id: lstring.h,v 1.30 2001/02/20 18:15:33 roberto Exp roberto $
** String table (keep all strings handled by Lua) ** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -22,20 +22,20 @@
#define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \ #define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \
((lu_mem)(l)+1)*sizeof(char)) ((lu_mem)(l)+1)*sizeof(l_char))
#define sizeudata(l) ((lu_mem)sizeof(union L_UTString)+(l)) #define sizeudata(l) ((lu_mem)sizeof(union L_UTString)+(l))
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ #define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \
(sizeof(s)/sizeof(char))-1)) (sizeof(s)/sizeof(l_char))-1))
void luaS_init (lua_State *L); void luaS_init (lua_State *L);
void luaS_resize (lua_State *L, stringtable *tb, int newsize); void luaS_resize (lua_State *L, stringtable *tb, int newsize);
TString *luaS_newudata (lua_State *L, size_t s, void *udata); TString *luaS_newudata (lua_State *L, size_t s, void *udata);
int luaS_createudata (lua_State *L, void *udata, TObject *o); int luaS_createudata (lua_State *L, void *udata, TObject *o);
void luaS_freeall (lua_State *L); void luaS_freeall (lua_State *L);
TString *luaS_newlstr (lua_State *L, const char *str, size_t l); TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l);
#endif #endif

254
lstrlib.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.63 2001/02/22 17:15:18 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.64 2001/02/22 18:59:59 roberto Exp roberto $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -36,14 +36,14 @@ static sint32 posrelat (sint32 pos, size_t len) {
static int str_sub (lua_State *L) { static int str_sub (lua_State *L) {
size_t l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
sint32 start = posrelat(luaL_check_long(L, 2), l); sint32 start = posrelat(luaL_check_long(L, 2), l);
sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); sint32 end = posrelat(luaL_opt_long(L, 3, -1), l);
if (start < 1) start = 1; if (start < 1) start = 1;
if (end > (sint32)l) end = l; if (end > (sint32)l) end = l;
if (start <= end) if (start <= end)
lua_pushlstring(L, s+start-1, end-start+1); lua_pushlstring(L, s+start-1, end-start+1);
else lua_pushliteral(L, ""); else lua_pushliteral(L, l_s(""));
return 1; return 1;
} }
@@ -52,7 +52,7 @@ static int str_lower (lua_State *L) {
size_t l; size_t l;
size_t i; size_t i;
luaL_Buffer b; luaL_Buffer b;
const char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (i=0; i<l; i++) for (i=0; i<l; i++)
luaL_putchar(&b, tolower(uchar(s[i]))); luaL_putchar(&b, tolower(uchar(s[i])));
@@ -65,7 +65,7 @@ static int str_upper (lua_State *L) {
size_t l; size_t l;
size_t i; size_t i;
luaL_Buffer b; luaL_Buffer b;
const char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (i=0; i<l; i++) for (i=0; i<l; i++)
luaL_putchar(&b, toupper(uchar(s[i]))); luaL_putchar(&b, toupper(uchar(s[i])));
@@ -76,7 +76,7 @@ static int str_upper (lua_State *L) {
static int str_rep (lua_State *L) { static int str_rep (lua_State *L) {
size_t l; size_t l;
luaL_Buffer b; luaL_Buffer b;
const char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
int n = luaL_check_int(L, 2); int n = luaL_check_int(L, 2);
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
while (n-- > 0) while (n-- > 0)
@@ -88,9 +88,9 @@ static int str_rep (lua_State *L) {
static int str_byte (lua_State *L) { static int str_byte (lua_State *L) {
size_t l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l);
luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range"); luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, l_s("out of range"));
lua_pushnumber(L, uchar(s[pos-1])); lua_pushnumber(L, uchar(s[pos-1]));
return 1; return 1;
} }
@@ -103,7 +103,7 @@ static int str_char (lua_State *L) {
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (i=1; i<=n; i++) { for (i=1; i<=n; i++) {
int c = luaL_check_int(L, i); int c = luaL_check_int(L, i);
luaL_arg_check(L, uchar(c) == c, i, "invalid value"); luaL_arg_check(L, uchar(c) == c, i, l_s("invalid value"));
luaL_putchar(&b, uchar(c)); luaL_putchar(&b, uchar(c));
} }
luaL_pushresult(&b); luaL_pushresult(&b);
@@ -127,25 +127,25 @@ static int str_char (lua_State *L) {
#define CAP_POSITION (-2) #define CAP_POSITION (-2)
typedef struct MatchState { typedef struct MatchState {
const char *src_init; /* init of source string */ const l_char *src_init; /* init of source string */
const char *src_end; /* end (`\0') of source string */ const l_char *src_end; /* end (`\0') of source string */
int level; /* total number of captures (finished or unfinished) */ int level; /* total number of captures (finished or unfinished) */
struct { struct {
const char *init; const l_char *init;
sint32 len; sint32 len;
} capture[MAX_CAPTURES]; } capture[MAX_CAPTURES];
lua_State *L; lua_State *L;
} MatchState; } MatchState;
#define ESC '%' #define ESC l_c('%')
#define SPECIALS "^$*+?.([%-" #define SPECIALS l_s("^$*+?.([%-")
static int check_capture (MatchState *ms, int l) { static int check_capture (MatchState *ms, int l) {
l -= '1'; l -= l_c('1');
if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
lua_error(ms->L, "invalid capture index"); lua_error(ms->L, l_s("invalid capture index"));
return l; return l;
} }
@@ -154,22 +154,22 @@ static int capture_to_close (MatchState *ms) {
int level = ms->level; int level = ms->level;
for (level--; level>=0; level--) for (level--; level>=0; level--)
if (ms->capture[level].len == CAP_UNFINISHED) return level; if (ms->capture[level].len == CAP_UNFINISHED) return level;
lua_error(ms->L, "invalid pattern capture"); lua_error(ms->L, l_s("invalid pattern capture"));
return 0; /* to avoid warnings */ return 0; /* to avoid warnings */
} }
static const char *luaI_classend (MatchState *ms, const char *p) { static const l_char *luaI_classend (MatchState *ms, const l_char *p) {
switch (*p++) { switch (*p++) {
case ESC: case ESC:
if (*p == '\0') lua_error(ms->L, "malformed pattern (ends with `%')"); if (*p == l_c('\0')) lua_error(ms->L, l_s("malformed pattern (ends with `%')"));
return p+1; return p+1;
case '[': case l_c('['):
if (*p == '^') p++; if (*p == l_c('^')) p++;
do { /* look for a `]' */ do { /* look for a `]' */
if (*p == '\0') lua_error(ms->L, "malformed pattern (missing `]')"); if (*p == l_c('\0')) lua_error(ms->L, l_s("malformed pattern (missing `]')"));
if (*(p++) == ESC && *p != '\0') p++; /* skip escapes (e.g. `%]') */ if (*(p++) == ESC && *p != l_c('\0')) p++; /* skip escapes (e.g. `%]') */
} while (*p != ']'); } while (*p != l_c(']'));
return p+1; return p+1;
default: default:
return p; return p;
@@ -177,28 +177,28 @@ static const char *luaI_classend (MatchState *ms, const char *p) {
} }
static int match_class (char c, char cl) { static int match_class (l_char c, l_char cl) {
int res; int res;
switch (tolower(uchar(cl))) { switch (tolower(uchar(cl))) {
case 'a' : res = isalpha(uchar(c)); break; case l_c('a') : res = isalpha(uchar(c)); break;
case 'c' : res = iscntrl(uchar(c)); break; case l_c('c') : res = iscntrl(uchar(c)); break;
case 'd' : res = isdigit(uchar(c)); break; case l_c('d') : res = isdigit(uchar(c)); break;
case 'l' : res = islower(uchar(c)); break; case l_c('l') : res = islower(uchar(c)); break;
case 'p' : res = ispunct(uchar(c)); break; case l_c('p') : res = ispunct(uchar(c)); break;
case 's' : res = isspace(uchar(c)); break; case l_c('s') : res = isspace(uchar(c)); break;
case 'u' : res = isupper(uchar(c)); break; case l_c('u') : res = isupper(uchar(c)); break;
case 'w' : res = isalnum(uchar(c)); break; case l_c('w') : res = isalnum(uchar(c)); break;
case 'x' : res = isxdigit(uchar(c)); break; case l_c('x') : res = isxdigit(uchar(c)); break;
case 'z' : res = (c == '\0'); break; case l_c('z') : res = (c == l_c('\0')); break;
default: return (cl == c); default: return (cl == c);
} }
return (islower(uchar(cl)) ? res : !res); return (islower(uchar(cl)) ? res : !res);
} }
static int matchbracketclass (char c, const char *p, const char *endclass) { static int matchbracketclass (l_char c, const l_char *p, const l_char *endclass) {
int sig = 1; int sig = 1;
if (*(p+1) == '^') { if (*(p+1) == l_c('^')) {
sig = 0; sig = 0;
p++; /* skip the `^' */ p++; /* skip the `^' */
} }
@@ -208,7 +208,7 @@ static int matchbracketclass (char c, const char *p, const char *endclass) {
if (match_class(c, *p)) if (match_class(c, *p))
return sig; return sig;
} }
else if ((*(p+1) == '-') && (p+2 < endclass)) { else if ((*(p+1) == l_c('-')) && (p+2 < endclass)) {
p+=2; p+=2;
if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p)) if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p))
return sig; return sig;
@@ -219,13 +219,13 @@ static int matchbracketclass (char c, const char *p, const char *endclass) {
} }
static int luaI_singlematch (char c, const char *p, const char *ep) { static int luaI_singlematch (l_char c, const l_char *p, const l_char *ep) {
switch (*p) { switch (*p) {
case '.': /* matches any char */ case l_c('.'): /* matches any char */
return 1; return 1;
case ESC: case ESC:
return match_class(c, *(p+1)); return match_class(c, *(p+1));
case '[': case l_c('['):
return matchbracketclass(c, p, ep-1); return matchbracketclass(c, p, ep-1);
default: default:
return (*p == c); return (*p == c);
@@ -233,12 +233,12 @@ static int luaI_singlematch (char c, const char *p, const char *ep) {
} }
static const char *match (MatchState *ms, const char *s, const char *p); static const l_char *match (MatchState *ms, const l_char *s, const l_char *p);
static const char *matchbalance (MatchState *ms, const char *s, const char *p) { static const l_char *matchbalance (MatchState *ms, const l_char *s, const l_char *p) {
if (*p == 0 || *(p+1) == 0) if (*p == 0 || *(p+1) == 0)
lua_error(ms->L, "unbalanced pattern"); lua_error(ms->L, l_s("unbalanced pattern"));
if (*s != *p) return NULL; if (*s != *p) return NULL;
else { else {
int b = *p; int b = *p;
@@ -255,14 +255,14 @@ static const char *matchbalance (MatchState *ms, const char *s, const char *p) {
} }
static const char *max_expand (MatchState *ms, const char *s, const char *p, static const l_char *max_expand (MatchState *ms, const l_char *s, const l_char *p,
const char *ep) { const l_char *ep) {
sint32 i = 0; /* counts maximum expand for item */ sint32 i = 0; /* counts maximum expand for item */
while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep)) while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep))
i++; i++;
/* keeps trying to match with the maximum repetitions */ /* keeps trying to match with the maximum repetitions */
while (i>=0) { while (i>=0) {
const char *res = match(ms, (s+i), ep+1); const l_char *res = match(ms, (s+i), ep+1);
if (res) return res; if (res) return res;
i--; /* else didn't match; reduce 1 repetition to try again */ i--; /* else didn't match; reduce 1 repetition to try again */
} }
@@ -270,10 +270,10 @@ static const char *max_expand (MatchState *ms, const char *s, const char *p,
} }
static const char *min_expand (MatchState *ms, const char *s, const char *p, static const l_char *min_expand (MatchState *ms, const l_char *s, const l_char *p,
const char *ep) { const l_char *ep) {
for (;;) { for (;;) {
const char *res = match(ms, s, ep+1); const l_char *res = match(ms, s, ep+1);
if (res != NULL) if (res != NULL)
return res; return res;
else if (s<ms->src_end && luaI_singlematch(*s, p, ep)) 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,
} }
static const char *start_capture (MatchState *ms, const char *s, static const l_char *start_capture (MatchState *ms, const l_char *s,
const char *p, int what) { const l_char *p, int what) {
const char *res; const l_char *res;
int level = ms->level; int level = ms->level;
if (level >= MAX_CAPTURES) lua_error(ms->L, "too many captures"); if (level >= MAX_CAPTURES) lua_error(ms->L, l_s("too many captures"));
ms->capture[level].init = s; ms->capture[level].init = s;
ms->capture[level].len = what; ms->capture[level].len = what;
ms->level = level+1; ms->level = level+1;
@@ -297,9 +297,9 @@ static const char *start_capture (MatchState *ms, const char *s,
} }
static const char *end_capture (MatchState *ms, const char *s, const char *p) { static const l_char *end_capture (MatchState *ms, const l_char *s, const l_char *p) {
int l = capture_to_close(ms); int l = capture_to_close(ms);
const char *res; const l_char *res;
ms->capture[l].len = s - ms->capture[l].init; /* close capture */ ms->capture[l].len = s - ms->capture[l].init; /* close capture */
if ((res = match(ms, s, p)) == NULL) /* match failed? */ if ((res = match(ms, s, p)) == NULL) /* match failed? */
ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ 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) {
} }
static const char *match_capture (MatchState *ms, const char *s, int level) { static const l_char *match_capture (MatchState *ms, const l_char *s, int level) {
int l = check_capture(ms, level); int l = check_capture(ms, level);
size_t len = ms->capture[l].len; size_t len = ms->capture[l].len;
if ((size_t)(ms->src_end-s) >= len && if ((size_t)(ms->src_end-s) >= len &&
@@ -317,15 +317,15 @@ static const char *match_capture (MatchState *ms, const char *s, int level) {
} }
static const char *match (MatchState *ms, const char *s, const char *p) { static const l_char *match (MatchState *ms, const l_char *s, const l_char *p) {
init: /* using goto's to optimize tail recursion */ init: /* using goto's to optimize tail recursion */
switch (*p) { switch (*p) {
case '(': /* start capture */ case l_c('('): /* start capture */
if (*(p+1) == ')') /* position capture? */ if (*(p+1) == l_c(')')) /* position capture? */
return start_capture(ms, s, p+2, CAP_POSITION); return start_capture(ms, s, p+2, CAP_POSITION);
else else
return start_capture(ms, s, p+1, CAP_UNFINISHED); return start_capture(ms, s, p+1, CAP_UNFINISHED);
case ')': /* end capture */ case l_c(')'): /* end capture */
return end_capture(ms, s, p+1); return end_capture(ms, s, p+1);
case ESC: /* may be %[0-9] or %b */ case ESC: /* may be %[0-9] or %b */
if (isdigit(uchar(*(p+1)))) { /* capture? */ if (isdigit(uchar(*(p+1)))) { /* capture? */
@@ -333,33 +333,33 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
if (s == NULL) return NULL; if (s == NULL) return NULL;
p+=2; goto init; /* else return match(ms, s, p+2) */ p+=2; goto init; /* else return match(ms, s, p+2) */
} }
else if (*(p+1) == 'b') { /* balanced string? */ else if (*(p+1) == l_c('b')) { /* balanced string? */
s = matchbalance(ms, s, p+2); s = matchbalance(ms, s, p+2);
if (s == NULL) return NULL; if (s == NULL) return NULL;
p+=4; goto init; /* else return match(ms, s, p+4); */ p+=4; goto init; /* else return match(ms, s, p+4); */
} }
else goto dflt; /* case default */ else goto dflt; /* case default */
case '\0': /* end of pattern */ case l_c('\0'): /* end of pattern */
return s; /* match succeeded */ return s; /* match succeeded */
case '$': case l_c('$'):
if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ if (*(p+1) == l_c('\0')) /* is the `$' the last char in pattern? */
return (s == ms->src_end) ? s : NULL; /* check end of string */ return (s == ms->src_end) ? s : NULL; /* check end of string */
else goto dflt; else goto dflt;
default: dflt: { /* it is a pattern item */ default: dflt: { /* it is a pattern item */
const char *ep = luaI_classend(ms, p); /* points to what is next */ const l_char *ep = luaI_classend(ms, p); /* points to what is next */
int m = s<ms->src_end && luaI_singlematch(*s, p, ep); int m = s<ms->src_end && luaI_singlematch(*s, p, ep);
switch (*ep) { switch (*ep) {
case '?': { /* optional */ case l_c('?'): { /* optional */
const char *res; const l_char *res;
if (m && ((res=match(ms, s+1, ep+1)) != NULL)) if (m && ((res=match(ms, s+1, ep+1)) != NULL))
return res; return res;
p=ep+1; goto init; /* else return match(ms, s, ep+1); */ p=ep+1; goto init; /* else return match(ms, s, ep+1); */
} }
case '*': /* 0 or more repetitions */ case l_c('*'): /* 0 or more repetitions */
return max_expand(ms, s, p, ep); return max_expand(ms, s, p, ep);
case '+': /* 1 or more repetitions */ case l_c('+'): /* 1 or more repetitions */
return (m ? max_expand(ms, s+1, p, ep) : NULL); return (m ? max_expand(ms, s+1, p, ep) : NULL);
case '-': /* 0 or more repetitions (minimum) */ case l_c('-'): /* 0 or more repetitions (minimum) */
return min_expand(ms, s, p, ep); return min_expand(ms, s, p, ep);
default: default:
if (!m) return NULL; if (!m) return NULL;
@@ -371,15 +371,15 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
static const char *lmemfind (const char *s1, size_t l1, static const l_char *lmemfind (const l_char *s1, size_t l1,
const char *s2, size_t l2) { const l_char *s2, size_t l2) {
if (l2 == 0) return s1; /* empty strings are everywhere */ if (l2 == 0) return s1; /* empty strings are everywhere */
else if (l2 > l1) return NULL; /* avoids a negative `l1' */ else if (l2 > l1) return NULL; /* avoids a negative `l1' */
else { else {
const char *init; /* to search for a `*s2' inside `s1' */ const l_char *init; /* to search for a `*s2' inside `s1' */
l2--; /* 1st char will be checked by `memchr' */ l2--; /* 1st char will be checked by `memchr' */
l1 = l1-l2; /* `s2' cannot be found after that */ l1 = l1-l2; /* `s2' cannot be found after that */
while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { while (l1 > 0 && (init = (const l_char *)memchr(s1, *s2, l1)) != NULL) {
init++; /* 1st char is already checked */ init++; /* 1st char is already checked */
if (memcmp(init, s2+1, l2) == 0) if (memcmp(init, s2+1, l2) == 0)
return init-1; return init-1;
@@ -395,7 +395,7 @@ static const char *lmemfind (const char *s1, size_t l1,
static void push_onecapture (MatchState *ms, int i) { static void push_onecapture (MatchState *ms, int i) {
int l = ms->capture[i].len; int l = ms->capture[i].len;
if (l == CAP_UNFINISHED) lua_error(ms->L, "unfinished capture"); if (l == CAP_UNFINISHED) lua_error(ms->L, l_s("unfinished capture"));
if (l == CAP_POSITION) if (l == CAP_POSITION)
lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1);
else else
@@ -405,7 +405,7 @@ static void push_onecapture (MatchState *ms, int i) {
static int push_captures (MatchState *ms) { static int push_captures (MatchState *ms) {
int i; int i;
luaL_checkstack(ms->L, ms->level, "too many captures"); luaL_checkstack(ms->L, ms->level, l_s("too many captures"));
for (i=0; i<ms->level; i++) for (i=0; i<ms->level; i++)
push_onecapture(ms, i); push_onecapture(ms, i);
return ms->level; /* number of strings pushed */ return ms->level; /* number of strings pushed */
@@ -414,13 +414,13 @@ static int push_captures (MatchState *ms) {
static int str_find (lua_State *L) { static int str_find (lua_State *L) {
size_t l1, l2; size_t l1, l2;
const char *s = luaL_check_lstr(L, 1, &l1); const l_char *s = luaL_check_lstr(L, 1, &l1);
const char *p = luaL_check_lstr(L, 2, &l2); const l_char *p = luaL_check_lstr(L, 2, &l2);
sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range"); luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, l_s("out of range"));
if (lua_gettop(L) > 3 || /* extra argument? */ if (lua_gettop(L) > 3 || /* extra argument? */
strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
const char *s2 = lmemfind(s+init, l1-init, p, l2); const l_char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) { if (s2) {
lua_pushnumber(L, s2-s+1); lua_pushnumber(L, s2-s+1);
lua_pushnumber(L, s2-s+l2); lua_pushnumber(L, s2-s+l2);
@@ -429,13 +429,13 @@ static int str_find (lua_State *L) {
} }
else { else {
MatchState ms; MatchState ms;
int anchor = (*p == '^') ? (p++, 1) : 0; int anchor = (*p == l_c('^')) ? (p++, 1) : 0;
const char *s1=s+init; const l_char *s1=s+init;
ms.L = L; ms.L = L;
ms.src_init = s; ms.src_init = s;
ms.src_end = s+l1; ms.src_end = s+l1;
do { do {
const char *res; const l_char *res;
ms.level = 0; ms.level = 0;
if ((res=match(&ms, s1, p)) != NULL) { if ((res=match(&ms, s1, p)) != NULL) {
lua_pushnumber(L, s1-s+1); /* start */ lua_pushnumber(L, s1-s+1); /* start */
@@ -452,7 +452,7 @@ static int str_find (lua_State *L) {
static void add_s (MatchState *ms, luaL_Buffer *b) { static void add_s (MatchState *ms, luaL_Buffer *b) {
lua_State *L = ms->L; lua_State *L = ms->L;
if (lua_isstring(L, 3)) { if (lua_isstring(L, 3)) {
const char *news = lua_tostring(L, 3); const l_char *news = lua_tostring(L, 3);
size_t l = lua_strlen(L, 3); size_t l = lua_strlen(L, 3);
size_t i; size_t i;
for (i=0; i<l; i++) { for (i=0; i<l; i++) {
@@ -485,22 +485,22 @@ static void add_s (MatchState *ms, luaL_Buffer *b) {
static int str_gsub (lua_State *L) { static int str_gsub (lua_State *L) {
size_t srcl; size_t srcl;
const char *src = luaL_check_lstr(L, 1, &srcl); const l_char *src = luaL_check_lstr(L, 1, &srcl);
const char *p = luaL_check_string(L, 2); const l_char *p = luaL_check_string(L, 2);
int max_s = luaL_opt_int(L, 4, srcl+1); int max_s = luaL_opt_int(L, 4, srcl+1);
int anchor = (*p == '^') ? (p++, 1) : 0; int anchor = (*p == l_c('^')) ? (p++, 1) : 0;
int n = 0; int n = 0;
MatchState ms; MatchState ms;
luaL_Buffer b; luaL_Buffer b;
luaL_arg_check(L, luaL_arg_check(L,
lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)), lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)),
3, "string or function expected"); 3, l_s("string or function expected"));
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
ms.L = L; ms.L = L;
ms.src_init = src; ms.src_init = src;
ms.src_end = src+srcl; ms.src_end = src+srcl;
while (n < max_s) { while (n < max_s) {
const char *e; const l_char *e;
ms.level = 0; ms.level = 0;
e = match(&ms, src, p); e = match(&ms, src, p);
if (e) { if (e) {
@@ -531,40 +531,40 @@ static int str_gsub (lua_State *L) {
static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) {
size_t l; size_t l;
const char *s = luaL_check_lstr(L, arg, &l); const l_char *s = luaL_check_lstr(L, arg, &l);
luaL_putchar(b, '"'); luaL_putchar(b, l_c('"'));
while (l--) { while (l--) {
switch (*s) { switch (*s) {
case '"': case '\\': case '\n': case l_c('"'): case l_c('\\'): case l_c('\n'):
luaL_putchar(b, '\\'); luaL_putchar(b, l_c('\\'));
luaL_putchar(b, *s); luaL_putchar(b, *s);
break; break;
case '\0': luaL_addlstring(b, "\\000", 4); break; case l_c('\0'): luaL_addlstring(b, l_s("\\000"), 4); break;
default: luaL_putchar(b, *s); default: luaL_putchar(b, *s);
} }
s++; s++;
} }
luaL_putchar(b, '"'); luaL_putchar(b, l_c('"'));
} }
static const char *scanformat (lua_State *L, const char *strfrmt, char *form, static const l_char *scanformat (lua_State *L, const l_char *strfrmt, l_char *form,
int *hasprecision) { int *hasprecision) {
const char *p = strfrmt; const l_char *p = strfrmt;
while (strchr("-+ #0", *p)) p++; /* skip flags */ while (strchr(l_s("-+ #0"), *p)) p++; /* skip flags */
if (isdigit(uchar(*p))) p++; /* skip width */ if (isdigit(uchar(*p))) p++; /* skip width */
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
if (*p == '.') { if (*p == l_c('.')) {
p++; p++;
*hasprecision = 1; *hasprecision = 1;
if (isdigit(uchar(*p))) p++; /* skip precision */ if (isdigit(uchar(*p))) p++; /* skip precision */
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
} }
if (isdigit(uchar(*p))) if (isdigit(uchar(*p)))
lua_error(L, "invalid format (width or precision too long)"); lua_error(L, l_s("invalid format (width or precision too long)"));
if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
lua_error(L, "invalid format (too long)"); lua_error(L, l_s("invalid format (too long)"));
form[0] = '%'; form[0] = l_c('%');
strncpy(form+1, strfrmt, p-strfrmt+1); strncpy(form+1, strfrmt, p-strfrmt+1);
form[p-strfrmt+2] = 0; form[p-strfrmt+2] = 0;
return p; return p;
@@ -573,38 +573,38 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form,
static int str_format (lua_State *L) { static int str_format (lua_State *L) {
int arg = 1; int arg = 1;
const char *strfrmt = luaL_check_string(L, arg); const l_char *strfrmt = luaL_check_string(L, arg);
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
while (*strfrmt) { while (*strfrmt) {
if (*strfrmt != '%') if (*strfrmt != l_c('%'))
luaL_putchar(&b, *strfrmt++); luaL_putchar(&b, *strfrmt++);
else if (*++strfrmt == '%') else if (*++strfrmt == l_c('%'))
luaL_putchar(&b, *strfrmt++); /* %% */ luaL_putchar(&b, *strfrmt++); /* %% */
else { /* format item */ else { /* format item */
char form[MAX_FORMAT]; /* to store the format (`%...') */ l_char form[MAX_FORMAT]; /* to store the format (`%...') */
char buff[MAX_ITEM]; /* to store the formatted item */ l_char buff[MAX_ITEM]; /* to store the formatted item */
int hasprecision = 0; int hasprecision = 0;
if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == l_c('$'))
lua_error(L, "obsolete `format' option (d$)"); lua_error(L, l_s("obsolete `format' option (d$)"));
arg++; arg++;
strfrmt = scanformat(L, strfrmt, form, &hasprecision); strfrmt = scanformat(L, strfrmt, form, &hasprecision);
switch (*strfrmt++) { switch (*strfrmt++) {
case 'c': case 'd': case 'i': case l_c('c'): case l_c('d'): case l_c('i'):
sprintf(buff, form, luaL_check_int(L, arg)); sprintf(buff, form, luaL_check_int(L, arg));
break; break;
case 'o': case 'u': case 'x': case 'X': case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'):
sprintf(buff, form, (unsigned int)luaL_check_number(L, arg)); sprintf(buff, form, (unsigned int)luaL_check_number(L, arg));
break; break;
case 'e': case 'E': case 'f': case 'g': case 'G': case l_c('e'): case l_c('E'): case l_c('f'): case l_c('g'): case l_c('G'):
sprintf(buff, form, luaL_check_number(L, arg)); sprintf(buff, form, luaL_check_number(L, arg));
break; break;
case 'q': case l_c('q'):
luaI_addquoted(L, &b, arg); luaI_addquoted(L, &b, arg);
continue; /* skip the `addsize' at the end */ continue; /* skip the `addsize' at the end */
case 's': { case l_c('s'): {
size_t l; size_t l;
const char *s = luaL_check_lstr(L, arg, &l); const l_char *s = luaL_check_lstr(L, arg, &l);
if (!hasprecision && l >= 100) { if (!hasprecision && l >= 100) {
/* no precision and string is too long to be formatted; /* no precision and string is too long to be formatted;
keep original string */ keep original string */
@@ -618,7 +618,7 @@ static int str_format (lua_State *L) {
} }
} }
default: /* also treat cases `pnLlh' */ default: /* also treat cases `pnLlh' */
lua_error(L, "invalid option in `format'"); lua_error(L, l_s("invalid option in `format'"));
} }
luaL_addlstring(&b, buff, strlen(buff)); luaL_addlstring(&b, buff, strlen(buff));
} }
@@ -629,16 +629,16 @@ static int str_format (lua_State *L) {
static const luaL_reg strlib[] = { static const luaL_reg strlib[] = {
{"strlen", str_len}, {l_s("strlen"), str_len},
{"strsub", str_sub}, {l_s("strsub"), str_sub},
{"strlower", str_lower}, {l_s("strlower"), str_lower},
{"strupper", str_upper}, {l_s("strupper"), str_upper},
{"strchar", str_char}, {l_s("strchar"), str_char},
{"strrep", str_rep}, {l_s("strrep"), str_rep},
{"strbyte", str_byte}, {l_s("strbyte"), str_byte},
{"format", str_format}, {l_s("format"), str_format},
{"strfind", str_find}, {l_s("strfind"), str_find},
{"gsub", str_gsub} {l_s("gsub"), str_gsub}
}; };

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltable.c,v 1.75 2001/02/01 17:40:48 roberto Exp roberto $ ** $Id: ltable.c,v 1.76 2001/02/20 18:15:33 roberto Exp roberto $
** Lua tables (hash) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -59,9 +59,9 @@ Node *luaH_next (lua_State *L, Hash *t, const TObject *key) {
else { else {
const TObject *v = luaH_get(t, key); const TObject *v = luaH_get(t, key);
if (v == &luaO_nilobject) if (v == &luaO_nilobject)
luaD_error(L, "invalid key for `next'"); luaD_error(L, l_s("invalid key for `next'"));
i = (int)(((const char *)v - i = (int)(((const l_char *)v -
(const char *)(&t->node[0].val)) / sizeof(Node)) + 1; (const l_char *)(&t->node[0].val)) / sizeof(Node)) + 1;
} }
for (; i<t->size; i++) { for (; i<t->size; i++) {
Node *n = node(t, i); Node *n = node(t, i);
@@ -82,7 +82,7 @@ int luaH_nexti (Hash *t, int i) {
#define check_grow(L, p, n) \ #define check_grow(L, p, n) \
if ((p) >= MAX_INT/(n)) luaD_error(L, "table overflow"); if ((p) >= MAX_INT/(n)) luaD_error(L, l_s("table overflow"));
/* /*
** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) ** 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) {
case LUA_TNUMBER: return luaH_setnum(L, t, nvalue(key)); case LUA_TNUMBER: return luaH_setnum(L, t, nvalue(key));
case LUA_TSTRING: return luaH_setstr(L, t, tsvalue(key)); case LUA_TSTRING: return luaH_setstr(L, t, tsvalue(key));
case LUA_TNIL: case LUA_TNIL:
if (L) luaD_error(L, "table index is nil"); if (L) luaD_error(L, l_s("table index is nil"));
return (TObject *)&luaO_nilobject; /* get option */ return (TObject *)&luaO_nilobject; /* get option */
default: return luaH_setany(L, t, key); default: return luaH_setany(L, t, key);
} }

266
ltests.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 1.70 2001/02/21 16:51:25 roberto Exp roberto $ ** $Id: ltests.c,v 1.71 2001/02/22 18:59:59 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -42,7 +42,7 @@ int islocked = 0;
static void setnameval (lua_State *L, const char *name, int val) { static void setnameval (lua_State *L, const l_char *name, int val) {
lua_pushstring(L, name); lua_pushstring(L, name);
lua_pushnumber(L, val); lua_pushnumber(L, val);
lua_settable(L, -3); lua_settable(L, -3);
@@ -63,7 +63,7 @@ static void setnameval (lua_State *L, const char *name, int val) {
#define MARK 0x55 /* 01010101 (a nice pattern) */ #define MARK 0x55 /* 01010101 (a nice pattern) */
#define blocksize(b) ((size_t *)((char *)(b) - HEADER)) #define blocksize(b) ((size_t *)((l_char *)(b) - HEADER))
unsigned long memdebug_numblocks = 0; unsigned long memdebug_numblocks = 0;
unsigned long memdebug_total = 0; unsigned long memdebug_total = 0;
@@ -76,7 +76,7 @@ static void *checkblock (void *block) {
size_t size = *b; size_t size = *b;
int i; int i;
for (i=0;i<MARKSIZE;i++) for (i=0;i<MARKSIZE;i++)
lua_assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ lua_assert(*(((l_char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */
return b; return b;
} }
@@ -102,11 +102,11 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
else if (memdebug_total+size-oldsize > memdebug_memlimit) else if (memdebug_total+size-oldsize > memdebug_memlimit)
return NULL; /* to test memory allocation errors */ return NULL; /* to test memory allocation errors */
else { else {
char *newblock; l_char *newblock;
int i; int i;
size_t realsize = HEADER+size+MARKSIZE; size_t realsize = HEADER+size+MARKSIZE;
if (realsize < size) return NULL; /* overflow! */ if (realsize < size) return NULL; /* overflow! */
newblock = (char *)malloc(realsize); /* alloc a new block */ newblock = (l_char *)malloc(realsize); /* alloc a new block */
if (newblock == NULL) return NULL; if (newblock == NULL) return NULL;
if (oldsize > size) oldsize = size; if (oldsize > size) oldsize = size;
if (block) { if (block) {
@@ -121,7 +121,7 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
memdebug_numblocks++; memdebug_numblocks++;
*(size_t *)newblock = size; *(size_t *)newblock = size;
for (i=0;i<MARKSIZE;i++) for (i=0;i<MARKSIZE;i++)
*(newblock+HEADER+size+i) = (char)(MARK+i); *(newblock+HEADER+size+i) = (l_char)(MARK+i);
return newblock+HEADER; return newblock+HEADER;
} }
} }
@@ -138,36 +138,36 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
*/ */
static const char *const instrname[NUM_OPCODES] = { static const l_char *const instrname[NUM_OPCODES] = {
"RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT", l_s("RETURN"), l_s("CALL"), l_s("TAILCALL"), l_s("PUSHNIL"), l_s("POP"), l_s("PUSHINT"),
"PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL", l_s("PUSHSTRING"), l_s("PUSHNUM"), l_s("PUSHNEGNUM"), l_s("PUSHUPVALUE"), l_s("GETLOCAL"),
"GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF", l_s("GETGLOBAL"), l_s("GETTABLE"), l_s("GETDOTTED"), l_s("GETINDEXED"), l_s("PUSHSELF"),
"CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP", l_s("CREATETABLE"), l_s("SETLOCAL"), l_s("SETGLOBAL"), l_s("SETTABLE"), l_s("SETLIST"), l_s("SETMAP"),
"ADD", "ADDI", "SUB", "MULT", "DIV", "POW", "CONCAT", "MINUS", "NOT", 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"),
"JMPNE", "JMPEQ", "JMPLT", "JMPLE", "JMPGT", "JMPGE", "JMPT", "JMPF", l_s("JMPNE"), l_s("JMPEQ"), l_s("JMPLT"), l_s("JMPLE"), l_s("JMPGT"), l_s("JMPGE"), l_s("JMPT"), l_s("JMPF"),
"JMPONT", "JMPONF", "JMP", "PUSHNILJMP", "FORPREP", "FORLOOP", "LFORPREP", l_s("JMPONT"), l_s("JMPONF"), l_s("JMP"), l_s("PUSHNILJMP"), l_s("FORPREP"), l_s("FORLOOP"), l_s("LFORPREP"),
"LFORLOOP", "CLOSURE" l_s("LFORLOOP"), l_s("CLOSURE")
}; };
static void pushop (lua_State *L, Proto *p, int pc) { static void pushop (lua_State *L, Proto *p, int pc) {
char buff[100]; l_char buff[100];
Instruction i = p->code[pc]; Instruction i = p->code[pc];
OpCode o = GET_OPCODE(i); OpCode o = GET_OPCODE(i);
const char *name = instrname[o]; const l_char *name = instrname[o];
sprintf(buff, "%5d - ", luaG_getline(p->lineinfo, pc, 1, NULL)); sprintf(buff, l_s("%5d - "), luaG_getline(p->lineinfo, pc, 1, NULL));
switch ((enum Mode)luaK_opproperties[o].mode) { switch ((enum Mode)luaK_opproperties[o].mode) {
case iO: case iO:
sprintf(buff+8, "%-12s", name); sprintf(buff+8, l_s("%-12s"), name);
break; break;
case iU: case iU:
sprintf(buff+8, "%-12s%4u", name, GETARG_U(i)); sprintf(buff+8, l_s("%-12s%4u"), name, GETARG_U(i));
break; break;
case iS: case iS:
sprintf(buff+8, "%-12s%4d", name, GETARG_S(i)); sprintf(buff+8, l_s("%-12s%4d"), name, GETARG_S(i));
break; break;
case iAB: case iAB:
sprintf(buff+8, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); sprintf(buff+8, l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_B(i));
break; break;
} }
lua_pushstring(L, buff); lua_pushstring(L, buff);
@@ -178,11 +178,11 @@ static int listcode (lua_State *L) {
int pc; int pc;
Proto *p; Proto *p;
luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected"); 1, l_s("Lua function expected"));
p = clvalue(luaA_index(L, 1))->f.l; p = clvalue(luaA_index(L, 1))->f.l;
lua_newtable(L); lua_newtable(L);
setnameval(L, "maxstack", p->maxstacksize); setnameval(L, l_s("maxstack"), p->maxstacksize);
setnameval(L, "numparams", p->numparams); setnameval(L, l_s("numparams"), p->numparams);
for (pc=0; pc<p->sizecode; pc++) { for (pc=0; pc<p->sizecode; pc++) {
lua_pushnumber(L, pc+1); lua_pushnumber(L, pc+1);
pushop(L, p, pc); pushop(L, p, pc);
@@ -196,7 +196,7 @@ static int liststrings (lua_State *L) {
Proto *p; Proto *p;
int i; int i;
luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected"); 1, l_s("Lua function expected"));
p = clvalue(luaA_index(L, 1))->f.l; p = clvalue(luaA_index(L, 1))->f.l;
lua_newtable(L); lua_newtable(L);
for (i=0; i<p->sizekstr; i++) { for (i=0; i<p->sizekstr; i++) {
@@ -212,9 +212,9 @@ static int listlocals (lua_State *L) {
Proto *p; Proto *p;
int pc = luaL_check_int(L, 2) - 1; int pc = luaL_check_int(L, 2) - 1;
int i = 0; int i = 0;
const char *name; const l_char *name;
luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected"); 1, l_s("Lua function expected"));
p = clvalue(luaA_index(L, 1))->f.l; p = clvalue(luaA_index(L, 1))->f.l;
while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) while ((name = luaF_getlocalname(p, ++i, pc)) != NULL)
lua_pushstring(L, name); lua_pushstring(L, name);
@@ -234,22 +234,22 @@ static int pushbool (lua_State *L, int b) {
static int get_limits (lua_State *L) { static int get_limits (lua_State *L) {
lua_newtable(L); lua_newtable(L);
setnameval(L, "BITS_INT", BITS_INT); setnameval(L, l_s("BITS_INT"), BITS_INT);
setnameval(L, "LFPF", LFIELDS_PER_FLUSH); setnameval(L, l_s("LFPF"), LFIELDS_PER_FLUSH);
setnameval(L, "MAXARG_A", MAXARG_A); setnameval(L, l_s("MAXARG_A"), MAXARG_A);
setnameval(L, "MAXARG_B", MAXARG_B); setnameval(L, l_s("MAXARG_B"), MAXARG_B);
setnameval(L, "MAXARG_S", MAXARG_S); setnameval(L, l_s("MAXARG_S"), MAXARG_S);
setnameval(L, "MAXARG_U", MAXARG_U); setnameval(L, l_s("MAXARG_U"), MAXARG_U);
setnameval(L, "MAXLOCALS", MAXLOCALS); setnameval(L, l_s("MAXLOCALS"), MAXLOCALS);
setnameval(L, "MAXPARAMS", MAXPARAMS); setnameval(L, l_s("MAXPARAMS"), MAXPARAMS);
setnameval(L, "MAXSTACK", MAXSTACK); setnameval(L, l_s("MAXSTACK"), MAXSTACK);
setnameval(L, "MAXUPVALUES", MAXUPVALUES); setnameval(L, l_s("MAXUPVALUES"), MAXUPVALUES);
setnameval(L, "MAXVARSLH", MAXVARSLH); setnameval(L, l_s("MAXVARSLH"), MAXVARSLH);
setnameval(L, "RFPF", RFIELDS_PER_FLUSH); setnameval(L, l_s("RFPF"), RFIELDS_PER_FLUSH);
setnameval(L, "SIZE_A", SIZE_A); setnameval(L, l_s("SIZE_A"), SIZE_A);
setnameval(L, "SIZE_B", SIZE_B); setnameval(L, l_s("SIZE_B"), SIZE_B);
setnameval(L, "SIZE_OP", SIZE_OP); setnameval(L, l_s("SIZE_OP"), SIZE_OP);
setnameval(L, "SIZE_U", SIZE_U); setnameval(L, l_s("SIZE_U"), SIZE_U);
return 1; return 1;
} }
@@ -270,7 +270,7 @@ static int mem_query (lua_State *L) {
static int hash_query (lua_State *L) { static int hash_query (lua_State *L) {
if (lua_isnull(L, 2)) { if (lua_isnull(L, 2)) {
luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, "string expected"); luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected"));
lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash);
} }
else { else {
@@ -313,7 +313,7 @@ static int table_query (lua_State *L) {
static int string_query (lua_State *L) { static int string_query (lua_State *L) {
stringtable *tb = (*luaL_check_string(L, 1) == 's') ? &G(L)->strt : stringtable *tb = (*luaL_check_string(L, 1) == l_c('s')) ? &G(L)->strt :
&G(L)->udt; &G(L)->udt;
int s = luaL_opt_int(L, 2, 0) - 1; int s = luaL_opt_int(L, 2, 0) - 1;
if (s==-1) { if (s==-1) {
@@ -364,8 +364,8 @@ static int newuserdata (lua_State *L) {
} }
else { else {
size_t size = luaL_check_int(L, 1); size_t size = luaL_check_int(L, 1);
char *p = (char *)lua_newuserdata(L, size); l_char *p = (l_char *)lua_newuserdata(L, size);
while (size--) *p++ = '\0'; while (size--) *p++ = l_c('\0');
return 1; return 1;
} }
} }
@@ -400,7 +400,7 @@ static int s2d (lua_State *L) {
static int d2s (lua_State *L) { static int d2s (lua_State *L) {
double d = luaL_check_number(L, 1); double d = luaL_check_number(L, 1);
lua_pushlstring(L, (char *)&d, sizeof(d)); lua_pushlstring(L, (l_char *)&d, sizeof(d));
return 1; return 1;
} }
@@ -419,12 +419,12 @@ static int newstate (lua_State *L) {
static int loadlib (lua_State *L) { static int loadlib (lua_State *L) {
lua_State *L1 = (lua_State *)lua_touserdata(L, 1); lua_State *L1 = (lua_State *)lua_touserdata(L, 1);
switch (*luaL_check_string(L, 2)) { switch (*luaL_check_string(L, 2)) {
case 'm': lua_mathlibopen(L1); break; case l_c('m'): lua_mathlibopen(L1); break;
case 's': lua_strlibopen(L1); break; case l_c('s'): lua_strlibopen(L1); break;
case 'i': lua_iolibopen(L1); break; case l_c('i'): lua_iolibopen(L1); break;
case 'd': lua_dblibopen(L1); break; case l_c('d'): lua_dblibopen(L1); break;
case 'b': lua_baselibopen(L1); break; case l_c('b'): lua_baselibopen(L1); break;
default: luaL_argerror(L, 2, "invalid option"); default: luaL_argerror(L, 2, l_s("invalid option"));
} }
return 0; return 0;
} }
@@ -438,7 +438,7 @@ static int closestate (lua_State *L) {
static int doremote (lua_State *L) { static int doremote (lua_State *L) {
lua_State *L1; lua_State *L1;
const char *code = luaL_check_string(L, 2); const l_char *code = luaL_check_string(L, 2);
int status; int status;
L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1);
status = lua_dostring(L1, code); status = lua_dostring(L1, code);
@@ -457,7 +457,7 @@ static int doremote (lua_State *L) {
static int settagmethod (lua_State *L) { static int settagmethod (lua_State *L) {
int tag = luaL_check_int(L, 1); int tag = luaL_check_int(L, 1);
const char *event = luaL_check_string(L, 2); const l_char *event = luaL_check_string(L, 2);
luaL_checkany(L, 3); luaL_checkany(L, 3);
lua_gettagmethod(L, tag, event); lua_gettagmethod(L, tag, event);
lua_pushvalue(L, 3); lua_pushvalue(L, 3);
@@ -478,36 +478,36 @@ static int equal (lua_State *L) {
** ======================================================= ** =======================================================
*/ */
static const char *const delimits = " \t\n,;"; static const l_char *const delimits = l_s(" \t\n,;");
static void skip (const char **pc) { static void skip (const l_char **pc) {
while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++;
} }
static int getnum (lua_State *L, const char **pc) { static int getnum (lua_State *L, const l_char **pc) {
int res = 0; int res = 0;
int sig = 1; int sig = 1;
skip(pc); skip(pc);
if (**pc == '.') { if (**pc == l_c('.')) {
res = (int)lua_tonumber(L, -1); res = (int)lua_tonumber(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
(*pc)++; (*pc)++;
return res; return res;
} }
else if (**pc == '-') { else if (**pc == l_c('-')) {
sig = -1; sig = -1;
(*pc)++; (*pc)++;
} }
while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0'; while (isdigit(**pc)) res = res*10 + (*(*pc)++) - l_c('0');
return sig*res; return sig*res;
} }
static const char *getname (char *buff, const char **pc) { static const l_char *getname (l_char *buff, const l_char **pc) {
int i = 0; int i = 0;
skip(pc); skip(pc);
while (**pc != '\0' && !strchr(delimits, **pc)) while (**pc != l_c('\0') && !strchr(delimits, **pc))
buff[i++] = *(*pc)++; buff[i++] = *(*pc)++;
buff[i] = '\0'; buff[i] = l_c('\0');
return buff; return buff;
} }
@@ -519,121 +519,121 @@ static const char *getname (char *buff, const char **pc) {
static int testC (lua_State *L) { static int testC (lua_State *L) {
char buff[30]; l_char buff[30];
const char *pc = luaL_check_string(L, 1); const l_char *pc = luaL_check_string(L, 1);
for (;;) { for (;;) {
const char *inst = getname; const l_char *inst = getname;
if EQ("") return 0; if EQ(l_s("")) return 0;
else if EQ("isnumber") { else if EQ(l_s("isnumber")) {
lua_pushnumber(L, lua_isnumber(L, getnum)); lua_pushnumber(L, lua_isnumber(L, getnum));
} }
else if EQ("isstring") { else if EQ(l_s("isstring")) {
lua_pushnumber(L, lua_isstring(L, getnum)); lua_pushnumber(L, lua_isstring(L, getnum));
} }
else if EQ("istable") { else if EQ(l_s("istable")) {
lua_pushnumber(L, lua_istable(L, getnum)); lua_pushnumber(L, lua_istable(L, getnum));
} }
else if EQ("iscfunction") { else if EQ(l_s("iscfunction")) {
lua_pushnumber(L, lua_iscfunction(L, getnum)); lua_pushnumber(L, lua_iscfunction(L, getnum));
} }
else if EQ("isfunction") { else if EQ(l_s("isfunction")) {
lua_pushnumber(L, lua_isfunction(L, getnum)); lua_pushnumber(L, lua_isfunction(L, getnum));
} }
else if EQ("isuserdata") { else if EQ(l_s("isuserdata")) {
lua_pushnumber(L, lua_isuserdata(L, getnum)); lua_pushnumber(L, lua_isuserdata(L, getnum));
} }
else if EQ("isnil") { else if EQ(l_s("isnil")) {
lua_pushnumber(L, lua_isnil(L, getnum)); lua_pushnumber(L, lua_isnil(L, getnum));
} }
else if EQ("isnull") { else if EQ(l_s("isnull")) {
lua_pushnumber(L, lua_isnull(L, getnum)); lua_pushnumber(L, lua_isnull(L, getnum));
} }
else if EQ("tonumber") { else if EQ(l_s("tonumber")) {
lua_pushnumber(L, lua_tonumber(L, getnum)); lua_pushnumber(L, lua_tonumber(L, getnum));
} }
else if EQ("tostring") { else if EQ(l_s("tostring")) {
const char *s = lua_tostring(L, getnum); const l_char *s = lua_tostring(L, getnum);
lua_pushstring(L, s); lua_pushstring(L, s);
} }
else if EQ("tonumber") { else if EQ(l_s("tonumber")) {
lua_pushnumber(L, lua_tonumber(L, getnum)); lua_pushnumber(L, lua_tonumber(L, getnum));
} }
else if EQ("strlen") { else if EQ(l_s("strlen")) {
lua_pushnumber(L, lua_strlen(L, getnum)); lua_pushnumber(L, lua_strlen(L, getnum));
} }
else if EQ("tocfunction") { else if EQ(l_s("tocfunction")) {
lua_pushcfunction(L, lua_tocfunction(L, getnum)); lua_pushcfunction(L, lua_tocfunction(L, getnum));
} }
else if EQ("return") { else if EQ(l_s("return")) {
return getnum; return getnum;
} }
else if EQ("gettop") { else if EQ(l_s("gettop")) {
lua_pushnumber(L, lua_gettop(L)); lua_pushnumber(L, lua_gettop(L));
} }
else if EQ("settop") { else if EQ(l_s("settop")) {
lua_settop(L, getnum); lua_settop(L, getnum);
} }
else if EQ("pop") { else if EQ(l_s("pop")) {
lua_pop(L, getnum); lua_pop(L, getnum);
} }
else if EQ("pushnum") { else if EQ(l_s("pushnum")) {
lua_pushnumber(L, getnum); lua_pushnumber(L, getnum);
} }
else if EQ("pushvalue") { else if EQ(l_s("pushvalue")) {
lua_pushvalue(L, getnum); lua_pushvalue(L, getnum);
} }
else if EQ("remove") { else if EQ(l_s("remove")) {
lua_remove(L, getnum); lua_remove(L, getnum);
} }
else if EQ("insert") { else if EQ(l_s("insert")) {
lua_insert(L, getnum); lua_insert(L, getnum);
} }
else if EQ("gettable") { else if EQ(l_s("gettable")) {
lua_gettable(L, getnum); lua_gettable(L, getnum);
} }
else if EQ("settable") { else if EQ(l_s("settable")) {
lua_settable(L, getnum); lua_settable(L, getnum);
} }
else if EQ("next") { else if EQ(l_s("next")) {
lua_next(L, -2); lua_next(L, -2);
} }
else if EQ("concat") { else if EQ(l_s("concat")) {
lua_concat(L, getnum); lua_concat(L, getnum);
} }
else if EQ("lessthan") { else if EQ(l_s("lessthan")) {
int a = getnum; int a = getnum;
if (lua_lessthan(L, a, getnum)) if (lua_lessthan(L, a, getnum))
lua_pushnumber(L, 1); lua_pushnumber(L, 1);
else else
lua_pushnil(L); lua_pushnil(L);
} }
else if EQ("rawcall") { else if EQ(l_s("rawcall")) {
int narg = getnum; int narg = getnum;
int nres = getnum; int nres = getnum;
lua_rawcall(L, narg, nres); lua_rawcall(L, narg, nres);
} }
else if EQ("call") { else if EQ(l_s("call")) {
int narg = getnum; int narg = getnum;
int nres = getnum; int nres = getnum;
lua_call(L, narg, nres); lua_call(L, narg, nres);
} }
else if EQ("dostring") { else if EQ(l_s("dostring")) {
lua_dostring(L, luaL_check_string(L, getnum)); lua_dostring(L, luaL_check_string(L, getnum));
} }
else if EQ("settagmethod") { else if EQ(l_s("settagmethod")) {
int tag = getnum; int tag = getnum;
const char *event = getname; const l_char *event = getname;
lua_settagmethod(L, tag, event); lua_settagmethod(L, tag, event);
} }
else if EQ("gettagmethod") { else if EQ(l_s("gettagmethod")) {
int tag = getnum; int tag = getnum;
const char *event = getname; const l_char *event = getname;
lua_gettagmethod(L, tag, event); lua_gettagmethod(L, tag, event);
} }
else if EQ("type") { else if EQ(l_s("type")) {
lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); lua_pushstring(L, lua_typename(L, lua_type(L, getnum)));
} }
else luaL_verror(L, "unknown instruction %.30s", buff); else luaL_verror(L, l_s("unknown instruction %.30s"), buff);
} }
return 0; return 0;
} }
@@ -643,30 +643,30 @@ static int testC (lua_State *L) {
static const struct luaL_reg tests_funcs[] = { static const struct luaL_reg tests_funcs[] = {
{"hash", hash_query}, {l_s("hash"), hash_query},
{"limits", get_limits}, {l_s("limits"), get_limits},
{"listcode", listcode}, {l_s("listcode"), listcode},
{"liststrings", liststrings}, {l_s("liststrings"), liststrings},
{"listlocals", listlocals}, {l_s("listlocals"), listlocals},
{"loadlib", loadlib}, {l_s("loadlib"), loadlib},
{"querystr", string_query}, {l_s("querystr"), string_query},
{"querytab", table_query}, {l_s("querytab"), table_query},
{"testC", testC}, {l_s("testC"), testC},
{"ref", tref}, {l_s("ref"), tref},
{"getref", getref}, {l_s("getref"), getref},
{"unref", unref}, {l_s("unref"), unref},
{"d2s", d2s}, {l_s("d2s"), d2s},
{"s2d", s2d}, {l_s("s2d"), s2d},
{"newuserdata", newuserdata}, {l_s("newuserdata"), newuserdata},
{"udataval", udataval}, {l_s("udataval"), udataval},
{"newtag", newtag}, {l_s("newtag"), newtag},
{"doonnewstack", doonnewstack}, {l_s("doonnewstack"), doonnewstack},
{"newstate", newstate}, {l_s("newstate"), newstate},
{"closestate", closestate}, {l_s("closestate"), closestate},
{"doremote", doremote}, {l_s("doremote"), doremote},
{"settagmethod", settagmethod}, {l_s("settagmethod"), settagmethod},
{"equal", equal}, {l_s("equal"), equal},
{"totalmem", mem_query} {l_s("totalmem"), mem_query}
}; };
@@ -680,7 +680,7 @@ void luaB_opentests (lua_State *L) {
lua_setglobals(L); lua_setglobals(L);
luaL_openl(L, tests_funcs); /* open functions inside new table */ luaL_openl(L, tests_funcs); /* open functions inside new table */
lua_setglobals(L); /* restore old table of globals */ lua_setglobals(L); /* restore old table of globals */
lua_setglobal(L, "T"); /* set new table as global T */ lua_setglobal(L, l_s("T")); /* set new table as global T */
} }
#endif #endif

42
ltm.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 1.67 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: ltm.c,v 1.68 2001/02/22 18:59:59 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -19,15 +19,15 @@
#include "ltm.h" #include "ltm.h"
const char *const luaT_eventname[] = { /* ORDER TM */ const l_char *const luaT_eventname[] = { /* ORDER TM */
"gettable", "settable", "index", "getglobal", "setglobal", "add", "sub", l_s("gettable"), l_s("settable"), l_s("index"), l_s("getglobal"), l_s("setglobal"), l_s("add"), l_s("sub"),
"mul", "div", "pow", "unm", "lt", "concat", "gc", "function", l_s("mul"), l_s("div"), l_s("pow"), l_s("unm"), l_s("lt"), l_s("concat"), l_s("gc"), l_s("function"),
"le", "gt", "ge", /* deprecated options!! */ l_s("le"), l_s("gt"), l_s("ge"), /* deprecated options!! */
NULL NULL
}; };
static int findevent (const char *name) { static int findevent (const l_char *name) {
int i; int i;
for (i=0; luaT_eventname[i]; i++) for (i=0; luaT_eventname[i]; i++)
if (strcmp(luaT_eventname[i], name) == 0) if (strcmp(luaT_eventname[i], name) == 0)
@@ -36,14 +36,14 @@ static int findevent (const char *name) {
} }
static int luaI_checkevent (lua_State *L, const char *name, int t) { static int luaI_checkevent (lua_State *L, const l_char *name, int t) {
int e = findevent(name); int e = findevent(name);
if (e >= TM_N) if (e >= TM_N)
luaO_verror(L, "event `%.50s' is deprecated", name); luaO_verror(L, l_s("event `%.50s' is deprecated"), name);
if (e == TM_GC && t == LUA_TTABLE) if (e == TM_GC && t == LUA_TTABLE)
luaO_verror(L, "event `gc' for tables is deprecated"); luaO_verror(L, l_s("event `gc' for tables is deprecated"));
if (e < 0) if (e < 0)
luaO_verror(L, "`%.50s' is not a valid event name", name); luaO_verror(L, l_s("`%.50s' is not a valid event name"), name);
return e; return e;
} }
@@ -68,8 +68,8 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */
void luaT_init (lua_State *L) { void luaT_init (lua_State *L) {
static const char *const typenames[NUM_TAGS] = { static const l_char *const typenames[NUM_TAGS] = {
"userdata", "nil", "number", "string", "table", "function" l_s("userdata"), l_s("nil"), l_s("number"), l_s("string"), l_s("table"), l_s("function")
}; };
int i; int i;
for (i=0; i<NUM_TAGS; i++) for (i=0; i<NUM_TAGS; i++)
@@ -77,12 +77,12 @@ void luaT_init (lua_State *L) {
} }
int luaT_newtag (lua_State *L, const char *name, int basictype) { int luaT_newtag (lua_State *L, const l_char *name, int basictype) {
int tag; int tag;
int i; int i;
TString *ts; TString *ts;
luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM,
MAX_INT, "tag table overflow"); MAX_INT, l_s("tag table overflow"));
tag = G(L)->ntag; tag = G(L)->ntag;
if (name == NULL) if (name == NULL)
ts = NULL; ts = NULL;
@@ -105,7 +105,7 @@ int luaT_newtag (lua_State *L, const char *name, int basictype) {
static void checktag (lua_State *L, int tag) { static void checktag (lua_State *L, int tag) {
if (!(0 <= tag && tag < G(L)->ntag)) if (!(0 <= tag && tag < G(L)->ntag))
luaO_verror(L, "%d is not a valid tag", tag); luaO_verror(L, l_s("%d is not a valid tag"), tag);
} }
@@ -133,7 +133,7 @@ int luaT_tag (const TObject *o) {
} }
const char *luaT_typename (global_State *G, const TObject *o) { const l_char *luaT_typename (global_State *G, const TObject *o) {
int t = ttype(o); int t = ttype(o);
int tag; int tag;
TString *ts; TString *ts;
@@ -154,7 +154,7 @@ const char *luaT_typename (global_State *G, const TObject *o) {
} }
LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { LUA_API void lua_gettagmethod (lua_State *L, int t, const l_char *event) {
int e; int e;
LUA_LOCK(L); LUA_LOCK(L);
e = luaI_checkevent(L, event, t); e = luaI_checkevent(L, event, t);
@@ -169,16 +169,16 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) {
} }
LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { LUA_API void lua_settagmethod (lua_State *L, int t, const l_char *event) {
int e; int e;
LUA_LOCK(L); LUA_LOCK(L);
e = luaI_checkevent(L, event, t); e = luaI_checkevent(L, event, t);
checktag(L, t); checktag(L, t);
if (!luaT_validevent(t, e)) if (!luaT_validevent(t, e))
luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", luaO_verror(L, l_s("cannot change `%.20s' tag method for type `%.20s'%.20s"),
luaT_eventname[e], basictypename(G(L), t), luaT_eventname[e], basictypename(G(L), t),
(t == LUA_TTABLE || t == LUA_TUSERDATA) ? (t == LUA_TTABLE || t == LUA_TUSERDATA) ?
" with default tag" : ""); l_s(" with default tag") : l_s(""));
switch (ttype(L->top - 1)) { switch (ttype(L->top - 1)) {
case LUA_TNIL: case LUA_TNIL:
luaT_gettm(G(L), t, e) = NULL; luaT_gettm(G(L), t, e) = NULL;
@@ -187,7 +187,7 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) {
luaT_gettm(G(L), t, e) = clvalue(L->top - 1); luaT_gettm(G(L), t, e) = clvalue(L->top - 1);
break; break;
default: default:
luaD_error(L, "tag method must be a function (or nil)"); luaD_error(L, l_s("tag method must be a function (or nil)"));
} }
L->top--; L->top--;
LUA_UNLOCK(L); LUA_UNLOCK(L);

8
ltm.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltm.h,v 1.22 2001/01/25 16:45:36 roberto Exp roberto $ ** $Id: ltm.h,v 1.23 2001/02/09 20:22:29 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -67,12 +67,12 @@ struct TM {
#define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag)
extern const char *const luaT_eventname[]; extern const l_char *const luaT_eventname[];
void luaT_init (lua_State *L); void luaT_init (lua_State *L);
int luaT_newtag (lua_State *L, const char *name, int basictype); int luaT_newtag (lua_State *L, const l_char *name, int basictype);
const char *luaT_typename (global_State *G, const TObject *o); const l_char *luaT_typename (global_State *G, const TObject *o);
int luaT_tag (const TObject *o); int luaT_tag (const TObject *o);
int luaT_validevent (int t, int e); /* used by compatibility module */ int luaT_validevent (int t, int e); /* used by compatibility module */

106
lua.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lua.c,v 1.60 2001/02/14 17:19:01 roberto Exp roberto $ ** $Id: lua.c,v 1.61 2001/02/20 18:15:33 roberto Exp roberto $
** Lua stand-alone interpreter ** Lua stand-alone interpreter
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -25,7 +25,7 @@ static int isatty (int x) { return x==0; } /* assume stdin is a tty */
#ifndef PROMPT #ifndef PROMPT
#define PROMPT "> " #define PROMPT l_s("> ")
#endif #endif
@@ -70,7 +70,7 @@ static void lstop (void) {
lua_setlinehook(L, old_linehook); lua_setlinehook(L, old_linehook);
lua_setcallhook(L, old_callhook); lua_setcallhook(L, old_callhook);
lreset(); lreset();
lua_error(L, "interrupted!"); lua_error(L, l_s("interrupted!"));
} }
@@ -83,7 +83,7 @@ static void laction (int i) {
} }
static int ldo (int (*f)(lua_State *l, const char *), const char *name) { static int ldo (int (*f)(lua_State *l, const l_char *), const l_char *name) {
int res; int res;
handler h = lreset(); handler h = lreset();
int top = lua_gettop(L); int top = lua_gettop(L);
@@ -92,45 +92,45 @@ static int ldo (int (*f)(lua_State *l, const char *), const char *name) {
signal(SIGINT, h); /* restore old action */ signal(SIGINT, h); /* restore old action */
/* Lua gives no message in such cases, so lua.c provides one */ /* Lua gives no message in such cases, so lua.c provides one */
if (res == LUA_ERRMEM) { if (res == LUA_ERRMEM) {
fprintf(stderr, "lua: memory allocation error\n"); fprintf(stderr, l_s("lua: memory allocation error\n"));
} }
else if (res == LUA_ERRERR) else if (res == LUA_ERRERR)
fprintf(stderr, "lua: error in error message\n"); fprintf(stderr, l_s("lua: error in error message\n"));
return res; return res;
} }
static void print_message (void) { static void print_message (void) {
fprintf(stderr, fprintf(stderr,
"usage: lua [options]. Available options are:\n" l_s("usage: lua [options]. Available options are:\n")
" - execute stdin as a file\n" l_s(" - execute stdin as a file\n")
" -c close Lua when exiting\n" l_s(" -c close Lua when exiting\n")
" -e stat execute string `stat'\n" l_s(" -e stat execute string `stat'\n")
" -f name execute file `name' with remaining arguments in table `arg'\n" l_s(" -f name execute file `name' with remaining arguments in table `arg'\n")
" -i enter interactive mode with prompt\n" l_s(" -i enter interactive mode with prompt\n")
" -q enter interactive mode without prompt\n" l_s(" -q enter interactive mode without prompt\n")
" -sNUM set stack size to NUM (must be the first option)\n" l_s(" -sNUM set stack size to NUM (must be the first option)\n")
" -v print version information\n" l_s(" -v print version information\n")
" a=b set global `a' to string `b'\n" l_s(" a=b set global `a' to string `b'\n")
" name execute file `name'\n" l_s(" name execute file `name'\n")
); );
} }
static void print_version (void) { static void print_version (void) {
printf("%.80s %.80s\n", LUA_VERSION, LUA_COPYRIGHT); printf(l_s("%.80s %.80s\n"), l_s(LUA_VERSION), l_s(LUA_COPYRIGHT));
} }
static void assign (char *arg) { static void assign (l_char *arg) {
char *eq = strchr(arg, '='); l_char *eq = strchr(arg, l_c('='));
*eq = '\0'; /* spilt `arg' in two strings (name & value) */ *eq = l_c('\0'); /* spilt `arg' in two strings (name & value) */
lua_pushstring(L, eq+1); lua_pushstring(L, eq+1);
lua_setglobal(L, arg); lua_setglobal(L, arg);
} }
static void getargs (char *argv[]) { static void getargs (l_char *argv[]) {
int i; int i;
lua_newtable(L); lua_newtable(L);
for (i=0; argv[i]; i++) { for (i=0; argv[i]; i++) {
@@ -140,24 +140,24 @@ static void getargs (char *argv[]) {
lua_settable(L, -3); lua_settable(L, -3);
} }
/* arg.n = maximum index in table `arg' */ /* arg.n = maximum index in table `arg' */
lua_pushliteral(L, "n"); lua_pushliteral(L, l_s("n"));
lua_pushnumber(L, i-1); lua_pushnumber(L, i-1);
lua_settable(L, -3); lua_settable(L, -3);
} }
static int l_getargs (lua_State *l) { static int l_getargs (lua_State *l) {
char **argv = (char **)lua_touserdata(l, -1); l_char **argv = (l_char **)lua_touserdata(l, -1);
getargs(argv); getargs(argv);
return 1; return 1;
} }
static int file_input (const char *argv) { static int file_input (const l_char *argv) {
int result = ldo(lua_dofile, argv); int result = ldo(lua_dofile, argv);
if (result) { if (result) {
if (result == LUA_ERRFILE) { if (result == LUA_ERRFILE) {
fprintf(stderr, "lua: cannot execute file "); fprintf(stderr, l_s("lua: cannot execute file "));
perror(argv); perror(argv);
} }
return EXIT_FAILURE; return EXIT_FAILURE;
@@ -173,12 +173,12 @@ static int file_input (const char *argv) {
#endif #endif
static const char *get_prompt (int prompt) { static const l_char *get_prompt (int prompt) {
if (!prompt) if (!prompt)
return ""; return l_s("");
else { else {
const char *s; const l_char *s;
lua_getglobal(L, "_PROMPT"); lua_getglobal(L, l_s("_PROMPT"));
s = lua_tostring(L, -1); s = lua_tostring(L, -1);
if (!s) s = PROMPT; if (!s) s = PROMPT;
lua_pop(L, 1); /* remove global */ lua_pop(L, 1); /* remove global */
@@ -192,15 +192,15 @@ static void manual_input (int version, int prompt) {
for (;;) { for (;;) {
fputs(get_prompt(prompt), stdout); /* show prompt */ fputs(get_prompt(prompt), stdout); /* show prompt */
for(;;) { for(;;) {
char buffer[MAXINPUT]; l_char buffer[MAXINPUT];
size_t l; size_t l;
if (fgets(buffer, sizeof(buffer), stdin) == NULL) { if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
printf("\n"); printf(l_s("\n"));
return; return;
} }
l = strlen(buffer); l = strlen(buffer);
if (buffer[l-1] == '\n' && buffer[l-2] == '\\') { if (buffer[l-1] == l_c('\n') && buffer[l-2] == l_c('\\')) {
buffer[l-2] = '\n'; buffer[l-2] = l_c('\n');
lua_pushlstring(L, buffer, l-1); lua_pushlstring(L, buffer, l-1);
} }
else { else {
@@ -215,7 +215,7 @@ static void manual_input (int version, int prompt) {
} }
static int handle_argv (char *argv[], struct Options *opt) { static int handle_argv (l_char *argv[], struct Options *opt) {
if (opt->stacksize > 0) argv++; /* skip option `-s' (if present) */ if (opt->stacksize > 0) argv++; /* skip option `-s' (if present) */
if (*argv == NULL) { /* no more arguments? */ if (*argv == NULL) { /* no more arguments? */
if (isatty(0)) { if (isatty(0)) {
@@ -227,8 +227,8 @@ static int handle_argv (char *argv[], struct Options *opt) {
else { /* other arguments; loop over them */ else { /* other arguments; loop over them */
int i; int i;
for (i = 0; argv[i] != NULL; i++) { for (i = 0; argv[i] != NULL; i++) {
if (argv[i][0] != '-') { /* not an option? */ if (argv[i][0] != l_c('-')) { /* not an option? */
if (strchr(argv[i], '=')) if (strchr(argv[i], l_c('=')))
assign(argv[i]); assign(argv[i]);
else else
if (file_input(argv[i]) != EXIT_SUCCESS) if (file_input(argv[i]) != EXIT_SUCCESS)
@@ -239,46 +239,46 @@ static int handle_argv (char *argv[], struct Options *opt) {
ldo(lua_dofile, NULL); /* executes stdin as a file */ ldo(lua_dofile, NULL); /* executes stdin as a file */
break; break;
} }
case 'i': { case l_c('i'): {
manual_input(0, 1); manual_input(0, 1);
break; break;
} }
case 'q': { case l_c('q'): {
manual_input(0, 0); manual_input(0, 0);
break; break;
} }
case 'c': { case l_c('c'): {
opt->toclose = 1; opt->toclose = 1;
break; break;
} }
case 'v': { case l_c('v'): {
print_version(); print_version();
break; break;
} }
case 'e': { case l_c('e'): {
i++; i++;
if (argv[i] == NULL) { if (argv[i] == NULL) {
print_message(); print_message();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (ldo(lua_dostring, argv[i]) != 0) { if (ldo(lua_dostring, argv[i]) != 0) {
fprintf(stderr, "lua: error running argument `%.99s'\n", argv[i]); fprintf(stderr, l_s("lua: error running argument `%.99s'\n"), argv[i]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
break; break;
} }
case 'f': { case l_c('f'): {
i++; i++;
if (argv[i] == NULL) { if (argv[i] == NULL) {
print_message(); print_message();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
getargs(argv+i); /* collect remaining arguments */ getargs(argv+i); /* collect remaining arguments */
lua_setglobal(L, "arg"); lua_setglobal(L, l_s("arg"));
return file_input(argv[i]); /* stop scanning arguments */ return file_input(argv[i]); /* stop scanning arguments */
} }
case 's': { case l_c('s'): {
fprintf(stderr, "lua: stack size (`-s') must be the first option\n"); fprintf(stderr, l_s("lua: stack size (`-s') must be the first option\n"));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
default: { default: {
@@ -292,11 +292,11 @@ static int handle_argv (char *argv[], struct Options *opt) {
} }
static void getstacksize (int argc, char *argv[], struct Options *opt) { static void getstacksize (int argc, l_char *argv[], struct Options *opt) {
if (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 's') { if (argc >= 2 && argv[1][0] == l_c('-') && argv[1][1] == l_c('s')) {
int stacksize = atoi(&argv[1][2]); int stacksize = atoi(&argv[1][2]);
if (stacksize <= 0) { if (stacksize <= 0) {
fprintf(stderr, "lua: invalid stack size ('%.20s')\n", &argv[1][2]); fprintf(stderr, l_s("lua: invalid stack size ('%.20s')\n"), &argv[1][2]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
opt->stacksize = stacksize; opt->stacksize = stacksize;
@@ -306,10 +306,10 @@ static void getstacksize (int argc, char *argv[], struct Options *opt) {
} }
static void register_getargs (char *argv[]) { static void register_getargs (l_char *argv[]) {
lua_pushuserdata(L, argv); lua_pushuserdata(L, argv);
lua_pushcclosure(L, l_getargs, 1); lua_pushcclosure(L, l_getargs, 1);
lua_setglobal(L, "getargs"); lua_setglobal(L, l_s("getargs"));
} }
@@ -322,7 +322,7 @@ static void openstdlibs (lua_State *l) {
} }
int main (int argc, char *argv[]) { int main (int argc, l_char *argv[]) {
struct Options opt; struct Options opt;
int status; int status;
opt.toclose = 0; opt.toclose = 0;

41
lua.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lua.h,v 1.87 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lua.h,v 1.88 2001/02/22 17:15:18 roberto Exp roberto $
** Lua - An Extensible Extension Language ** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br ** e-mail: lua@tecgraf.puc-rio.br
@@ -79,6 +79,8 @@ typedef int (*lua_CFunction) (lua_State *L);
/* Lua numerical type */ /* Lua numerical type */
typedef double lua_Number; typedef double lua_Number;
/* Lua character type */
typedef char l_char;
/* mark for all API functions */ /* mark for all API functions */
@@ -111,8 +113,8 @@ LUA_API int lua_stackspace (lua_State *L);
*/ */
LUA_API int lua_type (lua_State *L, int index); LUA_API int lua_type (lua_State *L, int index);
LUA_API const char *lua_typename (lua_State *L, int t); LUA_API const l_char *lua_typename (lua_State *L, int t);
LUA_API const char *lua_xtype (lua_State *L, int index); LUA_API const l_char *lua_xtype (lua_State *L, int index);
LUA_API int lua_isnumber (lua_State *L, int index); LUA_API int lua_isnumber (lua_State *L, int index);
LUA_API int lua_isstring (lua_State *L, int index); LUA_API int lua_isstring (lua_State *L, int index);
LUA_API int lua_iscfunction (lua_State *L, int index); 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);
LUA_API int lua_lessthan (lua_State *L, int index1, int index2); LUA_API int lua_lessthan (lua_State *L, int index1, int index2);
LUA_API lua_Number lua_tonumber (lua_State *L, int index); LUA_API lua_Number lua_tonumber (lua_State *L, int index);
LUA_API const char *lua_tostring (lua_State *L, int index); LUA_API const l_char *lua_tostring (lua_State *L, int index);
LUA_API size_t lua_strlen (lua_State *L, int index); LUA_API size_t lua_strlen (lua_State *L, int index);
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index); LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index);
LUA_API void *lua_touserdata (lua_State *L, int index); 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);
*/ */
LUA_API void lua_pushnil (lua_State *L); LUA_API void lua_pushnil (lua_State *L);
LUA_API void lua_pushnumber (lua_State *L, lua_Number n); LUA_API void lua_pushnumber (lua_State *L, lua_Number n);
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len);
LUA_API void lua_pushstring (lua_State *L, const char *s); LUA_API void lua_pushstring (lua_State *L, const l_char *s);
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
LUA_API int lua_pushuserdata (lua_State *L, void *u); LUA_API int lua_pushuserdata (lua_State *L, void *u);
@@ -143,12 +145,12 @@ LUA_API int lua_pushuserdata (lua_State *L, void *u);
/* /*
** get functions (Lua -> stack) ** get functions (Lua -> stack)
*/ */
LUA_API void lua_getglobal (lua_State *L, const char *name); LUA_API void lua_getglobal (lua_State *L, const l_char *name);
LUA_API void lua_gettable (lua_State *L, int index); LUA_API void lua_gettable (lua_State *L, int index);
LUA_API void lua_rawget (lua_State *L, int index); LUA_API void lua_rawget (lua_State *L, int index);
LUA_API void lua_rawgeti (lua_State *L, int index, int n); LUA_API void lua_rawgeti (lua_State *L, int index, int n);
LUA_API void lua_getglobals (lua_State *L); LUA_API void lua_getglobals (lua_State *L);
LUA_API void lua_gettagmethod (lua_State *L, int tag, const char *event); LUA_API void lua_gettagmethod (lua_State *L, int tag, const l_char *event);
LUA_API int lua_getref (lua_State *L, int ref); LUA_API int lua_getref (lua_State *L, int ref);
LUA_API void lua_newtable (lua_State *L); LUA_API void lua_newtable (lua_State *L);
@@ -156,23 +158,24 @@ LUA_API void lua_newtable (lua_State *L);
/* /*
** set functions (stack -> Lua) ** set functions (stack -> Lua)
*/ */
LUA_API void lua_setglobal (lua_State *L, const char *name); LUA_API void lua_setglobal (lua_State *L, const l_char *name);
LUA_API void lua_settable (lua_State *L, int index); LUA_API void lua_settable (lua_State *L, int index);
LUA_API void lua_rawset (lua_State *L, int index); LUA_API void lua_rawset (lua_State *L, int index);
LUA_API void lua_rawseti (lua_State *L, int index, int n); LUA_API void lua_rawseti (lua_State *L, int index, int n);
LUA_API void lua_setglobals (lua_State *L); LUA_API void lua_setglobals (lua_State *L);
LUA_API void lua_settagmethod (lua_State *L, int tag, const char *event); LUA_API void lua_settagmethod (lua_State *L, int tag, const l_char *event);
LUA_API int lua_ref (lua_State *L, int lock); LUA_API int lua_ref (lua_State *L, int lock);
/* /*
** "do" functions (run Lua code) ** `do' functions (run Lua code)
*/ */
LUA_API int lua_call (lua_State *L, int nargs, int nresults); LUA_API int lua_call (lua_State *L, int nargs, int nresults);
LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults);
LUA_API int lua_dofile (lua_State *L, const char *filename); LUA_API int lua_dofile (lua_State *L, const l_char *filename);
LUA_API int lua_dostring (lua_State *L, const char *str); LUA_API int lua_dostring (lua_State *L, const l_char *str);
LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name); LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size,
const l_char *name);
/* /*
** Garbage-collection functions ** Garbage-collection functions
@@ -184,12 +187,12 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold);
/* /*
** miscellaneous functions ** miscellaneous functions
*/ */
LUA_API int lua_newtype (lua_State *L, const char *name, int basictype); LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype);
LUA_API int lua_type2tag (lua_State *L, const char *name); LUA_API int lua_type2tag (lua_State *L, const l_char *name);
LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom);
LUA_API void lua_settag (lua_State *L, int tag); LUA_API void lua_settag (lua_State *L, int tag);
LUA_API void lua_error (lua_State *L, const char *s); LUA_API void lua_error (lua_State *L, const l_char *s);
LUA_API void lua_unref (lua_State *L, int ref); LUA_API void lua_unref (lua_State *L, int ref);
@@ -222,8 +225,8 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size);
#define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY) #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY)
#define lua_pushliteral(L, s) lua_pushlstring(L, "" s, \ #define lua_pushliteral(L, s) lua_pushlstring(L, l_s("") s, \
(sizeof(s)/sizeof(char))-1) (sizeof(s)/sizeof(l_char))-1)

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: luadebug.h,v 1.16 2000/10/20 16:39:03 roberto Exp roberto $ ** $Id: luadebug.h,v 1.17 2000/10/30 12:38:50 roberto Exp roberto $
** Debugging API ** Debugging API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -18,9 +18,9 @@ typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); LUA_API int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar);
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); LUA_API const l_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func);
LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); 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);
#define LUA_IDSIZE 60 #define LUA_IDSIZE 60
struct lua_Debug { struct lua_Debug {
const char *event; /* `call', `return' */ const l_char *event; /* `call', `return' */
int currentline; /* (l) */ int currentline; /* (l) */
const char *name; /* (n) */ const l_char *name; /* (n) */
const char *namewhat; /* (n) `global', `tag method', `local', `field' */ const l_char *namewhat; /* (n) `global', `tag method', `local', `field' */
int nups; /* (u) number of upvalues */ int nups; /* (u) number of upvalues */
int linedefined; /* (S) */ int linedefined; /* (S) */
const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ const l_char *what; /* (S) `Lua' function, `C' function, Lua `main' */
const char *source; /* (S) */ const l_char *source; /* (S) */
char short_src[LUA_IDSIZE]; /* (S) */ l_char short_src[LUA_IDSIZE]; /* (S) */
/* private part */ /* private part */
struct lua_TObject *_func; /* active function */ struct lua_TObject *_func; /* active function */
}; };

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lualib.h,v 1.15 2000/11/23 13:49:35 roberto Exp roberto $ ** $Id: lualib.h,v 1.16 2001/02/22 17:15:18 roberto Exp roberto $
** Lua standard libraries ** Lua standard libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -36,4 +36,14 @@ LUALIB_API void lua_dblibopen (lua_State *L);
/* integer type to hold the result of fgetc */ /* integer type to hold the result of fgetc */
typedef int l_charint; typedef int l_charint;
/* macro to control type of literal strings */
#ifndef l_s
#define l_s(x) x
#endif
/* macro to control type of literal chars */
#ifndef l_c
#define l_c(x) x
#endif
#endif #endif

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 1.37 2000/12/28 12:59:41 roberto Exp roberto $ ** $Id: lundump.c,v 1.38 2001/01/15 16:13:24 roberto Exp roberto $
** load bytecodes from files ** load bytecodes from files
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -15,15 +15,15 @@
#define LoadByte ezgetc #define LoadByte ezgetc
static const char* ZNAME (ZIO* Z) static const l_char* ZNAME (ZIO* Z)
{ {
const char* s=zname(Z); const l_char* s=zname(Z);
return (*s=='@') ? s+1 : s; return (*s==l_c('@')) ? s+1 : s;
} }
static void unexpectedEOZ (lua_State* L, ZIO* Z) static void unexpectedEOZ (lua_State* L, ZIO* Z)
{ {
luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z)); luaO_verror(L,l_s("unexpected end of file in `%.99s'"),ZNAME(Z));
} }
static int ezgetc (lua_State* L, ZIO* Z) 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)
{ {
if (swap) if (swap)
{ {
char *p=(char *) b+size-1; l_char *p=(l_char *) b+size-1;
int n=size; int n=size;
while (n--) *p--=(char)ezgetc(L,Z); while (n--) *p--=(l_char)ezgetc(L,Z);
} }
else else
ezread(L,Z,b,size); 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
{ {
if (swap) if (swap)
{ {
char *q=(char *) b; l_char *q=(l_char *) b;
while (m--) while (m--)
{ {
char *p=q+size-1; l_char *p=q+size-1;
int n=size; int n=size;
while (n--) *p--=(char)ezgetc(L,Z); while (n--) *p--=(l_char)ezgetc(L,Z);
q+=size; q+=size;
} }
} }
@@ -96,9 +96,9 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap)
return NULL; return NULL;
else else
{ {
char* s=luaO_openspace(L,size); l_char* s=luaO_openspace(L,size);
LoadBlock(L,s,size,Z,0); LoadBlock(L,s,size,Z,0);
return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ return luaS_newlstr(L,s,size-1); /* remove trailing l_c('\0') */
} }
} }
@@ -171,18 +171,18 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
static void LoadSignature (lua_State* L, ZIO* Z) static void LoadSignature (lua_State* L, ZIO* Z)
{ {
const char* s=SIGNATURE; const l_char* s=SIGNATURE;
while (*s!=0 && ezgetc(L,Z)==*s) while (*s!=0 && ezgetc(L,Z)==*s)
++s; ++s;
if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z)); if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z));
} }
static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) static void TestSize (lua_State* L, int s, const l_char* what, ZIO* Z)
{ {
int r=ezgetc(L,Z); int r=ezgetc(L,Z);
if (r!=s) if (r!=s)
luaO_verror(L,"virtual machine mismatch in `%.99s':\n" luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n")
" %.20s is %d but read %d",ZNAME(Z),what,s,r); l_s(" %.20s is %d but read %d"),ZNAME(Z),what,s,r);
} }
#define TESTSIZE(s) TestSize(L,s,#s,Z) #define TESTSIZE(s) TestSize(L,s,#s,Z)
@@ -195,12 +195,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
LoadSignature(L,Z); LoadSignature(L,Z);
version=ezgetc(L,Z); version=ezgetc(L,Z);
if (version>VERSION) if (version>VERSION)
luaO_verror(L,"`%.99s' too new:\n" luaO_verror(L,l_s("`%.99s' too new:\n")
" read version %d.%d; expected at most %d.%d", l_s(" read version %d.%d; expected at most %d.%d"),
ZNAME(Z),V(version),V(VERSION)); ZNAME(Z),V(version),V(VERSION));
if (version<VERSION0) /* check last major change */ if (version<VERSION0) /* check last major change */
luaO_verror(L,"`%.99s' too old:\n" luaO_verror(L,l_s("`%.99s' too old:\n")
" read version %d.%d; expected at least %d.%d", l_s(" read version %d.%d; expected at least %d.%d"),
ZNAME(Z),V(version),V(VERSION)); ZNAME(Z),V(version),V(VERSION));
swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */ swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */
TESTSIZE(sizeof(int)); TESTSIZE(sizeof(int));
@@ -212,8 +212,8 @@ static int LoadHeader (lua_State* L, ZIO* Z)
TESTSIZE(sizeof(lua_Number)); TESTSIZE(sizeof(lua_Number));
f=LoadNumber(L,Z,swap); f=LoadNumber(L,Z,swap);
if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
luaO_verror(L,"unknown number format in `%.99s':\n" luaO_verror(L,l_s("unknown number format in `%.99s':\n")
" read " NUMBER_FMT "; expected " NUMBER_FMT, ZNAME(Z),f,tf); l_s(" read ") NUMBER_FMT l_s("; expected ") NUMBER_FMT, ZNAME(Z),f,tf);
return swap; return swap;
} }
@@ -234,7 +234,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
tf=LoadChunk(L,Z); tf=LoadChunk(L,Z);
c=zgetc(Z); c=zgetc(Z);
if (c!=EOZ) if (c!=EOZ)
luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z)); luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z));
return tf; return tf;
} }
@@ -244,5 +244,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
int luaU_endianess (void) int luaU_endianess (void)
{ {
int x=1; int x=1;
return *(char*)&x; return *(l_char*)&x;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lundump.h,v 1.21 2000/10/31 16:57:23 lhf Exp $ ** $Id: lundump.h,v 1.19 2000/11/07 12:44:44 roberto Exp roberto $
** load pre-compiled Lua chunks ** load pre-compiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -20,12 +20,12 @@ int luaU_endianess (void);
#define VERSION 0x40 /* last format change was in 4.0 */ #define VERSION 0x40 /* last format change was in 4.0 */
#define VERSION0 0x40 /* last major change was in 4.0 */ #define VERSION0 0x40 /* last major change was in 4.0 */
#define ID_CHUNK 27 /* binary files start with ESC... */ #define ID_CHUNK 27 /* binary files start with ESC... */
#define SIGNATURE "Lua" /* ...followed by this signature */ #define SIGNATURE l_s("Lua") /* ...followed by this signature */
/* formats for error messages */ /* formats for error messages */
#define SOURCE_FMT "<%d:%.99s>" #define SOURCE_FMT l_s("<%d:%.99s>")
#define SOURCE tf->lineDefined,tf->source->str #define SOURCE tf->lineDefined,tf->source->str
#define IN_FMT " in %p " SOURCE_FMT #define IN_FMT l_s(" in %p ") SOURCE_FMT
#define IN tf,SOURCE #define IN tf,SOURCE
/* a multiple of PI for testing native format */ /* a multiple of PI for testing native format */

54
lvm.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 1.170 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lvm.c,v 1.171 2001/02/22 18:59:59 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -43,7 +43,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_TNUMBER) if (ttype(obj) != LUA_TNUMBER)
return 1; return 1;
else { else {
char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ l_char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
lua_number2str(s, nvalue(obj)); /* convert `s' to number */ lua_number2str(s, nvalue(obj)); /* convert `s' to number */
setsvalue(obj, luaS_new(L, s)); setsvalue(obj, luaS_new(L, s));
return 0; return 0;
@@ -96,23 +96,23 @@ void luaV_Lclosure (lua_State *L, Proto *l, int nelems) {
} }
static void callTM (lua_State *L, const char *fmt, ...) { static void callTM (lua_State *L, const l_char *fmt, ...) {
va_list argp; va_list argp;
StkId base = L->top; StkId base = L->top;
int has_result = 0; int has_result = 0;
va_start(argp, fmt); va_start(argp, fmt);
while (*fmt) { while (*fmt) {
switch (*fmt++) { switch (*fmt++) {
case 'c': case l_c('c'):
setclvalue(L->top, va_arg(argp, Closure *)); setclvalue(L->top, va_arg(argp, Closure *));
break; break;
case 'o': case l_c('o'):
setobj(L->top, va_arg(argp, TObject *)); setobj(L->top, va_arg(argp, TObject *));
break; break;
case 's': case l_c('s'):
setsvalue(L->top, va_arg(argp, TString *)); setsvalue(L->top, va_arg(argp, TString *));
break; break;
case 'r': case l_c('r'):
has_result = 1; has_result = 1;
continue; continue;
} }
@@ -151,9 +151,9 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) {
else { /* not a table; try a `gettable' tag method */ else { /* not a table; try a `gettable' tag method */
tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE);
if (tm == NULL) /* no tag method? */ if (tm == NULL) /* no tag method? */
luaG_typeerror(L, t, "index"); luaG_typeerror(L, t, l_s("index"));
} }
callTM(L, "coor", tm, t, key, res); callTM(L, l_s("coor"), tm, t, key, res);
} }
@@ -175,9 +175,9 @@ void luaV_settable (lua_State *L, StkId t, StkId key, StkId val) {
else { /* not a table; try a `settable' tag method */ else { /* not a table; try a `settable' tag method */
tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE);
if (tm == NULL) /* no tag method? */ if (tm == NULL) /* no tag method? */
luaG_typeerror(L, t, "index"); luaG_typeerror(L, t, l_s("index"));
} }
callTM(L, "cooo", tm, t, key, val); callTM(L, l_s("cooo"), tm, t, key, val);
} }
@@ -189,7 +189,7 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) {
setobj(res, value); /* default behavior */ setobj(res, value); /* default behavior */
} }
else else
callTM(L, "csor", tm, name, value, res); callTM(L, l_s("csor"), tm, name, value, res);
} }
@@ -201,7 +201,7 @@ void luaV_setglobal (lua_State *L, TString *name, StkId val) {
setobj(oldvalue, val); /* raw set */ setobj(oldvalue, val); /* raw set */
} }
else else
callTM(L, "csoo", tm, name, oldvalue, val); callTM(L, l_s("csoo"), tm, name, oldvalue, val);
} }
@@ -218,21 +218,21 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2,
} }
} }
opname = luaS_new(L, luaT_eventname[event]); opname = luaS_new(L, luaT_eventname[event]);
callTM(L, "coosr", tm, p1, p2, opname, res); callTM(L, l_s("coosr"), tm, p1, p2, opname, res);
return 1; return 1;
} }
static void call_arith (lua_State *L, StkId p1, TMS event) { static void call_arith (lua_State *L, StkId p1, TMS event) {
if (!call_binTM(L, p1, p1+1, p1, event)) if (!call_binTM(L, p1, p1+1, p1, event))
luaG_binerror(L, p1, LUA_TNUMBER, "perform arithmetic on"); luaG_binerror(L, p1, LUA_TNUMBER, l_s("perform arithmetic on"));
} }
static int luaV_strlessthan (const TString *ls, const TString *rs) { static int luaV_strlessthan (const TString *ls, const TString *rs) {
const char *l = getstr(ls); const l_char *l = getstr(ls);
size_t ll = ls->len; size_t ll = ls->len;
const char *r = getstr(rs); const l_char *r = getstr(rs);
size_t lr = rs->len; size_t lr = rs->len;
for (;;) { for (;;) {
int temp = strcoll(l, r); int temp = strcoll(l, r);
@@ -269,18 +269,18 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
int n = 2; /* number of elements handled in this pass (at least 2) */ int n = 2; /* number of elements handled in this pass (at least 2) */
if (tostring(L, top-2) || tostring(L, top-1)) { if (tostring(L, top-2) || tostring(L, top-1)) {
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_binerror(L, top-2, LUA_TSTRING, "concat"); luaG_binerror(L, top-2, LUA_TSTRING, l_s("concat"));
} }
else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */ /* at least two string values; get as many as possible */
lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len; lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len;
char *buffer; l_char *buffer;
int i; int i;
while (n < total && !tostring(L, top-n-1)) { /* collect total length */ while (n < total && !tostring(L, top-n-1)) { /* collect total length */
tl += tsvalue(top-n-1)->len; tl += tsvalue(top-n-1)->len;
n++; n++;
} }
if (tl > MAX_SIZET) luaD_error(L, "string size overflow"); if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow"));
buffer = luaO_openspace(L, tl); buffer = luaO_openspace(L, tl);
tl = 0; tl = 0;
for (i=n; i>0; i--) { /* concat all strings */ for (i=n; i>0; i--) { /* concat all strings */
@@ -303,7 +303,7 @@ static void luaV_pack (lua_State *L, StkId firstelem) {
for (i=0; firstelem+i<L->top; i++) for (i=0; firstelem+i<L->top; i++)
setobj(luaH_setnum(L, htab, i+1), firstelem+i); setobj(luaH_setnum(L, htab, i+1), firstelem+i);
/* store counter in field `n' */ /* store counter in field `n' */
n = luaH_setstr(L, htab, luaS_newliteral(L, "n")); n = luaH_setstr(L, htab, luaS_newliteral(L, l_s("n")));
setnvalue(n, i); setnvalue(n, i);
L->top = firstelem; /* remove elements from the stack */ L->top = firstelem; /* remove elements from the stack */
sethvalue(L->top, htab); sethvalue(L->top, htab);
@@ -509,7 +509,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
} }
case OP_POW: { case OP_POW: {
if (!call_binTM(L, top-2, top-1, top-2, TM_POW)) if (!call_binTM(L, top-2, top-1, top-2, TM_POW))
luaD_error(L, "undefined operation"); luaD_error(L, l_s("undefined operation"));
top--; top--;
break; break;
} }
@@ -595,11 +595,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
case OP_FORPREP: { case OP_FORPREP: {
int jmp = GETARG_S(i); int jmp = GETARG_S(i);
if (tonumber(top-1)) if (tonumber(top-1))
luaD_error(L, "`for' step must be a number"); luaD_error(L, l_s("`for' step must be a number"));
if (tonumber(top-2)) if (tonumber(top-2))
luaD_error(L, "`for' limit must be a number"); luaD_error(L, l_s("`for' limit must be a number"));
if (tonumber(top-3)) if (tonumber(top-3))
luaD_error(L, "`for' initial value must be a number"); luaD_error(L, l_s("`for' initial value must be a number"));
pc += -jmp; /* `jump' to loop end (delta is negated here) */ pc += -jmp; /* `jump' to loop end (delta is negated here) */
goto forloop; /* do not increment index */ goto forloop; /* do not increment index */
} }
@@ -607,7 +607,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
lua_assert(ttype(top-1) == LUA_TNUMBER); lua_assert(ttype(top-1) == LUA_TNUMBER);
lua_assert(ttype(top-2) == LUA_TNUMBER); lua_assert(ttype(top-2) == LUA_TNUMBER);
if (ttype(top-3) != LUA_TNUMBER) if (ttype(top-3) != LUA_TNUMBER)
luaD_error(L, "`for' index must be a number"); luaD_error(L, l_s("`for' index must be a number"));
nvalue(top-3) += nvalue(top-1); /* increment index */ nvalue(top-3) += nvalue(top-1); /* increment index */
forloop: forloop:
if (nvalue(top-1) > 0 ? if (nvalue(top-1) > 0 ?
@@ -621,7 +621,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
case OP_LFORPREP: { case OP_LFORPREP: {
int jmp = GETARG_S(i); int jmp = GETARG_S(i);
if (ttype(top-1) != LUA_TTABLE) if (ttype(top-1) != LUA_TTABLE)
luaD_error(L, "`for' table must be a table"); luaD_error(L, l_s("`for' table must be a table"));
top += 3; /* index,key,value */ top += 3; /* index,key,value */
setnvalue(top-3, -1); /* initial index */ setnvalue(top-3, -1); /* initial index */
setnilvalue(top-2); setnilvalue(top-2);