mirror of
https://github.com/lua/lua
synced 2024-11-22 12:51:30 +03:00
first (big) step to support wide chars
This commit is contained in:
parent
d164e2294f
commit
39b7978329
50
lapi.c
50
lapi.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -22,8 +22,8 @@
|
||||
#include "lvm.h"
|
||||
|
||||
|
||||
const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
|
||||
"$Authors: " LUA_AUTHORS " $";
|
||||
const l_char lua_ident[] = l_s("$Lua: ") l_s(LUA_VERSION) l_s(" ")
|
||||
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) {
|
||||
const char *s;
|
||||
LUA_API const l_char *lua_typename (lua_State *L, int t) {
|
||||
const l_char *s;
|
||||
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);
|
||||
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;
|
||||
const char *type;
|
||||
const l_char *type;
|
||||
LUA_LOCK(L);
|
||||
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);
|
||||
return type;
|
||||
}
|
||||
@ -242,9 +242,9 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
|
||||
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;
|
||||
const char *s;
|
||||
const l_char *s;
|
||||
LUA_LOCK(L);
|
||||
o = luaA_indexAcceptable(L, index);
|
||||
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);
|
||||
setsvalue(L->top, luaS_newlstr(L, s, len));
|
||||
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)
|
||||
lua_pushnil(L);
|
||||
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);
|
||||
luaV_getglobal(L, luaS_new(L, name), L->top);
|
||||
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);
|
||||
api_checknelems(L, 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 */
|
||||
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++;
|
||||
}
|
||||
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
|
||||
*/
|
||||
|
||||
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;
|
||||
LUA_LOCK(L);
|
||||
if (basictype != LUA_TNONE &&
|
||||
basictype != LUA_TTABLE &&
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
const TObject *v;
|
||||
LUA_LOCK(L);
|
||||
@ -618,10 +618,10 @@ LUA_API void lua_settag (lua_State *L, int tag) {
|
||||
LUA_LOCK(L);
|
||||
api_checknelems(L, 1);
|
||||
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;
|
||||
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));
|
||||
switch (ttype(L->top-1)) {
|
||||
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;
|
||||
break;
|
||||
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));
|
||||
}
|
||||
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);
|
||||
luaD_error(L, s);
|
||||
LUA_UNLOCK(L);
|
||||
@ -685,7 +685,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
|
||||
int n;
|
||||
LUA_LOCK(L);
|
||||
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)
|
||||
n = (int)nvalue(value);
|
||||
else {
|
||||
|
43
lauxlib.c
43
lauxlib.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -18,10 +18,11 @@
|
||||
|
||||
#include "lauxlib.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;
|
||||
for (i=0; list[i]; i++)
|
||||
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 */
|
||||
}
|
||||
|
||||
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_getstack(L, 0, &ar);
|
||||
lua_getinfo(L, "n", &ar);
|
||||
lua_getinfo(L, l_s("n"), &ar);
|
||||
if (ar.name == NULL)
|
||||
ar.name = "?";
|
||||
luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)",
|
||||
ar.name = l_s("?");
|
||||
luaL_verror(L, l_s("bad argument #%d to `%.50s' (%.100s)"),
|
||||
narg, ar.name, extramsg);
|
||||
}
|
||||
|
||||
|
||||
static void type_error (lua_State *L, int narg, const char *tname) {
|
||||
char buff[80];
|
||||
sprintf(buff, "%.25s expected, got %.25s", tname, lua_xtype(L, narg));
|
||||
static void type_error (lua_State *L, int narg, const l_char *tname) {
|
||||
l_char buff[80];
|
||||
sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtype(L, narg));
|
||||
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))
|
||||
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) {
|
||||
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,
|
||||
const char *name) {
|
||||
const l_char *name) {
|
||||
if (strcmp(lua_xtype(L, narg), name) != 0)
|
||||
type_error(L, narg, name);
|
||||
return lua_touserdata(L, narg);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
|
||||
const char *s = lua_tostring(L, narg);
|
||||
LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
|
||||
const l_char *s = lua_tostring(L, narg);
|
||||
if (!s) tag_error(L, narg, LUA_TSTRING);
|
||||
if (len) *len = lua_strlen(L, narg);
|
||||
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 (len)
|
||||
*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, ...) {
|
||||
char buff[500];
|
||||
LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...) {
|
||||
l_char buff[500];
|
||||
va_list argp;
|
||||
va_start(argp, fmt);
|
||||
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))
|
||||
adjuststack(B);
|
||||
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--)
|
||||
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));
|
||||
}
|
||||
|
||||
|
30
lauxlib.h
30
lauxlib.h
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -21,25 +21,25 @@
|
||||
|
||||
|
||||
typedef struct luaL_reg {
|
||||
const char *name;
|
||||
const l_char *name;
|
||||
lua_CFunction func;
|
||||
} luaL_reg;
|
||||
|
||||
|
||||
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 const 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 void luaL_argerror (lua_State *L, int numarg, const l_char *extramsg);
|
||||
LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int numArg, 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_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_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 int luaL_findstring (const char *name, const char *const list[]);
|
||||
LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...);
|
||||
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 {
|
||||
char *p; /* current position in buffer */
|
||||
l_char *p; /* current position in buffer */
|
||||
int level;
|
||||
lua_State *L;
|
||||
char buffer[LUAL_BUFFERSIZE];
|
||||
l_char buffer[LUAL_BUFFERSIZE];
|
||||
} luaL_Buffer;
|
||||
|
||||
#define luaL_putchar(B,c) \
|
||||
((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))
|
||||
|
||||
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B);
|
||||
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B);
|
||||
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
|
||||
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s);
|
||||
LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B);
|
||||
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l);
|
||||
LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s);
|
||||
LUALIB_API void luaL_addvalue (luaL_Buffer *B);
|
||||
LUALIB_API void luaL_pushresult (luaL_Buffer *B);
|
||||
|
||||
|
194
lbaselib.c
194
lbaselib.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -35,21 +35,21 @@ static int luaB__ALERT (lua_State *L) {
|
||||
*/
|
||||
static int luaB__ERRORMESSAGE (lua_State *L) {
|
||||
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 */
|
||||
lua_Debug ar;
|
||||
lua_pushliteral(L, "error: ");
|
||||
lua_pushliteral(L, l_s("error: "));
|
||||
lua_pushvalue(L, 1);
|
||||
if (lua_getstack(L, 1, &ar)) {
|
||||
lua_getinfo(L, "Sl", &ar);
|
||||
lua_getinfo(L, l_s("Sl"), &ar);
|
||||
if (ar.source && ar.currentline > 0) {
|
||||
char buff[100];
|
||||
sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline);
|
||||
l_char buff[100];
|
||||
sprintf(buff, l_s("\n <%.70s: line %d>"), ar.short_src, ar.currentline);
|
||||
lua_pushstring(L, buff);
|
||||
lua_concat(L, 2);
|
||||
}
|
||||
}
|
||||
lua_pushliteral(L, "\n");
|
||||
lua_pushliteral(L, l_s("\n"));
|
||||
lua_concat(L, 3);
|
||||
lua_rawcall(L, 1, 0);
|
||||
}
|
||||
@ -66,20 +66,20 @@ static int luaB__ERRORMESSAGE (lua_State *L) {
|
||||
static int luaB_print (lua_State *L) {
|
||||
int n = lua_gettop(L); /* number of arguments */
|
||||
int i;
|
||||
lua_getglobal(L, "tostring");
|
||||
lua_getglobal(L, l_s("tostring"));
|
||||
for (i=1; i<=n; i++) {
|
||||
const char *s;
|
||||
const l_char *s;
|
||||
lua_pushvalue(L, -1); /* function to be called */
|
||||
lua_pushvalue(L, i); /* value to print */
|
||||
lua_rawcall(L, 1, 1);
|
||||
s = lua_tostring(L, -1); /* get result */
|
||||
if (s == NULL)
|
||||
lua_error(L, "`tostring' must return a string to `print'");
|
||||
if (i>1) fputs("\t", stdout);
|
||||
lua_error(L, l_s("`tostring' must return a string to `print'"));
|
||||
if (i>1) fputs(l_s("\t"), stdout);
|
||||
fputs(s, stdout);
|
||||
lua_pop(L, 1); /* pop result */
|
||||
}
|
||||
fputs("\n", stdout);
|
||||
fputs(l_s("\n"), stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -94,14 +94,14 @@ static int luaB_tonumber (lua_State *L) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
const char *s1 = luaL_check_string(L, 1);
|
||||
char *s2;
|
||||
const l_char *s1 = luaL_check_string(L, 1);
|
||||
l_char *s2;
|
||||
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);
|
||||
if (s1 != s2) { /* at least one valid digit? */
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
@ -135,14 +135,14 @@ static int gettag (lua_State *L, int narg) {
|
||||
case LUA_TNUMBER:
|
||||
return (int)lua_tonumber(L, narg);
|
||||
case LUA_TSTRING: {
|
||||
const char *name = lua_tostring(L, narg);
|
||||
const l_char *name = lua_tostring(L, narg);
|
||||
int tag = lua_type2tag(L, name);
|
||||
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;
|
||||
}
|
||||
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 */
|
||||
}
|
||||
}
|
||||
@ -162,7 +162,7 @@ static int luaB_settag (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));
|
||||
return 1;
|
||||
}
|
||||
@ -199,11 +199,11 @@ static int luaB_rawset (lua_State *L) {
|
||||
|
||||
static int luaB_settagmethod (lua_State *L) {
|
||||
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,
|
||||
"function or nil expected");
|
||||
if (strcmp(event, "gc") == 0)
|
||||
lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua");
|
||||
l_s("function or nil expected"));
|
||||
if (strcmp(event, l_s("gc")) == 0)
|
||||
lua_error(L, l_s("deprecated use: cannot set the `gc' tag method from Lua"));
|
||||
lua_gettagmethod(L, tag, event);
|
||||
lua_pushvalue(L, 3);
|
||||
lua_settagmethod(L, tag, event);
|
||||
@ -213,9 +213,9 @@ static int luaB_settagmethod (lua_State *L) {
|
||||
|
||||
static int luaB_gettagmethod (lua_State *L) {
|
||||
int tag = gettag(L, 1);
|
||||
const char *event = luaL_check_string(L, 2);
|
||||
if (strcmp(event, "gc") == 0)
|
||||
lua_error(L, "deprecated use: cannot get the `gc' tag method from Lua");
|
||||
const l_char *event = luaL_check_string(L, 2);
|
||||
if (strcmp(event, l_s("gc")) == 0)
|
||||
lua_error(L, l_s("deprecated use: cannot get the `gc' tag method from Lua"));
|
||||
lua_gettagmethod(L, tag, event);
|
||||
return 1;
|
||||
}
|
||||
@ -261,9 +261,9 @@ static int luaB_next (lua_State *L) {
|
||||
|
||||
|
||||
static int passresults (lua_State *L, int status, int oldtop) {
|
||||
static const char *const errornames[] =
|
||||
{"ok", "run-time error", "file error", "syntax error",
|
||||
"memory error", "error in error handling"};
|
||||
static const l_char *const errornames[] =
|
||||
{l_s("ok"), l_s("run-time error"), l_s("file error"), l_s("syntax error"),
|
||||
l_s("memory error"), l_s("error in error handling")};
|
||||
if (status == 0) {
|
||||
int nresults = lua_gettop(L) - oldtop;
|
||||
if (nresults > 0)
|
||||
@ -283,59 +283,59 @@ static int passresults (lua_State *L, int status, int oldtop) {
|
||||
static int luaB_dostring (lua_State *L) {
|
||||
int oldtop = lua_gettop(L);
|
||||
size_t l;
|
||||
const char *s = luaL_check_lstr(L, 1, &l);
|
||||
const char *chunkname = luaL_opt_string(L, 2, s);
|
||||
const l_char *s = luaL_check_lstr(L, 1, &l);
|
||||
const l_char *chunkname = luaL_opt_string(L, 2, s);
|
||||
return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop);
|
||||
}
|
||||
|
||||
|
||||
static int luaB_dofile (lua_State *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);
|
||||
}
|
||||
|
||||
|
||||
static int luaB_call (lua_State *L) {
|
||||
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 i, status;
|
||||
int n;
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
n = lua_getn(L, 2);
|
||||
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 */
|
||||
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 */
|
||||
/* push function */
|
||||
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] */
|
||||
lua_rawgeti(L, 2, i+1);
|
||||
status = lua_call(L, n, LUA_MULTRET);
|
||||
if (err != 0) { /* restore old error method */
|
||||
lua_pushvalue(L, err);
|
||||
lua_setglobal(L, LUA_ERRORMESSAGE);
|
||||
lua_setglobal(L, l_s(LUA_ERRORMESSAGE));
|
||||
}
|
||||
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 */
|
||||
else
|
||||
lua_error(L, NULL); /* propagate error without additional messages */
|
||||
return 1;
|
||||
}
|
||||
if (strchr(options, 'p')) /* pack results? */
|
||||
lua_error(L, "deprecated option `p' in `call'");
|
||||
if (strchr(options, l_c('p'))) /* pack results? */
|
||||
lua_error(L, l_s("deprecated option `p' in `call'"));
|
||||
return lua_gettop(L) - oldtop; /* results are already on the stack */
|
||||
}
|
||||
|
||||
|
||||
static int luaB_tostring (lua_State *L) {
|
||||
char buff[64];
|
||||
l_char buff[64];
|
||||
switch (lua_type(L, 1)) {
|
||||
case LUA_TNUMBER:
|
||||
lua_pushstring(L, lua_tostring(L, 1));
|
||||
@ -344,24 +344,24 @@ static int luaB_tostring (lua_State *L) {
|
||||
lua_pushvalue(L, 1);
|
||||
return 1;
|
||||
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;
|
||||
case LUA_TFUNCTION:
|
||||
sprintf(buff, "function: %p", lua_topointer(L, 1));
|
||||
sprintf(buff, l_s("function: %p"), lua_topointer(L, 1));
|
||||
break;
|
||||
case LUA_TUSERDATA: {
|
||||
const char *t = lua_xtype(L, 1);
|
||||
if (strcmp(t, "userdata") == 0)
|
||||
sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
|
||||
const l_char *t = lua_xtype(L, 1);
|
||||
if (strcmp(t, l_s("userdata")) == 0)
|
||||
sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), lua_touserdata(L, 1));
|
||||
else
|
||||
sprintf(buff, "%.40s: %p", t, lua_touserdata(L, 1));
|
||||
sprintf(buff, l_s("%.40s: %p"), t, lua_touserdata(L, 1));
|
||||
break;
|
||||
}
|
||||
case LUA_TNIL:
|
||||
lua_pushliteral(L, "nil");
|
||||
lua_pushliteral(L, l_s("nil"));
|
||||
return 1;
|
||||
default:
|
||||
luaL_argerror(L, 1, "value expected");
|
||||
luaL_argerror(L, 1, l_s("value expected"));
|
||||
}
|
||||
lua_pushstring(L, buff);
|
||||
return 1;
|
||||
@ -407,7 +407,7 @@ static int luaB_foreach (lua_State *L) {
|
||||
static int luaB_assert (lua_State *L) {
|
||||
luaL_checkany(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);
|
||||
return 1;
|
||||
}
|
||||
@ -429,7 +429,7 @@ static int luaB_tinsert (lua_State *L) {
|
||||
pos = n+1;
|
||||
else
|
||||
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_rawset(L, 1); /* t.n = n+1 */
|
||||
for (; n>=pos; n--) {
|
||||
@ -453,7 +453,7 @@ static int luaB_tremove (lua_State *L) {
|
||||
lua_rawgeti(L, 1, 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_rawset(L, 1); /* t.n = n-1 */
|
||||
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] */
|
||||
/* repeat ++i until a[i] >= P */
|
||||
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] */
|
||||
}
|
||||
/* repeat --j until a[j] <= P */
|
||||
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] */
|
||||
}
|
||||
if (j<i) {
|
||||
@ -581,10 +581,10 @@ static int luaB_sort (lua_State *L) {
|
||||
#define num_deprecated 4
|
||||
|
||||
static const luaL_reg deprecated_names [num_deprecated] = {
|
||||
{"foreachvar", luaB_foreach},
|
||||
{"nextvar", luaB_next},
|
||||
{"rawgetglobal", luaB_rawget},
|
||||
{"rawsetglobal", luaB_rawset}
|
||||
{l_s("foreachvar"), luaB_foreach},
|
||||
{l_s("nextvar"), luaB_next},
|
||||
{l_s("rawgetglobal"), luaB_rawget},
|
||||
{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
|
||||
*/
|
||||
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 */
|
||||
}
|
||||
|
||||
@ -637,49 +637,49 @@ static void deprecated_funcs (lua_State *L) {
|
||||
/* }====================================================== */
|
||||
|
||||
static const luaL_reg base_funcs[] = {
|
||||
{LUA_ALERT, luaB__ALERT},
|
||||
{LUA_ERRORMESSAGE, luaB__ERRORMESSAGE},
|
||||
{"call", luaB_call},
|
||||
{"collectgarbage", luaB_collectgarbage},
|
||||
{"copytagmethods", luaB_copytagmethods},
|
||||
{"dofile", luaB_dofile},
|
||||
{"dostring", luaB_dostring},
|
||||
{"error", luaB_error},
|
||||
{"foreach", luaB_foreach},
|
||||
{"foreachi", luaB_foreachi},
|
||||
{"gcinfo", luaB_gcinfo},
|
||||
{"getglobal", luaB_getglobal},
|
||||
{"gettagmethod", luaB_gettagmethod},
|
||||
{"globals", luaB_globals},
|
||||
{"newtype", luaB_newtype},
|
||||
{"newtag", luaB_newtype}, /* for compatibility 4.0 */
|
||||
{"next", luaB_next},
|
||||
{"print", luaB_print},
|
||||
{"rawget", luaB_rawget},
|
||||
{"rawset", luaB_rawset},
|
||||
{"rawgettable", luaB_rawget}, /* for compatibility 3.2 */
|
||||
{"rawsettable", luaB_rawset}, /* for compatibility 3.2 */
|
||||
{"setglobal", luaB_setglobal},
|
||||
{"settag", luaB_settag},
|
||||
{"settagmethod", luaB_settagmethod},
|
||||
{"tag", luaB_tag},
|
||||
{"tonumber", luaB_tonumber},
|
||||
{"tostring", luaB_tostring},
|
||||
{"type", luaB_type},
|
||||
{"assert", luaB_assert},
|
||||
{"getn", luaB_getn},
|
||||
{"sort", luaB_sort},
|
||||
{"tinsert", luaB_tinsert},
|
||||
{"tremove", luaB_tremove},
|
||||
{"xtype", luaB_xtype},
|
||||
{l_s(LUA_ALERT), luaB__ALERT},
|
||||
{l_s(LUA_ERRORMESSAGE), luaB__ERRORMESSAGE},
|
||||
{l_s("call"), luaB_call},
|
||||
{l_s("collectgarbage"), luaB_collectgarbage},
|
||||
{l_s("copytagmethods"), luaB_copytagmethods},
|
||||
{l_s("dofile"), luaB_dofile},
|
||||
{l_s("dostring"), luaB_dostring},
|
||||
{l_s("error"), luaB_error},
|
||||
{l_s("foreach"), luaB_foreach},
|
||||
{l_s("foreachi"), luaB_foreachi},
|
||||
{l_s("gcinfo"), luaB_gcinfo},
|
||||
{l_s("getglobal"), luaB_getglobal},
|
||||
{l_s("gettagmethod"), luaB_gettagmethod},
|
||||
{l_s("globals"), luaB_globals},
|
||||
{l_s("newtype"), luaB_newtype},
|
||||
{l_s("newtag"), luaB_newtype}, /* for compatibility 4.0 */
|
||||
{l_s("next"), luaB_next},
|
||||
{l_s("print"), luaB_print},
|
||||
{l_s("rawget"), luaB_rawget},
|
||||
{l_s("rawset"), luaB_rawset},
|
||||
{l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */
|
||||
{l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */
|
||||
{l_s("setglobal"), luaB_setglobal},
|
||||
{l_s("settag"), luaB_settag},
|
||||
{l_s("settagmethod"), luaB_settagmethod},
|
||||
{l_s("tag"), luaB_tag},
|
||||
{l_s("tonumber"), luaB_tonumber},
|
||||
{l_s("tostring"), luaB_tostring},
|
||||
{l_s("type"), luaB_type},
|
||||
{l_s("assert"), luaB_assert},
|
||||
{l_s("getn"), luaB_getn},
|
||||
{l_s("sort"), luaB_sort},
|
||||
{l_s("tinsert"), luaB_tinsert},
|
||||
{l_s("tremove"), luaB_tremove},
|
||||
{l_s("xtype"), luaB_xtype},
|
||||
};
|
||||
|
||||
|
||||
|
||||
LUALIB_API void lua_baselibopen (lua_State *L) {
|
||||
luaL_openl(L, base_funcs);
|
||||
lua_pushliteral(L, LUA_VERSION);
|
||||
lua_setglobal(L, "_VERSION");
|
||||
lua_pushliteral(L, l_s(LUA_VERSION));
|
||||
lua_setglobal(L, l_s("_VERSION"));
|
||||
deprecated_funcs(L);
|
||||
}
|
||||
|
||||
|
16
lcode.c
16
lcode.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -18,7 +18,7 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ static void luaK_fixjump (FuncState *fs, int pc, int dest) {
|
||||
else { /* jump is relative to position following jump instruction */
|
||||
int offset = dest-(pc+1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ void luaK_deltastack (FuncState *fs, int delta) {
|
||||
fs->stacklevel += delta;
|
||||
if (fs->stacklevel > fs->f->maxstacksize) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ static int number_constant (FuncState *fs, lua_Number r) {
|
||||
if (f->knum[c] == r) return c;
|
||||
/* not found; create a new entry */
|
||||
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++;
|
||||
f->knum[c] = r;
|
||||
return c;
|
||||
@ -436,11 +436,11 @@ static void codelineinfo (FuncState *fs) {
|
||||
if (ls->lastline > fs->lastline) {
|
||||
if (ls->lastline > fs->lastline+1) {
|
||||
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));
|
||||
}
|
||||
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;
|
||||
fs->lastline = ls->lastline;
|
||||
}
|
||||
@ -660,7 +660,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
|
||||
codelineinfo(fs);
|
||||
/* put new instruction in code array */
|
||||
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;
|
||||
return fs->pc++;
|
||||
}
|
||||
|
4
lcode.h
4
lcode.h
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -47,7 +47,7 @@ typedef struct 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_code1 (FuncState *fs, OpCode o, int arg1);
|
||||
int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2);
|
||||
|
64
ldblib.c
64
ldblib.c
@ -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
|
||||
** 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, v);
|
||||
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_pushnumber(L, v);
|
||||
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) {
|
||||
lua_Debug ar;
|
||||
const char *options = luaL_opt_string(L, 2, "flnSu");
|
||||
char buff[20];
|
||||
const l_char *options = luaL_opt_string(L, 2, l_s("flnSu"));
|
||||
l_char buff[20];
|
||||
if (lua_isnumber(L, 1)) {
|
||||
if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) {
|
||||
lua_pushnil(L); /* level out of range */
|
||||
@ -43,35 +43,35 @@ static int getinfo (lua_State *L) {
|
||||
}
|
||||
else if (lua_isfunction(L, 1)) {
|
||||
lua_pushvalue(L, 1);
|
||||
sprintf(buff, ">%.10s", options);
|
||||
sprintf(buff, l_s(">%.10s"), options);
|
||||
options = buff;
|
||||
}
|
||||
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))
|
||||
luaL_argerror(L, 2, "invalid option");
|
||||
luaL_argerror(L, 2, l_s("invalid option"));
|
||||
lua_newtable(L);
|
||||
for (; *options; options++) {
|
||||
switch (*options) {
|
||||
case 'S':
|
||||
settabss(L, "source", ar.source);
|
||||
case l_c('S'):
|
||||
settabss(L, l_s("source"), ar.source);
|
||||
if (ar.source)
|
||||
settabss(L, "short_src", ar.short_src);
|
||||
settabsi(L, "linedefined", ar.linedefined);
|
||||
settabss(L, "what", ar.what);
|
||||
settabss(L, l_s("short_src"), ar.short_src);
|
||||
settabsi(L, l_s("linedefined"), ar.linedefined);
|
||||
settabss(L, l_s("what"), ar.what);
|
||||
break;
|
||||
case 'l':
|
||||
settabsi(L, "currentline", ar.currentline);
|
||||
case l_c('l'):
|
||||
settabsi(L, l_s("currentline"), ar.currentline);
|
||||
break;
|
||||
case 'u':
|
||||
settabsi(L, "nups", ar.nups);
|
||||
case l_c('u'):
|
||||
settabsi(L, l_s("nups"), ar.nups);
|
||||
break;
|
||||
case 'n':
|
||||
settabss(L, "name", ar.name);
|
||||
settabss(L, "namewhat", ar.namewhat);
|
||||
case l_c('n'):
|
||||
settabss(L, l_s("name"), ar.name);
|
||||
settabss(L, l_s("namewhat"), ar.namewhat);
|
||||
break;
|
||||
case 'f':
|
||||
lua_pushliteral(L, "func");
|
||||
case l_c('f'):
|
||||
lua_pushliteral(L, l_s("func"));
|
||||
lua_pushvalue(L, -3);
|
||||
lua_settable(L, -3);
|
||||
break;
|
||||
@ -83,9 +83,9 @@ static int getinfo (lua_State *L) {
|
||||
|
||||
static int getlocal (lua_State *L) {
|
||||
lua_Debug ar;
|
||||
const char *name;
|
||||
const l_char *name;
|
||||
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));
|
||||
if (name) {
|
||||
lua_pushstring(L, name);
|
||||
@ -102,7 +102,7 @@ static int getlocal (lua_State *L) {
|
||||
static int setlocal (lua_State *L) {
|
||||
lua_Debug ar;
|
||||
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);
|
||||
lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2)));
|
||||
return 1;
|
||||
@ -111,7 +111,7 @@ static int setlocal (lua_State *L) {
|
||||
|
||||
|
||||
/* 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_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))
|
||||
(*sethookf)(L, hook);
|
||||
else
|
||||
luaL_argerror(L, 1, "function expected");
|
||||
luaL_argerror(L, 1, l_s("function expected"));
|
||||
lua_getregistry(L);
|
||||
lua_pushuserdata(L, key);
|
||||
lua_pushvalue(L, -1); /* dup key */
|
||||
@ -174,11 +174,11 @@ static int setlinehook (lua_State *L) {
|
||||
|
||||
|
||||
static const luaL_reg dblib[] = {
|
||||
{"getlocal", getlocal},
|
||||
{"getinfo", getinfo},
|
||||
{"setcallhook", setcallhook},
|
||||
{"setlinehook", setlinehook},
|
||||
{"setlocal", setlocal}
|
||||
{l_s("getlocal"), getlocal},
|
||||
{l_s("getinfo"), getinfo},
|
||||
{l_s("setcallhook"), setcallhook},
|
||||
{l_s("setlinehook"), setlinehook},
|
||||
{l_s("setlocal"), setlocal}
|
||||
};
|
||||
|
||||
|
||||
|
80
ldebug.c
80
ldebug.c
@ -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
|
||||
** 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) {
|
||||
@ -158,8 +158,8 @@ static Proto *getluaproto (StkId f) {
|
||||
}
|
||||
|
||||
|
||||
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
const char *name;
|
||||
LUA_API const l_char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
const l_char *name;
|
||||
StkId f;
|
||||
Proto *fp;
|
||||
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) {
|
||||
const char *name;
|
||||
LUA_API const l_char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
const l_char *name;
|
||||
StkId f;
|
||||
Proto *fp;
|
||||
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 */
|
||||
if (fp) { /* `f' is a Lua function? */
|
||||
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;
|
||||
else
|
||||
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) {
|
||||
ar->source = getstr(f->source);
|
||||
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;
|
||||
break;
|
||||
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) {
|
||||
ar->source = "=C";
|
||||
ar->source = l_s("=C");
|
||||
ar->linedefined = -1;
|
||||
ar->what = "C";
|
||||
ar->what = l_s("C");
|
||||
}
|
||||
else
|
||||
infoLproto(ar, cl->f.l);
|
||||
luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src));
|
||||
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) {
|
||||
int 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;
|
||||
int 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);
|
||||
/* try to find a name for given function */
|
||||
if ((ar->name = travglobals(L, &o)) != NULL)
|
||||
ar->namewhat = "global";
|
||||
ar->namewhat = l_s("global");
|
||||
/* not found: try tag methods */
|
||||
else if ((ar->name = travtagmethods(G(L), &o)) != NULL)
|
||||
ar->namewhat = "tag-method";
|
||||
else ar->namewhat = ""; /* not found at all */
|
||||
ar->namewhat = l_s("tag-method");
|
||||
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;
|
||||
int isactive;
|
||||
int status = 1;
|
||||
LUA_LOCK(L);
|
||||
isactive = (*what != '>');
|
||||
isactive = (*what != l_c('>'));
|
||||
if (isactive)
|
||||
func = ar->_func;
|
||||
else {
|
||||
@ -282,25 +282,25 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
|
||||
}
|
||||
for (; *what; what++) {
|
||||
switch (*what) {
|
||||
case 'S': {
|
||||
case l_c('S'): {
|
||||
funcinfo(L, ar, func);
|
||||
break;
|
||||
}
|
||||
case 'l': {
|
||||
case l_c('l'): {
|
||||
ar->currentline = currentline(func);
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
case l_c('u'): {
|
||||
ar->nups = nups(func);
|
||||
break;
|
||||
}
|
||||
case 'n': {
|
||||
case l_c('n'): {
|
||||
ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL;
|
||||
if (ar->namewhat == NULL)
|
||||
getname(L, func, ar);
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
case l_c('f'): {
|
||||
setnormalized(L->top, func);
|
||||
incr_top; /* push function */
|
||||
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);
|
||||
if (!isLmark(func))
|
||||
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)) {
|
||||
case OP_GETGLOBAL: {
|
||||
*name = getstr(p->kstr[GETARG_U(i)]);
|
||||
return "global";
|
||||
return l_s("global");
|
||||
}
|
||||
case OP_GETLOCAL: {
|
||||
*name = luaF_getlocalname(p, GETARG_U(i)+1, pc);
|
||||
lua_assert(*name);
|
||||
return "local";
|
||||
return l_s("local");
|
||||
}
|
||||
case OP_PUSHSELF:
|
||||
case OP_GETDOTTED: {
|
||||
*name = getstr(p->kstr[GETARG_U(i)]);
|
||||
return "field";
|
||||
return l_s("field");
|
||||
}
|
||||
default:
|
||||
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 */
|
||||
if (!isLmark(func))
|
||||
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) {
|
||||
const char *name;
|
||||
const char *kind = getobjname(L, o, &name);
|
||||
const char *t = luaT_typename(G(L), o);
|
||||
void luaG_typeerror (lua_State *L, StkId o, const l_char *op) {
|
||||
const l_char *name;
|
||||
const l_char *kind = getobjname(L, o, &name);
|
||||
const l_char *t = luaT_typename(G(L), o);
|
||||
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);
|
||||
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++;
|
||||
lua_assert(ttype(p1) != t);
|
||||
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) {
|
||||
const char *t1 = luaT_typename(G(L), p1);
|
||||
const char *t2 = luaT_typename(G(L), p2);
|
||||
const l_char *t1 = luaT_typename(G(L), p1);
|
||||
const l_char *t2 = luaT_typename(G(L), p2);
|
||||
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
|
||||
luaO_verror(L, "attempt to compare %.10s with %.10s", t1, t2);
|
||||
luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2);
|
||||
}
|
||||
|
||||
|
6
ldebug.h
6
ldebug.h
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -12,8 +12,8 @@
|
||||
#include "luadebug.h"
|
||||
|
||||
|
||||
void luaG_typeerror (lua_State *L, StkId o, const char *op);
|
||||
void luaG_binerror (lua_State *L, StkId p1, int t, 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 l_char *op);
|
||||
int luaG_getline (int *lineinfo, int pc, int refline, int *refi);
|
||||
void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2);
|
||||
int luaG_checkcode (lua_State *L, const Proto *pt);
|
||||
|
44
ldo.c
44
ldo.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -56,7 +56,7 @@ void luaD_checkstack (lua_State *L, int n) {
|
||||
else {
|
||||
L->stack_last += EXTRA_STACK; /* to be used by error message */
|
||||
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) {
|
||||
lua_Debug ar;
|
||||
ar._func = func;
|
||||
ar.event = "line";
|
||||
ar.event = l_s("line");
|
||||
ar.currentline = line;
|
||||
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,
|
||||
const char *event) {
|
||||
const l_char *event) {
|
||||
if (L->allowhooks) {
|
||||
lua_Debug ar;
|
||||
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 */
|
||||
Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION);
|
||||
if (tm == NULL)
|
||||
luaG_typeerror(L, func, "call");
|
||||
luaG_typeerror(L, func, l_s("call"));
|
||||
luaD_openstack(L, func);
|
||||
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);
|
||||
callhook = L->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) :
|
||||
luaV_execute(L, cl, func+1));
|
||||
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);
|
||||
setnilvalue(func); /* remove callinfo from the stack */
|
||||
/* 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;
|
||||
int status;
|
||||
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 */
|
||||
bin = (ungetc(fgetc(f), f) == ID_CHUNK);
|
||||
if (bin && f != stdin) {
|
||||
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 */
|
||||
}
|
||||
lua_pushliteral(L, "@");
|
||||
lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename);
|
||||
lua_pushliteral(L, l_s("@"));
|
||||
lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename);
|
||||
lua_concat(L, 2);
|
||||
filename = lua_tostring(L, -1); /* filename = `@'..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;
|
||||
status = parse_file(L, filename);
|
||||
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,
|
||||
const char *name) {
|
||||
static int parse_buffer (lua_State *L, const l_char *buff, size_t size,
|
||||
const l_char *name) {
|
||||
ZIO z;
|
||||
int status;
|
||||
if (!name) name = "?";
|
||||
if (!name) name = l_s("?");
|
||||
luaZ_mopen(&z, buff, size, name);
|
||||
status = protectedparser(L, &z, buff[0]==ID_CHUNK);
|
||||
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;
|
||||
status = parse_buffer(L, buff, size, name);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -334,8 +334,8 @@ struct lua_longjmp {
|
||||
};
|
||||
|
||||
|
||||
static void message (lua_State *L, const char *s) {
|
||||
luaV_getglobal(L, luaS_newliteral(L, LUA_ERRORMESSAGE), L->top);
|
||||
static void message (lua_State *L, const l_char *s) {
|
||||
luaV_getglobal(L, luaS_newliteral(L, l_s(LUA_ERRORMESSAGE)), L->top);
|
||||
if (ttype(L->top) == LUA_TFUNCTION) {
|
||||
incr_top;
|
||||
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
|
||||
*/
|
||||
void luaD_error (lua_State *L, const char *s) {
|
||||
void luaD_error (lua_State *L, const l_char *s) {
|
||||
if (s) message(L, s);
|
||||
luaD_breakrun(L, LUA_ERRRUN);
|
||||
}
|
||||
@ -361,7 +361,7 @@ void luaD_breakrun (lua_State *L, int errcode) {
|
||||
}
|
||||
else {
|
||||
if (errcode != LUA_ERRMEM)
|
||||
message(L, "unable to recover; exiting\n");
|
||||
message(L, l_s("unable to recover; exiting\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
4
ldo.h
4
ldo.h
@ -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
|
||||
** 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_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);
|
||||
int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud);
|
||||
|
||||
|
4
lfunc.c
4
lfunc.c
@ -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
|
||||
** 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'.
|
||||
** 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;
|
||||
for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
|
||||
if (pc < f->locvars[i].endpc) { /* is variable active? */
|
||||
|
4
lfunc.h
4
lfunc.h
@ -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
|
||||
** 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_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
|
||||
|
4
lgc.c
4
lgc.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -331,7 +331,7 @@ static void collectudata (lua_State *L, int all) {
|
||||
static void checkMbuffer (lua_State *L) {
|
||||
if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
252
liolib.c
252
liolib.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -47,10 +47,10 @@ int pclose(); */
|
||||
#define OUTFILE 1
|
||||
#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) {
|
||||
@ -81,10 +81,10 @@ static FILE *getopthandle (lua_State *L, int inout) {
|
||||
FILE *p = (FILE *)lua_touserdata(L, 1);
|
||||
if (p != NULL) { /* is it a userdata ? */
|
||||
if (!checkfile(L, 1)) {
|
||||
if (strcmp(lua_xtype(L, 1), "ClosedFileHandle") == 0)
|
||||
luaL_argerror(L, 1, "file is closed");
|
||||
if (strcmp(lua_xtype(L, 1), l_s("ClosedFileHandle")) == 0)
|
||||
luaL_argerror(L, 1, l_s("file is closed"));
|
||||
else
|
||||
luaL_argerror(L, 1, "(invalid value)");
|
||||
luaL_argerror(L, 1, l_s("(invalid value)"));
|
||||
}
|
||||
/* move it to stack top */
|
||||
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 */
|
||||
lua_getglobal(L, filenames[inout]);
|
||||
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]);
|
||||
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);
|
||||
lua_setglobal(L, name);
|
||||
}
|
||||
@ -131,7 +131,7 @@ static int closefile (lua_State *L, FILE *f) {
|
||||
return 1;
|
||||
else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
if (lua_isnull(L, 1)) {
|
||||
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 */
|
||||
current = (FILE *)lua_touserdata(L, 1);
|
||||
else {
|
||||
const char *s = luaL_check_string(L, 1);
|
||||
current = (*s == '|') ? popen(s+1, mode) : fopen(s, mode);
|
||||
const l_char *s = luaL_check_string(L, 1);
|
||||
current = (*s == l_c('|')) ? popen(s+1, mode) : fopen(s, mode);
|
||||
}
|
||||
return setreturn(L, current, inout);
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
return io_fromto(L, OUTFILE, "w");
|
||||
return io_fromto(L, OUTFILE, l_s("w"));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ static int io_appendto (lua_State *L) {
|
||||
|
||||
static int read_number (lua_State *L, FILE *f) {
|
||||
double d;
|
||||
if (fscanf(f, "%lf", &d) == 1) {
|
||||
if (fscanf(f, l_s("%lf"), &d) == 1) {
|
||||
lua_pushnumber(L, d);
|
||||
return 1;
|
||||
}
|
||||
@ -233,11 +233,11 @@ static int read_line (lua_State *L, FILE *f) {
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
for (;;) {
|
||||
char *p = luaL_prepbuffer(&b);
|
||||
l_char *p = luaL_prepbuffer(&b);
|
||||
if (!fgets(p, LUAL_BUFFERSIZE, f)) /* read fails? */
|
||||
break;
|
||||
n = strlen(p);
|
||||
if (p[n-1] != '\n')
|
||||
if (p[n-1] != l_c('\n'))
|
||||
luaL_addsize(&b, n);
|
||||
else {
|
||||
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 size = LUAL_BUFFERSIZE;
|
||||
size_t oldsize = 0;
|
||||
char *buffer = NULL;
|
||||
l_char *buffer = NULL;
|
||||
for (;;) {
|
||||
char *newbuffer = (char *)l_realloc(buffer, oldsize, size);
|
||||
l_char *newbuffer = (l_char *)l_realloc(buffer, oldsize, size);
|
||||
if (newbuffer == NULL) {
|
||||
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;
|
||||
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 */
|
||||
oldsize = size;
|
||||
size *= 2;
|
||||
@ -279,17 +279,17 @@ static int read_chars (lua_State *L, FILE *f, size_t n) {
|
||||
return (c != EOF);
|
||||
}
|
||||
else {
|
||||
char *buffer;
|
||||
l_char *buffer;
|
||||
size_t n1;
|
||||
char statbuff[LUAL_BUFFERSIZE];
|
||||
l_char statbuff[LUAL_BUFFERSIZE];
|
||||
if (n <= LUAL_BUFFERSIZE)
|
||||
buffer = statbuff;
|
||||
else {
|
||||
buffer = (char *)l_malloc(n);
|
||||
buffer = (l_char *)l_malloc(n);
|
||||
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);
|
||||
if (buffer != statbuff) l_free(buffer, n);
|
||||
return (n1 > 0 || n == 0);
|
||||
@ -307,31 +307,31 @@ static int io_read (lua_State *L) {
|
||||
n = 2; /* will return n-1 results */
|
||||
}
|
||||
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;
|
||||
for (n = 1; n<=nargs && success; n++) {
|
||||
if (lua_type(L, n) == LUA_TNUMBER)
|
||||
success = read_chars(L, f, (size_t)lua_tonumber(L, n));
|
||||
else {
|
||||
const char *p = lua_tostring(L, n);
|
||||
if (!p || p[0] != '*')
|
||||
lua_error(L, "invalid `read' option");
|
||||
const l_char *p = lua_tostring(L, n);
|
||||
if (!p || p[0] != l_c('*'))
|
||||
lua_error(L, l_s("invalid `read' option"));
|
||||
switch (p[1]) {
|
||||
case 'n': /* number */
|
||||
case l_c('n'): /* number */
|
||||
success = read_number(L, f);
|
||||
break;
|
||||
case 'l': /* line */
|
||||
case l_c('l'): /* line */
|
||||
success = read_line(L, f);
|
||||
break;
|
||||
case 'a': /* file */
|
||||
case l_c('a'): /* file */
|
||||
read_file(L, f);
|
||||
success = 1; /* always success */
|
||||
break;
|
||||
case 'w': /* word */
|
||||
case l_c('w'): /* word */
|
||||
success = read_word(L, f);
|
||||
break;
|
||||
default:
|
||||
luaL_argerror(L, n, "invalid format");
|
||||
luaL_argerror(L, n, l_s("invalid format"));
|
||||
success = 0; /* to avoid warnings */
|
||||
}
|
||||
}
|
||||
@ -355,12 +355,12 @@ static int io_write (lua_State *L) {
|
||||
for (arg=1; arg<=nargs; arg++) {
|
||||
if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */
|
||||
/* 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 {
|
||||
size_t l;
|
||||
const char *s = luaL_check_lstr(L, arg, &l);
|
||||
status = status && (fwrite(s, sizeof(char), l, f) == l);
|
||||
const l_char *s = luaL_check_lstr(L, arg, &l);
|
||||
status = status && (fwrite(s, sizeof(l_char), l, f) == l);
|
||||
}
|
||||
}
|
||||
pushresult(L, status);
|
||||
@ -370,11 +370,11 @@ static int io_write (lua_State *L) {
|
||||
|
||||
static int io_seek (lua_State *L) {
|
||||
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);
|
||||
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);
|
||||
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]);
|
||||
if (op)
|
||||
return pushresult(L, 0); /* error */
|
||||
@ -387,7 +387,7 @@ static int io_seek (lua_State *L) {
|
||||
|
||||
static int io_flush (lua_State *L) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -418,9 +418,9 @@ static int io_rename (lua_State *L) {
|
||||
|
||||
|
||||
static int io_tmpname (lua_State *L) {
|
||||
char buff[L_tmpnam];
|
||||
l_char buff[L_tmpnam];
|
||||
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);
|
||||
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_pushnumber(L, value);
|
||||
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;
|
||||
lua_pushstring(L, key);
|
||||
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);
|
||||
else {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
struct tm *stm;
|
||||
if (t == (time_t)-1) /* no time given? */
|
||||
t = time(NULL); /* use current time */
|
||||
if (*s == '!') { /* UTC? */
|
||||
if (*s == l_c('!')) { /* UTC? */
|
||||
stm = gmtime(&t);
|
||||
s++; /* skip `!' */
|
||||
}
|
||||
@ -484,24 +484,24 @@ static int io_date (lua_State *L) {
|
||||
stm = localtime(&t);
|
||||
if (stm == NULL) /* invalid date? */
|
||||
lua_pushnil(L);
|
||||
else if (strcmp(s, "*t") == 0) {
|
||||
else if (strcmp(s, l_s("*t")) == 0) {
|
||||
lua_newtable(L);
|
||||
setfield(L, "sec", stm->tm_sec);
|
||||
setfield(L, "min", stm->tm_min);
|
||||
setfield(L, "hour", stm->tm_hour);
|
||||
setfield(L, "day", stm->tm_mday);
|
||||
setfield(L, "month", stm->tm_mon+1);
|
||||
setfield(L, "year", stm->tm_year+1900);
|
||||
setfield(L, "wday", stm->tm_wday+1);
|
||||
setfield(L, "yday", stm->tm_yday+1);
|
||||
setfield(L, "isdst", stm->tm_isdst);
|
||||
setfield(L, l_s("sec"), stm->tm_sec);
|
||||
setfield(L, l_s("min"), stm->tm_min);
|
||||
setfield(L, l_s("hour"), stm->tm_hour);
|
||||
setfield(L, l_s("day"), stm->tm_mday);
|
||||
setfield(L, l_s("month"), stm->tm_mon+1);
|
||||
setfield(L, l_s("year"), stm->tm_year+1900);
|
||||
setfield(L, l_s("wday"), stm->tm_wday+1);
|
||||
setfield(L, l_s("yday"), stm->tm_yday+1);
|
||||
setfield(L, l_s("isdst"), stm->tm_isdst);
|
||||
}
|
||||
else {
|
||||
char b[256];
|
||||
l_char b[256];
|
||||
if (strftime(b, sizeof(b), s, stm))
|
||||
lua_pushstring(L, b);
|
||||
else
|
||||
lua_error(L, "invalid `date' format");
|
||||
lua_error(L, l_s("invalid `date' format"));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -515,13 +515,13 @@ static int io_time (lua_State *L) {
|
||||
struct tm ts;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
lua_settop(L, 1); /* make sure table is at the top */
|
||||
ts.tm_sec = getfield(L, "sec", 0);
|
||||
ts.tm_min = getfield(L, "min", 0);
|
||||
ts.tm_hour = getfield(L, "hour", 12);
|
||||
ts.tm_mday = getfield(L, "day", -2);
|
||||
ts.tm_mon = getfield(L, "month", -2)-1;
|
||||
ts.tm_year = getfield(L, "year", -2)-1900;
|
||||
ts.tm_isdst = getfield(L, "isdst", -1);
|
||||
ts.tm_sec = getfield(L, l_s("sec"), 0);
|
||||
ts.tm_min = getfield(L, l_s("min"), 0);
|
||||
ts.tm_hour = getfield(L, l_s("hour"), 12);
|
||||
ts.tm_mday = getfield(L, l_s("day"), -2);
|
||||
ts.tm_mon = getfield(L, l_s("month"), -2)-1;
|
||||
ts.tm_year = getfield(L, l_s("year"), -2)-1900;
|
||||
ts.tm_isdst = getfield(L, l_s("isdst"), -1);
|
||||
t = mktime(&ts);
|
||||
if (t == (time_t)-1)
|
||||
lua_pushnil(L);
|
||||
@ -544,10 +544,10 @@ static int io_difftime (lua_State *L) {
|
||||
static int io_setloc (lua_State *L) {
|
||||
static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
|
||||
LC_NUMERIC, LC_TIME};
|
||||
static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
|
||||
"numeric", "time", NULL};
|
||||
int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames);
|
||||
luaL_arg_check(L, op != -1, 2, "invalid option");
|
||||
static const l_char *const catnames[] = {l_s("all"), l_s("collate"), l_s("ctype"), l_s("monetary"),
|
||||
l_s("numeric"), l_s("time"), NULL};
|
||||
int op = luaL_findstring(luaL_opt_string(L, 2, l_s("all")), catnames);
|
||||
luaL_arg_check(L, op != -1, 2, l_s("invalid option"));
|
||||
lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
@ -564,10 +564,10 @@ static int io_exit (lua_State *L) {
|
||||
|
||||
static int io_debug (lua_State *L) {
|
||||
for (;;) {
|
||||
char buffer[250];
|
||||
fprintf(stderr, "lua_debug> ");
|
||||
l_char buffer[250];
|
||||
fprintf(stderr, l_s("lua_debug> "));
|
||||
if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
|
||||
strcmp(buffer, "cont\n") == 0)
|
||||
strcmp(buffer, l_s("cont\n")) == 0)
|
||||
return 0;
|
||||
lua_dostring(L, buffer);
|
||||
lua_settop(L, 0); /* remove eventual returns */
|
||||
@ -584,61 +584,61 @@ static int errorfb (lua_State *L) {
|
||||
lua_Debug ar;
|
||||
luaL_Buffer 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, "\n");
|
||||
luaL_addstring(&b, l_s("\n"));
|
||||
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)
|
||||
luaL_addstring(&b, "stack traceback:\n");
|
||||
luaL_addstring(&b, l_s("stack traceback:\n"));
|
||||
else if (level > LEVELS1 && firstpart) {
|
||||
/* no more than `LEVELS2' more levels? */
|
||||
if (!lua_getstack(L, level+LEVELS2, &ar))
|
||||
level--; /* keep going */
|
||||
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 */
|
||||
level++;
|
||||
}
|
||||
firstpart = 0;
|
||||
continue;
|
||||
}
|
||||
sprintf(buff, "%4d: ", level-1);
|
||||
sprintf(buff, l_s("%4d: "), level-1);
|
||||
luaL_addstring(&b, buff);
|
||||
lua_getinfo(L, "Snl", &ar);
|
||||
lua_getinfo(L, l_s("Snl"), &ar);
|
||||
switch (*ar.namewhat) {
|
||||
case 'g': case 'l': /* global, local */
|
||||
sprintf(buff, "function `%.50s'", ar.name);
|
||||
case l_c('g'): case l_c('l'): /* global, local */
|
||||
sprintf(buff, l_s("function `%.50s'"), ar.name);
|
||||
break;
|
||||
case 'f': /* field */
|
||||
sprintf(buff, "method `%.50s'", ar.name);
|
||||
case l_c('f'): /* field */
|
||||
sprintf(buff, l_s("method `%.50s'"), ar.name);
|
||||
break;
|
||||
case 't': /* tag method */
|
||||
sprintf(buff, "`%.50s' tag method", ar.name);
|
||||
case l_c('t'): /* tag method */
|
||||
sprintf(buff, l_s("`%.50s' tag method"), ar.name);
|
||||
break;
|
||||
default: {
|
||||
if (*ar.what == 'm') /* main? */
|
||||
sprintf(buff, "main of %.70s", ar.short_src);
|
||||
else if (*ar.what == 'C') /* C function? */
|
||||
sprintf(buff, "%.70s", ar.short_src);
|
||||
if (*ar.what == l_c('m')) /* main? */
|
||||
sprintf(buff, l_s("main of %.70s"), ar.short_src);
|
||||
else if (*ar.what == l_c('C')) /* C function? */
|
||||
sprintf(buff, l_s("%.70s"), ar.short_src);
|
||||
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 */
|
||||
}
|
||||
}
|
||||
luaL_addstring(&b, buff);
|
||||
if (ar.currentline > 0) {
|
||||
sprintf(buff, " at line %d", ar.currentline);
|
||||
sprintf(buff, l_s(" at line %d"), ar.currentline);
|
||||
luaL_addstring(&b, buff);
|
||||
}
|
||||
if (ar.source) {
|
||||
sprintf(buff, " [%.70s]", ar.short_src);
|
||||
sprintf(buff, l_s(" [%.70s]"), ar.short_src);
|
||||
luaL_addstring(&b, buff);
|
||||
}
|
||||
luaL_addstring(&b, "\n");
|
||||
luaL_addstring(&b, l_s("\n"));
|
||||
}
|
||||
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 */
|
||||
lua_pushvalue(L, -2); /* error message */
|
||||
lua_rawcall(L, 1, 0);
|
||||
@ -649,44 +649,44 @@ static int errorfb (lua_State *L) {
|
||||
|
||||
|
||||
static const luaL_reg iolib[] = {
|
||||
{"appendto", io_appendto},
|
||||
{"clock", io_clock},
|
||||
{"closefile", io_close},
|
||||
{"date", io_date},
|
||||
{"debug", io_debug},
|
||||
{"difftime", io_difftime},
|
||||
{"execute", io_execute},
|
||||
{"exit", io_exit},
|
||||
{"flush", io_flush},
|
||||
{"getenv", io_getenv},
|
||||
{"openfile", io_open},
|
||||
{"read", io_read},
|
||||
{"readfrom", io_readfrom},
|
||||
{"remove", io_remove},
|
||||
{"rename", io_rename},
|
||||
{"seek", io_seek},
|
||||
{"setlocale", io_setloc},
|
||||
{"time", io_time},
|
||||
{"tmpfile", io_tmpfile},
|
||||
{"tmpname", io_tmpname},
|
||||
{"write", io_write},
|
||||
{"writeto", io_writeto},
|
||||
{LUA_ERRORMESSAGE, errorfb}
|
||||
{l_s("appendto"), io_appendto},
|
||||
{l_s("clock"), io_clock},
|
||||
{l_s("closefile"), io_close},
|
||||
{l_s("date"), io_date},
|
||||
{l_s("debug"), io_debug},
|
||||
{l_s("difftime"), io_difftime},
|
||||
{l_s("execute"), io_execute},
|
||||
{l_s("exit"), io_exit},
|
||||
{l_s("flush"), io_flush},
|
||||
{l_s("getenv"), io_getenv},
|
||||
{l_s("openfile"), io_open},
|
||||
{l_s("read"), io_read},
|
||||
{l_s("readfrom"), io_readfrom},
|
||||
{l_s("remove"), io_remove},
|
||||
{l_s("rename"), io_rename},
|
||||
{l_s("seek"), io_seek},
|
||||
{l_s("setlocale"), io_setloc},
|
||||
{l_s("time"), io_time},
|
||||
{l_s("tmpfile"), io_tmpfile},
|
||||
{l_s("tmpname"), io_tmpname},
|
||||
{l_s("write"), io_write},
|
||||
{l_s("writeto"), io_writeto},
|
||||
{l_s(LUA_ERRORMESSAGE), errorfb}
|
||||
};
|
||||
|
||||
|
||||
LUALIB_API void lua_iolibopen (lua_State *L) {
|
||||
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);
|
||||
/* predefined file handles */
|
||||
setfile(L, stdin, INFILE);
|
||||
setfile(L, stdout, OUTFILE);
|
||||
setfilebyname(L, stdin, "_STDIN");
|
||||
setfilebyname(L, stdout, "_STDOUT");
|
||||
setfilebyname(L, stderr, "_STDERR");
|
||||
setfilebyname(L, stdin, l_s("_STDIN"));
|
||||
setfilebyname(L, stdout, l_s("_STDOUT"));
|
||||
setfilebyname(L, stderr, l_s("_STDERR"));
|
||||
/* close files when collected */
|
||||
lua_pushcfunction(L, file_collect);
|
||||
lua_settagmethod(L, iotag, "gc");
|
||||
lua_settagmethod(L, iotag, l_s("gc"));
|
||||
}
|
||||
|
||||
|
230
llex.c
230
llex.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -25,10 +25,13 @@
|
||||
|
||||
|
||||
/* ORDER RESERVED */
|
||||
static const char *const token2string [] = {
|
||||
"and", "break", "do", "else", "elseif", "end", "for",
|
||||
"function", "if", "local", "nil", "not", "or", "repeat", "return", "then",
|
||||
"until", "while", "", "..", "...", "==", ">=", "<=", "~=", "", "", "<eof>"};
|
||||
static const l_char *const token2string [] = {
|
||||
l_s("and"), l_s("break"), l_s("do"), l_s("else"), l_s("elseif"),
|
||||
l_s("end"), l_s("for"), l_s("function"), l_s("if"), l_s("local"),
|
||||
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) {
|
||||
@ -44,37 +47,38 @@ void luaX_init (lua_State *L) {
|
||||
#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) {
|
||||
char buff[90];
|
||||
sprintf(buff, "too many %.40s (limit=%d)", msg, limit);
|
||||
l_char buff[90];
|
||||
sprintf(buff, l_s("too many %.40s (limit=%d)"), msg, limit);
|
||||
luaX_error(ls, buff, ls->t.token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
|
||||
char buff[MAXSRC];
|
||||
void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token) {
|
||||
l_char buff[MAXSRC];
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void luaX_error (LexState *ls, const char *s, int token) {
|
||||
char buff[TOKEN_LEN];
|
||||
void luaX_error (LexState *ls, const l_char *s, int token) {
|
||||
l_char buff[TOKEN_LEN];
|
||||
luaX_token2str(token, buff);
|
||||
if (buff[0] == '\0')
|
||||
if (buff[0] == l_c('\0'))
|
||||
luaX_syntaxerror(ls, s, G(ls->L)->Mbuffer);
|
||||
else
|
||||
luaX_syntaxerror(ls, s, buff);
|
||||
}
|
||||
|
||||
|
||||
void luaX_token2str (int token, char *s) {
|
||||
void luaX_token2str (int token, l_char *s) {
|
||||
if (token < 256) {
|
||||
s[0] = (char)token;
|
||||
s[1] = '\0';
|
||||
s[0] = (l_char)token;
|
||||
s[1] = l_c('\0');
|
||||
}
|
||||
else
|
||||
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) {
|
||||
char buff[8];
|
||||
sprintf(buff, "0x%02X", c);
|
||||
luaX_syntaxerror(ls, "invalid control char", buff);
|
||||
l_char buff[8];
|
||||
sprintf(buff, l_s("0x%02X"), c);
|
||||
luaX_syntaxerror(ls, l_s("invalid control l_char"), buff);
|
||||
}
|
||||
|
||||
|
||||
static void inclinenumber (LexState *LS) {
|
||||
next(LS); /* skip `\n' */
|
||||
++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->source = source;
|
||||
next(LS); /* read first char */
|
||||
if (LS->current == '#') {
|
||||
if (LS->current == l_c('#')) {
|
||||
do { /* skip first line */
|
||||
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) \
|
||||
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))
|
||||
|
||||
|
||||
@ -137,8 +141,8 @@ static size_t readname (LexState *LS) {
|
||||
do {
|
||||
checkbuffer(L, 10, l);
|
||||
save_and_next(L, LS, l);
|
||||
} while (isalnum(LS->current) || LS->current == '_');
|
||||
save(L, '\0', l);
|
||||
} while (isalnum(LS->current) || LS->current == l_c('_'));
|
||||
save(L, l_c('\0'), l);
|
||||
return l-1;
|
||||
}
|
||||
|
||||
@ -148,36 +152,37 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) {
|
||||
lua_State *L = LS->L;
|
||||
size_t l = 0;
|
||||
checkbuffer(L, 10, l);
|
||||
if (comma) save(L, '.', l);
|
||||
if (comma) save(L, l_c('.'), l);
|
||||
while (isdigit(LS->current)) {
|
||||
checkbuffer(L, 10, l);
|
||||
save_and_next(L, LS, l);
|
||||
}
|
||||
if (LS->current == '.') {
|
||||
if (LS->current == l_c('.')) {
|
||||
save_and_next(L, LS, l);
|
||||
if (LS->current == '.') {
|
||||
if (LS->current == l_c('.')) {
|
||||
save_and_next(L, LS, l);
|
||||
save(L, '\0', l);
|
||||
luaX_error(LS, "ambiguous syntax"
|
||||
" (decimal point x string concatenation)", TK_NUMBER);
|
||||
save(L, l_c('\0'), l);
|
||||
luaX_error(LS,
|
||||
l_s("ambiguous syntax (decimal point x string concatenation)"),
|
||||
TK_NUMBER);
|
||||
}
|
||||
}
|
||||
while (isdigit(LS->current)) {
|
||||
checkbuffer(L, 10, 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' */
|
||||
if (LS->current == '+' || LS->current == '-')
|
||||
if (LS->current == l_c('+') || LS->current == l_c('-'))
|
||||
save_and_next(L, LS, l); /* optional exponent sign */
|
||||
while (isdigit(LS->current)) {
|
||||
checkbuffer(L, 10, 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))
|
||||
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;
|
||||
size_t l = 0;
|
||||
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 `[' */
|
||||
for (;;) {
|
||||
checkbuffer(L, 10, l);
|
||||
switch (LS->current) {
|
||||
case EOZ:
|
||||
save(L, '\0', l);
|
||||
luaX_error(LS, "unfinished long string", TK_STRING);
|
||||
save(L, l_c('\0'), l);
|
||||
luaX_error(LS, l_s("unfinished long string"), TK_STRING);
|
||||
break; /* to avoid warnings */
|
||||
case '[':
|
||||
case l_c('['):
|
||||
save_and_next(L, LS, l);
|
||||
if (LS->current == '[') {
|
||||
if (LS->current == l_c('[')) {
|
||||
cont++;
|
||||
save_and_next(L, LS, l);
|
||||
}
|
||||
continue;
|
||||
case ']':
|
||||
case l_c(']'):
|
||||
save_and_next(L, LS, l);
|
||||
if (LS->current == ']') {
|
||||
if (LS->current == l_c(']')) {
|
||||
if (cont == 0) goto endloop;
|
||||
cont--;
|
||||
save_and_next(L, LS, l);
|
||||
}
|
||||
continue;
|
||||
case '\n':
|
||||
save(L, '\n', l);
|
||||
case l_c('\n'):
|
||||
save(L, l_c('\n'), l);
|
||||
inclinenumber(LS);
|
||||
continue;
|
||||
default:
|
||||
@ -219,7 +224,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) {
|
||||
}
|
||||
} endloop:
|
||||
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);
|
||||
}
|
||||
|
||||
@ -232,38 +237,38 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
|
||||
while (LS->current != del) {
|
||||
checkbuffer(L, 10, l);
|
||||
switch (LS->current) {
|
||||
case EOZ: case '\n':
|
||||
save(L, '\0', l);
|
||||
luaX_error(LS, "unfinished string", TK_STRING);
|
||||
case EOZ: case l_c('\n'):
|
||||
save(L, l_c('\0'), l);
|
||||
luaX_error(LS, l_s("unfinished string"), TK_STRING);
|
||||
break; /* to avoid warnings */
|
||||
case '\\':
|
||||
case l_c('\\'):
|
||||
next(LS); /* do not save the `\' */
|
||||
switch (LS->current) {
|
||||
case 'a': save(L, '\a', l); next(LS); break;
|
||||
case 'b': save(L, '\b', l); next(LS); break;
|
||||
case 'f': save(L, '\f', l); next(LS); break;
|
||||
case 'n': save(L, '\n', l); next(LS); break;
|
||||
case 'r': save(L, '\r', l); next(LS); break;
|
||||
case 't': save(L, '\t', l); next(LS); break;
|
||||
case 'v': save(L, '\v', l); next(LS); break;
|
||||
case '\n': save(L, '\n', l); inclinenumber(LS); break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9': {
|
||||
int c = 0;
|
||||
int i = 0;
|
||||
do {
|
||||
c = 10*c + (LS->current-'0');
|
||||
next(LS);
|
||||
} while (++i<3 && isdigit(LS->current));
|
||||
if (c > UCHAR_MAX) {
|
||||
save(L, '\0', l);
|
||||
luaX_error(LS, "escape sequence too large", TK_STRING);
|
||||
case l_c('a'): save(L, l_c('\a'), l); next(LS); break;
|
||||
case l_c('b'): save(L, l_c('\b'), l); next(LS); break;
|
||||
case l_c('f'): save(L, l_c('\f'), l); next(LS); break;
|
||||
case l_c('n'): save(L, l_c('\n'), l); next(LS); break;
|
||||
case l_c('r'): save(L, l_c('\r'), l); next(LS); break;
|
||||
case l_c('t'): save(L, l_c('\t'), l); next(LS); break;
|
||||
case l_c('v'): save(L, l_c('\v'), l); next(LS); break;
|
||||
case l_c('\n'): save(L, l_c('\n'), l); inclinenumber(LS); break;
|
||||
default: {
|
||||
if (!isdigit(LS->current))
|
||||
save_and_next(L, LS, l); /* handles \\, \", \', and \? */
|
||||
else { /* \xxx */
|
||||
int c = 0;
|
||||
int i = 0;
|
||||
do {
|
||||
c = 10*c + (LS->current-l_c('0'));
|
||||
next(LS);
|
||||
} while (++i<3 && isdigit(LS->current));
|
||||
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;
|
||||
default:
|
||||
@ -271,7 +276,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@ -280,92 +285,85 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
|
||||
for (;;) {
|
||||
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);
|
||||
continue;
|
||||
|
||||
case '\n':
|
||||
case l_c('\n'):
|
||||
inclinenumber(LS);
|
||||
continue;
|
||||
|
||||
case '$':
|
||||
luaX_error(LS, "unexpected `$' (pragmas are no longer supported)", '$');
|
||||
case l_c('$'):
|
||||
luaX_error(LS,
|
||||
l_s("unexpected `$' (pragmas are no longer supported)"),
|
||||
LS->current);
|
||||
break;
|
||||
|
||||
case '-':
|
||||
case l_c('-'):
|
||||
next(LS);
|
||||
if (LS->current != '-') return '-';
|
||||
do { next(LS); } while (LS->current != '\n' && LS->current != EOZ);
|
||||
if (LS->current != l_c('-')) return l_c('-');
|
||||
do { next(LS); } while (LS->current != l_c('\n') && LS->current != EOZ);
|
||||
continue;
|
||||
|
||||
case '[':
|
||||
case l_c('['):
|
||||
next(LS);
|
||||
if (LS->current != '[') return '[';
|
||||
if (LS->current != l_c('[')) return l_c('[');
|
||||
else {
|
||||
read_long_string(LS, seminfo);
|
||||
return TK_STRING;
|
||||
}
|
||||
|
||||
case '=':
|
||||
case l_c('='):
|
||||
next(LS);
|
||||
if (LS->current != '=') return '=';
|
||||
if (LS->current != l_c('=')) return l_c('=');
|
||||
else { next(LS); return TK_EQ; }
|
||||
|
||||
case '<':
|
||||
case l_c('<'):
|
||||
next(LS);
|
||||
if (LS->current != '=') return '<';
|
||||
if (LS->current != l_c('=')) return l_c('<');
|
||||
else { next(LS); return TK_LE; }
|
||||
|
||||
case '>':
|
||||
case l_c('>'):
|
||||
next(LS);
|
||||
if (LS->current != '=') return '>';
|
||||
if (LS->current != l_c('=')) return l_c('>');
|
||||
else { next(LS); return TK_GE; }
|
||||
|
||||
case '~':
|
||||
case l_c('~'):
|
||||
next(LS);
|
||||
if (LS->current != '=') return '~';
|
||||
if (LS->current != l_c('=')) return l_c('~');
|
||||
else { next(LS); return TK_NE; }
|
||||
|
||||
case '"':
|
||||
case '\'':
|
||||
case l_c('"'):
|
||||
case l_c('\''):
|
||||
read_string(LS, LS->current, seminfo);
|
||||
return TK_STRING;
|
||||
|
||||
case '.':
|
||||
case l_c('.'):
|
||||
next(LS);
|
||||
if (LS->current == '.') {
|
||||
if (LS->current == l_c('.')) {
|
||||
next(LS);
|
||||
if (LS->current == '.') {
|
||||
if (LS->current == l_c('.')) {
|
||||
next(LS);
|
||||
return TK_DOTS; /* ... */
|
||||
}
|
||||
else return TK_CONCAT; /* .. */
|
||||
}
|
||||
else if (!isdigit(LS->current)) return '.';
|
||||
else if (!isdigit(LS->current)) return l_c('.');
|
||||
else {
|
||||
read_number(LS, 1, seminfo);
|
||||
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:
|
||||
return TK_EOS;
|
||||
|
||||
case '_': goto tname;
|
||||
|
||||
default:
|
||||
if (!isalpha(LS->current)) {
|
||||
int c = LS->current;
|
||||
if (iscntrl(c))
|
||||
luaX_invalidchar(LS, c);
|
||||
next(LS);
|
||||
return c;
|
||||
default: {
|
||||
if (isdigit(LS->current)) {
|
||||
read_number(LS, 0, seminfo);
|
||||
return TK_NUMBER;
|
||||
}
|
||||
tname: { /* identifier or reserved word */
|
||||
else if (isalpha(LS->current) || LS->current == l_c('_')) {
|
||||
/* identifier or reserved word */
|
||||
size_t l = readname(LS);
|
||||
TString *ts = luaS_newlstr(LS->L, G(LS->L)->Mbuffer, l);
|
||||
if (ts->marked >= RESERVEDMARK) /* reserved word? */
|
||||
@ -373,6 +371,14 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
|
||||
seminfo->ts = ts;
|
||||
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
12
llex.h
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -14,7 +14,7 @@
|
||||
#define FIRST_RESERVED 257
|
||||
|
||||
/* 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_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
|
||||
int luaX_lex (LexState *LS, SemInfo *seminfo);
|
||||
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
|
||||
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
|
||||
void luaX_error (LexState *ls, const char *s, int token);
|
||||
void luaX_token2str (int token, char *s);
|
||||
void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg);
|
||||
void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token);
|
||||
void luaX_error (LexState *ls, const l_char *s, int token);
|
||||
void luaX_token2str (int token, l_char *s);
|
||||
|
||||
|
||||
#endif
|
||||
|
22
llimits.h
22
llimits.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** $Id: llimits.h,v 1.23 2001/02/20 18:15:33 roberto Exp roberto $
|
||||
** Limits, basic types, and some other "installation-dependent" definitions
|
||||
** $Id: llimits.h,v 1.24 2001/02/22 17:15:18 roberto Exp roberto $
|
||||
** Limits, basic types, and some other `installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
/* function to convert a lua_Number to a string */
|
||||
#ifndef NUMBER_FMT
|
||||
#define NUMBER_FMT "%.16g" /* LUA_NUMBER */
|
||||
#define NUMBER_FMT l_s("%.16g") /* LUA_NUMBER */
|
||||
#endif
|
||||
#ifndef lua_number2str
|
||||
#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n))
|
||||
@ -45,11 +45,21 @@
|
||||
#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
|
||||
** fit in a "small int" (16 bits), but may waste space in a
|
||||
** "large long" (64 bits). The current definitions should work in
|
||||
** fit in a `small int' (16 bits), but may waste space in a
|
||||
** `large long' (64 bits). The current definitions should work in
|
||||
** 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 */
|
||||
|
||||
|
||||
|
||||
|
58
lmathlib.c
58
lmathlib.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -176,18 +176,18 @@ static int math_random (lua_State *L) {
|
||||
}
|
||||
case 1: { /* only upper limit */
|
||||
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' */
|
||||
break;
|
||||
}
|
||||
case 2: { /* lower and upper limits */
|
||||
int l = luaL_check_int(L, 1);
|
||||
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' */
|
||||
break;
|
||||
}
|
||||
default: lua_error(L, "wrong number of arguments");
|
||||
default: lua_error(L, l_s("wrong number of arguments"));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -200,29 +200,29 @@ static int math_randomseed (lua_State *L) {
|
||||
|
||||
|
||||
static const luaL_reg mathlib[] = {
|
||||
{"abs", math_abs},
|
||||
{"sin", math_sin},
|
||||
{"cos", math_cos},
|
||||
{"tan", math_tan},
|
||||
{"asin", math_asin},
|
||||
{"acos", math_acos},
|
||||
{"atan", math_atan},
|
||||
{"atan2", math_atan2},
|
||||
{"ceil", math_ceil},
|
||||
{"floor", math_floor},
|
||||
{"mod", math_mod},
|
||||
{"frexp", math_frexp},
|
||||
{"ldexp", math_ldexp},
|
||||
{"sqrt", math_sqrt},
|
||||
{"min", math_min},
|
||||
{"max", math_max},
|
||||
{"log", math_log},
|
||||
{"log10", math_log10},
|
||||
{"exp", math_exp},
|
||||
{"deg", math_deg},
|
||||
{"rad", math_rad},
|
||||
{"random", math_random},
|
||||
{"randomseed", math_randomseed}
|
||||
{l_s("abs"), math_abs},
|
||||
{l_s("sin"), math_sin},
|
||||
{l_s("cos"), math_cos},
|
||||
{l_s("tan"), math_tan},
|
||||
{l_s("asin"), math_asin},
|
||||
{l_s("acos"), math_acos},
|
||||
{l_s("atan"), math_atan},
|
||||
{l_s("atan2"), math_atan2},
|
||||
{l_s("ceil"), math_ceil},
|
||||
{l_s("floor"), math_floor},
|
||||
{l_s("mod"), math_mod},
|
||||
{l_s("frexp"), math_frexp},
|
||||
{l_s("ldexp"), math_ldexp},
|
||||
{l_s("sqrt"), math_sqrt},
|
||||
{l_s("min"), math_min},
|
||||
{l_s("max"), math_max},
|
||||
{l_s("log"), math_log},
|
||||
{l_s("log10"), math_log10},
|
||||
{l_s("exp"), math_exp},
|
||||
{l_s("deg"), math_deg},
|
||||
{l_s("rad"), math_rad},
|
||||
{l_s("random"), math_random},
|
||||
{l_s("randomseed"), math_randomseed}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -231,8 +231,8 @@ static const luaL_reg mathlib[] = {
|
||||
LUALIB_API void lua_mathlibopen (lua_State *L) {
|
||||
luaL_openl(L, mathlib);
|
||||
lua_pushcfunction(L, math_pow);
|
||||
lua_settagmethod(L, LUA_TNUMBER, "pow");
|
||||
lua_settagmethod(L, LUA_TNUMBER, l_s("pow"));
|
||||
lua_pushnumber(L, PI);
|
||||
lua_setglobal(L, "PI");
|
||||
lua_setglobal(L, l_s("PI"));
|
||||
}
|
||||
|
||||
|
6
lmem.c
6
lmem.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
|
||||
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;
|
||||
int newsize = (*size)*2;
|
||||
if (newsize < MINPOWER2)
|
||||
@ -49,7 +49,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
|
||||
block = NULL;
|
||||
}
|
||||
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 {
|
||||
block = l_realloc(block, oldsize, size);
|
||||
if (block == NULL) {
|
||||
|
4
lmem.h
4
lmem.h
@ -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
|
||||
** 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_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_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0)
|
||||
|
42
lobject.c
42
lobject.c
@ -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
|
||||
** 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) {
|
||||
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;
|
||||
}
|
||||
return G(L)->Mbuffer;
|
||||
}
|
||||
|
||||
|
||||
int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */
|
||||
char *endptr;
|
||||
int luaO_str2d (const l_char *s, lua_Number *result) { /* LUA_NUMBER */
|
||||
l_char *endptr;
|
||||
lua_Number res = lua_str2number(s, &endptr);
|
||||
if (endptr == s) return 0; /* no conversion */
|
||||
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;
|
||||
return 1;
|
||||
}
|
||||
@ -59,9 +59,9 @@ int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */
|
||||
#define MAX_VERROR 280
|
||||
|
||||
/* 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;
|
||||
char buff[MAX_VERROR]; /* to hold formatted message */
|
||||
l_char buff[MAX_VERROR]; /* to hold formatted message */
|
||||
va_start(argp, fmt);
|
||||
vsprintf(buff, fmt, 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) {
|
||||
if (*source == '=') {
|
||||
void luaO_chunkid (l_char *out, const l_char *source, int bufflen) {
|
||||
if (*source == l_c('=')) {
|
||||
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 {
|
||||
if (*source == '@') {
|
||||
if (*source == l_c('@')) {
|
||||
int l;
|
||||
source++; /* skip the `@' */
|
||||
bufflen -= sizeof("file `...%s'");
|
||||
bufflen -= sizeof(l_s("file `...%s'"));
|
||||
l = strlen(source);
|
||||
if (l>bufflen) {
|
||||
source += (l-bufflen); /* get last part of file name */
|
||||
sprintf(out, "file `...%.99s'", source);
|
||||
sprintf(out, l_s("file `...%.99s'"), source);
|
||||
}
|
||||
else
|
||||
sprintf(out, "file `%.99s'", source);
|
||||
sprintf(out, l_s("file `%.99s'"), source);
|
||||
}
|
||||
else {
|
||||
int len = strcspn(source, "\n"); /* stop at first newline */
|
||||
bufflen -= sizeof("string \"%.*s...\"");
|
||||
int len = strcspn(source, l_s("\n")); /* stop at first newline */
|
||||
bufflen -= sizeof(l_s("string \"%.*s...\""));
|
||||
if (len > bufflen) len = bufflen;
|
||||
if (source[len] != '\0') { /* must truncate? */
|
||||
strcpy(out, "string \"");
|
||||
if (source[len] != l_c('\0')) { /* must truncate? */
|
||||
strcpy(out, l_s("string \""));
|
||||
out += strlen(out);
|
||||
strncpy(out, source, len);
|
||||
strcpy(out+len, "...\"");
|
||||
strcpy(out+len, l_s("...\""));
|
||||
}
|
||||
else
|
||||
sprintf(out, "string \"%.99s\"", source);
|
||||
sprintf(out, l_s("string \"%.99s\""), source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
lobject.h
14
lobject.h
@ -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
|
||||
** 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))
|
||||
|
||||
|
||||
@ -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)))
|
||||
|
||||
@ -220,13 +220,13 @@ typedef struct CallInfo {
|
||||
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_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_chunkid (char *out, const char *source, int len);
|
||||
void luaO_verror (lua_State *L, const l_char *fmt, ...);
|
||||
void luaO_chunkid (l_char *out, const l_char *source, int len);
|
||||
|
||||
|
||||
#endif
|
||||
|
184
lparser.c
184
lparser.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -72,9 +72,9 @@ static void lookahead (LexState *ls) {
|
||||
|
||||
|
||||
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);
|
||||
sprintf(buff, "`%.10s' expected", t);
|
||||
sprintf(buff, l_s("`%.10s' expected"), t);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -105,11 +105,11 @@ static void check_match (LexState *ls, int what, int who, int where) {
|
||||
if (where == ls->linenumber)
|
||||
error_expected(ls, what);
|
||||
else {
|
||||
char buff[70];
|
||||
char t_what[TOKEN_LEN], t_who[TOKEN_LEN];
|
||||
l_char buff[70];
|
||||
l_char t_what[TOKEN_LEN], t_who[TOKEN_LEN];
|
||||
luaX_token2str(what, t_what);
|
||||
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);
|
||||
luaK_error(ls, buff);
|
||||
}
|
||||
@ -123,7 +123,7 @@ static int string_constant (FuncState *fs, TString *s) {
|
||||
int c = s->u.s.constindex;
|
||||
if (c >= fs->nkstr || f->kstr[c] != s) {
|
||||
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++;
|
||||
f->kstr[c] = s;
|
||||
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) {
|
||||
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;
|
||||
next(ls);
|
||||
return ts;
|
||||
@ -155,7 +155,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
|
||||
FuncState *fs = ls->fs;
|
||||
Proto *f = fs->f;
|
||||
luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
|
||||
LocVar, MAX_INT, "");
|
||||
LocVar, MAX_INT, l_s(""));
|
||||
f->locvars[fs->nlocvars].varname = varname;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ static int search_local (LexState *ls, TString *n, expdesc *var) {
|
||||
static void singlevar (LexState *ls, TString *n, expdesc *var) {
|
||||
int level = search_local(ls, n, var);
|
||||
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));
|
||||
else if (level == -1) /* global? */
|
||||
var->u.index = string_constant(ls->fs, n);
|
||||
@ -224,7 +224,7 @@ static int indexupvalue (LexState *ls, expdesc *v) {
|
||||
return i;
|
||||
}
|
||||
/* 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;
|
||||
return fs->f->nupvalues++;
|
||||
}
|
||||
@ -236,12 +236,12 @@ static void pushupvalue (LexState *ls, TString *n) {
|
||||
int level = search_local(ls, n, &v);
|
||||
if (level == -1) { /* global? */
|
||||
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);
|
||||
}
|
||||
else if (level != 1) {
|
||||
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));
|
||||
}
|
||||
@ -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) {
|
||||
FuncState *fs = ls->fs;
|
||||
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->is_vararg = dots;
|
||||
if (dots) {
|
||||
new_localvarstr(ls, "arg", 0);
|
||||
new_localvarstr(ls, l_s("arg"), 0);
|
||||
adjustlocalvars(ls, 1);
|
||||
}
|
||||
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++)
|
||||
luaK_tostack(ls, &func->upvalues[i], 1);
|
||||
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;
|
||||
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);
|
||||
next(&lexstate); /* read first token */
|
||||
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);
|
||||
lua_assert(funcstate.prev == NULL);
|
||||
lua_assert(funcstate.f->nupvalues == 0);
|
||||
@ -385,7 +385,7 @@ static int explist1 (LexState *ls) {
|
||||
int n = 1; /* at least one expression */
|
||||
expdesc v;
|
||||
expr(ls, &v);
|
||||
while (ls->t.token == ',') {
|
||||
while (ls->t.token == l_c(',')) {
|
||||
next(ls); /* skip comma */
|
||||
luaK_tostack(ls, &v, 1); /* gets only 1 value from previous expression */
|
||||
expr(ls, &v);
|
||||
@ -400,13 +400,13 @@ static void funcargs (LexState *ls, int slf) {
|
||||
FuncState *fs = ls->fs;
|
||||
int slevel = fs->stacklevel - slf - 1; /* where is func in the stack */
|
||||
switch (ls->t.token) {
|
||||
case '(': { /* funcargs -> `(' [ explist1 ] `)' */
|
||||
case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */
|
||||
int line = ls->linenumber;
|
||||
int nargs = 0;
|
||||
next(ls);
|
||||
if (ls->t.token != ')') /* arg list not empty? */
|
||||
if (ls->t.token != l_c(')')) /* arg list not empty? */
|
||||
nargs = explist1(ls);
|
||||
check_match(ls, ')', '(', line);
|
||||
check_match(ls, l_c(')'), l_c('('), line);
|
||||
#ifdef LUA_COMPAT_ARGRET
|
||||
if (nargs > 0) /* arg list is not empty? */
|
||||
luaK_setcallreturns(fs, 1); /* last call returns only 1 value */
|
||||
@ -415,7 +415,7 @@ static void funcargs (LexState *ls, int slf) {
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case '{': { /* funcargs -> constructor */
|
||||
case l_c('{'): { /* funcargs -> constructor */
|
||||
constructor(ls);
|
||||
break;
|
||||
}
|
||||
@ -425,7 +425,7 @@ static void funcargs (LexState *ls, int slf) {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
luaK_error(ls, "function arguments expected");
|
||||
luaK_error(ls, l_s("function arguments expected"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -448,15 +448,15 @@ static void recfield (LexState *ls) {
|
||||
luaK_kstr(ls, checkname(ls));
|
||||
break;
|
||||
}
|
||||
case '[': {
|
||||
case l_c('['): {
|
||||
next(ls);
|
||||
exp1(ls);
|
||||
check(ls, ']');
|
||||
check(ls, l_c(']'));
|
||||
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);
|
||||
}
|
||||
|
||||
@ -466,9 +466,9 @@ static int recfields (LexState *ls) {
|
||||
FuncState *fs = ls->fs;
|
||||
int n = 1; /* at least one element */
|
||||
recfield(ls);
|
||||
while (ls->t.token == ',') {
|
||||
while (ls->t.token == l_c(',')) {
|
||||
next(ls);
|
||||
if (ls->t.token == ';' || ls->t.token == '}')
|
||||
if (ls->t.token == l_c(';') || ls->t.token == l_c('}'))
|
||||
break;
|
||||
recfield(ls);
|
||||
n++;
|
||||
@ -485,14 +485,14 @@ static int listfields (LexState *ls) {
|
||||
FuncState *fs = ls->fs;
|
||||
int n = 1; /* at least one element */
|
||||
exp1(ls);
|
||||
while (ls->t.token == ',') {
|
||||
while (ls->t.token == l_c(',')) {
|
||||
next(ls);
|
||||
if (ls->t.token == ';' || ls->t.token == '}')
|
||||
if (ls->t.token == l_c(';') || ls->t.token == l_c('}'))
|
||||
break;
|
||||
exp1(ls);
|
||||
n++;
|
||||
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)
|
||||
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) {
|
||||
switch (ls->t.token) {
|
||||
case ';': case '}': { /* constructor_part -> empty */
|
||||
case l_c(';'): case l_c('}'): { /* constructor_part -> empty */
|
||||
cd->n = 0;
|
||||
cd->k = ls->t.token;
|
||||
break;
|
||||
}
|
||||
case TK_NAME: { /* may be listfields or recfields */
|
||||
lookahead(ls);
|
||||
if (ls->lookahead.token != '=') /* expression? */
|
||||
if (ls->lookahead.token != l_c('=')) /* expression? */
|
||||
goto case_default;
|
||||
/* else go through to recfields */
|
||||
}
|
||||
case '[': { /* constructor_part -> recfields */
|
||||
case l_c('['): { /* constructor_part -> recfields */
|
||||
cd->n = recfields(ls);
|
||||
cd->k = 1; /* record */
|
||||
break;
|
||||
@ -537,17 +537,17 @@ static void constructor (LexState *ls) {
|
||||
int pc = luaK_code1(fs, OP_CREATETABLE, 0);
|
||||
int nelems;
|
||||
Constdesc cd;
|
||||
check(ls, '{');
|
||||
check(ls, l_c('{'));
|
||||
constructor_part(ls, &cd);
|
||||
nelems = cd.n;
|
||||
if (optional(ls, ';')) {
|
||||
if (optional(ls, l_c(';'))) {
|
||||
Constdesc 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;
|
||||
}
|
||||
check_match(ls, '}', '{', line);
|
||||
luaX_checklimit(ls, nelems, MAXARG_U, "elements in a table constructor");
|
||||
check_match(ls, l_c('}'), l_c('{'), line);
|
||||
luaX_checklimit(ls, nelems, MAXARG_U, l_s("elements in a table constructor"));
|
||||
SETARG_U(fs->f->code[pc], nelems); /* set initial table size */
|
||||
}
|
||||
|
||||
@ -581,7 +581,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
|
||||
next(ls);
|
||||
break;
|
||||
}
|
||||
case '{': { /* constructor */
|
||||
case l_c('{'): { /* constructor */
|
||||
constructor(ls);
|
||||
break;
|
||||
}
|
||||
@ -590,23 +590,23 @@ static void primaryexp (LexState *ls, expdesc *v) {
|
||||
body(ls, 0, ls->linenumber);
|
||||
break;
|
||||
}
|
||||
case '(': {
|
||||
case l_c('('): {
|
||||
next(ls);
|
||||
expr(ls, v);
|
||||
check(ls, ')');
|
||||
check(ls, l_c(')'));
|
||||
return;
|
||||
}
|
||||
case TK_NAME: {
|
||||
singlevar(ls, str_checkname(ls), v);
|
||||
return;
|
||||
}
|
||||
case '%': {
|
||||
case l_c('%'): {
|
||||
next(ls); /* skip `%' */
|
||||
pushupvalue(ls, str_checkname(ls));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
luaK_error(ls, "unexpected symbol");
|
||||
luaK_error(ls, l_s("unexpected symbol"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -621,22 +621,22 @@ static void simpleexp (LexState *ls, expdesc *v) {
|
||||
primaryexp(ls, v);
|
||||
for (;;) {
|
||||
switch (ls->t.token) {
|
||||
case '.': { /* `.' NAME */
|
||||
case l_c('.'): { /* `.' NAME */
|
||||
next(ls);
|
||||
luaK_tostack(ls, v, 1); /* `v' must be on stack */
|
||||
luaK_kstr(ls, checkname(ls));
|
||||
v->k = VINDEXED;
|
||||
break;
|
||||
}
|
||||
case '[': { /* `[' exp1 `]' */
|
||||
case l_c('['): { /* `[' exp1 `]' */
|
||||
next(ls);
|
||||
luaK_tostack(ls, v, 1); /* `v' must be on stack */
|
||||
v->k = VINDEXED;
|
||||
exp1(ls);
|
||||
check(ls, ']');
|
||||
check(ls, l_c(']'));
|
||||
break;
|
||||
}
|
||||
case ':': { /* `:' NAME funcargs */
|
||||
case l_c(':'): { /* `:' NAME funcargs */
|
||||
next(ls);
|
||||
luaK_tostack(ls, v, 1); /* `v' must be on stack */
|
||||
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;
|
||||
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 */
|
||||
funcargs(ls, 0);
|
||||
v->k = VEXP;
|
||||
@ -661,7 +661,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
|
||||
static UnOpr getunopr (int op) {
|
||||
switch (op) {
|
||||
case TK_NOT: return OPR_NOT;
|
||||
case '-': return OPR_MINUS;
|
||||
case l_c('-'): return OPR_MINUS;
|
||||
default: return OPR_NOUNOPR;
|
||||
}
|
||||
}
|
||||
@ -669,17 +669,17 @@ static UnOpr getunopr (int op) {
|
||||
|
||||
static BinOpr getbinopr (int op) {
|
||||
switch (op) {
|
||||
case '+': return OPR_ADD;
|
||||
case '-': return OPR_SUB;
|
||||
case '*': return OPR_MULT;
|
||||
case '/': return OPR_DIV;
|
||||
case '^': return OPR_POW;
|
||||
case l_c('+'): return OPR_ADD;
|
||||
case l_c('-'): return OPR_SUB;
|
||||
case l_c('*'): return OPR_MULT;
|
||||
case l_c('/'): return OPR_DIV;
|
||||
case l_c('^'): return OPR_POW;
|
||||
case TK_CONCAT: return OPR_CONCAT;
|
||||
case TK_NE: return OPR_NE;
|
||||
case TK_EQ: return OPR_EQ;
|
||||
case '<': return OPR_LT;
|
||||
case l_c('<'): return OPR_LT;
|
||||
case TK_LE: return OPR_LE;
|
||||
case '>': return OPR_GT;
|
||||
case l_c('>'): return OPR_GT;
|
||||
case TK_GE: return OPR_GE;
|
||||
case TK_AND: return OPR_AND;
|
||||
case TK_OR: return OPR_OR;
|
||||
@ -774,17 +774,17 @@ static void block (LexState *ls) {
|
||||
|
||||
static int assignment (LexState *ls, expdesc *v, int nvars) {
|
||||
int left = 0; /* number of values left in the stack after assignment */
|
||||
luaX_checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment");
|
||||
if (ls->t.token == ',') { /* assignment -> `,' simpleexp assignment */
|
||||
luaX_checklimit(ls, nvars, MAXVARSLH, l_s("variables in a multiple assignment"));
|
||||
if (ls->t.token == l_c(',')) { /* assignment -> `,' simpleexp assignment */
|
||||
expdesc nv;
|
||||
next(ls);
|
||||
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);
|
||||
}
|
||||
else { /* assignment -> `=' explist1 */
|
||||
int nexps;
|
||||
check(ls, '=');
|
||||
check(ls, l_c('='));
|
||||
nexps = explist1(ls);
|
||||
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) {
|
||||
/* fornum -> NAME = exp1,exp1[,exp1] forbody */
|
||||
FuncState *fs = ls->fs;
|
||||
check(ls, '=');
|
||||
check(ls, l_c('='));
|
||||
exp1(ls); /* initial value */
|
||||
check(ls, ',');
|
||||
check(ls, l_c(','));
|
||||
exp1(ls); /* limit */
|
||||
if (optional(ls, ','))
|
||||
if (optional(ls, l_c(',')))
|
||||
exp1(ls); /* optional step */
|
||||
else
|
||||
luaK_code1(fs, OP_PUSHINT, 1); /* default step */
|
||||
new_localvar(ls, varname, 0);
|
||||
new_localvarstr(ls, "(limit)", 1);
|
||||
new_localvarstr(ls, "(step)", 2);
|
||||
new_localvarstr(ls, l_s("(limit)"), 1);
|
||||
new_localvarstr(ls, l_s("(step)"), 2);
|
||||
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) {
|
||||
/* forlist -> NAME,NAME IN exp1 forbody */
|
||||
TString *valname;
|
||||
check(ls, ',');
|
||||
check(ls, l_c(','));
|
||||
valname = str_checkname(ls);
|
||||
/* next test is dirty, but avoids `in' being a reserved word */
|
||||
check_condition(ls,
|
||||
(ls->t.token == TK_NAME &&
|
||||
ls->t.seminfo.ts == luaS_newliteral(ls->L, "in")),
|
||||
"`in' expected");
|
||||
ls->t.seminfo.ts == luaS_newliteral(ls->L, l_s("in"))),
|
||||
l_s("`in' expected"));
|
||||
next(ls); /* skip `in' */
|
||||
exp1(ls); /* table */
|
||||
new_localvarstr(ls, "(table)", 0);
|
||||
new_localvarstr(ls, "(index)", 1);
|
||||
new_localvarstr(ls, l_s("(table)"), 0);
|
||||
new_localvarstr(ls, l_s("(index)"), 1);
|
||||
new_localvar(ls, indexname, 2);
|
||||
new_localvar(ls, valname, 3);
|
||||
forbody(ls, 4, OP_LFORPREP, OP_LFORLOOP);
|
||||
@ -900,9 +900,9 @@ static void forstat (LexState *ls, int line) {
|
||||
next(ls); /* skip `for' */
|
||||
varname = str_checkname(ls); /* first variable name */
|
||||
switch (ls->t.token) {
|
||||
case '=': fornum(ls, varname); break;
|
||||
case ',': forlist(ls, varname); break;
|
||||
default: luaK_error(ls, "`=' or `,' expected");
|
||||
case l_c('='): fornum(ls, varname); break;
|
||||
case l_c(','): forlist(ls, varname); break;
|
||||
default: luaK_error(ls, l_s("`=' or `,' expected"));
|
||||
}
|
||||
check_match(ls, TK_END, TK_FOR, line);
|
||||
leavebreak(fs, &bl);
|
||||
@ -949,8 +949,8 @@ static void localstat (LexState *ls) {
|
||||
do {
|
||||
next(ls); /* skip LOCAL or `,' */
|
||||
new_localvar(ls, str_checkname(ls), nvars++);
|
||||
} while (ls->t.token == ',');
|
||||
if (optional(ls, '='))
|
||||
} while (ls->t.token == l_c(','));
|
||||
if (optional(ls, l_c('=')))
|
||||
nexps = explist1(ls);
|
||||
else
|
||||
nexps = 0;
|
||||
@ -963,13 +963,13 @@ static int funcname (LexState *ls, expdesc *v) {
|
||||
/* funcname -> NAME {`.' NAME} [`:' NAME] */
|
||||
int needself = 0;
|
||||
singlevar(ls, str_checkname(ls), v);
|
||||
while (ls->t.token == '.') {
|
||||
while (ls->t.token == l_c('.')) {
|
||||
next(ls);
|
||||
luaK_tostack(ls, v, 1);
|
||||
luaK_kstr(ls, checkname(ls));
|
||||
v->k = VINDEXED;
|
||||
}
|
||||
if (ls->t.token == ':') {
|
||||
if (ls->t.token == l_c(':')) {
|
||||
needself = 1;
|
||||
next(ls);
|
||||
luaK_tostack(ls, v, 1);
|
||||
@ -997,7 +997,7 @@ static void namestat (LexState *ls) {
|
||||
expdesc v;
|
||||
simpleexp(ls, &v);
|
||||
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 */
|
||||
}
|
||||
else { /* stat -> assignment */
|
||||
@ -1011,7 +1011,7 @@ static void retstat (LexState *ls) {
|
||||
/* stat -> RETURN explist */
|
||||
FuncState *fs = ls->fs;
|
||||
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 */
|
||||
luaK_code1(fs, OP_RETURN, ls->fs->nactloc);
|
||||
fs->stacklevel = fs->nactloc; /* removes all temp values */
|
||||
@ -1024,7 +1024,7 @@ static void breakstat (LexState *ls) {
|
||||
int currentlevel = fs->stacklevel;
|
||||
Breaklabel *bl = fs->bl;
|
||||
if (!bl)
|
||||
luaK_error(ls, "no loop to break");
|
||||
luaK_error(ls, l_s("no loop to break"));
|
||||
next(ls); /* skip BREAK */
|
||||
luaK_adjuststack(fs, currentlevel - bl->stacklevel);
|
||||
luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
|
||||
@ -1086,14 +1086,14 @@ static void parlist (LexState *ls) {
|
||||
/* parlist -> [ param { `,' param } ] */
|
||||
int nparams = 0;
|
||||
short dots = 0;
|
||||
if (ls->t.token != ')') { /* is `parlist' not empty? */
|
||||
if (ls->t.token != l_c(')')) { /* is `parlist' not empty? */
|
||||
do {
|
||||
switch (ls->t.token) {
|
||||
case TK_DOTS: next(ls); dots = 1; 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);
|
||||
}
|
||||
@ -1104,13 +1104,13 @@ static void body (LexState *ls, int needself, int line) {
|
||||
FuncState new_fs;
|
||||
open_func(ls, &new_fs);
|
||||
new_fs.f->lineDefined = line;
|
||||
check(ls, '(');
|
||||
check(ls, l_c('('));
|
||||
if (needself) {
|
||||
new_localvarstr(ls, "self", 0);
|
||||
new_localvarstr(ls, l_s("self"), 0);
|
||||
adjustlocalvars(ls, 1);
|
||||
}
|
||||
parlist(ls);
|
||||
check(ls, ')');
|
||||
check(ls, l_c(')'));
|
||||
chunk(ls);
|
||||
check_match(ls, TK_END, TK_FUNCTION, line);
|
||||
close_func(ls);
|
||||
@ -1126,7 +1126,7 @@ static void chunk (LexState *ls) {
|
||||
int islast = 0;
|
||||
while (!islast && !block_follow(ls->t.token)) {
|
||||
islast = statement(ls);
|
||||
optional(ls, ';');
|
||||
optional(ls, l_c(';'));
|
||||
lua_assert(ls->fs->stacklevel == ls->fs->nactloc);
|
||||
}
|
||||
}
|
||||
|
4
lstate.c
4
lstate.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -131,7 +131,7 @@ static void close_state (lua_State *L, lua_State *OL) {
|
||||
luaS_freeall(L);
|
||||
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)->Mbuffer, G(L)->Mbuffsize, char);
|
||||
luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, l_char);
|
||||
luaM_freelem(NULL, L->G, global_State);
|
||||
}
|
||||
luaM_freearray(OL, L->stack, L->stacksize, TObject);
|
||||
|
8
lstate.h
8
lstate.h
@ -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
|
||||
** 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 {
|
||||
char *Mbuffer; /* global buffer */
|
||||
l_char *Mbuffer; /* global buffer */
|
||||
size_t Mbuffsize; /* size of Mbuffer */
|
||||
Proto *rootproto; /* list of all prototypes */
|
||||
Closure *rootcl; /* list of all closures */
|
||||
@ -85,7 +85,7 @@ typedef struct global_State {
|
||||
|
||||
|
||||
/*
|
||||
** "per thread" state
|
||||
** `per thread' state
|
||||
*/
|
||||
struct lua_State {
|
||||
LUA_USERSTATE
|
||||
|
@ -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)
|
||||
** 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;
|
||||
lu_hash h = l; /* seed */
|
||||
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->u.s.hash = h;
|
||||
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 */
|
||||
newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */
|
||||
return ts;
|
||||
|
10
lstring.h
10
lstring.h
@ -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)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -22,20 +22,20 @@
|
||||
|
||||
|
||||
#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 luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1))
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \
|
||||
(sizeof(s)/sizeof(l_char))-1))
|
||||
|
||||
void luaS_init (lua_State *L);
|
||||
void luaS_resize (lua_State *L, stringtable *tb, int newsize);
|
||||
TString *luaS_newudata (lua_State *L, size_t s, void *udata);
|
||||
int luaS_createudata (lua_State *L, void *udata, TObject *o);
|
||||
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
|
||||
|
254
lstrlib.c
254
lstrlib.c
@ -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
|
||||
** 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) {
|
||||
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 end = posrelat(luaL_opt_long(L, 3, -1), l);
|
||||
if (start < 1) start = 1;
|
||||
if (end > (sint32)l) end = l;
|
||||
if (start <= end)
|
||||
lua_pushlstring(L, s+start-1, end-start+1);
|
||||
else lua_pushliteral(L, "");
|
||||
else lua_pushliteral(L, l_s(""));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ static int str_lower (lua_State *L) {
|
||||
size_t l;
|
||||
size_t i;
|
||||
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);
|
||||
for (i=0; i<l; i++)
|
||||
luaL_putchar(&b, tolower(uchar(s[i])));
|
||||
@ -65,7 +65,7 @@ static int str_upper (lua_State *L) {
|
||||
size_t l;
|
||||
size_t i;
|
||||
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);
|
||||
for (i=0; i<l; 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) {
|
||||
size_t l;
|
||||
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);
|
||||
luaL_buffinit(L, &b);
|
||||
while (n-- > 0)
|
||||
@ -88,9 +88,9 @@ static int str_rep (lua_State *L) {
|
||||
|
||||
static int str_byte (lua_State *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);
|
||||
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]));
|
||||
return 1;
|
||||
}
|
||||
@ -103,7 +103,7 @@ static int str_char (lua_State *L) {
|
||||
luaL_buffinit(L, &b);
|
||||
for (i=1; i<=n; 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_pushresult(&b);
|
||||
@ -127,25 +127,25 @@ static int str_char (lua_State *L) {
|
||||
#define CAP_POSITION (-2)
|
||||
|
||||
typedef struct MatchState {
|
||||
const char *src_init; /* init of source string */
|
||||
const char *src_end; /* end (`\0') of source string */
|
||||
const l_char *src_init; /* init of source string */
|
||||
const l_char *src_end; /* end (`\0') of source string */
|
||||
int level; /* total number of captures (finished or unfinished) */
|
||||
struct {
|
||||
const char *init;
|
||||
const l_char *init;
|
||||
sint32 len;
|
||||
} capture[MAX_CAPTURES];
|
||||
lua_State *L;
|
||||
} MatchState;
|
||||
|
||||
|
||||
#define ESC '%'
|
||||
#define SPECIALS "^$*+?.([%-"
|
||||
#define ESC l_c('%')
|
||||
#define SPECIALS l_s("^$*+?.([%-")
|
||||
|
||||
|
||||
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)
|
||||
lua_error(ms->L, "invalid capture index");
|
||||
lua_error(ms->L, l_s("invalid capture index"));
|
||||
return l;
|
||||
}
|
||||
|
||||
@ -154,22 +154,22 @@ static int capture_to_close (MatchState *ms) {
|
||||
int level = ms->level;
|
||||
for (level--; level>=0; 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 */
|
||||
}
|
||||
|
||||
|
||||
static const char *luaI_classend (MatchState *ms, const char *p) {
|
||||
static const l_char *luaI_classend (MatchState *ms, const l_char *p) {
|
||||
switch (*p++) {
|
||||
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;
|
||||
case '[':
|
||||
if (*p == '^') p++;
|
||||
case l_c('['):
|
||||
if (*p == l_c('^')) p++;
|
||||
do { /* look for a `]' */
|
||||
if (*p == '\0') lua_error(ms->L, "malformed pattern (missing `]')");
|
||||
if (*(p++) == ESC && *p != '\0') p++; /* skip escapes (e.g. `%]') */
|
||||
} while (*p != ']');
|
||||
if (*p == l_c('\0')) lua_error(ms->L, l_s("malformed pattern (missing `]')"));
|
||||
if (*(p++) == ESC && *p != l_c('\0')) p++; /* skip escapes (e.g. `%]') */
|
||||
} while (*p != l_c(']'));
|
||||
return p+1;
|
||||
default:
|
||||
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;
|
||||
switch (tolower(uchar(cl))) {
|
||||
case 'a' : res = isalpha(uchar(c)); break;
|
||||
case 'c' : res = iscntrl(uchar(c)); break;
|
||||
case 'd' : res = isdigit(uchar(c)); break;
|
||||
case 'l' : res = islower(uchar(c)); break;
|
||||
case 'p' : res = ispunct(uchar(c)); break;
|
||||
case 's' : res = isspace(uchar(c)); break;
|
||||
case 'u' : res = isupper(uchar(c)); break;
|
||||
case 'w' : res = isalnum(uchar(c)); break;
|
||||
case 'x' : res = isxdigit(uchar(c)); break;
|
||||
case 'z' : res = (c == '\0'); break;
|
||||
case l_c('a') : res = isalpha(uchar(c)); break;
|
||||
case l_c('c') : res = iscntrl(uchar(c)); break;
|
||||
case l_c('d') : res = isdigit(uchar(c)); break;
|
||||
case l_c('l') : res = islower(uchar(c)); break;
|
||||
case l_c('p') : res = ispunct(uchar(c)); break;
|
||||
case l_c('s') : res = isspace(uchar(c)); break;
|
||||
case l_c('u') : res = isupper(uchar(c)); break;
|
||||
case l_c('w') : res = isalnum(uchar(c)); break;
|
||||
case l_c('x') : res = isxdigit(uchar(c)); break;
|
||||
case l_c('z') : res = (c == l_c('\0')); break;
|
||||
default: return (cl == c);
|
||||
}
|
||||
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;
|
||||
if (*(p+1) == '^') {
|
||||
if (*(p+1) == l_c('^')) {
|
||||
sig = 0;
|
||||
p++; /* skip the `^' */
|
||||
}
|
||||
@ -208,7 +208,7 @@ static int matchbracketclass (char c, const char *p, const char *endclass) {
|
||||
if (match_class(c, *p))
|
||||
return sig;
|
||||
}
|
||||
else if ((*(p+1) == '-') && (p+2 < endclass)) {
|
||||
else if ((*(p+1) == l_c('-')) && (p+2 < endclass)) {
|
||||
p+=2;
|
||||
if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p))
|
||||
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) {
|
||||
case '.': /* matches any char */
|
||||
case l_c('.'): /* matches any char */
|
||||
return 1;
|
||||
case ESC:
|
||||
return match_class(c, *(p+1));
|
||||
case '[':
|
||||
case l_c('['):
|
||||
return matchbracketclass(c, p, ep-1);
|
||||
default:
|
||||
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)
|
||||
lua_error(ms->L, "unbalanced pattern");
|
||||
lua_error(ms->L, l_s("unbalanced pattern"));
|
||||
if (*s != *p) return NULL;
|
||||
else {
|
||||
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,
|
||||
const char *ep) {
|
||||
static const l_char *max_expand (MatchState *ms, const l_char *s, const l_char *p,
|
||||
const l_char *ep) {
|
||||
sint32 i = 0; /* counts maximum expand for item */
|
||||
while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep))
|
||||
i++;
|
||||
/* keeps trying to match with the maximum repetitions */
|
||||
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;
|
||||
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,
|
||||
const char *ep) {
|
||||
static const l_char *min_expand (MatchState *ms, const l_char *s, const l_char *p,
|
||||
const l_char *ep) {
|
||||
for (;;) {
|
||||
const char *res = match(ms, s, ep+1);
|
||||
const l_char *res = match(ms, s, ep+1);
|
||||
if (res != NULL)
|
||||
return res;
|
||||
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,
|
||||
const char *p, int what) {
|
||||
const char *res;
|
||||
static const l_char *start_capture (MatchState *ms, const l_char *s,
|
||||
const l_char *p, int what) {
|
||||
const l_char *res;
|
||||
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].len = what;
|
||||
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);
|
||||
const char *res;
|
||||
const l_char *res;
|
||||
ms->capture[l].len = s - ms->capture[l].init; /* close capture */
|
||||
if ((res = match(ms, s, p)) == NULL) /* match failed? */
|
||||
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);
|
||||
size_t len = ms->capture[l].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 */
|
||||
switch (*p) {
|
||||
case '(': /* start capture */
|
||||
if (*(p+1) == ')') /* position capture? */
|
||||
case l_c('('): /* start capture */
|
||||
if (*(p+1) == l_c(')')) /* position capture? */
|
||||
return start_capture(ms, s, p+2, CAP_POSITION);
|
||||
else
|
||||
return start_capture(ms, s, p+1, CAP_UNFINISHED);
|
||||
case ')': /* end capture */
|
||||
case l_c(')'): /* end capture */
|
||||
return end_capture(ms, s, p+1);
|
||||
case ESC: /* may be %[0-9] or %b */
|
||||
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;
|
||||
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);
|
||||
if (s == NULL) return NULL;
|
||||
p+=4; goto init; /* else return match(ms, s, p+4); */
|
||||
}
|
||||
else goto dflt; /* case default */
|
||||
case '\0': /* end of pattern */
|
||||
case l_c('\0'): /* end of pattern */
|
||||
return s; /* match succeeded */
|
||||
case '$':
|
||||
if (*(p+1) == '\0') /* is the `$' the last char in pattern? */
|
||||
case l_c('$'):
|
||||
if (*(p+1) == l_c('\0')) /* is the `$' the last char in pattern? */
|
||||
return (s == ms->src_end) ? s : NULL; /* check end of string */
|
||||
else goto dflt;
|
||||
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);
|
||||
switch (*ep) {
|
||||
case '?': { /* optional */
|
||||
const char *res;
|
||||
case l_c('?'): { /* optional */
|
||||
const l_char *res;
|
||||
if (m && ((res=match(ms, s+1, ep+1)) != NULL))
|
||||
return res;
|
||||
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);
|
||||
case '+': /* 1 or more repetitions */
|
||||
case l_c('+'): /* 1 or more repetitions */
|
||||
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);
|
||||
default:
|
||||
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,
|
||||
const char *s2, size_t l2) {
|
||||
static const l_char *lmemfind (const l_char *s1, size_t l1,
|
||||
const l_char *s2, size_t l2) {
|
||||
if (l2 == 0) return s1; /* empty strings are everywhere */
|
||||
else if (l2 > l1) return NULL; /* avoids a negative `l1' */
|
||||
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' */
|
||||
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 */
|
||||
if (memcmp(init, s2+1, l2) == 0)
|
||||
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) {
|
||||
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)
|
||||
lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1);
|
||||
else
|
||||
@ -405,7 +405,7 @@ static void push_onecapture (MatchState *ms, int i) {
|
||||
|
||||
static int push_captures (MatchState *ms) {
|
||||
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++)
|
||||
push_onecapture(ms, i);
|
||||
return ms->level; /* number of strings pushed */
|
||||
@ -414,13 +414,13 @@ static int push_captures (MatchState *ms) {
|
||||
|
||||
static int str_find (lua_State *L) {
|
||||
size_t l1, l2;
|
||||
const char *s = luaL_check_lstr(L, 1, &l1);
|
||||
const char *p = luaL_check_lstr(L, 2, &l2);
|
||||
const l_char *s = luaL_check_lstr(L, 1, &l1);
|
||||
const l_char *p = luaL_check_lstr(L, 2, &l2);
|
||||
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? */
|
||||
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) {
|
||||
lua_pushnumber(L, s2-s+1);
|
||||
lua_pushnumber(L, s2-s+l2);
|
||||
@ -429,13 +429,13 @@ static int str_find (lua_State *L) {
|
||||
}
|
||||
else {
|
||||
MatchState ms;
|
||||
int anchor = (*p == '^') ? (p++, 1) : 0;
|
||||
const char *s1=s+init;
|
||||
int anchor = (*p == l_c('^')) ? (p++, 1) : 0;
|
||||
const l_char *s1=s+init;
|
||||
ms.L = L;
|
||||
ms.src_init = s;
|
||||
ms.src_end = s+l1;
|
||||
do {
|
||||
const char *res;
|
||||
const l_char *res;
|
||||
ms.level = 0;
|
||||
if ((res=match(&ms, s1, p)) != NULL) {
|
||||
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) {
|
||||
lua_State *L = ms->L;
|
||||
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 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) {
|
||||
size_t srcl;
|
||||
const char *src = luaL_check_lstr(L, 1, &srcl);
|
||||
const char *p = luaL_check_string(L, 2);
|
||||
const l_char *src = luaL_check_lstr(L, 1, &srcl);
|
||||
const l_char *p = luaL_check_string(L, 2);
|
||||
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;
|
||||
MatchState ms;
|
||||
luaL_Buffer b;
|
||||
luaL_arg_check(L,
|
||||
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);
|
||||
ms.L = L;
|
||||
ms.src_init = src;
|
||||
ms.src_end = src+srcl;
|
||||
while (n < max_s) {
|
||||
const char *e;
|
||||
const l_char *e;
|
||||
ms.level = 0;
|
||||
e = match(&ms, src, p);
|
||||
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) {
|
||||
size_t l;
|
||||
const char *s = luaL_check_lstr(L, arg, &l);
|
||||
luaL_putchar(b, '"');
|
||||
const l_char *s = luaL_check_lstr(L, arg, &l);
|
||||
luaL_putchar(b, l_c('"'));
|
||||
while (l--) {
|
||||
switch (*s) {
|
||||
case '"': case '\\': case '\n':
|
||||
luaL_putchar(b, '\\');
|
||||
case l_c('"'): case l_c('\\'): case l_c('\n'):
|
||||
luaL_putchar(b, l_c('\\'));
|
||||
luaL_putchar(b, *s);
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
const char *p = strfrmt;
|
||||
while (strchr("-+ #0", *p)) p++; /* skip flags */
|
||||
const l_char *p = strfrmt;
|
||||
while (strchr(l_s("-+ #0"), *p)) p++; /* skip flags */
|
||||
if (isdigit(uchar(*p))) p++; /* skip width */
|
||||
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
|
||||
if (*p == '.') {
|
||||
if (*p == l_c('.')) {
|
||||
p++;
|
||||
*hasprecision = 1;
|
||||
if (isdigit(uchar(*p))) p++; /* skip precision */
|
||||
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
|
||||
}
|
||||
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 */
|
||||
lua_error(L, "invalid format (too long)");
|
||||
form[0] = '%';
|
||||
lua_error(L, l_s("invalid format (too long)"));
|
||||
form[0] = l_c('%');
|
||||
strncpy(form+1, strfrmt, p-strfrmt+1);
|
||||
form[p-strfrmt+2] = 0;
|
||||
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) {
|
||||
int arg = 1;
|
||||
const char *strfrmt = luaL_check_string(L, arg);
|
||||
const l_char *strfrmt = luaL_check_string(L, arg);
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
while (*strfrmt) {
|
||||
if (*strfrmt != '%')
|
||||
if (*strfrmt != l_c('%'))
|
||||
luaL_putchar(&b, *strfrmt++);
|
||||
else if (*++strfrmt == '%')
|
||||
else if (*++strfrmt == l_c('%'))
|
||||
luaL_putchar(&b, *strfrmt++); /* %% */
|
||||
else { /* format item */
|
||||
char form[MAX_FORMAT]; /* to store the format (`%...') */
|
||||
char buff[MAX_ITEM]; /* to store the formatted item */
|
||||
l_char form[MAX_FORMAT]; /* to store the format (`%...') */
|
||||
l_char buff[MAX_ITEM]; /* to store the formatted item */
|
||||
int hasprecision = 0;
|
||||
if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$')
|
||||
lua_error(L, "obsolete `format' option (d$)");
|
||||
if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == l_c('$'))
|
||||
lua_error(L, l_s("obsolete `format' option (d$)"));
|
||||
arg++;
|
||||
strfrmt = scanformat(L, strfrmt, form, &hasprecision);
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
break;
|
||||
case 'q':
|
||||
case l_c('q'):
|
||||
luaI_addquoted(L, &b, arg);
|
||||
continue; /* skip the `addsize' at the end */
|
||||
case 's': {
|
||||
case l_c('s'): {
|
||||
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) {
|
||||
/* no precision and string is too long to be formatted;
|
||||
keep original string */
|
||||
@ -618,7 +618,7 @@ static int str_format (lua_State *L) {
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
@ -629,16 +629,16 @@ static int str_format (lua_State *L) {
|
||||
|
||||
|
||||
static const luaL_reg strlib[] = {
|
||||
{"strlen", str_len},
|
||||
{"strsub", str_sub},
|
||||
{"strlower", str_lower},
|
||||
{"strupper", str_upper},
|
||||
{"strchar", str_char},
|
||||
{"strrep", str_rep},
|
||||
{"strbyte", str_byte},
|
||||
{"format", str_format},
|
||||
{"strfind", str_find},
|
||||
{"gsub", str_gsub}
|
||||
{l_s("strlen"), str_len},
|
||||
{l_s("strsub"), str_sub},
|
||||
{l_s("strlower"), str_lower},
|
||||
{l_s("strupper"), str_upper},
|
||||
{l_s("strchar"), str_char},
|
||||
{l_s("strrep"), str_rep},
|
||||
{l_s("strbyte"), str_byte},
|
||||
{l_s("format"), str_format},
|
||||
{l_s("strfind"), str_find},
|
||||
{l_s("gsub"), str_gsub}
|
||||
};
|
||||
|
||||
|
||||
|
12
ltable.c
12
ltable.c
@ -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)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -59,9 +59,9 @@ Node *luaH_next (lua_State *L, Hash *t, const TObject *key) {
|
||||
else {
|
||||
const TObject *v = luaH_get(t, key);
|
||||
if (v == &luaO_nilobject)
|
||||
luaD_error(L, "invalid key for `next'");
|
||||
i = (int)(((const char *)v -
|
||||
(const char *)(&t->node[0].val)) / sizeof(Node)) + 1;
|
||||
luaD_error(L, l_s("invalid key for `next'"));
|
||||
i = (int)(((const l_char *)v -
|
||||
(const l_char *)(&t->node[0].val)) / sizeof(Node)) + 1;
|
||||
}
|
||||
for (; i<t->size; i++) {
|
||||
Node *n = node(t, i);
|
||||
@ -82,7 +82,7 @@ int luaH_nexti (Hash *t, int i) {
|
||||
|
||||
|
||||
#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)
|
||||
@ -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_TSTRING: return luaH_setstr(L, t, tsvalue(key));
|
||||
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 */
|
||||
default: return luaH_setany(L, t, key);
|
||||
}
|
||||
|
266
ltests.c
266
ltests.c
@ -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
|
||||
** 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_pushnumber(L, val);
|
||||
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 blocksize(b) ((size_t *)((char *)(b) - HEADER))
|
||||
#define blocksize(b) ((size_t *)((l_char *)(b) - HEADER))
|
||||
|
||||
unsigned long memdebug_numblocks = 0;
|
||||
unsigned long memdebug_total = 0;
|
||||
@ -76,7 +76,7 @@ static void *checkblock (void *block) {
|
||||
size_t size = *b;
|
||||
int 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;
|
||||
}
|
||||
|
||||
@ -102,11 +102,11 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
|
||||
else if (memdebug_total+size-oldsize > memdebug_memlimit)
|
||||
return NULL; /* to test memory allocation errors */
|
||||
else {
|
||||
char *newblock;
|
||||
l_char *newblock;
|
||||
int i;
|
||||
size_t realsize = HEADER+size+MARKSIZE;
|
||||
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 (oldsize > size) oldsize = size;
|
||||
if (block) {
|
||||
@ -121,7 +121,7 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
|
||||
memdebug_numblocks++;
|
||||
*(size_t *)newblock = size;
|
||||
for (i=0;i<MARKSIZE;i++)
|
||||
*(newblock+HEADER+size+i) = (char)(MARK+i);
|
||||
*(newblock+HEADER+size+i) = (l_char)(MARK+i);
|
||||
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] = {
|
||||
"RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT",
|
||||
"PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL",
|
||||
"GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF",
|
||||
"CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP",
|
||||
"ADD", "ADDI", "SUB", "MULT", "DIV", "POW", "CONCAT", "MINUS", "NOT",
|
||||
"JMPNE", "JMPEQ", "JMPLT", "JMPLE", "JMPGT", "JMPGE", "JMPT", "JMPF",
|
||||
"JMPONT", "JMPONF", "JMP", "PUSHNILJMP", "FORPREP", "FORLOOP", "LFORPREP",
|
||||
"LFORLOOP", "CLOSURE"
|
||||
static const l_char *const instrname[NUM_OPCODES] = {
|
||||
l_s("RETURN"), l_s("CALL"), l_s("TAILCALL"), l_s("PUSHNIL"), l_s("POP"), l_s("PUSHINT"),
|
||||
l_s("PUSHSTRING"), l_s("PUSHNUM"), l_s("PUSHNEGNUM"), l_s("PUSHUPVALUE"), l_s("GETLOCAL"),
|
||||
l_s("GETGLOBAL"), l_s("GETTABLE"), l_s("GETDOTTED"), l_s("GETINDEXED"), l_s("PUSHSELF"),
|
||||
l_s("CREATETABLE"), l_s("SETLOCAL"), l_s("SETGLOBAL"), l_s("SETTABLE"), l_s("SETLIST"), l_s("SETMAP"),
|
||||
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"),
|
||||
l_s("JMPNE"), l_s("JMPEQ"), l_s("JMPLT"), l_s("JMPLE"), l_s("JMPGT"), l_s("JMPGE"), l_s("JMPT"), l_s("JMPF"),
|
||||
l_s("JMPONT"), l_s("JMPONF"), l_s("JMP"), l_s("PUSHNILJMP"), l_s("FORPREP"), l_s("FORLOOP"), l_s("LFORPREP"),
|
||||
l_s("LFORLOOP"), l_s("CLOSURE")
|
||||
};
|
||||
|
||||
|
||||
static void pushop (lua_State *L, Proto *p, int pc) {
|
||||
char buff[100];
|
||||
l_char buff[100];
|
||||
Instruction i = p->code[pc];
|
||||
OpCode o = GET_OPCODE(i);
|
||||
const char *name = instrname[o];
|
||||
sprintf(buff, "%5d - ", luaG_getline(p->lineinfo, pc, 1, NULL));
|
||||
const l_char *name = instrname[o];
|
||||
sprintf(buff, l_s("%5d - "), luaG_getline(p->lineinfo, pc, 1, NULL));
|
||||
switch ((enum Mode)luaK_opproperties[o].mode) {
|
||||
case iO:
|
||||
sprintf(buff+8, "%-12s", name);
|
||||
sprintf(buff+8, l_s("%-12s"), name);
|
||||
break;
|
||||
case iU:
|
||||
sprintf(buff+8, "%-12s%4u", name, GETARG_U(i));
|
||||
sprintf(buff+8, l_s("%-12s%4u"), name, GETARG_U(i));
|
||||
break;
|
||||
case iS:
|
||||
sprintf(buff+8, "%-12s%4d", name, GETARG_S(i));
|
||||
sprintf(buff+8, l_s("%-12s%4d"), name, GETARG_S(i));
|
||||
break;
|
||||
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;
|
||||
}
|
||||
lua_pushstring(L, buff);
|
||||
@ -178,11 +178,11 @@ static int listcode (lua_State *L) {
|
||||
int pc;
|
||||
Proto *p;
|
||||
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;
|
||||
lua_newtable(L);
|
||||
setnameval(L, "maxstack", p->maxstacksize);
|
||||
setnameval(L, "numparams", p->numparams);
|
||||
setnameval(L, l_s("maxstack"), p->maxstacksize);
|
||||
setnameval(L, l_s("numparams"), p->numparams);
|
||||
for (pc=0; pc<p->sizecode; pc++) {
|
||||
lua_pushnumber(L, pc+1);
|
||||
pushop(L, p, pc);
|
||||
@ -196,7 +196,7 @@ static int liststrings (lua_State *L) {
|
||||
Proto *p;
|
||||
int i;
|
||||
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;
|
||||
lua_newtable(L);
|
||||
for (i=0; i<p->sizekstr; i++) {
|
||||
@ -212,9 +212,9 @@ static int listlocals (lua_State *L) {
|
||||
Proto *p;
|
||||
int pc = luaL_check_int(L, 2) - 1;
|
||||
int i = 0;
|
||||
const char *name;
|
||||
const l_char *name;
|
||||
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;
|
||||
while ((name = luaF_getlocalname(p, ++i, pc)) != NULL)
|
||||
lua_pushstring(L, name);
|
||||
@ -234,22 +234,22 @@ static int pushbool (lua_State *L, int b) {
|
||||
|
||||
static int get_limits (lua_State *L) {
|
||||
lua_newtable(L);
|
||||
setnameval(L, "BITS_INT", BITS_INT);
|
||||
setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
|
||||
setnameval(L, "MAXARG_A", MAXARG_A);
|
||||
setnameval(L, "MAXARG_B", MAXARG_B);
|
||||
setnameval(L, "MAXARG_S", MAXARG_S);
|
||||
setnameval(L, "MAXARG_U", MAXARG_U);
|
||||
setnameval(L, "MAXLOCALS", MAXLOCALS);
|
||||
setnameval(L, "MAXPARAMS", MAXPARAMS);
|
||||
setnameval(L, "MAXSTACK", MAXSTACK);
|
||||
setnameval(L, "MAXUPVALUES", MAXUPVALUES);
|
||||
setnameval(L, "MAXVARSLH", MAXVARSLH);
|
||||
setnameval(L, "RFPF", RFIELDS_PER_FLUSH);
|
||||
setnameval(L, "SIZE_A", SIZE_A);
|
||||
setnameval(L, "SIZE_B", SIZE_B);
|
||||
setnameval(L, "SIZE_OP", SIZE_OP);
|
||||
setnameval(L, "SIZE_U", SIZE_U);
|
||||
setnameval(L, l_s("BITS_INT"), BITS_INT);
|
||||
setnameval(L, l_s("LFPF"), LFIELDS_PER_FLUSH);
|
||||
setnameval(L, l_s("MAXARG_A"), MAXARG_A);
|
||||
setnameval(L, l_s("MAXARG_B"), MAXARG_B);
|
||||
setnameval(L, l_s("MAXARG_S"), MAXARG_S);
|
||||
setnameval(L, l_s("MAXARG_U"), MAXARG_U);
|
||||
setnameval(L, l_s("MAXLOCALS"), MAXLOCALS);
|
||||
setnameval(L, l_s("MAXPARAMS"), MAXPARAMS);
|
||||
setnameval(L, l_s("MAXSTACK"), MAXSTACK);
|
||||
setnameval(L, l_s("MAXUPVALUES"), MAXUPVALUES);
|
||||
setnameval(L, l_s("MAXVARSLH"), MAXVARSLH);
|
||||
setnameval(L, l_s("RFPF"), RFIELDS_PER_FLUSH);
|
||||
setnameval(L, l_s("SIZE_A"), SIZE_A);
|
||||
setnameval(L, l_s("SIZE_B"), SIZE_B);
|
||||
setnameval(L, l_s("SIZE_OP"), SIZE_OP);
|
||||
setnameval(L, l_s("SIZE_U"), SIZE_U);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ static int mem_query (lua_State *L) {
|
||||
|
||||
static int hash_query (lua_State *L) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
@ -313,7 +313,7 @@ static int table_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;
|
||||
int s = luaL_opt_int(L, 2, 0) - 1;
|
||||
if (s==-1) {
|
||||
@ -364,8 +364,8 @@ static int newuserdata (lua_State *L) {
|
||||
}
|
||||
else {
|
||||
size_t size = luaL_check_int(L, 1);
|
||||
char *p = (char *)lua_newuserdata(L, size);
|
||||
while (size--) *p++ = '\0';
|
||||
l_char *p = (l_char *)lua_newuserdata(L, size);
|
||||
while (size--) *p++ = l_c('\0');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -400,7 +400,7 @@ static int s2d (lua_State *L) {
|
||||
|
||||
static int d2s (lua_State *L) {
|
||||
double d = luaL_check_number(L, 1);
|
||||
lua_pushlstring(L, (char *)&d, sizeof(d));
|
||||
lua_pushlstring(L, (l_char *)&d, sizeof(d));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -419,12 +419,12 @@ static int newstate (lua_State *L) {
|
||||
static int loadlib (lua_State *L) {
|
||||
lua_State *L1 = (lua_State *)lua_touserdata(L, 1);
|
||||
switch (*luaL_check_string(L, 2)) {
|
||||
case 'm': lua_mathlibopen(L1); break;
|
||||
case 's': lua_strlibopen(L1); break;
|
||||
case 'i': lua_iolibopen(L1); break;
|
||||
case 'd': lua_dblibopen(L1); break;
|
||||
case 'b': lua_baselibopen(L1); break;
|
||||
default: luaL_argerror(L, 2, "invalid option");
|
||||
case l_c('m'): lua_mathlibopen(L1); break;
|
||||
case l_c('s'): lua_strlibopen(L1); break;
|
||||
case l_c('i'): lua_iolibopen(L1); break;
|
||||
case l_c('d'): lua_dblibopen(L1); break;
|
||||
case l_c('b'): lua_baselibopen(L1); break;
|
||||
default: luaL_argerror(L, 2, l_s("invalid option"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -438,7 +438,7 @@ static int closestate (lua_State *L) {
|
||||
|
||||
static int doremote (lua_State *L) {
|
||||
lua_State *L1;
|
||||
const char *code = luaL_check_string(L, 2);
|
||||
const l_char *code = luaL_check_string(L, 2);
|
||||
int status;
|
||||
L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1);
|
||||
status = lua_dostring(L1, code);
|
||||
@ -457,7 +457,7 @@ static int doremote (lua_State *L) {
|
||||
|
||||
static int settagmethod (lua_State *L) {
|
||||
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);
|
||||
lua_gettagmethod(L, tag, event);
|
||||
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) {
|
||||
while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++;
|
||||
static void skip (const l_char **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 sig = 1;
|
||||
skip(pc);
|
||||
if (**pc == '.') {
|
||||
if (**pc == l_c('.')) {
|
||||
res = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
(*pc)++;
|
||||
return res;
|
||||
}
|
||||
else if (**pc == '-') {
|
||||
else if (**pc == l_c('-')) {
|
||||
sig = -1;
|
||||
(*pc)++;
|
||||
}
|
||||
while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0';
|
||||
while (isdigit(**pc)) res = res*10 + (*(*pc)++) - l_c('0');
|
||||
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;
|
||||
skip(pc);
|
||||
while (**pc != '\0' && !strchr(delimits, **pc))
|
||||
while (**pc != l_c('\0') && !strchr(delimits, **pc))
|
||||
buff[i++] = *(*pc)++;
|
||||
buff[i] = '\0';
|
||||
buff[i] = l_c('\0');
|
||||
return buff;
|
||||
}
|
||||
|
||||
@ -519,121 +519,121 @@ static const char *getname (char *buff, const char **pc) {
|
||||
|
||||
|
||||
static int testC (lua_State *L) {
|
||||
char buff[30];
|
||||
const char *pc = luaL_check_string(L, 1);
|
||||
l_char buff[30];
|
||||
const l_char *pc = luaL_check_string(L, 1);
|
||||
for (;;) {
|
||||
const char *inst = getname;
|
||||
if EQ("") return 0;
|
||||
else if EQ("isnumber") {
|
||||
const l_char *inst = getname;
|
||||
if EQ(l_s("")) return 0;
|
||||
else if EQ(l_s("isnumber")) {
|
||||
lua_pushnumber(L, lua_isnumber(L, getnum));
|
||||
}
|
||||
else if EQ("isstring") {
|
||||
else if EQ(l_s("isstring")) {
|
||||
lua_pushnumber(L, lua_isstring(L, getnum));
|
||||
}
|
||||
else if EQ("istable") {
|
||||
else if EQ(l_s("istable")) {
|
||||
lua_pushnumber(L, lua_istable(L, getnum));
|
||||
}
|
||||
else if EQ("iscfunction") {
|
||||
else if EQ(l_s("iscfunction")) {
|
||||
lua_pushnumber(L, lua_iscfunction(L, getnum));
|
||||
}
|
||||
else if EQ("isfunction") {
|
||||
else if EQ(l_s("isfunction")) {
|
||||
lua_pushnumber(L, lua_isfunction(L, getnum));
|
||||
}
|
||||
else if EQ("isuserdata") {
|
||||
else if EQ(l_s("isuserdata")) {
|
||||
lua_pushnumber(L, lua_isuserdata(L, getnum));
|
||||
}
|
||||
else if EQ("isnil") {
|
||||
else if EQ(l_s("isnil")) {
|
||||
lua_pushnumber(L, lua_isnil(L, getnum));
|
||||
}
|
||||
else if EQ("isnull") {
|
||||
else if EQ(l_s("isnull")) {
|
||||
lua_pushnumber(L, lua_isnull(L, getnum));
|
||||
}
|
||||
else if EQ("tonumber") {
|
||||
else if EQ(l_s("tonumber")) {
|
||||
lua_pushnumber(L, lua_tonumber(L, getnum));
|
||||
}
|
||||
else if EQ("tostring") {
|
||||
const char *s = lua_tostring(L, getnum);
|
||||
else if EQ(l_s("tostring")) {
|
||||
const l_char *s = lua_tostring(L, getnum);
|
||||
lua_pushstring(L, s);
|
||||
}
|
||||
else if EQ("tonumber") {
|
||||
else if EQ(l_s("tonumber")) {
|
||||
lua_pushnumber(L, lua_tonumber(L, getnum));
|
||||
}
|
||||
else if EQ("strlen") {
|
||||
else if EQ(l_s("strlen")) {
|
||||
lua_pushnumber(L, lua_strlen(L, getnum));
|
||||
}
|
||||
else if EQ("tocfunction") {
|
||||
else if EQ(l_s("tocfunction")) {
|
||||
lua_pushcfunction(L, lua_tocfunction(L, getnum));
|
||||
}
|
||||
else if EQ("return") {
|
||||
else if EQ(l_s("return")) {
|
||||
return getnum;
|
||||
}
|
||||
else if EQ("gettop") {
|
||||
else if EQ(l_s("gettop")) {
|
||||
lua_pushnumber(L, lua_gettop(L));
|
||||
}
|
||||
else if EQ("settop") {
|
||||
else if EQ(l_s("settop")) {
|
||||
lua_settop(L, getnum);
|
||||
}
|
||||
else if EQ("pop") {
|
||||
else if EQ(l_s("pop")) {
|
||||
lua_pop(L, getnum);
|
||||
}
|
||||
else if EQ("pushnum") {
|
||||
else if EQ(l_s("pushnum")) {
|
||||
lua_pushnumber(L, getnum);
|
||||
}
|
||||
else if EQ("pushvalue") {
|
||||
else if EQ(l_s("pushvalue")) {
|
||||
lua_pushvalue(L, getnum);
|
||||
}
|
||||
else if EQ("remove") {
|
||||
else if EQ(l_s("remove")) {
|
||||
lua_remove(L, getnum);
|
||||
}
|
||||
else if EQ("insert") {
|
||||
else if EQ(l_s("insert")) {
|
||||
lua_insert(L, getnum);
|
||||
}
|
||||
else if EQ("gettable") {
|
||||
else if EQ(l_s("gettable")) {
|
||||
lua_gettable(L, getnum);
|
||||
}
|
||||
else if EQ("settable") {
|
||||
else if EQ(l_s("settable")) {
|
||||
lua_settable(L, getnum);
|
||||
}
|
||||
else if EQ("next") {
|
||||
else if EQ(l_s("next")) {
|
||||
lua_next(L, -2);
|
||||
}
|
||||
else if EQ("concat") {
|
||||
else if EQ(l_s("concat")) {
|
||||
lua_concat(L, getnum);
|
||||
}
|
||||
else if EQ("lessthan") {
|
||||
else if EQ(l_s("lessthan")) {
|
||||
int a = getnum;
|
||||
if (lua_lessthan(L, a, getnum))
|
||||
lua_pushnumber(L, 1);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else if EQ("rawcall") {
|
||||
else if EQ(l_s("rawcall")) {
|
||||
int narg = getnum;
|
||||
int nres = getnum;
|
||||
lua_rawcall(L, narg, nres);
|
||||
}
|
||||
else if EQ("call") {
|
||||
else if EQ(l_s("call")) {
|
||||
int narg = getnum;
|
||||
int nres = getnum;
|
||||
lua_call(L, narg, nres);
|
||||
}
|
||||
else if EQ("dostring") {
|
||||
else if EQ(l_s("dostring")) {
|
||||
lua_dostring(L, luaL_check_string(L, getnum));
|
||||
}
|
||||
else if EQ("settagmethod") {
|
||||
else if EQ(l_s("settagmethod")) {
|
||||
int tag = getnum;
|
||||
const char *event = getname;
|
||||
const l_char *event = getname;
|
||||
lua_settagmethod(L, tag, event);
|
||||
}
|
||||
else if EQ("gettagmethod") {
|
||||
else if EQ(l_s("gettagmethod")) {
|
||||
int tag = getnum;
|
||||
const char *event = getname;
|
||||
const l_char *event = getname;
|
||||
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)));
|
||||
}
|
||||
else luaL_verror(L, "unknown instruction %.30s", buff);
|
||||
else luaL_verror(L, l_s("unknown instruction %.30s"), buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -643,30 +643,30 @@ static int testC (lua_State *L) {
|
||||
|
||||
|
||||
static const struct luaL_reg tests_funcs[] = {
|
||||
{"hash", hash_query},
|
||||
{"limits", get_limits},
|
||||
{"listcode", listcode},
|
||||
{"liststrings", liststrings},
|
||||
{"listlocals", listlocals},
|
||||
{"loadlib", loadlib},
|
||||
{"querystr", string_query},
|
||||
{"querytab", table_query},
|
||||
{"testC", testC},
|
||||
{"ref", tref},
|
||||
{"getref", getref},
|
||||
{"unref", unref},
|
||||
{"d2s", d2s},
|
||||
{"s2d", s2d},
|
||||
{"newuserdata", newuserdata},
|
||||
{"udataval", udataval},
|
||||
{"newtag", newtag},
|
||||
{"doonnewstack", doonnewstack},
|
||||
{"newstate", newstate},
|
||||
{"closestate", closestate},
|
||||
{"doremote", doremote},
|
||||
{"settagmethod", settagmethod},
|
||||
{"equal", equal},
|
||||
{"totalmem", mem_query}
|
||||
{l_s("hash"), hash_query},
|
||||
{l_s("limits"), get_limits},
|
||||
{l_s("listcode"), listcode},
|
||||
{l_s("liststrings"), liststrings},
|
||||
{l_s("listlocals"), listlocals},
|
||||
{l_s("loadlib"), loadlib},
|
||||
{l_s("querystr"), string_query},
|
||||
{l_s("querytab"), table_query},
|
||||
{l_s("testC"), testC},
|
||||
{l_s("ref"), tref},
|
||||
{l_s("getref"), getref},
|
||||
{l_s("unref"), unref},
|
||||
{l_s("d2s"), d2s},
|
||||
{l_s("s2d"), s2d},
|
||||
{l_s("newuserdata"), newuserdata},
|
||||
{l_s("udataval"), udataval},
|
||||
{l_s("newtag"), newtag},
|
||||
{l_s("doonnewstack"), doonnewstack},
|
||||
{l_s("newstate"), newstate},
|
||||
{l_s("closestate"), closestate},
|
||||
{l_s("doremote"), doremote},
|
||||
{l_s("settagmethod"), settagmethod},
|
||||
{l_s("equal"), equal},
|
||||
{l_s("totalmem"), mem_query}
|
||||
};
|
||||
|
||||
|
||||
@ -680,7 +680,7 @@ void luaB_opentests (lua_State *L) {
|
||||
lua_setglobals(L);
|
||||
luaL_openl(L, tests_funcs); /* open functions inside new table */
|
||||
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
|
||||
|
42
ltm.c
42
ltm.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -19,15 +19,15 @@
|
||||
#include "ltm.h"
|
||||
|
||||
|
||||
const char *const luaT_eventname[] = { /* ORDER TM */
|
||||
"gettable", "settable", "index", "getglobal", "setglobal", "add", "sub",
|
||||
"mul", "div", "pow", "unm", "lt", "concat", "gc", "function",
|
||||
"le", "gt", "ge", /* deprecated options!! */
|
||||
const l_char *const luaT_eventname[] = { /* ORDER TM */
|
||||
l_s("gettable"), l_s("settable"), l_s("index"), l_s("getglobal"), l_s("setglobal"), l_s("add"), l_s("sub"),
|
||||
l_s("mul"), l_s("div"), l_s("pow"), l_s("unm"), l_s("lt"), l_s("concat"), l_s("gc"), l_s("function"),
|
||||
l_s("le"), l_s("gt"), l_s("ge"), /* deprecated options!! */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static int findevent (const char *name) {
|
||||
static int findevent (const l_char *name) {
|
||||
int i;
|
||||
for (i=0; luaT_eventname[i]; i++)
|
||||
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);
|
||||
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)
|
||||
luaO_verror(L, "event `gc' for tables is deprecated");
|
||||
luaO_verror(L, l_s("event `gc' for tables is deprecated"));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -68,8 +68,8 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */
|
||||
|
||||
|
||||
void luaT_init (lua_State *L) {
|
||||
static const char *const typenames[NUM_TAGS] = {
|
||||
"userdata", "nil", "number", "string", "table", "function"
|
||||
static const l_char *const typenames[NUM_TAGS] = {
|
||||
l_s("userdata"), l_s("nil"), l_s("number"), l_s("string"), l_s("table"), l_s("function")
|
||||
};
|
||||
int 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 i;
|
||||
TString *ts;
|
||||
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;
|
||||
if (name == 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) {
|
||||
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 tag;
|
||||
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;
|
||||
LUA_LOCK(L);
|
||||
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;
|
||||
LUA_LOCK(L);
|
||||
e = luaI_checkevent(L, event, t);
|
||||
checktag(L, t);
|
||||
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),
|
||||
(t == LUA_TTABLE || t == LUA_TUSERDATA) ?
|
||||
" with default tag" : "");
|
||||
l_s(" with default tag") : l_s(""));
|
||||
switch (ttype(L->top - 1)) {
|
||||
case LUA_TNIL:
|
||||
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);
|
||||
break;
|
||||
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--;
|
||||
LUA_UNLOCK(L);
|
||||
|
8
ltm.h
8
ltm.h
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -67,12 +67,12 @@ struct TM {
|
||||
|
||||
#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);
|
||||
int luaT_newtag (lua_State *L, const char *name, int basictype);
|
||||
const char *luaT_typename (global_State *G, const TObject *o);
|
||||
int luaT_newtag (lua_State *L, const l_char *name, int basictype);
|
||||
const l_char *luaT_typename (global_State *G, const TObject *o);
|
||||
int luaT_tag (const TObject *o);
|
||||
int luaT_validevent (int t, int e); /* used by compatibility module */
|
||||
|
||||
|
106
lua.c
106
lua.c
@ -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
|
||||
** 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
|
||||
#define PROMPT "> "
|
||||
#define PROMPT l_s("> ")
|
||||
#endif
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ static void lstop (void) {
|
||||
lua_setlinehook(L, old_linehook);
|
||||
lua_setcallhook(L, old_callhook);
|
||||
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;
|
||||
handler h = lreset();
|
||||
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 */
|
||||
/* Lua gives no message in such cases, so lua.c provides one */
|
||||
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)
|
||||
fprintf(stderr, "lua: error in error message\n");
|
||||
fprintf(stderr, l_s("lua: error in error message\n"));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void print_message (void) {
|
||||
fprintf(stderr,
|
||||
"usage: lua [options]. Available options are:\n"
|
||||
" - execute stdin as a file\n"
|
||||
" -c close Lua when exiting\n"
|
||||
" -e stat execute string `stat'\n"
|
||||
" -f name execute file `name' with remaining arguments in table `arg'\n"
|
||||
" -i enter interactive mode with prompt\n"
|
||||
" -q enter interactive mode without prompt\n"
|
||||
" -sNUM set stack size to NUM (must be the first option)\n"
|
||||
" -v print version information\n"
|
||||
" a=b set global `a' to string `b'\n"
|
||||
" name execute file `name'\n"
|
||||
l_s("usage: lua [options]. Available options are:\n")
|
||||
l_s(" - execute stdin as a file\n")
|
||||
l_s(" -c close Lua when exiting\n")
|
||||
l_s(" -e stat execute string `stat'\n")
|
||||
l_s(" -f name execute file `name' with remaining arguments in table `arg'\n")
|
||||
l_s(" -i enter interactive mode with prompt\n")
|
||||
l_s(" -q enter interactive mode without prompt\n")
|
||||
l_s(" -sNUM set stack size to NUM (must be the first option)\n")
|
||||
l_s(" -v print version information\n")
|
||||
l_s(" a=b set global `a' to string `b'\n")
|
||||
l_s(" name execute file `name'\n")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
char *eq = strchr(arg, '=');
|
||||
*eq = '\0'; /* spilt `arg' in two strings (name & value) */
|
||||
static void assign (l_char *arg) {
|
||||
l_char *eq = strchr(arg, l_c('='));
|
||||
*eq = l_c('\0'); /* spilt `arg' in two strings (name & value) */
|
||||
lua_pushstring(L, eq+1);
|
||||
lua_setglobal(L, arg);
|
||||
}
|
||||
|
||||
|
||||
static void getargs (char *argv[]) {
|
||||
static void getargs (l_char *argv[]) {
|
||||
int i;
|
||||
lua_newtable(L);
|
||||
for (i=0; argv[i]; i++) {
|
||||
@ -140,24 +140,24 @@ static void getargs (char *argv[]) {
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
/* arg.n = maximum index in table `arg' */
|
||||
lua_pushliteral(L, "n");
|
||||
lua_pushliteral(L, l_s("n"));
|
||||
lua_pushnumber(L, i-1);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int file_input (const char *argv) {
|
||||
static int file_input (const l_char *argv) {
|
||||
int result = ldo(lua_dofile, argv);
|
||||
if (result) {
|
||||
if (result == LUA_ERRFILE) {
|
||||
fprintf(stderr, "lua: cannot execute file ");
|
||||
fprintf(stderr, l_s("lua: cannot execute file "));
|
||||
perror(argv);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
@ -173,12 +173,12 @@ static int file_input (const char *argv) {
|
||||
#endif
|
||||
|
||||
|
||||
static const char *get_prompt (int prompt) {
|
||||
static const l_char *get_prompt (int prompt) {
|
||||
if (!prompt)
|
||||
return "";
|
||||
return l_s("");
|
||||
else {
|
||||
const char *s;
|
||||
lua_getglobal(L, "_PROMPT");
|
||||
const l_char *s;
|
||||
lua_getglobal(L, l_s("_PROMPT"));
|
||||
s = lua_tostring(L, -1);
|
||||
if (!s) s = PROMPT;
|
||||
lua_pop(L, 1); /* remove global */
|
||||
@ -192,15 +192,15 @@ static void manual_input (int version, int prompt) {
|
||||
for (;;) {
|
||||
fputs(get_prompt(prompt), stdout); /* show prompt */
|
||||
for(;;) {
|
||||
char buffer[MAXINPUT];
|
||||
l_char buffer[MAXINPUT];
|
||||
size_t l;
|
||||
if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
|
||||
printf("\n");
|
||||
printf(l_s("\n"));
|
||||
return;
|
||||
}
|
||||
l = strlen(buffer);
|
||||
if (buffer[l-1] == '\n' && buffer[l-2] == '\\') {
|
||||
buffer[l-2] = '\n';
|
||||
if (buffer[l-1] == l_c('\n') && buffer[l-2] == l_c('\\')) {
|
||||
buffer[l-2] = l_c('\n');
|
||||
lua_pushlstring(L, buffer, l-1);
|
||||
}
|
||||
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 (*argv == NULL) { /* no more arguments? */
|
||||
if (isatty(0)) {
|
||||
@ -227,8 +227,8 @@ static int handle_argv (char *argv[], struct Options *opt) {
|
||||
else { /* other arguments; loop over them */
|
||||
int i;
|
||||
for (i = 0; argv[i] != NULL; i++) {
|
||||
if (argv[i][0] != '-') { /* not an option? */
|
||||
if (strchr(argv[i], '='))
|
||||
if (argv[i][0] != l_c('-')) { /* not an option? */
|
||||
if (strchr(argv[i], l_c('=')))
|
||||
assign(argv[i]);
|
||||
else
|
||||
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 */
|
||||
break;
|
||||
}
|
||||
case 'i': {
|
||||
case l_c('i'): {
|
||||
manual_input(0, 1);
|
||||
break;
|
||||
}
|
||||
case 'q': {
|
||||
case l_c('q'): {
|
||||
manual_input(0, 0);
|
||||
break;
|
||||
}
|
||||
case 'c': {
|
||||
case l_c('c'): {
|
||||
opt->toclose = 1;
|
||||
break;
|
||||
}
|
||||
case 'v': {
|
||||
case l_c('v'): {
|
||||
print_version();
|
||||
break;
|
||||
}
|
||||
case 'e': {
|
||||
case l_c('e'): {
|
||||
i++;
|
||||
if (argv[i] == NULL) {
|
||||
print_message();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
case l_c('f'): {
|
||||
i++;
|
||||
if (argv[i] == NULL) {
|
||||
print_message();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
getargs(argv+i); /* collect remaining arguments */
|
||||
lua_setglobal(L, "arg");
|
||||
lua_setglobal(L, l_s("arg"));
|
||||
return file_input(argv[i]); /* stop scanning arguments */
|
||||
}
|
||||
case 's': {
|
||||
fprintf(stderr, "lua: stack size (`-s') must be the first option\n");
|
||||
case l_c('s'): {
|
||||
fprintf(stderr, l_s("lua: stack size (`-s') must be the first option\n"));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default: {
|
||||
@ -292,11 +292,11 @@ static int handle_argv (char *argv[], struct Options *opt) {
|
||||
}
|
||||
|
||||
|
||||
static void getstacksize (int argc, char *argv[], struct Options *opt) {
|
||||
if (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 's') {
|
||||
static void getstacksize (int argc, l_char *argv[], struct Options *opt) {
|
||||
if (argc >= 2 && argv[1][0] == l_c('-') && argv[1][1] == l_c('s')) {
|
||||
int stacksize = atoi(&argv[1][2]);
|
||||
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);
|
||||
}
|
||||
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_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;
|
||||
int status;
|
||||
opt.toclose = 0;
|
||||
|
41
lua.h
41
lua.h
@ -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
|
||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||
** e-mail: lua@tecgraf.puc-rio.br
|
||||
@ -79,6 +79,8 @@ typedef int (*lua_CFunction) (lua_State *L);
|
||||
/* Lua numerical type */
|
||||
typedef double lua_Number;
|
||||
|
||||
/* Lua character type */
|
||||
typedef char l_char;
|
||||
|
||||
|
||||
/* 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 const 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_typename (lua_State *L, int t);
|
||||
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_isstring (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 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 lua_CFunction lua_tocfunction (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_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_pushstring (lua_State *L, const char *s);
|
||||
LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len);
|
||||
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 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)
|
||||
*/
|
||||
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_rawget (lua_State *L, int index);
|
||||
LUA_API void lua_rawgeti (lua_State *L, int index, int n);
|
||||
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 void lua_newtable (lua_State *L);
|
||||
|
||||
@ -156,23 +158,24 @@ LUA_API void lua_newtable (lua_State *L);
|
||||
/*
|
||||
** 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_rawset (lua_State *L, int index);
|
||||
LUA_API void lua_rawseti (lua_State *L, int index, int n);
|
||||
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);
|
||||
|
||||
|
||||
/*
|
||||
** "do" functions (run Lua code)
|
||||
** `do' functions (run Lua code)
|
||||
*/
|
||||
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 int lua_dofile (lua_State *L, const char *filename);
|
||||
LUA_API int lua_dostring (lua_State *L, const char *str);
|
||||
LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name);
|
||||
LUA_API int lua_dofile (lua_State *L, const l_char *filename);
|
||||
LUA_API int lua_dostring (lua_State *L, const l_char *str);
|
||||
LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size,
|
||||
const l_char *name);
|
||||
|
||||
/*
|
||||
** Garbage-collection functions
|
||||
@ -184,12 +187,12 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold);
|
||||
/*
|
||||
** miscellaneous functions
|
||||
*/
|
||||
LUA_API int lua_newtype (lua_State *L, const char *name, int basictype);
|
||||
LUA_API int lua_type2tag (lua_State *L, const char *name);
|
||||
LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype);
|
||||
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 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);
|
||||
|
||||
@ -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_pushliteral(L, s) lua_pushlstring(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1)
|
||||
#define lua_pushliteral(L, s) lua_pushlstring(L, l_s("") s, \
|
||||
(sizeof(s)/sizeof(l_char))-1)
|
||||
|
||||
|
||||
|
||||
|
20
luadebug.h
20
luadebug.h
@ -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
|
||||
** 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_getinfo (lua_State *L, const char *what, lua_Debug *ar);
|
||||
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 int lua_getinfo (lua_State *L, const l_char *what, lua_Debug *ar);
|
||||
LUA_API const l_char *lua_getlocal (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_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
|
||||
|
||||
struct lua_Debug {
|
||||
const char *event; /* `call', `return' */
|
||||
const l_char *event; /* `call', `return' */
|
||||
int currentline; /* (l) */
|
||||
const char *name; /* (n) */
|
||||
const char *namewhat; /* (n) `global', `tag method', `local', `field' */
|
||||
const l_char *name; /* (n) */
|
||||
const l_char *namewhat; /* (n) `global', `tag method', `local', `field' */
|
||||
int nups; /* (u) number of upvalues */
|
||||
int linedefined; /* (S) */
|
||||
const char *what; /* (S) `Lua' function, `C' function, Lua `main' */
|
||||
const char *source; /* (S) */
|
||||
char short_src[LUA_IDSIZE]; /* (S) */
|
||||
const l_char *what; /* (S) `Lua' function, `C' function, Lua `main' */
|
||||
const l_char *source; /* (S) */
|
||||
l_char short_src[LUA_IDSIZE]; /* (S) */
|
||||
/* private part */
|
||||
struct lua_TObject *_func; /* active function */
|
||||
};
|
||||
|
12
lualib.h
12
lualib.h
@ -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
|
||||
** 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 */
|
||||
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
|
||||
|
50
lundump.c
50
lundump.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -15,15 +15,15 @@
|
||||
|
||||
#define LoadByte ezgetc
|
||||
|
||||
static const char* ZNAME (ZIO* Z)
|
||||
static const l_char* ZNAME (ZIO* Z)
|
||||
{
|
||||
const char* s=zname(Z);
|
||||
return (*s=='@') ? s+1 : s;
|
||||
const l_char* s=zname(Z);
|
||||
return (*s==l_c('@')) ? s+1 : s;
|
||||
}
|
||||
|
||||
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)
|
||||
@ -43,9 +43,9 @@ static void LoadBlock (lua_State* L, void* b, size_t size, ZIO* Z, int swap)
|
||||
{
|
||||
if (swap)
|
||||
{
|
||||
char *p=(char *) b+size-1;
|
||||
l_char *p=(l_char *) b+size-1;
|
||||
int n=size;
|
||||
while (n--) *p--=(char)ezgetc(L,Z);
|
||||
while (n--) *p--=(l_char)ezgetc(L,Z);
|
||||
}
|
||||
else
|
||||
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)
|
||||
{
|
||||
char *q=(char *) b;
|
||||
l_char *q=(l_char *) b;
|
||||
while (m--)
|
||||
{
|
||||
char *p=q+size-1;
|
||||
l_char *p=q+size-1;
|
||||
int n=size;
|
||||
while (n--) *p--=(char)ezgetc(L,Z);
|
||||
while (n--) *p--=(l_char)ezgetc(L,Z);
|
||||
q+=size;
|
||||
}
|
||||
}
|
||||
@ -96,9 +96,9 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap)
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
char* s=luaO_openspace(L,size);
|
||||
l_char* s=luaO_openspace(L,size);
|
||||
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)
|
||||
{
|
||||
const char* s=SIGNATURE;
|
||||
const l_char* s=SIGNATURE;
|
||||
while (*s!=0 && ezgetc(L,Z)==*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);
|
||||
if (r!=s)
|
||||
luaO_verror(L,"virtual machine mismatch in `%.99s':\n"
|
||||
" %.20s is %d but read %d",ZNAME(Z),what,s,r);
|
||||
luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n")
|
||||
l_s(" %.20s is %d but read %d"),ZNAME(Z),what,s,r);
|
||||
}
|
||||
|
||||
#define TESTSIZE(s) TestSize(L,s,#s,Z)
|
||||
@ -195,12 +195,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
|
||||
LoadSignature(L,Z);
|
||||
version=ezgetc(L,Z);
|
||||
if (version>VERSION)
|
||||
luaO_verror(L,"`%.99s' too new:\n"
|
||||
" read version %d.%d; expected at most %d.%d",
|
||||
luaO_verror(L,l_s("`%.99s' too new:\n")
|
||||
l_s(" read version %d.%d; expected at most %d.%d"),
|
||||
ZNAME(Z),V(version),V(VERSION));
|
||||
if (version<VERSION0) /* check last major change */
|
||||
luaO_verror(L,"`%.99s' too old:\n"
|
||||
" read version %d.%d; expected at least %d.%d",
|
||||
luaO_verror(L,l_s("`%.99s' too old:\n")
|
||||
l_s(" read version %d.%d; expected at least %d.%d"),
|
||||
ZNAME(Z),V(version),V(VERSION));
|
||||
swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */
|
||||
TESTSIZE(sizeof(int));
|
||||
@ -212,8 +212,8 @@ static int LoadHeader (lua_State* L, ZIO* Z)
|
||||
TESTSIZE(sizeof(lua_Number));
|
||||
f=LoadNumber(L,Z,swap);
|
||||
if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
|
||||
luaO_verror(L,"unknown number format in `%.99s':\n"
|
||||
" read " NUMBER_FMT "; expected " NUMBER_FMT, ZNAME(Z),f,tf);
|
||||
luaO_verror(L,l_s("unknown number format in `%.99s':\n")
|
||||
l_s(" read ") NUMBER_FMT l_s("; expected ") NUMBER_FMT, ZNAME(Z),f,tf);
|
||||
return swap;
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
|
||||
tf=LoadChunk(L,Z);
|
||||
c=zgetc(Z);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -244,5 +244,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
|
||||
int luaU_endianess (void)
|
||||
{
|
||||
int x=1;
|
||||
return *(char*)&x;
|
||||
return *(l_char*)&x;
|
||||
}
|
||||
|
@ -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
|
||||
** 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 VERSION0 0x40 /* last major change was in 4.0 */
|
||||
#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 */
|
||||
#define SOURCE_FMT "<%d:%.99s>"
|
||||
#define SOURCE_FMT l_s("<%d:%.99s>")
|
||||
#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
|
||||
|
||||
/* a multiple of PI for testing native format */
|
||||
|
54
lvm.c
54
lvm.c
@ -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
|
||||
** 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)
|
||||
return 1;
|
||||
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 */
|
||||
setsvalue(obj, luaS_new(L, s));
|
||||
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;
|
||||
StkId base = L->top;
|
||||
int has_result = 0;
|
||||
va_start(argp, fmt);
|
||||
while (*fmt) {
|
||||
switch (*fmt++) {
|
||||
case 'c':
|
||||
case l_c('c'):
|
||||
setclvalue(L->top, va_arg(argp, Closure *));
|
||||
break;
|
||||
case 'o':
|
||||
case l_c('o'):
|
||||
setobj(L->top, va_arg(argp, TObject *));
|
||||
break;
|
||||
case 's':
|
||||
case l_c('s'):
|
||||
setsvalue(L->top, va_arg(argp, TString *));
|
||||
break;
|
||||
case 'r':
|
||||
case l_c('r'):
|
||||
has_result = 1;
|
||||
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 */
|
||||
tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE);
|
||||
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 */
|
||||
tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE);
|
||||
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 */
|
||||
}
|
||||
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 */
|
||||
}
|
||||
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]);
|
||||
callTM(L, "coosr", tm, p1, p2, opname, res);
|
||||
callTM(L, l_s("coosr"), tm, p1, p2, opname, res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void call_arith (lua_State *L, StkId p1, TMS 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) {
|
||||
const char *l = getstr(ls);
|
||||
const l_char *l = getstr(ls);
|
||||
size_t ll = ls->len;
|
||||
const char *r = getstr(rs);
|
||||
const l_char *r = getstr(rs);
|
||||
size_t lr = rs->len;
|
||||
for (;;) {
|
||||
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) */
|
||||
if (tostring(L, top-2) || tostring(L, top-1)) {
|
||||
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 */
|
||||
/* 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;
|
||||
char *buffer;
|
||||
l_char *buffer;
|
||||
int i;
|
||||
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
|
||||
tl += tsvalue(top-n-1)->len;
|
||||
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);
|
||||
tl = 0;
|
||||
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++)
|
||||
setobj(luaH_setnum(L, htab, i+1), firstelem+i);
|
||||
/* 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);
|
||||
L->top = firstelem; /* remove elements from the stack */
|
||||
sethvalue(L->top, htab);
|
||||
@ -509,7 +509,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
|
||||
}
|
||||
case OP_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--;
|
||||
break;
|
||||
}
|
||||
@ -595,11 +595,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
|
||||
case OP_FORPREP: {
|
||||
int jmp = GETARG_S(i);
|
||||
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))
|
||||
luaD_error(L, "`for' limit must be a number");
|
||||
luaD_error(L, l_s("`for' limit must be a number"));
|
||||
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) */
|
||||
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-2) == 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 */
|
||||
forloop:
|
||||
if (nvalue(top-1) > 0 ?
|
||||
@ -621,7 +621,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
|
||||
case OP_LFORPREP: {
|
||||
int jmp = GETARG_S(i);
|
||||
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 */
|
||||
setnvalue(top-3, -1); /* initial index */
|
||||
setnilvalue(top-2);
|
||||
|
Loading…
Reference in New Issue
Block a user