mirror of https://github.com/rusefi/lua.git
"const" !!!
This commit is contained in:
parent
b44e35b773
commit
c787dccd9b
153
lapi.c
153
lapi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 1.46 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: lapi.c,v 1.47 1999/06/22 20:37:23 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
#include "lvm.h"
|
#include "lvm.h"
|
||||||
|
|
||||||
|
|
||||||
char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
|
const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
|
||||||
"$Authors: " LUA_AUTHORS " $";
|
"$Authors: " LUA_AUTHORS " $";
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,8 +34,7 @@ TObject *luaA_Address (lua_Object o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static lua_Type normalized_type (TObject *o)
|
static lua_Type normalized_type (const TObject *o) {
|
||||||
{
|
|
||||||
int t = ttype(o);
|
int t = ttype(o);
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case LUA_T_PMARK:
|
case LUA_T_PMARK:
|
||||||
|
@ -50,21 +49,18 @@ static lua_Type normalized_type (TObject *o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void set_normalized (TObject *d, TObject *s)
|
static void set_normalized (TObject *d, const TObject *s) {
|
||||||
{
|
|
||||||
d->value = s->value;
|
d->value = s->value;
|
||||||
d->ttype = normalized_type(s);
|
d->ttype = normalized_type(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static TObject *luaA_protovalue (TObject *o)
|
static const TObject *luaA_protovalue (const TObject *o) {
|
||||||
{
|
|
||||||
return (normalized_type(o) == LUA_T_CLOSURE) ? protovalue(o) : o;
|
return (normalized_type(o) == LUA_T_CLOSURE) ? protovalue(o) : o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaA_packresults (void)
|
void luaA_packresults (void) {
|
||||||
{
|
|
||||||
luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top);
|
luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top);
|
||||||
incr_top;
|
incr_top;
|
||||||
}
|
}
|
||||||
|
@ -76,14 +72,13 @@ int luaA_passresults (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void checkCparams (int nParams)
|
static void checkCparams (int nParams) {
|
||||||
{
|
|
||||||
if (L->stack.top-L->stack.stack < L->Cstack.base+nParams)
|
if (L->stack.top-L->stack.stack < L->Cstack.base+nParams)
|
||||||
lua_error("API error - wrong number of arguments in C2lua stack");
|
lua_error("API error - wrong number of arguments in C2lua stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static lua_Object put_luaObject (TObject *o) {
|
static lua_Object put_luaObject (const TObject *o) {
|
||||||
luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
|
luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
|
||||||
L->stack.stack[L->Cstack.base++] = *o;
|
L->stack.stack[L->Cstack.base++] = *o;
|
||||||
return L->Cstack.base; /* this is +1 real position (see Ref) */
|
return L->Cstack.base; /* this is +1 real position (see Ref) */
|
||||||
|
@ -115,8 +110,7 @@ lua_Object lua_pop (void) {
|
||||||
** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
|
** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
|
||||||
** 'number' must be 1 to get the first parameter.
|
** 'number' must be 1 to get the first parameter.
|
||||||
*/
|
*/
|
||||||
lua_Object lua_lua2C (int number)
|
lua_Object lua_lua2C (int number) {
|
||||||
{
|
|
||||||
if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
|
if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
|
||||||
/* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) ==
|
/* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) ==
|
||||||
L->stack.stack+(L->Cstack.lua2C+number-1)-L->stack.stack+1 == */
|
L->stack.stack+(L->Cstack.lua2C+number-1)-L->stack.stack+1 == */
|
||||||
|
@ -124,8 +118,7 @@ lua_Object lua_lua2C (int number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_callfunction (lua_Object function)
|
int lua_callfunction (lua_Object function) {
|
||||||
{
|
|
||||||
if (function == LUA_NOOBJECT)
|
if (function == LUA_NOOBJECT)
|
||||||
return 1;
|
return 1;
|
||||||
else {
|
else {
|
||||||
|
@ -136,14 +129,12 @@ int lua_callfunction (lua_Object function)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_gettagmethod (int tag, char *event)
|
lua_Object lua_gettagmethod (int tag, const char *event) {
|
||||||
{
|
|
||||||
return put_luaObject(luaT_gettagmethod(tag, event));
|
return put_luaObject(luaT_gettagmethod(tag, event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_settagmethod (int tag, char *event)
|
lua_Object lua_settagmethod (int tag, const char *event) {
|
||||||
{
|
|
||||||
checkCparams(1);
|
checkCparams(1);
|
||||||
luaT_settagmethod(tag, event, L->stack.top-1);
|
luaT_settagmethod(tag, event, L->stack.top-1);
|
||||||
return put_luaObjectonTop();
|
return put_luaObjectonTop();
|
||||||
|
@ -159,8 +150,7 @@ lua_Object lua_seterrormethod (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_gettable (void)
|
lua_Object lua_gettable (void) {
|
||||||
{
|
|
||||||
checkCparams(2);
|
checkCparams(2);
|
||||||
luaV_gettable();
|
luaV_gettable();
|
||||||
return put_luaObjectonTop();
|
return put_luaObjectonTop();
|
||||||
|
@ -190,8 +180,7 @@ void lua_rawsettable (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_createtable (void)
|
lua_Object lua_createtable (void) {
|
||||||
{
|
|
||||||
TObject o;
|
TObject o;
|
||||||
luaC_checkGC();
|
luaC_checkGC();
|
||||||
avalue(&o) = luaH_new(0);
|
avalue(&o) = luaH_new(0);
|
||||||
|
@ -200,31 +189,27 @@ lua_Object lua_createtable (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_getglobal (char *name)
|
lua_Object lua_getglobal (const char *name) {
|
||||||
{
|
|
||||||
luaD_checkstack(2); /* may need that to call T.M. */
|
luaD_checkstack(2); /* may need that to call T.M. */
|
||||||
luaV_getglobal(luaS_new(name));
|
luaV_getglobal(luaS_new(name));
|
||||||
return put_luaObjectonTop();
|
return put_luaObjectonTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_rawgetglobal (char *name)
|
lua_Object lua_rawgetglobal (const char *name) {
|
||||||
{
|
|
||||||
TaggedString *ts = luaS_new(name);
|
TaggedString *ts = luaS_new(name);
|
||||||
return put_luaObject(&ts->u.s.globalval);
|
return put_luaObject(&ts->u.s.globalval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_setglobal (char *name)
|
void lua_setglobal (const char *name) {
|
||||||
{
|
|
||||||
checkCparams(1);
|
checkCparams(1);
|
||||||
luaD_checkstack(2); /* may need that to call T.M. */
|
luaD_checkstack(2); /* may need that to call T.M. */
|
||||||
luaV_setglobal(luaS_new(name));
|
luaV_setglobal(luaS_new(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_rawsetglobal (char *name)
|
void lua_rawsetglobal (const char *name) {
|
||||||
{
|
|
||||||
TaggedString *ts = luaS_new(name);
|
TaggedString *ts = luaS_new(name);
|
||||||
checkCparams(1);
|
checkCparams(1);
|
||||||
luaS_rawsetglobal(ts, --L->stack.top);
|
luaS_rawsetglobal(ts, --L->stack.top);
|
||||||
|
@ -232,113 +217,96 @@ void lua_rawsetglobal (char *name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int lua_isnil (lua_Object o)
|
int lua_isnil (lua_Object o) {
|
||||||
{
|
|
||||||
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL);
|
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_istable (lua_Object o)
|
int lua_istable (lua_Object o) {
|
||||||
{
|
|
||||||
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY);
|
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_isuserdata (lua_Object o)
|
int lua_isuserdata (lua_Object o) {
|
||||||
{
|
|
||||||
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA);
|
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_iscfunction (lua_Object o)
|
int lua_iscfunction (lua_Object o) {
|
||||||
{
|
|
||||||
return (lua_tag(o) == LUA_T_CPROTO);
|
return (lua_tag(o) == LUA_T_CPROTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_isnumber (lua_Object o)
|
int lua_isnumber (lua_Object o) {
|
||||||
{
|
|
||||||
return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
|
return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_isstring (lua_Object o)
|
int lua_isstring (lua_Object o) {
|
||||||
{
|
|
||||||
int t = lua_tag(o);
|
int t = lua_tag(o);
|
||||||
return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
|
return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_isfunction (lua_Object o)
|
int lua_isfunction (lua_Object o) {
|
||||||
{
|
|
||||||
int t = lua_tag(o);
|
int t = lua_tag(o);
|
||||||
return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO);
|
return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double lua_getnumber (lua_Object object)
|
double lua_getnumber (lua_Object object) {
|
||||||
{
|
|
||||||
if (object == LUA_NOOBJECT) return 0.0;
|
if (object == LUA_NOOBJECT) return 0.0;
|
||||||
if (tonumber(Address(object))) return 0.0;
|
if (tonumber(Address(object))) return 0.0;
|
||||||
else return (nvalue(Address(object)));
|
else return (nvalue(Address(object)));
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lua_getstring (lua_Object object)
|
const char *lua_getstring (lua_Object object) {
|
||||||
{
|
|
||||||
luaC_checkGC(); /* "tostring" may create a new string */
|
luaC_checkGC(); /* "tostring" may create a new string */
|
||||||
if (object == LUA_NOOBJECT || tostring(Address(object)))
|
if (object == LUA_NOOBJECT || tostring(Address(object)))
|
||||||
return NULL;
|
return NULL;
|
||||||
else return (svalue(Address(object)));
|
else return (svalue(Address(object)));
|
||||||
}
|
}
|
||||||
|
|
||||||
long lua_strlen (lua_Object object)
|
long lua_strlen (lua_Object object) {
|
||||||
{
|
|
||||||
luaC_checkGC(); /* "tostring" may create a new string */
|
luaC_checkGC(); /* "tostring" may create a new string */
|
||||||
if (object == LUA_NOOBJECT || tostring(Address(object)))
|
if (object == LUA_NOOBJECT || tostring(Address(object)))
|
||||||
return 0L;
|
return 0L;
|
||||||
else return (tsvalue(Address(object))->u.s.len);
|
else return (tsvalue(Address(object))->u.s.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *lua_getuserdata (lua_Object object)
|
void *lua_getuserdata (lua_Object object) {
|
||||||
{
|
|
||||||
if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
|
if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
|
||||||
return NULL;
|
return NULL;
|
||||||
else return tsvalue(Address(object))->u.d.v;
|
else return tsvalue(Address(object))->u.d.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_CFunction lua_getcfunction (lua_Object object)
|
lua_CFunction lua_getcfunction (lua_Object object) {
|
||||||
{
|
|
||||||
if (!lua_iscfunction(object))
|
if (!lua_iscfunction(object))
|
||||||
return NULL;
|
return NULL;
|
||||||
else return fvalue(luaA_protovalue(Address(object)));
|
else return fvalue(luaA_protovalue(Address(object)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_pushnil (void)
|
void lua_pushnil (void) {
|
||||||
{
|
|
||||||
ttype(L->stack.top) = LUA_T_NIL;
|
ttype(L->stack.top) = LUA_T_NIL;
|
||||||
incr_top;
|
incr_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_pushnumber (double n)
|
void lua_pushnumber (double n) {
|
||||||
{
|
|
||||||
ttype(L->stack.top) = LUA_T_NUMBER;
|
ttype(L->stack.top) = LUA_T_NUMBER;
|
||||||
nvalue(L->stack.top) = n;
|
nvalue(L->stack.top) = n;
|
||||||
incr_top;
|
incr_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_pushlstring (char *s, long len)
|
void lua_pushlstring (const char *s, long len) {
|
||||||
{
|
|
||||||
tsvalue(L->stack.top) = luaS_newlstr(s, len);
|
tsvalue(L->stack.top) = luaS_newlstr(s, len);
|
||||||
ttype(L->stack.top) = LUA_T_STRING;
|
ttype(L->stack.top) = LUA_T_STRING;
|
||||||
incr_top;
|
incr_top;
|
||||||
luaC_checkGC();
|
luaC_checkGC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_pushstring (char *s)
|
void lua_pushstring (const char *s) {
|
||||||
{
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
lua_pushnil();
|
lua_pushnil();
|
||||||
else
|
else
|
||||||
lua_pushlstring(s, strlen(s));
|
lua_pushlstring(s, strlen(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_pushcclosure (lua_CFunction fn, int n)
|
void lua_pushcclosure (lua_CFunction fn, int n) {
|
||||||
{
|
|
||||||
if (fn == NULL)
|
if (fn == NULL)
|
||||||
lua_error("API error - attempt to push a NULL Cfunction");
|
lua_error("API error - attempt to push a NULL Cfunction");
|
||||||
checkCparams(n);
|
checkCparams(n);
|
||||||
|
@ -349,8 +317,7 @@ void lua_pushcclosure (lua_CFunction fn, int n)
|
||||||
luaC_checkGC();
|
luaC_checkGC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_pushusertag (void *u, int tag)
|
void lua_pushusertag (void *u, int tag) {
|
||||||
{
|
|
||||||
if (tag < 0 && tag != LUA_ANYTAG)
|
if (tag < 0 && tag != LUA_ANYTAG)
|
||||||
luaT_realtag(tag); /* error if tag is not valid */
|
luaT_realtag(tag); /* error if tag is not valid */
|
||||||
tsvalue(L->stack.top) = luaS_createudata(u, tag);
|
tsvalue(L->stack.top) = luaS_createudata(u, tag);
|
||||||
|
@ -359,8 +326,7 @@ void lua_pushusertag (void *u, int tag)
|
||||||
luaC_checkGC();
|
luaC_checkGC();
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaA_pushobject (TObject *o)
|
void luaA_pushobject (const TObject *o) {
|
||||||
{
|
|
||||||
*L->stack.top = *o;
|
*L->stack.top = *o;
|
||||||
incr_top;
|
incr_top;
|
||||||
}
|
}
|
||||||
|
@ -373,12 +339,11 @@ void lua_pushobject (lua_Object o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_tag (lua_Object lo)
|
int lua_tag (lua_Object lo) {
|
||||||
{
|
|
||||||
if (lo == LUA_NOOBJECT)
|
if (lo == LUA_NOOBJECT)
|
||||||
return LUA_T_NIL;
|
return LUA_T_NIL;
|
||||||
else {
|
else {
|
||||||
TObject *o = Address(lo);
|
const TObject *o = Address(lo);
|
||||||
int t;
|
int t;
|
||||||
switch (t = ttype(o)) {
|
switch (t = ttype(o)) {
|
||||||
case LUA_T_USERDATA:
|
case LUA_T_USERDATA:
|
||||||
|
@ -402,8 +367,7 @@ int lua_tag (lua_Object lo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_settag (int tag)
|
void lua_settag (int tag) {
|
||||||
{
|
|
||||||
checkCparams(1);
|
checkCparams(1);
|
||||||
luaT_realtag(tag);
|
luaT_realtag(tag);
|
||||||
switch (ttype(L->stack.top-1)) {
|
switch (ttype(L->stack.top-1)) {
|
||||||
|
@ -440,7 +404,7 @@ TaggedString *luaA_nextvar (TaggedString *g) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *lua_nextvar (char *varname) {
|
const char *lua_nextvar (const char *varname) {
|
||||||
TaggedString *g = (varname == NULL) ? NULL : luaS_new(varname);
|
TaggedString *g = (varname == NULL) ? NULL : luaS_new(varname);
|
||||||
g = luaA_nextvar(g);
|
g = luaA_nextvar(g);
|
||||||
if (g) {
|
if (g) {
|
||||||
|
@ -454,7 +418,7 @@ char *lua_nextvar (char *varname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int luaA_next (Hash *t, int i) {
|
int luaA_next (const Hash *t, int i) {
|
||||||
int tsize = nhash(t);
|
int tsize = nhash(t);
|
||||||
for (; i<tsize; i++) {
|
for (; i<tsize; i++) {
|
||||||
Node *n = node(t, i);
|
Node *n = node(t, i);
|
||||||
|
@ -469,7 +433,7 @@ int luaA_next (Hash *t, int i) {
|
||||||
|
|
||||||
|
|
||||||
int lua_next (lua_Object o, int i) {
|
int lua_next (lua_Object o, int i) {
|
||||||
TObject *t = Address(o);
|
const TObject *t = Address(o);
|
||||||
if (ttype(t) != LUA_T_ARRAY)
|
if (ttype(t) != LUA_T_ARRAY)
|
||||||
lua_error("API error - object is not a table in `lua_next'");
|
lua_error("API error - object is not a table in `lua_next'");
|
||||||
i = luaA_next(avalue(t), i);
|
i = luaA_next(avalue(t), i);
|
||||||
|
@ -519,8 +483,7 @@ int lua_setdebug (int debug) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
lua_Function lua_stackedfunction (int level)
|
lua_Function lua_stackedfunction (int level) {
|
||||||
{
|
|
||||||
StkId i;
|
StkId i;
|
||||||
for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) {
|
for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) {
|
||||||
int t = L->stack.stack[i].ttype;
|
int t = L->stack.stack[i].ttype;
|
||||||
|
@ -533,20 +496,20 @@ lua_Function lua_stackedfunction (int level)
|
||||||
|
|
||||||
|
|
||||||
int lua_nups (lua_Function func) {
|
int lua_nups (lua_Function func) {
|
||||||
TObject *o = luaA_Address(func);
|
const TObject *o = luaA_Address(func);
|
||||||
return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems;
|
return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_currentline (lua_Function func)
|
int lua_currentline (lua_Function func) {
|
||||||
{
|
const TObject *f = Address(func);
|
||||||
TObject *f = Address(func);
|
|
||||||
return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ?
|
return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ?
|
||||||
(f+1)->value.i : -1;
|
(f+1)->value.i : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_getlocal (lua_Function func, int local_number, char **name) {
|
lua_Object lua_getlocal (lua_Function func, int local_number,
|
||||||
|
const char **name) {
|
||||||
/* check whether func is a Lua function */
|
/* check whether func is a Lua function */
|
||||||
if (lua_tag(func) != LUA_T_PROTO)
|
if (lua_tag(func) != LUA_T_PROTO)
|
||||||
return LUA_NOOBJECT;
|
return LUA_NOOBJECT;
|
||||||
|
@ -565,15 +528,14 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_setlocal (lua_Function func, int local_number)
|
int lua_setlocal (lua_Function func, int local_number) {
|
||||||
{
|
|
||||||
/* check whether func is a Lua function */
|
/* check whether func is a Lua function */
|
||||||
if (lua_tag(func) != LUA_T_PROTO)
|
if (lua_tag(func) != LUA_T_PROTO)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
TObject *f = Address(func);
|
TObject *f = Address(func);
|
||||||
TProtoFunc *fp = luaA_protovalue(f)->value.tf;
|
TProtoFunc *fp = luaA_protovalue(f)->value.tf;
|
||||||
char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
|
const char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
|
||||||
checkCparams(1);
|
checkCparams(1);
|
||||||
--L->stack.top;
|
--L->stack.top;
|
||||||
if (name) {
|
if (name) {
|
||||||
|
@ -588,11 +550,11 @@ int lua_setlocal (lua_Function func, int local_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_funcinfo (lua_Object func, char **source, int *linedefined) {
|
void lua_funcinfo (lua_Object func, const char **source, int *linedefined) {
|
||||||
if (!lua_isfunction(func))
|
if (!lua_isfunction(func))
|
||||||
lua_error("API error - `funcinfo' called with a non-function value");
|
lua_error("API error - `funcinfo' called with a non-function value");
|
||||||
else {
|
else {
|
||||||
TObject *f = luaA_protovalue(Address(func));
|
const TObject *f = luaA_protovalue(Address(func));
|
||||||
if (normalized_type(f) == LUA_T_PROTO) {
|
if (normalized_type(f) == LUA_T_PROTO) {
|
||||||
*source = tfvalue(f)->source->str;
|
*source = tfvalue(f)->source->str;
|
||||||
*linedefined = tfvalue(f)->lineDefined;
|
*linedefined = tfvalue(f)->lineDefined;
|
||||||
|
@ -605,14 +567,13 @@ void lua_funcinfo (lua_Object func, char **source, int *linedefined) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int checkfunc (TObject *o)
|
static int checkfunc (TObject *o) {
|
||||||
{
|
|
||||||
return luaO_equalObj(o, L->stack.top);
|
return luaO_equalObj(o, L->stack.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *lua_getobjname (lua_Object o, char **name)
|
const char *lua_getobjname (lua_Object o, const char **name) {
|
||||||
{ /* try to find a name for given function */
|
/* try to find a name for given function */
|
||||||
set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */
|
set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */
|
||||||
if ((*name = luaS_travsymbol(checkfunc)) != NULL)
|
if ((*name = luaS_travsymbol(checkfunc)) != NULL)
|
||||||
return "global";
|
return "global";
|
||||||
|
@ -662,7 +623,7 @@ int lua_ref (int lock) {
|
||||||
|
|
||||||
|
|
||||||
lua_Object lua_getref (int ref) {
|
lua_Object lua_getref (int ref) {
|
||||||
TObject *o = luaC_getref(ref);
|
const TObject *o = luaC_getref(ref);
|
||||||
return (o ? put_luaObject(o) : LUA_NOOBJECT);
|
return (o ? put_luaObject(o) : LUA_NOOBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
lapi.h
6
lapi.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.h,v 1.3 1999/02/22 19:13:12 roberto Exp roberto $
|
** $Id: lapi.h,v 1.4 1999/02/23 14:57:28 roberto Exp roberto $
|
||||||
** Auxiliary functions from Lua API
|
** Auxiliary functions from Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -13,10 +13,10 @@
|
||||||
|
|
||||||
|
|
||||||
TObject *luaA_Address (lua_Object o);
|
TObject *luaA_Address (lua_Object o);
|
||||||
void luaA_pushobject (TObject *o);
|
void luaA_pushobject (const TObject *o);
|
||||||
void luaA_packresults (void);
|
void luaA_packresults (void);
|
||||||
int luaA_passresults (void);
|
int luaA_passresults (void);
|
||||||
TaggedString *luaA_nextvar (TaggedString *g);
|
TaggedString *luaA_nextvar (TaggedString *g);
|
||||||
int luaA_next (Hash *t, int i);
|
int luaA_next (const Hash *t, int i);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
41
lauxlib.c
41
lauxlib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lauxlib.c,v 1.16 1999/03/10 14:19:41 roberto Exp roberto $
|
** $Id: lauxlib.c,v 1.17 1999/03/11 18:59:19 roberto Exp roberto $
|
||||||
** Auxiliary functions for building Lua libraries
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int luaL_findstring (char *name, char *list[]) {
|
int luaL_findstring (const char *name, const char *const list[]) {
|
||||||
int i;
|
int i;
|
||||||
for (i=0; list[i]; i++)
|
for (i=0; list[i]; i++)
|
||||||
if (strcmp(list[i], name) == 0)
|
if (strcmp(list[i], name) == 0)
|
||||||
|
@ -28,9 +28,9 @@ int luaL_findstring (char *name, char *list[]) {
|
||||||
return -1; /* name not found */
|
return -1; /* name not found */
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaL_argerror (int numarg, char *extramsg) {
|
void luaL_argerror (int numarg, const char *extramsg) {
|
||||||
lua_Function f = lua_stackedfunction(0);
|
lua_Function f = lua_stackedfunction(0);
|
||||||
char *funcname;
|
const char *funcname;
|
||||||
lua_getobjname(f, &funcname);
|
lua_getobjname(f, &funcname);
|
||||||
numarg -= lua_nups(f);
|
numarg -= lua_nups(f);
|
||||||
if (funcname == NULL)
|
if (funcname == NULL)
|
||||||
|
@ -42,58 +42,50 @@ void luaL_argerror (int numarg, char *extramsg) {
|
||||||
numarg, funcname, extramsg);
|
numarg, funcname, extramsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *luaL_check_lstr (int numArg, long *len)
|
const char *luaL_check_lstr (int numArg, long *len) {
|
||||||
{
|
|
||||||
lua_Object o = lua_getparam(numArg);
|
lua_Object o = lua_getparam(numArg);
|
||||||
luaL_arg_check(lua_isstring(o), numArg, "string expected");
|
luaL_arg_check(lua_isstring(o), numArg, "string expected");
|
||||||
if (len) *len = lua_strlen(o);
|
if (len) *len = lua_strlen(o);
|
||||||
return lua_getstring(o);
|
return lua_getstring(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *luaL_opt_lstr (int numArg, char *def, long *len)
|
const char *luaL_opt_lstr (int numArg, const char *def, long *len) {
|
||||||
{
|
|
||||||
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
|
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
|
||||||
luaL_check_lstr(numArg, len);
|
luaL_check_lstr(numArg, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
double luaL_check_number (int numArg)
|
double luaL_check_number (int numArg) {
|
||||||
{
|
|
||||||
lua_Object o = lua_getparam(numArg);
|
lua_Object o = lua_getparam(numArg);
|
||||||
luaL_arg_check(lua_isnumber(o), numArg, "number expected");
|
luaL_arg_check(lua_isnumber(o), numArg, "number expected");
|
||||||
return lua_getnumber(o);
|
return lua_getnumber(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double luaL_opt_number (int numArg, double def)
|
double luaL_opt_number (int numArg, double def) {
|
||||||
{
|
|
||||||
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
|
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
|
||||||
luaL_check_number(numArg);
|
luaL_check_number(numArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lua_Object luaL_tablearg (int arg)
|
lua_Object luaL_tablearg (int arg) {
|
||||||
{
|
|
||||||
lua_Object o = lua_getparam(arg);
|
lua_Object o = lua_getparam(arg);
|
||||||
luaL_arg_check(lua_istable(o), arg, "table expected");
|
luaL_arg_check(lua_istable(o), arg, "table expected");
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_Object luaL_functionarg (int arg)
|
lua_Object luaL_functionarg (int arg) {
|
||||||
{
|
|
||||||
lua_Object o = lua_getparam(arg);
|
lua_Object o = lua_getparam(arg);
|
||||||
luaL_arg_check(lua_isfunction(o), arg, "function expected");
|
luaL_arg_check(lua_isfunction(o), arg, "function expected");
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_Object luaL_nonnullarg (int numArg)
|
lua_Object luaL_nonnullarg (int numArg) {
|
||||||
{
|
|
||||||
lua_Object o = lua_getparam(numArg);
|
lua_Object o = lua_getparam(numArg);
|
||||||
luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
|
luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaL_openlib (struct luaL_reg *l, int n)
|
void luaL_openlib (const struct luaL_reg *l, int n) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
lua_open(); /* make sure lua is already open */
|
lua_open(); /* make sure lua is already open */
|
||||||
for (i=0; i<n; i++)
|
for (i=0; i<n; i++)
|
||||||
|
@ -101,8 +93,7 @@ void luaL_openlib (struct luaL_reg *l, int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_verror (char *fmt, ...)
|
void luaL_verror (const char *fmt, ...) {
|
||||||
{
|
|
||||||
char buff[500];
|
char buff[500];
|
||||||
va_list argp;
|
va_list argp;
|
||||||
va_start(argp, fmt);
|
va_start(argp, fmt);
|
||||||
|
@ -112,14 +103,14 @@ void luaL_verror (char *fmt, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_chunkid (char *out, char *source, int len) {
|
void luaL_chunkid (char *out, const char *source, int len) {
|
||||||
len -= 13; /* 13 = strlen("string ''...\0") */
|
len -= 13; /* 13 = strlen("string ''...\0") */
|
||||||
if (*source == '@')
|
if (*source == '@')
|
||||||
sprintf(out, "file `%.*s'", len, source+1);
|
sprintf(out, "file `%.*s'", len, source+1);
|
||||||
else if (*source == '(')
|
else if (*source == '(')
|
||||||
strcpy(out, "(C code)");
|
strcpy(out, "(C code)");
|
||||||
else {
|
else {
|
||||||
char *b = strchr(source , '\n'); /* stop string at first new line */
|
const char *b = strchr(source , '\n'); /* stop string at first new line */
|
||||||
int lim = (b && (b-source)<len) ? b-source : len;
|
int lim = (b && (b-source)<len) ? b-source : len;
|
||||||
sprintf(out, "string `%.*s'", lim, source);
|
sprintf(out, "string `%.*s'", lim, source);
|
||||||
strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */
|
strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */
|
||||||
|
@ -127,7 +118,7 @@ void luaL_chunkid (char *out, char *source, int len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_filesource (char *out, char *filename, int len) {
|
void luaL_filesource (char *out, const char *filename, int len) {
|
||||||
if (filename == NULL) filename = "(stdin)";
|
if (filename == NULL) filename = "(stdin)";
|
||||||
sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */
|
sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */
|
||||||
}
|
}
|
||||||
|
|
20
lauxlib.h
20
lauxlib.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lauxlib.h,v 1.11 1999/03/04 21:17:26 roberto Exp roberto $
|
** $Id: lauxlib.h,v 1.12 1999/03/10 14:19:41 roberto Exp roberto $
|
||||||
** Auxiliary functions for building Lua libraries
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
|
|
||||||
struct luaL_reg {
|
struct luaL_reg {
|
||||||
char *name;
|
const char *name;
|
||||||
lua_CFunction func;
|
lua_CFunction func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ struct luaL_reg {
|
||||||
#define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
|
#define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
|
||||||
luaL_argerror(numarg,extramsg)
|
luaL_argerror(numarg,extramsg)
|
||||||
|
|
||||||
void luaL_openlib (struct luaL_reg *l, int n);
|
void luaL_openlib (const struct luaL_reg *l, int n);
|
||||||
void luaL_argerror (int numarg, char *extramsg);
|
void luaL_argerror (int numarg, const char *extramsg);
|
||||||
#define luaL_check_string(n) (luaL_check_lstr((n), NULL))
|
#define luaL_check_string(n) (luaL_check_lstr((n), NULL))
|
||||||
char *luaL_check_lstr (int numArg, long *len);
|
const char *luaL_check_lstr (int numArg, long *len);
|
||||||
#define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
|
#define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
|
||||||
char *luaL_opt_lstr (int numArg, char *def, long *len);
|
const char *luaL_opt_lstr (int numArg, const char *def, long *len);
|
||||||
double luaL_check_number (int numArg);
|
double luaL_check_number (int numArg);
|
||||||
#define luaL_check_int(n) ((int)luaL_check_number(n))
|
#define luaL_check_int(n) ((int)luaL_check_number(n))
|
||||||
#define luaL_check_long(n) ((long)luaL_check_number(n))
|
#define luaL_check_long(n) ((long)luaL_check_number(n))
|
||||||
|
@ -36,7 +36,7 @@ double luaL_opt_number (int numArg, double def);
|
||||||
lua_Object luaL_functionarg (int arg);
|
lua_Object luaL_functionarg (int arg);
|
||||||
lua_Object luaL_tablearg (int arg);
|
lua_Object luaL_tablearg (int arg);
|
||||||
lua_Object luaL_nonnullarg (int numArg);
|
lua_Object luaL_nonnullarg (int numArg);
|
||||||
void luaL_verror (char *fmt, ...);
|
void luaL_verror (const char *fmt, ...);
|
||||||
char *luaL_openspace (int size);
|
char *luaL_openspace (int size);
|
||||||
void luaL_resetbuffer (void);
|
void luaL_resetbuffer (void);
|
||||||
void luaL_addchar (int c);
|
void luaL_addchar (int c);
|
||||||
|
@ -45,9 +45,9 @@ void luaL_addsize (int n);
|
||||||
int luaL_newbuffer (int size);
|
int luaL_newbuffer (int size);
|
||||||
void luaL_oldbuffer (int old);
|
void luaL_oldbuffer (int old);
|
||||||
char *luaL_buffer (void);
|
char *luaL_buffer (void);
|
||||||
int luaL_findstring (char *name, char *list[]);
|
int luaL_findstring (const char *name, const char *const list[]);
|
||||||
void luaL_chunkid (char *out, char *source, int len);
|
void luaL_chunkid (char *out, const char *source, int len);
|
||||||
void luaL_filesource (char *out, char *filename, int len);
|
void luaL_filesource (char *out, const char *filename, int len);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
44
lbuiltin.c
44
lbuiltin.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbuiltin.c,v 1.59 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: lbuiltin.c,v 1.60 1999/07/22 19:35:41 roberto Exp roberto $
|
||||||
** Built-in functions
|
** Built-in functions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -42,7 +42,7 @@ static void pushtagstring (TaggedString *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static real getsize (Hash *h) {
|
static real getsize (const Hash *h) {
|
||||||
real max = 0;
|
real max = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i<nhash(h); i++) {
|
for (i = 0; i<nhash(h); i++) {
|
||||||
|
@ -56,7 +56,7 @@ static real getsize (Hash *h) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static real getnarg (Hash *a) {
|
static real getnarg (const Hash *a) {
|
||||||
TObject index;
|
TObject index;
|
||||||
TObject *value;
|
TObject *value;
|
||||||
/* value = table.n */
|
/* value = table.n */
|
||||||
|
@ -146,10 +146,10 @@ static void luaB_tonumber (void) {
|
||||||
else lua_pushnil(); /* not a number */
|
else lua_pushnil(); /* not a number */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *s = luaL_check_string(1);
|
char *s;
|
||||||
long n;
|
long n;
|
||||||
luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
|
luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
|
||||||
n = strtol(s, &s, base);
|
n = strtol(luaL_check_string(1), &s, base);
|
||||||
while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */
|
while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */
|
||||||
if (*s) lua_pushnil(); /* invalid format: return nil */
|
if (*s) lua_pushnil(); /* invalid format: return nil */
|
||||||
else lua_pushnumber(n);
|
else lua_pushnumber(n);
|
||||||
|
@ -162,7 +162,7 @@ static void luaB_error (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void luaB_setglobal (void) {
|
static void luaB_setglobal (void) {
|
||||||
char *n = luaL_check_string(1);
|
const char *n = luaL_check_string(1);
|
||||||
lua_Object value = luaL_nonnullarg(2);
|
lua_Object value = luaL_nonnullarg(2);
|
||||||
lua_pushobject(value);
|
lua_pushobject(value);
|
||||||
lua_setglobal(n);
|
lua_setglobal(n);
|
||||||
|
@ -170,7 +170,7 @@ static void luaB_setglobal (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void luaB_rawsetglobal (void) {
|
static void luaB_rawsetglobal (void) {
|
||||||
char *n = luaL_check_string(1);
|
const char *n = luaL_check_string(1);
|
||||||
lua_Object value = luaL_nonnullarg(2);
|
lua_Object value = luaL_nonnullarg(2);
|
||||||
lua_pushobject(value);
|
lua_pushobject(value);
|
||||||
lua_rawsetglobal(n);
|
lua_rawsetglobal(n);
|
||||||
|
@ -250,7 +250,7 @@ static void luaB_collectgarbage (void) {
|
||||||
|
|
||||||
static void luaB_dostring (void) {
|
static void luaB_dostring (void) {
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
if (*s == ID_CHUNK)
|
if (*s == ID_CHUNK)
|
||||||
lua_error("`dostring' cannot run pre-compiled code");
|
lua_error("`dostring' cannot run pre-compiled code");
|
||||||
if (lua_dobuffer(s, l, luaL_opt_string(2, s)) == 0)
|
if (lua_dobuffer(s, l, luaL_opt_string(2, s)) == 0)
|
||||||
|
@ -260,7 +260,7 @@ static void luaB_dostring (void) {
|
||||||
|
|
||||||
|
|
||||||
static void luaB_dofile (void) {
|
static void luaB_dofile (void) {
|
||||||
char *fname = luaL_opt_string(1, NULL);
|
const char *fname = luaL_opt_string(1, NULL);
|
||||||
if (lua_dofile(fname) == 0)
|
if (lua_dofile(fname) == 0)
|
||||||
if (luaA_passresults() == 0)
|
if (luaA_passresults() == 0)
|
||||||
lua_pushuserdata(NULL); /* at least one result to signal no errors */
|
lua_pushuserdata(NULL); /* at least one result to signal no errors */
|
||||||
|
@ -269,8 +269,8 @@ static void luaB_dofile (void) {
|
||||||
|
|
||||||
static void luaB_call (void) {
|
static void luaB_call (void) {
|
||||||
lua_Object f = luaL_nonnullarg(1);
|
lua_Object f = luaL_nonnullarg(1);
|
||||||
Hash *arg = gethash(2);
|
const Hash *arg = gethash(2);
|
||||||
char *options = luaL_opt_string(3, "");
|
const char *options = luaL_opt_string(3, "");
|
||||||
lua_Object err = lua_getparam(4);
|
lua_Object err = lua_getparam(4);
|
||||||
int narg = (int)getnarg(arg);
|
int narg = (int)getnarg(arg);
|
||||||
int i, status;
|
int i, status;
|
||||||
|
@ -305,7 +305,7 @@ static void luaB_call (void) {
|
||||||
|
|
||||||
|
|
||||||
static void luaB_nextvar (void) {
|
static void luaB_nextvar (void) {
|
||||||
TObject *o = luaA_Address(luaL_nonnullarg(1));
|
const TObject *o = luaA_Address(luaL_nonnullarg(1));
|
||||||
TaggedString *g;
|
TaggedString *g;
|
||||||
if (ttype(o) == LUA_T_NIL)
|
if (ttype(o) == LUA_T_NIL)
|
||||||
g = NULL;
|
g = NULL;
|
||||||
|
@ -319,8 +319,8 @@ static void luaB_nextvar (void) {
|
||||||
|
|
||||||
|
|
||||||
static void luaB_next (void) {
|
static void luaB_next (void) {
|
||||||
Hash *a = gethash(1);
|
const Hash *a = gethash(1);
|
||||||
TObject *k = luaA_Address(luaL_nonnullarg(2));
|
const TObject *k = luaA_Address(luaL_nonnullarg(2));
|
||||||
int i = (ttype(k) == LUA_T_NIL) ? 0 : luaH_pos(a, k)+1;
|
int i = (ttype(k) == LUA_T_NIL) ? 0 : luaH_pos(a, k)+1;
|
||||||
if (luaA_next(a, i) == 0)
|
if (luaA_next(a, i) == 0)
|
||||||
lua_pushnil();
|
lua_pushnil();
|
||||||
|
@ -329,7 +329,7 @@ static void luaB_next (void) {
|
||||||
|
|
||||||
static void luaB_tostring (void) {
|
static void luaB_tostring (void) {
|
||||||
lua_Object obj = lua_getparam(1);
|
lua_Object obj = lua_getparam(1);
|
||||||
TObject *o = luaA_Address(obj);
|
const TObject *o = luaA_Address(obj);
|
||||||
char buff[64];
|
char buff[64];
|
||||||
switch (ttype(o)) {
|
switch (ttype(o)) {
|
||||||
case LUA_T_NUMBER:
|
case LUA_T_NUMBER:
|
||||||
|
@ -391,7 +391,7 @@ static void luaB_assert (void) {
|
||||||
|
|
||||||
|
|
||||||
static void luaB_foreachi (void) {
|
static void luaB_foreachi (void) {
|
||||||
Hash *t = gethash(1);
|
const Hash *t = gethash(1);
|
||||||
int i;
|
int i;
|
||||||
int n = (int)getnarg(t);
|
int n = (int)getnarg(t);
|
||||||
TObject f;
|
TObject f;
|
||||||
|
@ -413,13 +413,13 @@ static void luaB_foreachi (void) {
|
||||||
|
|
||||||
|
|
||||||
static void luaB_foreach (void) {
|
static void luaB_foreach (void) {
|
||||||
Hash *a = gethash(1);
|
const Hash *a = gethash(1);
|
||||||
int i;
|
int i;
|
||||||
TObject f; /* see comment in 'foreachi' */
|
TObject f; /* see comment in 'foreachi' */
|
||||||
f = *luaA_Address(luaL_functionarg(2));
|
f = *luaA_Address(luaL_functionarg(2));
|
||||||
luaD_checkstack(3); /* for f, ref, and val */
|
luaD_checkstack(3); /* for f, ref, and val */
|
||||||
for (i=0; i<a->nhash; i++) {
|
for (i=0; i<a->nhash; i++) {
|
||||||
Node *nd = &(a->node[i]);
|
const Node *nd = &(a->node[i]);
|
||||||
if (ttype(val(nd)) != LUA_T_NIL) {
|
if (ttype(val(nd)) != LUA_T_NIL) {
|
||||||
*(L->stack.top++) = f;
|
*(L->stack.top++) = f;
|
||||||
*(L->stack.top++) = *ref(nd);
|
*(L->stack.top++) = *ref(nd);
|
||||||
|
@ -504,7 +504,7 @@ static void swap (Hash *a, int i, int j) {
|
||||||
luaH_setint(a, j, &temp);
|
luaH_setint(a, j, &temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sort_comp (lua_Object f, TObject *a, TObject *b) {
|
static int sort_comp (lua_Object f, const TObject *a, const TObject *b) {
|
||||||
/* notice: the caller (auxsort) must check stack space */
|
/* notice: the caller (auxsort) must check stack space */
|
||||||
if (f != LUA_NOOBJECT) {
|
if (f != LUA_NOOBJECT) {
|
||||||
*(L->stack.top) = *luaA_Address(f);
|
*(L->stack.top) = *luaA_Address(f);
|
||||||
|
@ -604,7 +604,7 @@ static void query_strings (void) {
|
||||||
|
|
||||||
|
|
||||||
static void countlist (void) {
|
static void countlist (void) {
|
||||||
char *s = luaL_check_string(1);
|
const char *s = luaL_check_string(1);
|
||||||
GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next :
|
GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next :
|
||||||
(s[0]=='p') ? L->rootproto.next : L->rootglobal.next;
|
(s[0]=='p') ? L->rootproto.next : L->rootglobal.next;
|
||||||
int i=0;
|
int i=0;
|
||||||
|
@ -623,7 +623,7 @@ static void testC (void) {
|
||||||
static int locks[10];
|
static int locks[10];
|
||||||
lua_Object reg[10];
|
lua_Object reg[10];
|
||||||
char nome[2];
|
char nome[2];
|
||||||
char *s = luaL_check_string(1);
|
const char *s = luaL_check_string(1);
|
||||||
nome[1] = 0;
|
nome[1] = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (*s++) {
|
switch (*s++) {
|
||||||
|
@ -674,7 +674,7 @@ static void testC (void) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static struct luaL_reg builtin_funcs[] = {
|
static const struct luaL_reg builtin_funcs[] = {
|
||||||
#ifdef LUA_COMPAT2_5
|
#ifdef LUA_COMPAT2_5
|
||||||
{"setfallback", luaT_setfallback},
|
{"setfallback", luaT_setfallback},
|
||||||
#endif
|
#endif
|
||||||
|
|
20
ldblib.c
20
ldblib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldblib.c,v 1.4 1999/02/04 17:47:59 roberto Exp roberto $
|
** $Id: ldblib.c,v 1.5 1999/03/04 21:17:26 roberto Exp roberto $
|
||||||
** Interface from Lua to its debug API
|
** Interface from Lua to its debug API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void settabss (lua_Object t, char *i, char *v) {
|
static void settabss (lua_Object t, const char *i, const char *v) {
|
||||||
lua_pushobject(t);
|
lua_pushobject(t);
|
||||||
lua_pushstring(i);
|
lua_pushstring(i);
|
||||||
lua_pushstring(v);
|
lua_pushstring(v);
|
||||||
|
@ -23,7 +23,7 @@ static void settabss (lua_Object t, char *i, char *v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void settabsi (lua_Object t, char *i, int v) {
|
static void settabsi (lua_Object t, const char *i, int v) {
|
||||||
lua_pushobject(t);
|
lua_pushobject(t);
|
||||||
lua_pushstring(i);
|
lua_pushstring(i);
|
||||||
lua_pushnumber(v);
|
lua_pushnumber(v);
|
||||||
|
@ -33,7 +33,7 @@ static void settabsi (lua_Object t, char *i, int v) {
|
||||||
|
|
||||||
static lua_Object getfuncinfo (lua_Object func) {
|
static lua_Object getfuncinfo (lua_Object func) {
|
||||||
lua_Object result = lua_createtable();
|
lua_Object result = lua_createtable();
|
||||||
char *str;
|
const char *str;
|
||||||
int line;
|
int line;
|
||||||
lua_funcinfo(func, &str, &line);
|
lua_funcinfo(func, &str, &line);
|
||||||
if (line == -1) /* C function? */
|
if (line == -1) /* C function? */
|
||||||
|
@ -48,7 +48,7 @@ static lua_Object getfuncinfo (lua_Object func) {
|
||||||
settabss(result, "source", str);
|
settabss(result, "source", str);
|
||||||
}
|
}
|
||||||
if (line != 0) { /* is it not a "main"? */
|
if (line != 0) { /* is it not a "main"? */
|
||||||
char *kind = lua_getobjname(func, &str);
|
const char *kind = lua_getobjname(func, &str);
|
||||||
if (*kind) {
|
if (*kind) {
|
||||||
settabss(result, "name", str);
|
settabss(result, "name", str);
|
||||||
settabss(result, "where", kind);
|
settabss(result, "where", kind);
|
||||||
|
@ -86,10 +86,10 @@ static int findlocal (lua_Object func, int arg) {
|
||||||
if (lua_isnumber(v))
|
if (lua_isnumber(v))
|
||||||
return (int)lua_getnumber(v);
|
return (int)lua_getnumber(v);
|
||||||
else {
|
else {
|
||||||
char *name = luaL_check_string(arg);
|
const char *name = luaL_check_string(arg);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
char *vname;
|
const char *vname;
|
||||||
while (lua_getlocal(func, ++i, &vname) != LUA_NOOBJECT) {
|
while (lua_getlocal(func, ++i, &vname) != LUA_NOOBJECT) {
|
||||||
if (strcmp(name, vname) == 0)
|
if (strcmp(name, vname) == 0)
|
||||||
result = i; /* keep looping to get the last var with this name */
|
result = i; /* keep looping to get the last var with this name */
|
||||||
|
@ -104,7 +104,7 @@ static int findlocal (lua_Object func, int arg) {
|
||||||
static void getlocal (void) {
|
static void getlocal (void) {
|
||||||
lua_Object func = lua_stackedfunction(luaL_check_int(1));
|
lua_Object func = lua_stackedfunction(luaL_check_int(1));
|
||||||
lua_Object val;
|
lua_Object val;
|
||||||
char *name;
|
const char *name;
|
||||||
if (func == LUA_NOOBJECT) /* level out of range? */
|
if (func == LUA_NOOBJECT) /* level out of range? */
|
||||||
return; /* return nil */
|
return; /* return nil */
|
||||||
else if (lua_getparam(2) != LUA_NOOBJECT) { /* 2nd argument? */
|
else if (lua_getparam(2) != LUA_NOOBJECT) { /* 2nd argument? */
|
||||||
|
@ -161,7 +161,7 @@ static void linef (int line) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void callf (lua_Function func, char *file, int line) {
|
static void callf (lua_Function func, const char *file, int line) {
|
||||||
if (func != LUA_NOOBJECT) {
|
if (func != LUA_NOOBJECT) {
|
||||||
lua_pushobject(func);
|
lua_pushobject(func);
|
||||||
lua_pushstring(file);
|
lua_pushstring(file);
|
||||||
|
@ -201,7 +201,7 @@ static void setlinehook (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct luaL_reg dblib[] = {
|
static const struct luaL_reg dblib[] = {
|
||||||
{"funcinfo", funcinfo},
|
{"funcinfo", funcinfo},
|
||||||
{"getlocal", getlocal},
|
{"getlocal", getlocal},
|
||||||
{"getstack", getstack},
|
{"getstack", getstack},
|
||||||
|
|
26
ldo.c
26
ldo.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldo.c,v 1.44 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: ldo.c,v 1.45 1999/06/22 20:37:23 roberto Exp roberto $
|
||||||
** Stack and Call structure of Lua
|
** Stack and Call structure of Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -159,7 +159,7 @@ static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaD_callTM (TObject *f, int nParams, int nResults) {
|
void luaD_callTM (const TObject *f, int nParams, int nResults) {
|
||||||
luaD_openstack(nParams);
|
luaD_openstack(nParams);
|
||||||
*(L->stack.top-nParams-1) = *f;
|
*(L->stack.top-nParams-1) = *f;
|
||||||
luaD_calln(nParams, nResults);
|
luaD_calln(nParams, nResults);
|
||||||
|
@ -199,7 +199,7 @@ void luaD_calln (int nArgs, int nResults) {
|
||||||
}
|
}
|
||||||
default: { /* func is not a function */
|
default: { /* func is not a function */
|
||||||
/* Check the tag method for invalid functions */
|
/* Check the tag method for invalid functions */
|
||||||
TObject *im = luaT_getimbyObj(func, IM_FUNCTION);
|
const TObject *im = luaT_getimbyObj(func, IM_FUNCTION);
|
||||||
if (ttype(im) == LUA_T_NIL)
|
if (ttype(im) == LUA_T_NIL)
|
||||||
lua_error("call expression not a function");
|
lua_error("call expression not a function");
|
||||||
luaD_callTM(im, (S->top-S->stack)-(base-1), nResults);
|
luaD_callTM(im, (S->top-S->stack)-(base-1), nResults);
|
||||||
|
@ -222,8 +222,7 @@ void luaD_calln (int nArgs, int nResults) {
|
||||||
/*
|
/*
|
||||||
** Traverse all objects on L->stack.stack
|
** Traverse all objects on L->stack.stack
|
||||||
*/
|
*/
|
||||||
void luaD_travstack (int (*fn)(TObject *))
|
void luaD_travstack (int (*fn)(TObject *)) {
|
||||||
{
|
|
||||||
StkId i;
|
StkId i;
|
||||||
for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--)
|
for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--)
|
||||||
fn(L->stack.stack+i);
|
fn(L->stack.stack+i);
|
||||||
|
@ -231,8 +230,8 @@ void luaD_travstack (int (*fn)(TObject *))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void message (char *s) {
|
static void message (const char *s) {
|
||||||
TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
|
const TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
|
||||||
if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO ||
|
if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO ||
|
||||||
ttype(em) == LUA_T_CLOSURE) {
|
ttype(em) == LUA_T_CLOSURE) {
|
||||||
*L->stack.top = *em;
|
*L->stack.top = *em;
|
||||||
|
@ -245,7 +244,7 @@ static void message (char *s) {
|
||||||
/*
|
/*
|
||||||
** Reports an error, and jumps up to the available recover label
|
** Reports an error, and jumps up to the available recover label
|
||||||
*/
|
*/
|
||||||
void lua_error (char *s) {
|
void lua_error (const char *s) {
|
||||||
if (s) message(s);
|
if (s) message(s);
|
||||||
if (L->errorJmp)
|
if (L->errorJmp)
|
||||||
longjmp(L->errorJmp->b, 1);
|
longjmp(L->errorJmp->b, 1);
|
||||||
|
@ -335,9 +334,8 @@ static int do_main (ZIO *z, int bin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaD_gcIM (TObject *o)
|
void luaD_gcIM (const TObject *o) {
|
||||||
{
|
const TObject *im = luaT_getimbyObj(o, IM_GC);
|
||||||
TObject *im = luaT_getimbyObj(o, IM_GC);
|
|
||||||
if (ttype(im) != LUA_T_NIL) {
|
if (ttype(im) != LUA_T_NIL) {
|
||||||
*L->stack.top = *o;
|
*L->stack.top = *o;
|
||||||
incr_top;
|
incr_top;
|
||||||
|
@ -348,7 +346,7 @@ void luaD_gcIM (TObject *o)
|
||||||
|
|
||||||
#define MAXFILENAME 260 /* maximum part of a file name kept */
|
#define MAXFILENAME 260 /* maximum part of a file name kept */
|
||||||
|
|
||||||
int lua_dofile (char *filename) {
|
int lua_dofile (const char *filename) {
|
||||||
ZIO z;
|
ZIO z;
|
||||||
int status;
|
int status;
|
||||||
int c;
|
int c;
|
||||||
|
@ -371,12 +369,12 @@ int lua_dofile (char *filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_dostring (char *str) {
|
int lua_dostring (const char *str) {
|
||||||
return lua_dobuffer(str, strlen(str), str);
|
return lua_dobuffer(str, strlen(str), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_dobuffer (char *buff, int size, char *name) {
|
int lua_dobuffer (const char *buff, int size, const char *name) {
|
||||||
ZIO z;
|
ZIO z;
|
||||||
if (!name) name = "?";
|
if (!name) name = "?";
|
||||||
luaZ_mopen(&z, buff, size, name);
|
luaZ_mopen(&z, buff, size, name);
|
||||||
|
|
6
ldo.h
6
ldo.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldo.h,v 1.5 1998/07/12 16:14:34 roberto Exp roberto $
|
** $Id: ldo.h,v 1.6 1999/06/22 20:37:23 roberto Exp roberto $
|
||||||
** Stack and Call structure of Lua
|
** Stack and Call structure of Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -36,9 +36,9 @@ void luaD_openstack (int nelems);
|
||||||
void luaD_lineHook (int line);
|
void luaD_lineHook (int line);
|
||||||
void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn);
|
void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn);
|
||||||
void luaD_calln (int nArgs, int nResults);
|
void luaD_calln (int nArgs, int nResults);
|
||||||
void luaD_callTM (TObject *f, int nParams, int nResults);
|
void luaD_callTM (const TObject *f, int nParams, int nResults);
|
||||||
int luaD_protectedrun (void);
|
int luaD_protectedrun (void);
|
||||||
void luaD_gcIM (TObject *o);
|
void luaD_gcIM (const TObject *o);
|
||||||
void luaD_travstack (int (*fn)(TObject *));
|
void luaD_travstack (int (*fn)(TObject *));
|
||||||
void luaD_checkstack (int n);
|
void luaD_checkstack (int n);
|
||||||
|
|
||||||
|
|
22
lfunc.c
22
lfunc.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lfunc.c,v 1.9 1998/06/19 16:14:09 roberto Exp roberto $
|
** $Id: lfunc.c,v 1.10 1999/03/04 21:17:26 roberto Exp roberto $
|
||||||
** Auxiliary functions to manipulate prototypes and closures
|
** Auxiliary functions to manipulate prototypes and closures
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -16,8 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Closure *luaF_newclosure (int nelems)
|
Closure *luaF_newclosure (int nelems) {
|
||||||
{
|
|
||||||
Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
|
Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
|
||||||
luaO_insertlist(&(L->rootcl), (GCnode *)c);
|
luaO_insertlist(&(L->rootcl), (GCnode *)c);
|
||||||
L->nblocks += gcsizeclosure(c);
|
L->nblocks += gcsizeclosure(c);
|
||||||
|
@ -26,8 +25,7 @@ Closure *luaF_newclosure (int nelems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TProtoFunc *luaF_newproto (void)
|
TProtoFunc *luaF_newproto (void) {
|
||||||
{
|
|
||||||
TProtoFunc *f = luaM_new(TProtoFunc);
|
TProtoFunc *f = luaM_new(TProtoFunc);
|
||||||
f->code = NULL;
|
f->code = NULL;
|
||||||
f->lineDefined = 0;
|
f->lineDefined = 0;
|
||||||
|
@ -42,8 +40,7 @@ TProtoFunc *luaF_newproto (void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void freefunc (TProtoFunc *f)
|
static void freefunc (TProtoFunc *f) {
|
||||||
{
|
|
||||||
luaM_free(f->code);
|
luaM_free(f->code);
|
||||||
luaM_free(f->locvars);
|
luaM_free(f->locvars);
|
||||||
luaM_free(f->consts);
|
luaM_free(f->consts);
|
||||||
|
@ -51,8 +48,7 @@ static void freefunc (TProtoFunc *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaF_freeproto (TProtoFunc *l)
|
void luaF_freeproto (TProtoFunc *l) {
|
||||||
{
|
|
||||||
while (l) {
|
while (l) {
|
||||||
TProtoFunc *next = (TProtoFunc *)l->head.next;
|
TProtoFunc *next = (TProtoFunc *)l->head.next;
|
||||||
L->nblocks -= gcsizeproto(l);
|
L->nblocks -= gcsizeproto(l);
|
||||||
|
@ -62,8 +58,7 @@ void luaF_freeproto (TProtoFunc *l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaF_freeclosure (Closure *l)
|
void luaF_freeclosure (Closure *l) {
|
||||||
{
|
|
||||||
while (l) {
|
while (l) {
|
||||||
Closure *next = (Closure *)l->head.next;
|
Closure *next = (Closure *)l->head.next;
|
||||||
L->nblocks -= gcsizeclosure(l);
|
L->nblocks -= gcsizeclosure(l);
|
||||||
|
@ -77,10 +72,9 @@ void luaF_freeclosure (Closure *l)
|
||||||
** Look for n-th local variable at line "line" in function "func".
|
** Look for n-th local variable at line "line" in function "func".
|
||||||
** Returns NULL if not found.
|
** Returns NULL if not found.
|
||||||
*/
|
*/
|
||||||
char *luaF_getlocalname (TProtoFunc *func, int local_number, int line)
|
const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) {
|
||||||
{
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *varname = NULL;
|
const char *varname = NULL;
|
||||||
LocVar *lv = func->locvars;
|
LocVar *lv = func->locvars;
|
||||||
if (lv == NULL)
|
if (lv == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
4
lfunc.h
4
lfunc.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lfunc.h,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $
|
** $Id: lfunc.h,v 1.5 1997/12/15 16:17:20 roberto Exp roberto $
|
||||||
** Lua Function structures
|
** Lua Function structures
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,7 @@ Closure *luaF_newclosure (int nelems);
|
||||||
void luaF_freeproto (TProtoFunc *l);
|
void luaF_freeproto (TProtoFunc *l);
|
||||||
void luaF_freeclosure (Closure *l);
|
void luaF_freeclosure (Closure *l);
|
||||||
|
|
||||||
char *luaF_getlocalname (TProtoFunc *func, int local_number, int line);
|
const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
52
lgc.c
52
lgc.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 1.23 1999/03/04 21:17:26 roberto Exp roberto $
|
** $Id: lgc.c,v 1.24 1999/08/11 17:00:59 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +29,7 @@ static int markobject (TObject *o);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int luaC_ref (TObject *o, int lock) {
|
int luaC_ref (const TObject *o, int lock) {
|
||||||
int ref;
|
int ref;
|
||||||
if (ttype(o) == LUA_T_NIL)
|
if (ttype(o) == LUA_T_NIL)
|
||||||
ref = LUA_REFNIL;
|
ref = LUA_REFNIL;
|
||||||
|
@ -48,15 +48,13 @@ int luaC_ref (TObject *o, int lock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_unref (int ref)
|
void lua_unref (int ref) {
|
||||||
{
|
|
||||||
if (ref >= 0 && ref < L->refSize)
|
if (ref >= 0 && ref < L->refSize)
|
||||||
L->refArray[ref].status = FREE;
|
L->refArray[ref].status = FREE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TObject* luaC_getref (int ref)
|
const TObject *luaC_getref (int ref) {
|
||||||
{
|
|
||||||
if (ref == LUA_REFNIL)
|
if (ref == LUA_REFNIL)
|
||||||
return &luaO_nilobject;
|
return &luaO_nilobject;
|
||||||
if (ref >= 0 && ref < L->refSize &&
|
if (ref >= 0 && ref < L->refSize &&
|
||||||
|
@ -67,8 +65,7 @@ TObject* luaC_getref (int ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void travlock (void)
|
static void travlock (void) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<L->refSize; i++)
|
for (i=0; i<L->refSize; i++)
|
||||||
if (L->refArray[i].status == LOCK)
|
if (L->refArray[i].status == LOCK)
|
||||||
|
@ -76,8 +73,7 @@ static void travlock (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ismarked (TObject *o)
|
static int ismarked (const TObject *o) {
|
||||||
{
|
|
||||||
/* valid only for locked objects */
|
/* valid only for locked objects */
|
||||||
switch (o->ttype) {
|
switch (o->ttype) {
|
||||||
case LUA_T_STRING: case LUA_T_USERDATA:
|
case LUA_T_STRING: case LUA_T_USERDATA:
|
||||||
|
@ -99,8 +95,7 @@ static int ismarked (TObject *o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void invalidaterefs (void)
|
static void invalidaterefs (void) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<L->refSize; i++)
|
for (i=0; i<L->refSize; i++)
|
||||||
if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o))
|
if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o))
|
||||||
|
@ -109,8 +104,7 @@ static void invalidaterefs (void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void luaC_hashcallIM (Hash *l)
|
void luaC_hashcallIM (Hash *l) {
|
||||||
{
|
|
||||||
TObject t;
|
TObject t;
|
||||||
ttype(&t) = LUA_T_ARRAY;
|
ttype(&t) = LUA_T_ARRAY;
|
||||||
for (; l; l=(Hash *)l->head.next) {
|
for (; l; l=(Hash *)l->head.next) {
|
||||||
|
@ -120,8 +114,7 @@ void luaC_hashcallIM (Hash *l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaC_strcallIM (TaggedString *l)
|
void luaC_strcallIM (TaggedString *l) {
|
||||||
{
|
|
||||||
TObject o;
|
TObject o;
|
||||||
ttype(&o) = LUA_T_USERDATA;
|
ttype(&o) = LUA_T_USERDATA;
|
||||||
for (; l; l=(TaggedString *)l->head.next)
|
for (; l; l=(TaggedString *)l->head.next)
|
||||||
|
@ -133,8 +126,7 @@ void luaC_strcallIM (TaggedString *l)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static GCnode *listcollect (GCnode *l)
|
static GCnode *listcollect (GCnode *l) {
|
||||||
{
|
|
||||||
GCnode *frees = NULL;
|
GCnode *frees = NULL;
|
||||||
while (l) {
|
while (l) {
|
||||||
GCnode *next = l->next;
|
GCnode *next = l->next;
|
||||||
|
@ -151,8 +143,7 @@ static GCnode *listcollect (GCnode *l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void strmark (TaggedString *s)
|
static void strmark (TaggedString *s) {
|
||||||
{
|
|
||||||
if (!s->head.marked)
|
if (!s->head.marked)
|
||||||
s->head.marked = 1;
|
s->head.marked = 1;
|
||||||
}
|
}
|
||||||
|
@ -169,8 +160,7 @@ static void protomark (TProtoFunc *f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void closuremark (Closure *f)
|
static void closuremark (Closure *f) {
|
||||||
{
|
|
||||||
if (!f->head.marked) {
|
if (!f->head.marked) {
|
||||||
int i;
|
int i;
|
||||||
f->head.marked = 1;
|
f->head.marked = 1;
|
||||||
|
@ -180,8 +170,7 @@ static void closuremark (Closure *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void hashmark (Hash *h)
|
static void hashmark (Hash *h) {
|
||||||
{
|
|
||||||
if (!h->head.marked) {
|
if (!h->head.marked) {
|
||||||
int i;
|
int i;
|
||||||
h->head.marked = 1;
|
h->head.marked = 1;
|
||||||
|
@ -196,8 +185,7 @@ static void hashmark (Hash *h)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void globalmark (void)
|
static void globalmark (void) {
|
||||||
{
|
|
||||||
TaggedString *g;
|
TaggedString *g;
|
||||||
for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){
|
for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){
|
||||||
LUA_ASSERT(g->constindex >= 0, "userdata in global list");
|
LUA_ASSERT(g->constindex >= 0, "userdata in global list");
|
||||||
|
@ -209,8 +197,7 @@ static void globalmark (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int markobject (TObject *o)
|
static int markobject (TObject *o) {
|
||||||
{
|
|
||||||
switch (ttype(o)) {
|
switch (ttype(o)) {
|
||||||
case LUA_T_USERDATA: case LUA_T_STRING:
|
case LUA_T_USERDATA: case LUA_T_STRING:
|
||||||
strmark(tsvalue(o));
|
strmark(tsvalue(o));
|
||||||
|
@ -231,8 +218,7 @@ static int markobject (TObject *o)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void markall (void)
|
static void markall (void) {
|
||||||
{
|
|
||||||
luaD_travstack(markobject); /* mark stack objects */
|
luaD_travstack(markobject); /* mark stack objects */
|
||||||
globalmark(); /* mark global variable values and names */
|
globalmark(); /* mark global variable values and names */
|
||||||
travlock(); /* mark locked objects */
|
travlock(); /* mark locked objects */
|
||||||
|
@ -240,8 +226,7 @@ static void markall (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long lua_collectgarbage (long limit)
|
long lua_collectgarbage (long limit) {
|
||||||
{
|
|
||||||
unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */
|
unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */
|
||||||
Hash *freetable;
|
Hash *freetable;
|
||||||
TaggedString *freestr;
|
TaggedString *freestr;
|
||||||
|
@ -267,8 +252,7 @@ long lua_collectgarbage (long limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaC_checkGC (void)
|
void luaC_checkGC (void) {
|
||||||
{
|
|
||||||
if (L->nblocks >= L->GCthreshold)
|
if (L->nblocks >= L->GCthreshold)
|
||||||
lua_collectgarbage(0);
|
lua_collectgarbage(0);
|
||||||
}
|
}
|
||||||
|
|
6
lgc.h
6
lgc.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lgc.h,v 1.3 1997/11/19 17:29:23 roberto Exp roberto $
|
** $Id: lgc.h,v 1.4 1997/12/01 20:31:25 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
|
|
||||||
void luaC_checkGC (void);
|
void luaC_checkGC (void);
|
||||||
TObject* luaC_getref (int ref);
|
const TObject *luaC_getref (int ref);
|
||||||
int luaC_ref (TObject *o, int lock);
|
int luaC_ref (const TObject *o, int lock);
|
||||||
void luaC_hashcallIM (Hash *l);
|
void luaC_hashcallIM (Hash *l);
|
||||||
void luaC_strcallIM (TaggedString *l);
|
void luaC_strcallIM (TaggedString *l);
|
||||||
|
|
||||||
|
|
48
liolib.c
48
liolib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 1.42 1999/07/22 19:35:50 roberto Exp roberto $
|
** $Id: liolib.c,v 1.43 1999/08/10 13:05:16 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -44,8 +44,8 @@
|
||||||
|
|
||||||
|
|
||||||
#ifdef POPEN
|
#ifdef POPEN
|
||||||
FILE *popen();
|
/* FILE *popen();
|
||||||
int pclose();
|
int pclose(); */
|
||||||
#define CLOSEFILE(f) ((pclose(f) == -1) ? fclose(f) : 0)
|
#define CLOSEFILE(f) ((pclose(f) == -1) ? fclose(f) : 0)
|
||||||
#else
|
#else
|
||||||
/* no support for popen */
|
/* no support for popen */
|
||||||
|
@ -88,7 +88,7 @@ static int ishandle (lua_Object f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static FILE *getfilebyname (char *name) {
|
static FILE *getfilebyname (const char *name) {
|
||||||
lua_Object f = lua_rawgetglobal(name);
|
lua_Object f = lua_rawgetglobal(name);
|
||||||
if (!ishandle(f))
|
if (!ishandle(f))
|
||||||
luaL_verror("global variable `%.50s' is not a file handle", name);
|
luaL_verror("global variable `%.50s' is not a file handle", name);
|
||||||
|
@ -109,7 +109,7 @@ static FILE *getnonullfile (int arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static FILE *getfileparam (char *name, int *arg) {
|
static FILE *getfileparam (const char *name, int *arg) {
|
||||||
FILE *f = getfile(*arg);
|
FILE *f = getfile(*arg);
|
||||||
if (f) {
|
if (f) {
|
||||||
(*arg)++;
|
(*arg)++;
|
||||||
|
@ -152,13 +152,13 @@ static void io_open (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void setfile (FILE *f, char *name, int tag) {
|
static void setfile (FILE *f, const char *name, int tag) {
|
||||||
lua_pushusertag(f, tag);
|
lua_pushusertag(f, tag);
|
||||||
lua_setglobal(name);
|
lua_setglobal(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void setreturn (FILE *f, char *name) {
|
static void setreturn (FILE *f, const char *name) {
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
pushresult(0);
|
pushresult(0);
|
||||||
else {
|
else {
|
||||||
|
@ -181,7 +181,7 @@ static void io_readfrom (void) {
|
||||||
else if (lua_tag(f) == gettag()) /* deprecated option */
|
else if (lua_tag(f) == gettag()) /* deprecated option */
|
||||||
current = lua_getuserdata(f);
|
current = lua_getuserdata(f);
|
||||||
else {
|
else {
|
||||||
char *s = luaL_check_string(FIRSTARG);
|
const char *s = luaL_check_string(FIRSTARG);
|
||||||
current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
|
current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
|
||||||
}
|
}
|
||||||
setreturn(current, FINPUT);
|
setreturn(current, FINPUT);
|
||||||
|
@ -200,7 +200,7 @@ static void io_writeto (void) {
|
||||||
else if (lua_tag(f) == gettag()) /* deprecated option */
|
else if (lua_tag(f) == gettag()) /* deprecated option */
|
||||||
current = lua_getuserdata(f);
|
current = lua_getuserdata(f);
|
||||||
else {
|
else {
|
||||||
char *s = luaL_check_string(FIRSTARG);
|
const char *s = luaL_check_string(FIRSTARG);
|
||||||
current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w");
|
current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w");
|
||||||
}
|
}
|
||||||
setreturn(current, FOUTPUT);
|
setreturn(current, FOUTPUT);
|
||||||
|
@ -228,7 +228,7 @@ static void io_appendto (void) {
|
||||||
#define NEED_OTHER (EOF-1) /* just some flag different from EOF */
|
#define NEED_OTHER (EOF-1) /* just some flag different from EOF */
|
||||||
|
|
||||||
|
|
||||||
static int read_pattern (FILE *f, char *p) {
|
static int read_pattern (FILE *f, const char *p) {
|
||||||
int inskip = 0; /* {skip} level */
|
int inskip = 0; /* {skip} level */
|
||||||
int c = NEED_OTHER;
|
int c = NEED_OTHER;
|
||||||
while (*p != '\0') {
|
while (*p != '\0') {
|
||||||
|
@ -243,7 +243,7 @@ static int read_pattern (FILE *f, char *p) {
|
||||||
p++;
|
p++;
|
||||||
continue;
|
continue;
|
||||||
default: {
|
default: {
|
||||||
char *ep = luaI_classend(p); /* get what is next */
|
const char *ep = luaI_classend(p); /* get what is next */
|
||||||
int m; /* match result */
|
int m; /* match result */
|
||||||
if (c == NEED_OTHER) c = getc(f);
|
if (c == NEED_OTHER) c = getc(f);
|
||||||
m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
|
m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
|
||||||
|
@ -317,10 +317,10 @@ static void read_file (FILE *f) {
|
||||||
|
|
||||||
|
|
||||||
static void io_read (void) {
|
static void io_read (void) {
|
||||||
static char *options[] = {"*n", "*l", "*a", ".*", "*w", NULL};
|
static const char *const options[] = {"*n", "*l", "*a", ".*", "*w", NULL};
|
||||||
int arg = FIRSTARG;
|
int arg = FIRSTARG;
|
||||||
FILE *f = getfileparam(FINPUT, &arg);
|
FILE *f = getfileparam(FINPUT, &arg);
|
||||||
char *p = luaL_opt_string(arg++, "*l");
|
const char *p = luaL_opt_string(arg++, "*l");
|
||||||
do { /* repeat for each part */
|
do { /* repeat for each part */
|
||||||
long l;
|
long l;
|
||||||
int success;
|
int success;
|
||||||
|
@ -355,7 +355,7 @@ static void io_write (void) {
|
||||||
int arg = FIRSTARG;
|
int arg = FIRSTARG;
|
||||||
FILE *f = getfileparam(FOUTPUT, &arg);
|
FILE *f = getfileparam(FOUTPUT, &arg);
|
||||||
int status = 1;
|
int status = 1;
|
||||||
char *s;
|
const char *s;
|
||||||
long l;
|
long l;
|
||||||
while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
|
while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
|
||||||
status = status && ((long)fwrite(s, 1, l, f) == l);
|
status = status && ((long)fwrite(s, 1, l, f) == l);
|
||||||
|
@ -364,8 +364,8 @@ static void io_write (void) {
|
||||||
|
|
||||||
|
|
||||||
static void io_seek (void) {
|
static void io_seek (void) {
|
||||||
static int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
||||||
static char *modenames[] = {"set", "cur", "end", NULL};
|
static const char *const modenames[] = {"set", "cur", "end", NULL};
|
||||||
FILE *f = getnonullfile(FIRSTARG);
|
FILE *f = getnonullfile(FIRSTARG);
|
||||||
int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames);
|
int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames);
|
||||||
long offset = luaL_opt_long(FIRSTARG+2, 0);
|
long offset = luaL_opt_long(FIRSTARG+2, 0);
|
||||||
|
@ -428,7 +428,7 @@ static void io_clock (void) {
|
||||||
|
|
||||||
static void io_date (void) {
|
static void io_date (void) {
|
||||||
char b[256];
|
char b[256];
|
||||||
char *s = luaL_opt_string(1, "%c");
|
const char *s = luaL_opt_string(1, "%c");
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
time_t t;
|
time_t t;
|
||||||
time(&t); tm = localtime(&t);
|
time(&t); tm = localtime(&t);
|
||||||
|
@ -440,9 +440,9 @@ static void io_date (void) {
|
||||||
|
|
||||||
|
|
||||||
static void setloc (void) {
|
static void setloc (void) {
|
||||||
static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC,
|
static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
|
||||||
LC_TIME};
|
LC_NUMERIC, LC_TIME};
|
||||||
static char *catnames[] = {"all", "collate", "ctype", "monetary",
|
static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
|
||||||
"numeric", "time", NULL};
|
"numeric", "time", NULL};
|
||||||
int op = luaL_findstring(luaL_opt_string(2, "all"), catnames);
|
int op = luaL_findstring(luaL_opt_string(2, "all"), catnames);
|
||||||
luaL_arg_check(op != -1, 2, "invalid option");
|
luaL_arg_check(op != -1, 2, "invalid option");
|
||||||
|
@ -485,9 +485,9 @@ static void errorfb (void) {
|
||||||
lua_Object func;
|
lua_Object func;
|
||||||
sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1)));
|
sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1)));
|
||||||
while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
|
while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
|
||||||
char *name;
|
const char *name;
|
||||||
int currentline;
|
int currentline;
|
||||||
char *chunkname;
|
const char *chunkname;
|
||||||
char buffchunk[MAXSRC];
|
char buffchunk[MAXSRC];
|
||||||
int linedefined;
|
int linedefined;
|
||||||
lua_funcinfo(func, &chunkname, &linedefined);
|
lua_funcinfo(func, &chunkname, &linedefined);
|
||||||
|
@ -531,7 +531,7 @@ static void errorfb (void) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static struct luaL_reg iolib[] = {
|
static const struct luaL_reg iolib[] = {
|
||||||
{"_ERRORMESSAGE", errorfb},
|
{"_ERRORMESSAGE", errorfb},
|
||||||
{"clock", io_clock},
|
{"clock", io_clock},
|
||||||
{"date", io_date},
|
{"date", io_date},
|
||||||
|
@ -546,7 +546,7 @@ static struct luaL_reg iolib[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct luaL_reg iolibtag[] = {
|
static const struct luaL_reg iolibtag[] = {
|
||||||
{"appendto", io_appendto},
|
{"appendto", io_appendto},
|
||||||
{"closefile", io_close},
|
{"closefile", io_close},
|
||||||
{"flush", io_flush},
|
{"flush", io_flush},
|
||||||
|
|
16
llex.c
16
llex.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 1.36 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: llex.c,v 1.37 1999/07/22 19:29:42 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -28,8 +28,8 @@
|
||||||
|
|
||||||
|
|
||||||
/* ORDER RESERVED */
|
/* ORDER RESERVED */
|
||||||
static char *reserved [] = {"and", "do", "else", "elseif", "end", "function",
|
static const char *const reserved [] = {"and", "do", "else", "elseif", "end",
|
||||||
"if", "local", "nil", "not", "or", "repeat", "return", "then",
|
"function", "if", "local", "nil", "not", "or", "repeat", "return", "then",
|
||||||
"until", "while"};
|
"until", "while"};
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ void luaX_init (void) {
|
||||||
|
|
||||||
#define MAXSRC 80
|
#define MAXSRC 80
|
||||||
|
|
||||||
void luaX_syntaxerror (LexState *ls, char *s, char *token) {
|
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
|
||||||
char buff[MAXSRC];
|
char buff[MAXSRC];
|
||||||
luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff));
|
luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff));
|
||||||
if (token[0] == '\0')
|
if (token[0] == '\0')
|
||||||
|
@ -54,7 +54,7 @@ void luaX_syntaxerror (LexState *ls, char *s, char *token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaX_error (LexState *ls, char *s) {
|
void luaX_error (LexState *ls, const char *s) {
|
||||||
save('\0');
|
save('\0');
|
||||||
luaX_syntaxerror(ls, s, luaL_buffer());
|
luaX_syntaxerror(ls, s, luaL_buffer());
|
||||||
}
|
}
|
||||||
|
@ -117,8 +117,8 @@ static void skipspace (LexState *LS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int checkcond (LexState *LS, char *buff) {
|
static int checkcond (LexState *LS, const char *buff) {
|
||||||
static char *opts[] = {"nil", "1", NULL};
|
static const char *const opts[] = {"nil", "1", NULL};
|
||||||
int i = luaL_findstring(buff, opts);
|
int i = luaL_findstring(buff, opts);
|
||||||
if (i >= 0) return i;
|
if (i >= 0) return i;
|
||||||
else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
|
else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
|
||||||
|
@ -160,7 +160,7 @@ static void ifskip (LexState *LS) {
|
||||||
|
|
||||||
|
|
||||||
static void inclinenumber (LexState *LS) {
|
static void inclinenumber (LexState *LS) {
|
||||||
static char *pragmas [] =
|
static const char *const pragmas [] =
|
||||||
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
|
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
|
||||||
next(LS); /* skip '\n' */
|
next(LS); /* skip '\n' */
|
||||||
++LS->linenumber;
|
++LS->linenumber;
|
||||||
|
|
6
llex.h
6
llex.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llex.h,v 1.12 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: llex.h,v 1.13 1999/07/22 19:29:42 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -61,8 +61,8 @@ typedef struct LexState {
|
||||||
void luaX_init (void);
|
void luaX_init (void);
|
||||||
void luaX_setinput (LexState *LS, ZIO *z);
|
void luaX_setinput (LexState *LS, ZIO *z);
|
||||||
int luaX_lex (LexState *LS);
|
int luaX_lex (LexState *LS);
|
||||||
void luaX_syntaxerror (LexState *ls, char *s, char *token);
|
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
|
||||||
void luaX_error (LexState *ls, char *s);
|
void luaX_error (LexState *ls, const char *s);
|
||||||
void luaX_token2str (int token, char *s);
|
void luaX_token2str (int token, char *s);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lmathlib.c,v 1.16 1999/02/19 17:33:35 roberto Exp roberto $
|
** $Id: lmathlib.c,v 1.17 1999/07/07 17:54:08 roberto Exp roberto $
|
||||||
** Lua standard mathematical library
|
** Lua standard mathematical library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -164,7 +164,7 @@ static void math_randomseed (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct luaL_reg mathlib[] = {
|
static const struct luaL_reg mathlib[] = {
|
||||||
{"abs", math_abs},
|
{"abs", math_abs},
|
||||||
{"sin", math_sin},
|
{"sin", math_sin},
|
||||||
{"cos", math_cos},
|
{"cos", math_cos},
|
||||||
|
|
14
lmem.c
14
lmem.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lmem.c,v 1.16 1999/05/20 20:43:06 roberto Exp roberto $
|
** $Id: lmem.c,v 1.17 1999/05/24 17:51:05 roberto Exp roberto $
|
||||||
** Interface to Memory Manager
|
** Interface to Memory Manager
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,7 @@ static unsigned long power2 (unsigned long n) {
|
||||||
|
|
||||||
|
|
||||||
void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
|
void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
|
||||||
char *errormsg, unsigned long limit) {
|
const char *errormsg, unsigned long limit) {
|
||||||
unsigned long newn = nelems+inc;
|
unsigned long newn = nelems+inc;
|
||||||
if (newn >= limit) lua_error(errormsg);
|
if (newn >= limit) lua_error(errormsg);
|
||||||
if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */
|
if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */
|
||||||
|
@ -86,9 +86,6 @@ unsigned long totalmem = 0;
|
||||||
|
|
||||||
|
|
||||||
static void *checkblock (void *block) {
|
static void *checkblock (void *block) {
|
||||||
if (block == NULL)
|
|
||||||
return NULL;
|
|
||||||
else {
|
|
||||||
unsigned long *b = blocksize(block);
|
unsigned long *b = blocksize(block);
|
||||||
unsigned long size = *b;
|
unsigned long size = *b;
|
||||||
int i;
|
int i;
|
||||||
|
@ -98,13 +95,14 @@ static void *checkblock (void *block) {
|
||||||
totalmem -= size;
|
totalmem -= size;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void freeblock (void *block) {
|
static void freeblock (void *block) {
|
||||||
if (block)
|
if (block) {
|
||||||
memset(block, -1, *blocksize(block)); /* erase block */
|
memset(block, -1, *blocksize(block)); /* erase block */
|
||||||
free(checkblock(block));
|
block = checkblock(block);
|
||||||
|
free(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
4
lmem.h
4
lmem.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lmem.h,v 1.7 1999/02/25 15:16:26 roberto Exp roberto $
|
** $Id: lmem.h,v 1.8 1999/02/26 15:48:55 roberto Exp roberto $
|
||||||
** Interface to Memory Manager
|
** Interface to Memory Manager
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
void *luaM_realloc (void *oldblock, unsigned long size);
|
void *luaM_realloc (void *oldblock, unsigned long size);
|
||||||
void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
|
void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
|
||||||
char *errormsg, unsigned long limit);
|
const char *errormsg, unsigned long limit);
|
||||||
|
|
||||||
#define luaM_free(b) luaM_realloc((b), 0)
|
#define luaM_free(b) luaM_realloc((b), 0)
|
||||||
#define luaM_malloc(t) luaM_realloc(NULL, (t))
|
#define luaM_malloc(t) luaM_realloc(NULL, (t))
|
||||||
|
|
18
lobject.c
18
lobject.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lobject.c,v 1.18 1999/02/26 15:48:30 roberto Exp roberto $
|
** $Id: lobject.c,v 1.19 1999/04/13 19:28:49 roberto Exp roberto $
|
||||||
** Some generic functions over Lua objects
|
** Some generic functions over Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -11,25 +11,24 @@
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
|
|
||||||
char *luaO_typenames[] = { /* ORDER LUA_T */
|
const char *const luaO_typenames[] = { /* ORDER LUA_T */
|
||||||
"userdata", "number", "string", "table", "function", "function",
|
"userdata", "number", "string", "table", "function", "function",
|
||||||
"nil", "function", "mark", "mark", "mark", "line", NULL
|
"nil", "function", "mark", "mark", "mark", "line", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
|
const TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* hash dimensions values */
|
/* hash dimensions values */
|
||||||
static long dimensions[] =
|
static const long dimensions[] =
|
||||||
{5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L,
|
{5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L,
|
||||||
12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L,
|
12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L,
|
||||||
1644817L, 3289613L, 6579211L, 13158023L, MAX_INT};
|
1644817L, 3289613L, 6579211L, 13158023L, MAX_INT};
|
||||||
|
|
||||||
|
|
||||||
int luaO_redimension (int oldsize)
|
int luaO_redimension (int oldsize) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0; dimensions[i]<MAX_INT; i++) {
|
for (i=0; dimensions[i]<MAX_INT; i++) {
|
||||||
if (dimensions[i] > oldsize)
|
if (dimensions[i] > oldsize)
|
||||||
|
@ -40,7 +39,7 @@ int luaO_redimension (int oldsize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int luaO_equalval (TObject *t1, TObject *t2) {
|
int luaO_equalval (const TObject *t1, const TObject *t2) {
|
||||||
switch (ttype(t1)) {
|
switch (ttype(t1)) {
|
||||||
case LUA_T_NIL: return 1;
|
case LUA_T_NIL: return 1;
|
||||||
case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
|
case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
|
||||||
|
@ -56,8 +55,7 @@ int luaO_equalval (TObject *t1, TObject *t2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaO_insertlist (GCnode *root, GCnode *node)
|
void luaO_insertlist (GCnode *root, GCnode *node) {
|
||||||
{
|
|
||||||
node->next = root->next;
|
node->next = root->next;
|
||||||
root->next = node;
|
root->next = node;
|
||||||
node->marked = 0;
|
node->marked = 0;
|
||||||
|
@ -90,7 +88,7 @@ static double expten (unsigned int e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double luaO_str2d (char *s) { /* LUA_NUMBER */
|
double luaO_str2d (const char *s) { /* LUA_NUMBER */
|
||||||
double a = 0.0;
|
double a = 0.0;
|
||||||
int point = 0;
|
int point = 0;
|
||||||
while (isdigit((unsigned char)*s)) {
|
while (isdigit((unsigned char)*s)) {
|
||||||
|
|
10
lobject.h
10
lobject.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lobject.h,v 1.27 1999/03/04 21:17:26 roberto Exp roberto $
|
** $Id: lobject.h,v 1.28 1999/03/16 16:43:27 roberto Exp roberto $
|
||||||
** Type definitions for Lua objects
|
** Type definitions for Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -178,19 +178,19 @@ typedef struct Hash {
|
||||||
} Hash;
|
} Hash;
|
||||||
|
|
||||||
|
|
||||||
extern char *luaO_typenames[];
|
extern const char *const luaO_typenames[];
|
||||||
|
|
||||||
#define luaO_typename(o) luaO_typenames[-ttype(o)]
|
#define luaO_typename(o) luaO_typenames[-ttype(o)]
|
||||||
|
|
||||||
|
|
||||||
extern TObject luaO_nilobject;
|
extern const TObject luaO_nilobject;
|
||||||
|
|
||||||
#define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \
|
#define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \
|
||||||
: luaO_equalval(t1,t2))
|
: luaO_equalval(t1,t2))
|
||||||
int luaO_equalval (TObject *t1, TObject *t2);
|
int luaO_equalval (const TObject *t1, const TObject *t2);
|
||||||
int luaO_redimension (int oldsize);
|
int luaO_redimension (int oldsize);
|
||||||
void luaO_insertlist (GCnode *root, GCnode *node);
|
void luaO_insertlist (GCnode *root, GCnode *node);
|
||||||
double luaO_str2d (char *s);
|
double luaO_str2d (const char *s);
|
||||||
|
|
||||||
#ifdef OLD_ANSI
|
#ifdef OLD_ANSI
|
||||||
void luaO_memup (void *dest, void *src, int size);
|
void luaO_memup (void *dest, void *src, int size);
|
||||||
|
|
23
lparser.c
23
lparser.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 1.37 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: lparser.c,v 1.38 1999/07/22 19:29:42 roberto Exp roberto $
|
||||||
** LL(1) Parser and code generator for Lua
|
** LL(1) Parser and code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -142,7 +142,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void checklimit (LexState *ls, int val, int limit, char *msg) {
|
static void checklimit (LexState *ls, int val, int limit, const char *msg) {
|
||||||
if (val > limit) {
|
if (val > limit) {
|
||||||
char buff[100];
|
char buff[100];
|
||||||
sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
|
sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
|
||||||
|
@ -498,7 +498,7 @@ static void lua_pushvar (LexState *ls, vardesc *var) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void storevar (LexState *ls, vardesc *var) {
|
static void storevar (LexState *ls, const vardesc *var) {
|
||||||
switch (var->k) {
|
switch (var->k) {
|
||||||
case VLOCAL:
|
case VLOCAL:
|
||||||
code_oparg(ls, SETLOCAL, var->info, -1);
|
code_oparg(ls, SETLOCAL, var->info, -1);
|
||||||
|
@ -597,12 +597,13 @@ static void close_func (LexState *ls) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME,
|
static const int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT,
|
||||||
LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';', EOS, ',', 0};
|
DO, NAME, LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';',
|
||||||
|
EOS, ',', 0};
|
||||||
|
|
||||||
|
|
||||||
static int is_in (int tok, int *toks) {
|
static int is_in (int tok, const int *toks) {
|
||||||
int *t;
|
const int *t;
|
||||||
for (t=toks; *t; t++)
|
for (t=toks; *t; t++)
|
||||||
if (*t == tok) return t-toks;
|
if (*t == tok) return t-toks;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -923,13 +924,13 @@ static void ret (LexState *ls) {
|
||||||
*/
|
*/
|
||||||
#define POW 13
|
#define POW 13
|
||||||
|
|
||||||
static int binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
|
static const int binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
|
||||||
'+', '-', '*', '/', '^', 0};
|
'+', '-', '*', '/', '^', 0};
|
||||||
|
|
||||||
static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
|
static const int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
|
||||||
|
|
||||||
static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP,
|
static const OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP,
|
||||||
LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
|
LTOP, LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
|
||||||
|
|
||||||
#define MAXOPS 20 /* op's stack size (arbitrary limit) */
|
#define MAXOPS 20 /* op's stack size (arbitrary limit) */
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lparser.h,v 1.2 1997/12/22 20:57:18 roberto Exp roberto $
|
** $Id: lparser.h,v 1.3 1999/02/25 19:13:56 roberto Exp roberto $
|
||||||
** LL(1) Parser and code generator for Lua
|
** LL(1) Parser and code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
void luaY_codedebugline (int line);
|
void luaY_codedebugline (int line);
|
||||||
TProtoFunc *luaY_parser (ZIO *z);
|
TProtoFunc *luaY_parser (ZIO *z);
|
||||||
void luaY_error (char *s);
|
void luaY_error (const char *s);
|
||||||
void luaY_syntaxerror (char *s, char *token);
|
void luaY_syntaxerror (const char *s, const char *token);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
8
lstate.c
8
lstate.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstate.c,v 1.11 1999/05/11 14:19:32 roberto Exp roberto $
|
** $Id: lstate.c,v 1.12 1999/05/11 20:08:20 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,8 +20,7 @@
|
||||||
lua_State *lua_state = NULL;
|
lua_State *lua_state = NULL;
|
||||||
|
|
||||||
|
|
||||||
void lua_open (void)
|
void lua_open (void) {
|
||||||
{
|
|
||||||
if (lua_state) return;
|
if (lua_state) return;
|
||||||
lua_state = luaM_new(lua_State);
|
lua_state = luaM_new(lua_State);
|
||||||
L->Cstack.base = 0;
|
L->Cstack.base = 0;
|
||||||
|
@ -58,8 +57,7 @@ void lua_open (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lua_close (void)
|
void lua_close (void) {
|
||||||
{
|
|
||||||
TaggedString *alludata = luaS_collectudata();
|
TaggedString *alludata = luaS_collectudata();
|
||||||
L->GCthreshold = MAX_INT; /* to avoid GC during GC */
|
L->GCthreshold = MAX_INT; /* to avoid GC during GC */
|
||||||
luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */
|
luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */
|
||||||
|
|
20
lstring.c
20
lstring.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstring.c,v 1.18 1999/02/08 16:28:48 roberto Exp roberto $
|
** $Id: lstring.c,v 1.19 1999/02/26 15:49:53 roberto Exp roberto $
|
||||||
** String table (keeps all strings handled by Lua)
|
** String table (keeps all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -38,7 +38,7 @@ void luaS_init (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static unsigned long hash_s (char *s, long l) {
|
static unsigned long hash_s (const char *s, long l) {
|
||||||
unsigned long h = 0; /* seed */
|
unsigned long h = 0; /* seed */
|
||||||
while (l--)
|
while (l--)
|
||||||
h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++));
|
h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++));
|
||||||
|
@ -83,7 +83,7 @@ static void grow (stringtable *tb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static TaggedString *newone_s (char *str, long l, unsigned long h) {
|
static TaggedString *newone_s (const char *str, long l, unsigned long h) {
|
||||||
TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l);
|
TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l);
|
||||||
memcpy(ts->str, str, l);
|
memcpy(ts->str, str, l);
|
||||||
ts->str[l] = 0; /* ending 0 */
|
ts->str[l] = 0; /* ending 0 */
|
||||||
|
@ -97,7 +97,7 @@ static TaggedString *newone_s (char *str, long l, unsigned long h) {
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TaggedString *newone_u (char *buff, int tag, unsigned long h) {
|
static TaggedString *newone_u (void *buff, int tag, unsigned long h) {
|
||||||
TaggedString *ts = luaM_new(TaggedString);
|
TaggedString *ts = luaM_new(TaggedString);
|
||||||
ts->u.d.v = buff;
|
ts->u.d.v = buff;
|
||||||
ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
|
ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
|
||||||
|
@ -109,7 +109,7 @@ static TaggedString *newone_u (char *buff, int tag, unsigned long h) {
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TaggedString *insert_s (char *str, long l, stringtable *tb) {
|
static TaggedString *insert_s (const char *str, long l, stringtable *tb) {
|
||||||
TaggedString *ts;
|
TaggedString *ts;
|
||||||
unsigned long h = hash_s(str, l);
|
unsigned long h = hash_s(str, l);
|
||||||
int size = tb->size;
|
int size = tb->size;
|
||||||
|
@ -172,16 +172,16 @@ TaggedString *luaS_createudata (void *udata, int tag) {
|
||||||
return insert_u(udata, tag, &L->string_root[t]);
|
return insert_u(udata, tag, &L->string_root[t]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TaggedString *luaS_newlstr (char *str, long l) {
|
TaggedString *luaS_newlstr (const char *str, long l) {
|
||||||
int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR;
|
int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR;
|
||||||
return insert_s(str, l, &L->string_root[t]);
|
return insert_s(str, l, &L->string_root[t]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TaggedString *luaS_new (char *str) {
|
TaggedString *luaS_new (const char *str) {
|
||||||
return luaS_newlstr(str, strlen(str));
|
return luaS_newlstr(str, strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
TaggedString *luaS_newfixedstring (char *str) {
|
TaggedString *luaS_newfixedstring (const char *str) {
|
||||||
TaggedString *ts = luaS_new(str);
|
TaggedString *ts = luaS_new(str);
|
||||||
if (ts->head.marked == 0)
|
if (ts->head.marked == 0)
|
||||||
ts->head.marked = 2; /* avoid GC */
|
ts->head.marked = 2; /* avoid GC */
|
||||||
|
@ -282,7 +282,7 @@ void luaS_rawsetglobal (TaggedString *ts, TObject *newval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *luaS_travsymbol (int (*fn)(TObject *)) {
|
const char *luaS_travsymbol (int (*fn)(TObject *)) {
|
||||||
TaggedString *g;
|
TaggedString *g;
|
||||||
for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next)
|
for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next)
|
||||||
if (fn(&g->u.s.globalval))
|
if (fn(&g->u.s.globalval))
|
||||||
|
@ -291,7 +291,7 @@ char *luaS_travsymbol (int (*fn)(TObject *)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int luaS_globaldefined (char *name) {
|
int luaS_globaldefined (const char *name) {
|
||||||
TaggedString *ts = luaS_new(name);
|
TaggedString *ts = luaS_new(name);
|
||||||
return ts->u.s.globalval.ttype != LUA_T_NIL;
|
return ts->u.s.globalval.ttype != LUA_T_NIL;
|
||||||
}
|
}
|
||||||
|
|
12
lstring.h
12
lstring.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstring.h,v 1.6 1997/12/01 20:31:25 roberto Exp roberto $
|
** $Id: lstring.h,v 1.7 1998/03/06 16:54:42 roberto Exp roberto $
|
||||||
** String table (keep all strings handled by Lua)
|
** String table (keep all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -15,12 +15,12 @@ void luaS_init (void);
|
||||||
TaggedString *luaS_createudata (void *udata, int tag);
|
TaggedString *luaS_createudata (void *udata, int tag);
|
||||||
TaggedString *luaS_collector (void);
|
TaggedString *luaS_collector (void);
|
||||||
void luaS_free (TaggedString *l);
|
void luaS_free (TaggedString *l);
|
||||||
TaggedString *luaS_newlstr (char *str, long l);
|
TaggedString *luaS_newlstr (const char *str, long l);
|
||||||
TaggedString *luaS_new (char *str);
|
TaggedString *luaS_new (const char *str);
|
||||||
TaggedString *luaS_newfixedstring (char *str);
|
TaggedString *luaS_newfixedstring (const char *str);
|
||||||
void luaS_rawsetglobal (TaggedString *ts, TObject *newval);
|
void luaS_rawsetglobal (TaggedString *ts, TObject *newval);
|
||||||
char *luaS_travsymbol (int (*fn)(TObject *));
|
const char *luaS_travsymbol (int (*fn)(TObject *));
|
||||||
int luaS_globaldefined (char *name);
|
int luaS_globaldefined (const char *name);
|
||||||
TaggedString *luaS_collectudata (void);
|
TaggedString *luaS_collectudata (void);
|
||||||
void luaS_freeall (void);
|
void luaS_freeall (void);
|
||||||
|
|
||||||
|
|
91
lstrlib.c
91
lstrlib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstrlib.c,v 1.32 1999/06/17 17:04:03 roberto Exp roberto $
|
** $Id: lstrlib.c,v 1.33 1999/08/10 12:55:56 roberto Exp roberto $
|
||||||
** Standard library for strings and pattern-matching
|
** Standard library for strings and pattern-matching
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -16,16 +16,14 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void addnchar (char *s, int n)
|
static void addnchar (const char *s, int n) {
|
||||||
{
|
|
||||||
char *b = luaL_openspace(n);
|
char *b = luaL_openspace(n);
|
||||||
memcpy(b, s, n);
|
memcpy(b, s, n);
|
||||||
luaL_addsize(n);
|
luaL_addsize(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void str_len (void)
|
static void str_len (void) {
|
||||||
{
|
|
||||||
long l;
|
long l;
|
||||||
luaL_check_lstr(1, &l);
|
luaL_check_lstr(1, &l);
|
||||||
lua_pushnumber(l);
|
lua_pushnumber(l);
|
||||||
|
@ -45,7 +43,7 @@ static long posrelat (long pos, long len) {
|
||||||
|
|
||||||
static void str_sub (void) {
|
static void str_sub (void) {
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
long start = posrelat(luaL_check_long(2), l);
|
long start = posrelat(luaL_check_long(2), l);
|
||||||
long end = posrelat(luaL_opt_long(3, -1), l);
|
long end = posrelat(luaL_opt_long(3, -1), l);
|
||||||
if (start < 1) start = 1;
|
if (start < 1) start = 1;
|
||||||
|
@ -59,7 +57,7 @@ static void str_sub (void) {
|
||||||
static void str_lower (void) {
|
static void str_lower (void) {
|
||||||
long l;
|
long l;
|
||||||
int i;
|
int i;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
luaL_resetbuffer();
|
luaL_resetbuffer();
|
||||||
for (i=0; i<l; i++)
|
for (i=0; i<l; i++)
|
||||||
luaL_addchar(tolower((unsigned char)(s[i])));
|
luaL_addchar(tolower((unsigned char)(s[i])));
|
||||||
|
@ -70,17 +68,16 @@ static void str_lower (void) {
|
||||||
static void str_upper (void) {
|
static void str_upper (void) {
|
||||||
long l;
|
long l;
|
||||||
int i;
|
int i;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
luaL_resetbuffer();
|
luaL_resetbuffer();
|
||||||
for (i=0; i<l; i++)
|
for (i=0; i<l; i++)
|
||||||
luaL_addchar(toupper((unsigned char)(s[i])));
|
luaL_addchar(toupper((unsigned char)(s[i])));
|
||||||
closeandpush();
|
closeandpush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void str_rep (void)
|
static void str_rep (void) {
|
||||||
{
|
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
int n = luaL_check_int(2);
|
int n = luaL_check_int(2);
|
||||||
luaL_resetbuffer();
|
luaL_resetbuffer();
|
||||||
while (n-- > 0)
|
while (n-- > 0)
|
||||||
|
@ -91,7 +88,7 @@ static void str_rep (void)
|
||||||
|
|
||||||
static void str_byte (void) {
|
static void str_byte (void) {
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
long pos = posrelat(luaL_opt_long(2, 1), l);
|
long pos = posrelat(luaL_opt_long(2, 1), l);
|
||||||
luaL_arg_check(0<pos && pos<=l, 2, "out of range");
|
luaL_arg_check(0<pos && pos<=l, 2, "out of range");
|
||||||
lua_pushnumber((unsigned char)s[pos-1]);
|
lua_pushnumber((unsigned char)s[pos-1]);
|
||||||
|
@ -123,10 +120,10 @@ static void str_char (void) {
|
||||||
|
|
||||||
|
|
||||||
struct Capture {
|
struct Capture {
|
||||||
char *src_end; /* end ('\0') of source string */
|
const char *src_end; /* end ('\0') of source string */
|
||||||
int level; /* total number of captures (finished or unfinished) */
|
int level; /* total number of captures (finished or unfinished) */
|
||||||
struct {
|
struct {
|
||||||
char *init;
|
const char *init;
|
||||||
int len; /* -1 signals unfinished capture */
|
int len; /* -1 signals unfinished capture */
|
||||||
} capture[MAX_CAPT];
|
} capture[MAX_CAPT];
|
||||||
};
|
};
|
||||||
|
@ -163,7 +160,7 @@ static int capture_to_close (struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *luaI_classend (char *p) {
|
const char *luaI_classend (const char *p) {
|
||||||
switch (*p++) {
|
switch (*p++) {
|
||||||
case ESC:
|
case ESC:
|
||||||
if (*p == '\0') lua_error("incorrect pattern (ends with `%')");
|
if (*p == '\0') lua_error("incorrect pattern (ends with `%')");
|
||||||
|
@ -201,7 +198,7 @@ static int matchclass (int c, int cl) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int matchbracketclass (int c, char *p, char *endclass) {
|
static int matchbracketclass (int c, const char *p, const char *endclass) {
|
||||||
int sig = 1;
|
int sig = 1;
|
||||||
if (*(p+1) == '^') {
|
if (*(p+1) == '^') {
|
||||||
sig = 0;
|
sig = 0;
|
||||||
|
@ -225,7 +222,7 @@ static int matchbracketclass (int c, char *p, char *endclass) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int luaI_singlematch (int c, char *p, char *ep) {
|
int luaI_singlematch (int c, const char *p, const char *ep) {
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '.': /* matches any char */
|
case '.': /* matches any char */
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -239,10 +236,11 @@ int luaI_singlematch (int c, char *p, char *ep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *match (char *s, char *p, struct Capture *cap);
|
static const char *match (const char *s, const char *p, struct Capture *cap);
|
||||||
|
|
||||||
|
|
||||||
static char *matchbalance (char *s, char *p, struct Capture *cap) {
|
static const char *matchbalance (const char *s, const char *p,
|
||||||
|
struct Capture *cap) {
|
||||||
if (*p == 0 || *(p+1) == 0)
|
if (*p == 0 || *(p+1) == 0)
|
||||||
lua_error("unbalanced pattern");
|
lua_error("unbalanced pattern");
|
||||||
if (*s != *p) return NULL;
|
if (*s != *p) return NULL;
|
||||||
|
@ -261,13 +259,14 @@ static char *matchbalance (char *s, char *p, struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) {
|
static const char *max_expand (const char *s, const char *p, const char *ep,
|
||||||
|
struct Capture *cap) {
|
||||||
int i = 0; /* counts maximum expand for item */
|
int i = 0; /* counts maximum expand for item */
|
||||||
while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep))
|
while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep))
|
||||||
i++;
|
i++;
|
||||||
/* keeps trying to match mith the maximum repetitions */
|
/* keeps trying to match mith the maximum repetitions */
|
||||||
while (i>=0) {
|
while (i>=0) {
|
||||||
char *res = match((s+i), ep+1, cap);
|
const char *res = match((s+i), ep+1, cap);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
i--; /* else didn't match; reduce 1 repetition to try again */
|
i--; /* else didn't match; reduce 1 repetition to try again */
|
||||||
}
|
}
|
||||||
|
@ -275,9 +274,10 @@ static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) {
|
static const char *min_expand (const char *s, const char *p, const char *ep,
|
||||||
|
struct Capture *cap) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char *res = match(s, ep+1, cap);
|
const char *res = match(s, ep+1, cap);
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
return res;
|
return res;
|
||||||
else if (s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep))
|
else if (s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep))
|
||||||
|
@ -287,8 +287,9 @@ static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *start_capt (char *s, char *p, struct Capture *cap) {
|
static const char *start_capt (const char *s, const char *p,
|
||||||
char *res;
|
struct Capture *cap) {
|
||||||
|
const char *res;
|
||||||
int level = cap->level;
|
int level = cap->level;
|
||||||
if (level >= MAX_CAPT) lua_error("too many captures");
|
if (level >= MAX_CAPT) lua_error("too many captures");
|
||||||
cap->capture[level].init = s;
|
cap->capture[level].init = s;
|
||||||
|
@ -300,9 +301,10 @@ static char *start_capt (char *s, char *p, struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *end_capt (char *s, char *p, struct Capture *cap) {
|
static const char *end_capt (const char *s, const char *p,
|
||||||
|
struct Capture *cap) {
|
||||||
int l = capture_to_close(cap);
|
int l = capture_to_close(cap);
|
||||||
char *res;
|
const char *res;
|
||||||
cap->capture[l].len = s - cap->capture[l].init; /* close capture */
|
cap->capture[l].len = s - cap->capture[l].init; /* close capture */
|
||||||
if ((res = match(s, p+1, cap)) == NULL) /* match failed? */
|
if ((res = match(s, p+1, cap)) == NULL) /* match failed? */
|
||||||
cap->capture[l].len = -1; /* undo capture */
|
cap->capture[l].len = -1; /* undo capture */
|
||||||
|
@ -310,7 +312,8 @@ static char *end_capt (char *s, char *p, struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *match_capture (char *s, int level, struct Capture *cap) {
|
static const char *match_capture (const char *s, int level,
|
||||||
|
struct Capture *cap) {
|
||||||
int l = check_cap(level, cap);
|
int l = check_cap(level, cap);
|
||||||
int len = cap->capture[l].len;
|
int len = cap->capture[l].len;
|
||||||
if (cap->src_end-s >= len &&
|
if (cap->src_end-s >= len &&
|
||||||
|
@ -320,7 +323,7 @@ static char *match_capture (char *s, int level, struct Capture *cap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *match (char *s, char *p, struct Capture *cap) {
|
static const char *match (const char *s, const char *p, struct Capture *cap) {
|
||||||
init: /* using goto's to optimize tail recursion */
|
init: /* using goto's to optimize tail recursion */
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '(': /* start capture */
|
case '(': /* start capture */
|
||||||
|
@ -346,11 +349,11 @@ static char *match (char *s, char *p, struct Capture *cap) {
|
||||||
return (s == cap->src_end) ? s : NULL; /* check end of string */
|
return (s == cap->src_end) ? s : NULL; /* check end of string */
|
||||||
else goto dflt;
|
else goto dflt;
|
||||||
default: dflt: { /* it is a pattern item */
|
default: dflt: { /* it is a pattern item */
|
||||||
char *ep = luaI_classend(p); /* points to what is next */
|
const char *ep = luaI_classend(p); /* points to what is next */
|
||||||
int m = s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep);
|
int m = s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep);
|
||||||
switch (*ep) {
|
switch (*ep) {
|
||||||
case '?': { /* optional */
|
case '?': { /* optional */
|
||||||
char *res;
|
const char *res;
|
||||||
if (m && ((res=match(s+1, ep+1, cap)) != NULL))
|
if (m && ((res=match(s+1, ep+1, cap)) != NULL))
|
||||||
return res;
|
return res;
|
||||||
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
|
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
|
||||||
|
@ -372,8 +375,8 @@ static char *match (char *s, char *p, struct Capture *cap) {
|
||||||
|
|
||||||
static void str_find (void) {
|
static void str_find (void) {
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(1, &l);
|
const char *s = luaL_check_lstr(1, &l);
|
||||||
char *p = luaL_check_string(2);
|
const char *p = luaL_check_string(2);
|
||||||
long init = posrelat(luaL_opt_long(3, 1), l) - 1;
|
long init = posrelat(luaL_opt_long(3, 1), l) - 1;
|
||||||
struct Capture cap;
|
struct Capture cap;
|
||||||
luaL_arg_check(0 <= init && init <= l, 3, "out of range");
|
luaL_arg_check(0 <= init && init <= l, 3, "out of range");
|
||||||
|
@ -388,10 +391,10 @@ static void str_find (void) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int anchor = (*p == '^') ? (p++, 1) : 0;
|
int anchor = (*p == '^') ? (p++, 1) : 0;
|
||||||
char *s1=s+init;
|
const char *s1=s+init;
|
||||||
cap.src_end = s+l;
|
cap.src_end = s+l;
|
||||||
do {
|
do {
|
||||||
char *res;
|
const char *res;
|
||||||
cap.level = 0;
|
cap.level = 0;
|
||||||
if ((res=match(s1, p, &cap)) != NULL) {
|
if ((res=match(s1, p, &cap)) != NULL) {
|
||||||
lua_pushnumber(s1-s+1); /* start */
|
lua_pushnumber(s1-s+1); /* start */
|
||||||
|
@ -407,7 +410,7 @@ static void str_find (void) {
|
||||||
|
|
||||||
static void add_s (lua_Object newp, struct Capture *cap) {
|
static void add_s (lua_Object newp, struct Capture *cap) {
|
||||||
if (lua_isstring(newp)) {
|
if (lua_isstring(newp)) {
|
||||||
char *news = lua_getstring(newp);
|
const char *news = lua_getstring(newp);
|
||||||
int l = lua_strlen(newp);
|
int l = lua_strlen(newp);
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<l; i++) {
|
for (i=0; i<l; i++) {
|
||||||
|
@ -449,8 +452,8 @@ static void add_s (lua_Object newp, struct Capture *cap) {
|
||||||
|
|
||||||
static void str_gsub (void) {
|
static void str_gsub (void) {
|
||||||
long srcl;
|
long srcl;
|
||||||
char *src = luaL_check_lstr(1, &srcl);
|
const char *src = luaL_check_lstr(1, &srcl);
|
||||||
char *p = luaL_check_string(2);
|
const char *p = luaL_check_string(2);
|
||||||
lua_Object newp = lua_getparam(3);
|
lua_Object newp = lua_getparam(3);
|
||||||
int max_s = luaL_opt_int(4, srcl+1);
|
int max_s = luaL_opt_int(4, srcl+1);
|
||||||
int anchor = (*p == '^') ? (p++, 1) : 0;
|
int anchor = (*p == '^') ? (p++, 1) : 0;
|
||||||
|
@ -461,7 +464,7 @@ static void str_gsub (void) {
|
||||||
luaL_resetbuffer();
|
luaL_resetbuffer();
|
||||||
cap.src_end = src+srcl;
|
cap.src_end = src+srcl;
|
||||||
while (n < max_s) {
|
while (n < max_s) {
|
||||||
char *e;
|
const char *e;
|
||||||
cap.level = 0;
|
cap.level = 0;
|
||||||
e = match(src, p, &cap);
|
e = match(src, p, &cap);
|
||||||
if (e) {
|
if (e) {
|
||||||
|
@ -485,7 +488,7 @@ static void str_gsub (void) {
|
||||||
|
|
||||||
static void luaI_addquoted (int arg) {
|
static void luaI_addquoted (int arg) {
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(arg, &l);
|
const char *s = luaL_check_lstr(arg, &l);
|
||||||
luaL_addchar('"');
|
luaL_addchar('"');
|
||||||
while (l--) {
|
while (l--) {
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
|
@ -506,7 +509,7 @@ static void luaI_addquoted (int arg) {
|
||||||
|
|
||||||
static void str_format (void) {
|
static void str_format (void) {
|
||||||
int arg = 1;
|
int arg = 1;
|
||||||
char *strfrmt = luaL_check_string(arg);
|
const char *strfrmt = luaL_check_string(arg);
|
||||||
luaL_resetbuffer();
|
luaL_resetbuffer();
|
||||||
while (*strfrmt) {
|
while (*strfrmt) {
|
||||||
if (*strfrmt != '%')
|
if (*strfrmt != '%')
|
||||||
|
@ -517,7 +520,7 @@ static void str_format (void) {
|
||||||
struct Capture cap;
|
struct Capture cap;
|
||||||
char form[MAX_FORMAT]; /* to store the format ('%...') */
|
char form[MAX_FORMAT]; /* to store the format ('%...') */
|
||||||
char *buff; /* to store the formatted item */
|
char *buff; /* to store the formatted item */
|
||||||
char *initf = strfrmt;
|
const char *initf = strfrmt;
|
||||||
form[0] = '%';
|
form[0] = '%';
|
||||||
if (isdigit((unsigned char)*initf) && *(initf+1) == '$') {
|
if (isdigit((unsigned char)*initf) && *(initf+1) == '$') {
|
||||||
arg = *initf - '0';
|
arg = *initf - '0';
|
||||||
|
@ -548,7 +551,7 @@ static void str_format (void) {
|
||||||
continue; /* skip the "addsize" at the end */
|
continue; /* skip the "addsize" at the end */
|
||||||
case 's': {
|
case 's': {
|
||||||
long l;
|
long l;
|
||||||
char *s = luaL_check_lstr(arg, &l);
|
const char *s = luaL_check_lstr(arg, &l);
|
||||||
if (cap.capture[1].len == 0 && l >= 100) {
|
if (cap.capture[1].len == 0 && l >= 100) {
|
||||||
/* no precision and string is too big to be formatted;
|
/* no precision and string is too big to be formatted;
|
||||||
keep original string */
|
keep original string */
|
||||||
|
@ -570,7 +573,7 @@ static void str_format (void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct luaL_reg strlib[] = {
|
static const struct luaL_reg strlib[] = {
|
||||||
{"strlen", str_len},
|
{"strlen", str_len},
|
||||||
{"strsub", str_sub},
|
{"strsub", str_sub},
|
||||||
{"strlower", str_lower},
|
{"strlower", str_lower},
|
||||||
|
|
14
ltable.c
14
ltable.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 1.21 1999/02/23 14:57:28 roberto Exp roberto $
|
** $Id: ltable.c,v 1.22 1999/05/21 19:41:49 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static long int hashindex (TObject *ref) {
|
static long int hashindex (const TObject *ref) {
|
||||||
long int h;
|
long int h;
|
||||||
switch (ttype(ref)) {
|
switch (ttype(ref)) {
|
||||||
case LUA_T_NUMBER:
|
case LUA_T_NUMBER:
|
||||||
|
@ -53,7 +53,7 @@ static long int hashindex (TObject *ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Node *luaH_present (Hash *t, TObject *key) {
|
Node *luaH_present (const Hash *t, const TObject *key) {
|
||||||
int tsize = nhash(t);
|
int tsize = nhash(t);
|
||||||
long int h = hashindex(key);
|
long int h = hashindex(key);
|
||||||
int h1 = h%tsize;
|
int h1 = h%tsize;
|
||||||
|
@ -135,7 +135,7 @@ static void rehash (Hash *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaH_set (Hash *t, TObject *ref, TObject *val) {
|
void luaH_set (Hash *t, const TObject *ref, const TObject *val) {
|
||||||
Node *n = luaH_present(t, ref);
|
Node *n = luaH_present(t, ref);
|
||||||
if (ttype(ref(n)) != LUA_T_NIL)
|
if (ttype(ref(n)) != LUA_T_NIL)
|
||||||
*val(n) = *val;
|
*val(n) = *val;
|
||||||
|
@ -153,14 +153,14 @@ void luaH_set (Hash *t, TObject *ref, TObject *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int luaH_pos (Hash *t, TObject *r) {
|
int luaH_pos (const Hash *t, const TObject *r) {
|
||||||
Node *n = luaH_present(t, r);
|
Node *n = luaH_present(t, r);
|
||||||
luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found");
|
luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found");
|
||||||
return n-(t->node);
|
return n-(t->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaH_setint (Hash *t, int ref, TObject *val) {
|
void luaH_setint (Hash *t, int ref, const TObject *val) {
|
||||||
TObject index;
|
TObject index;
|
||||||
ttype(&index) = LUA_T_NUMBER;
|
ttype(&index) = LUA_T_NUMBER;
|
||||||
nvalue(&index) = ref;
|
nvalue(&index) = ref;
|
||||||
|
@ -168,7 +168,7 @@ void luaH_setint (Hash *t, int ref, TObject *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TObject *luaH_getint (Hash *t, int ref) {
|
TObject *luaH_getint (const Hash *t, int ref) {
|
||||||
TObject index;
|
TObject index;
|
||||||
ttype(&index) = LUA_T_NUMBER;
|
ttype(&index) = LUA_T_NUMBER;
|
||||||
nvalue(&index) = ref;
|
nvalue(&index) = ref;
|
||||||
|
|
12
ltable.h
12
ltable.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltable.h,v 1.10 1999/01/25 17:40:10 roberto Exp roberto $
|
** $Id: ltable.h,v 1.11 1999/02/23 14:57:28 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,11 +20,11 @@
|
||||||
|
|
||||||
Hash *luaH_new (int nhash);
|
Hash *luaH_new (int nhash);
|
||||||
void luaH_free (Hash *frees);
|
void luaH_free (Hash *frees);
|
||||||
Node *luaH_present (Hash *t, TObject *key);
|
Node *luaH_present (const Hash *t, const TObject *key);
|
||||||
void luaH_set (Hash *t, TObject *ref, TObject *val);
|
void luaH_set (Hash *t, const TObject *ref, const TObject *val);
|
||||||
int luaH_pos (Hash *t, TObject *r);
|
int luaH_pos (const Hash *t, const TObject *r);
|
||||||
void luaH_setint (Hash *t, int ref, TObject *val);
|
void luaH_setint (Hash *t, int ref, const TObject *val);
|
||||||
TObject *luaH_getint (Hash *t, int ref);
|
TObject *luaH_getint (const Hash *t, int ref);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
22
ltm.c
22
ltm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltm.c,v 1.24 1999/02/26 15:48:55 roberto Exp roberto $
|
** $Id: ltm.c,v 1.25 1999/05/21 19:41:49 roberto Exp roberto $
|
||||||
** Tag methods
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -15,14 +15,14 @@
|
||||||
#include "ltm.h"
|
#include "ltm.h"
|
||||||
|
|
||||||
|
|
||||||
char *luaT_eventname[] = { /* ORDER IM */
|
const char *const luaT_eventname[] = { /* ORDER IM */
|
||||||
"gettable", "settable", "index", "getglobal", "setglobal", "add",
|
"gettable", "settable", "index", "getglobal", "setglobal", "add",
|
||||||
"sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
|
"sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
|
||||||
"concat", "gc", "function", NULL
|
"concat", "gc", "function", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int luaI_checkevent (char *name, char *list[]) {
|
static int luaI_checkevent (const char *name, const char *const list[]) {
|
||||||
int e = luaL_findstring(name, list);
|
int e = luaL_findstring(name, list);
|
||||||
if (e < 0)
|
if (e < 0)
|
||||||
luaL_verror("`%.50s' is not a valid event name", name);
|
luaL_verror("`%.50s' is not a valid event name", name);
|
||||||
|
@ -34,7 +34,8 @@ static int luaI_checkevent (char *name, char *list[]) {
|
||||||
/* events in LUA_T_NIL are all allowed, since this is used as a
|
/* events in LUA_T_NIL are all allowed, since this is used as a
|
||||||
* 'placeholder' for "default" fallbacks
|
* 'placeholder' for "default" fallbacks
|
||||||
*/
|
*/
|
||||||
static char luaT_validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
|
/* ORDER LUA_T, ORDER IM */
|
||||||
|
static const char luaT_validevents[NUM_TAGS][IM_N] = {
|
||||||
{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */
|
{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */
|
||||||
{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */
|
{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */
|
||||||
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */
|
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */
|
||||||
|
@ -96,7 +97,7 @@ int lua_copytagmethods (int tagto, int tagfrom) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int luaT_effectivetag (TObject *o) {
|
int luaT_effectivetag (const TObject *o) {
|
||||||
int t;
|
int t;
|
||||||
switch (t = ttype(o)) {
|
switch (t = ttype(o)) {
|
||||||
case LUA_T_ARRAY:
|
case LUA_T_ARRAY:
|
||||||
|
@ -118,7 +119,7 @@ int luaT_effectivetag (TObject *o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TObject *luaT_gettagmethod (int t, char *event) {
|
const TObject *luaT_gettagmethod (int t, const char *event) {
|
||||||
int e = luaI_checkevent(event, luaT_eventname);
|
int e = luaI_checkevent(event, luaT_eventname);
|
||||||
checktag(t);
|
checktag(t);
|
||||||
if (luaT_validevent(t, e))
|
if (luaT_validevent(t, e))
|
||||||
|
@ -128,7 +129,7 @@ TObject *luaT_gettagmethod (int t, char *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaT_settagmethod (int t, char *event, TObject *func) {
|
void luaT_settagmethod (int t, const char *event, TObject *func) {
|
||||||
TObject temp;
|
TObject temp;
|
||||||
int e = luaI_checkevent(event, luaT_eventname);
|
int e = luaI_checkevent(event, luaT_eventname);
|
||||||
checktag(t);
|
checktag(t);
|
||||||
|
@ -143,7 +144,7 @@ void luaT_settagmethod (int t, char *event, TObject *func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */
|
const char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */
|
||||||
int e;
|
int e;
|
||||||
for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) {
|
for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) {
|
||||||
int t;
|
int t;
|
||||||
|
@ -191,10 +192,11 @@ static void fillvalids (IMS e, TObject *func) {
|
||||||
|
|
||||||
|
|
||||||
void luaT_setfallback (void) {
|
void luaT_setfallback (void) {
|
||||||
static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL};
|
static const char *const oldnames [] = {"error", "getglobal", "arith",
|
||||||
|
"order", NULL};
|
||||||
TObject oldfunc;
|
TObject oldfunc;
|
||||||
lua_CFunction replace;
|
lua_CFunction replace;
|
||||||
char *name = luaL_check_string(1);
|
const char *name = luaL_check_string(1);
|
||||||
lua_Object func = lua_getparam(2);
|
lua_Object func = lua_getparam(2);
|
||||||
luaL_arg_check(lua_isfunction(func), 2, "function expected");
|
luaL_arg_check(lua_isfunction(func), 2, "function expected");
|
||||||
switch (luaL_findstring(name, oldnames)) {
|
switch (luaL_findstring(name, oldnames)) {
|
||||||
|
|
12
ltm.h
12
ltm.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltm.h,v 1.4 1997/11/26 18:53:45 roberto Exp roberto $
|
** $Id: ltm.h,v 1.5 1999/01/15 13:11:57 roberto Exp roberto $
|
||||||
** Tag methods
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -47,15 +47,15 @@ struct IM {
|
||||||
#define luaT_getim(tag,event) (&L->IMtable[-(tag)].int_method[event])
|
#define luaT_getim(tag,event) (&L->IMtable[-(tag)].int_method[event])
|
||||||
#define luaT_getimbyObj(o,e) (luaT_getim(luaT_effectivetag(o),(e)))
|
#define luaT_getimbyObj(o,e) (luaT_getim(luaT_effectivetag(o),(e)))
|
||||||
|
|
||||||
extern char *luaT_eventname[];
|
extern const char *const luaT_eventname[];
|
||||||
|
|
||||||
|
|
||||||
void luaT_init (void);
|
void luaT_init (void);
|
||||||
void luaT_realtag (int tag);
|
void luaT_realtag (int tag);
|
||||||
int luaT_effectivetag (TObject *o);
|
int luaT_effectivetag (const TObject *o);
|
||||||
void luaT_settagmethod (int t, char *event, TObject *func);
|
void luaT_settagmethod (int t, const char *event, TObject *func);
|
||||||
TObject *luaT_gettagmethod (int t, char *event);
|
const TObject *luaT_gettagmethod (int t, const char *event);
|
||||||
char *luaT_travtagmethods (int (*fn)(TObject *));
|
const char *luaT_travtagmethods (int (*fn)(TObject *));
|
||||||
|
|
||||||
void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */
|
void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */
|
||||||
|
|
||||||
|
|
4
lua.c
4
lua.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lua.c,v 1.20 1999/06/24 19:42:02 roberto Exp roberto $
|
** $Id: lua.c,v 1.21 1999/07/02 18:22:38 roberto Exp roberto $
|
||||||
** Lua stand-alone interpreter
|
** Lua stand-alone interpreter
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +52,7 @@ static void laction (int i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ldo (int (*f)(char *), char *name) {
|
static int ldo (int (*f)(const char *), const char *name) {
|
||||||
int res;
|
int res;
|
||||||
handler h = lreset();
|
handler h = lreset();
|
||||||
res = f(name); /* dostring | dofile */
|
res = f(name); /* dostring | dofile */
|
||||||
|
|
33
lua.h
33
lua.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lua.h,v 1.32 1999/05/11 20:29:19 roberto Exp roberto $
|
** $Id: lua.h,v 1.33 1999/08/11 17:00:59 roberto Exp roberto $
|
||||||
** Lua - An Extensible Extension Language
|
** Lua - An Extensible Extension Language
|
||||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||||
** e-mail: lua@tecgraf.puc-rio.br
|
** e-mail: lua@tecgraf.puc-rio.br
|
||||||
|
@ -33,18 +33,21 @@ void lua_open (void);
|
||||||
void lua_close (void);
|
void lua_close (void);
|
||||||
lua_State *lua_setstate (lua_State *st);
|
lua_State *lua_setstate (lua_State *st);
|
||||||
|
|
||||||
lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
|
lua_Object lua_settagmethod (int tag, const char *event);
|
||||||
lua_Object lua_gettagmethod (int tag, char *event);
|
/* In: new method */
|
||||||
|
lua_Object lua_gettagmethod (int tag, const char *event);
|
||||||
|
|
||||||
int lua_newtag (void);
|
int lua_newtag (void);
|
||||||
int lua_copytagmethods (int tagto, int tagfrom);
|
int lua_copytagmethods (int tagto, int tagfrom);
|
||||||
void lua_settag (int tag); /* In: object */
|
void lua_settag (int tag); /* In: object */
|
||||||
|
|
||||||
void lua_error (char *s);
|
void lua_error (const char *s);
|
||||||
int lua_dofile (char *filename); /* Out: returns */
|
int lua_dofile (const char *filename);
|
||||||
int lua_dostring (char *string); /* Out: returns */
|
|
||||||
int lua_dobuffer (char *buff, int size, char *name);
|
|
||||||
/* Out: returns */
|
/* Out: returns */
|
||||||
|
int lua_dostring (const char *string);
|
||||||
|
/* Out: returns */
|
||||||
|
int lua_dobuffer (const char *buff, int size,
|
||||||
|
const char *name); /* Out: returns */
|
||||||
int lua_callfunction (lua_Object f);
|
int lua_callfunction (lua_Object f);
|
||||||
/* In: parameters; Out: returns */
|
/* In: parameters; Out: returns */
|
||||||
|
|
||||||
|
@ -64,7 +67,7 @@ int lua_isstring (lua_Object object);
|
||||||
int lua_isfunction (lua_Object object);
|
int lua_isfunction (lua_Object object);
|
||||||
|
|
||||||
double lua_getnumber (lua_Object object);
|
double lua_getnumber (lua_Object object);
|
||||||
char *lua_getstring (lua_Object object);
|
const char *lua_getstring (lua_Object object);
|
||||||
long lua_strlen (lua_Object object);
|
long lua_strlen (lua_Object object);
|
||||||
lua_CFunction lua_getcfunction (lua_Object object);
|
lua_CFunction lua_getcfunction (lua_Object object);
|
||||||
void *lua_getuserdata (lua_Object object);
|
void *lua_getuserdata (lua_Object object);
|
||||||
|
@ -72,18 +75,18 @@ void *lua_getuserdata (lua_Object object);
|
||||||
|
|
||||||
void lua_pushnil (void);
|
void lua_pushnil (void);
|
||||||
void lua_pushnumber (double n);
|
void lua_pushnumber (double n);
|
||||||
void lua_pushlstring (char *s, long len);
|
void lua_pushlstring (const char *s, long len);
|
||||||
void lua_pushstring (char *s);
|
void lua_pushstring (const char *s);
|
||||||
void lua_pushcclosure (lua_CFunction fn, int n);
|
void lua_pushcclosure (lua_CFunction fn, int n);
|
||||||
void lua_pushusertag (void *u, int tag);
|
void lua_pushusertag (void *u, int tag);
|
||||||
void lua_pushobject (lua_Object object);
|
void lua_pushobject (lua_Object object);
|
||||||
|
|
||||||
lua_Object lua_pop (void);
|
lua_Object lua_pop (void);
|
||||||
|
|
||||||
lua_Object lua_getglobal (char *name);
|
lua_Object lua_getglobal (const char *name);
|
||||||
lua_Object lua_rawgetglobal (char *name);
|
lua_Object lua_rawgetglobal (const char *name);
|
||||||
void lua_setglobal (char *name); /* In: value */
|
void lua_setglobal (const char *name); /* In: value */
|
||||||
void lua_rawsetglobal (char *name); /* In: value */
|
void lua_rawsetglobal (const char *name); /* In: value */
|
||||||
|
|
||||||
void lua_settable (void); /* In: table, index, value */
|
void lua_settable (void); /* In: table, index, value */
|
||||||
void lua_rawsettable (void); /* In: table, index, value */
|
void lua_rawsettable (void); /* In: table, index, value */
|
||||||
|
@ -92,7 +95,7 @@ lua_Object lua_rawgettable (void); /* In: table, index */
|
||||||
|
|
||||||
int lua_tag (lua_Object object);
|
int lua_tag (lua_Object object);
|
||||||
|
|
||||||
char *lua_nextvar (char *varname); /* Out: value */
|
const char *lua_nextvar (const char *varname); /* Out: value */
|
||||||
int lua_next (lua_Object o, int i);
|
int lua_next (lua_Object o, int i);
|
||||||
/* Out: ref, value */
|
/* Out: ref, value */
|
||||||
|
|
||||||
|
|
11
luadebug.h
11
luadebug.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: luadebug.h,v 1.5 1999/02/04 17:47:59 roberto Exp roberto $
|
** $Id: luadebug.h,v 1.6 1999/03/04 21:17:26 roberto Exp roberto $
|
||||||
** Debugging API
|
** Debugging API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -14,14 +14,15 @@
|
||||||
typedef lua_Object lua_Function;
|
typedef lua_Object lua_Function;
|
||||||
|
|
||||||
typedef void (*lua_LHFunction) (int line);
|
typedef void (*lua_LHFunction) (int line);
|
||||||
typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
|
typedef void (*lua_CHFunction) (lua_Function func, const char *file, int line);
|
||||||
|
|
||||||
lua_Function lua_stackedfunction (int level);
|
lua_Function lua_stackedfunction (int level);
|
||||||
void lua_funcinfo (lua_Object func, char **source, int *linedefined);
|
void lua_funcinfo (lua_Object func, const char **source, int *linedefined);
|
||||||
int lua_currentline (lua_Function func);
|
int lua_currentline (lua_Function func);
|
||||||
char *lua_getobjname (lua_Object o, char **name);
|
const char *lua_getobjname (lua_Object o, const char **name);
|
||||||
|
|
||||||
lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
|
lua_Object lua_getlocal (lua_Function func, int local_number,
|
||||||
|
const char **name);
|
||||||
int lua_setlocal (lua_Function func, int local_number);
|
int lua_setlocal (lua_Function func, int local_number);
|
||||||
|
|
||||||
int lua_nups (lua_Function func);
|
int lua_nups (lua_Function func);
|
||||||
|
|
6
lualib.h
6
lualib.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lualib.h,v 1.5 1999/01/08 16:47:44 roberto Exp roberto $
|
** $Id: lualib.h,v 1.6 1999/05/05 19:23:11 roberto Exp roberto $
|
||||||
** Lua standard libraries
|
** Lua standard libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -29,8 +29,8 @@ void lua_userinit (void);
|
||||||
|
|
||||||
/* Auxiliary functions (private) */
|
/* Auxiliary functions (private) */
|
||||||
|
|
||||||
char *luaI_classend (char *p);
|
const char *luaI_classend (const char *p);
|
||||||
int luaI_singlematch (int c, char *p, char *ep);
|
int luaI_singlematch (int c, const char *p, const char *ep);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
12
lundump.c
12
lundump.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lundump.c,v 1.21 1999/07/02 19:34:26 lhf Exp $
|
** $Id: lundump.c,v 1.12 1999/07/08 12:43:23 roberto Exp roberto $
|
||||||
** load bytecodes from files
|
** load bytecodes from files
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +50,7 @@ static unsigned long LoadLong (ZIO* Z)
|
||||||
/*
|
/*
|
||||||
* convert number from text
|
* convert number from text
|
||||||
*/
|
*/
|
||||||
double luaU_str2d (char* b, char* where)
|
double luaU_str2d (const char* b, const char* where)
|
||||||
{
|
{
|
||||||
int negative=(b[0]=='-');
|
int negative=(b[0]=='-');
|
||||||
double x=luaO_str2d(b+negative);
|
double x=luaO_str2d(b+negative);
|
||||||
|
@ -76,7 +76,7 @@ static real LoadNumber (ZIO* Z, int native)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LoadInt (ZIO* Z, char* message)
|
static int LoadInt (ZIO* Z, const char* message)
|
||||||
{
|
{
|
||||||
unsigned long l=LoadLong(Z);
|
unsigned long l=LoadLong(Z);
|
||||||
unsigned int i=l;
|
unsigned int i=l;
|
||||||
|
@ -169,7 +169,7 @@ static TProtoFunc* LoadFunction (ZIO* Z, int native)
|
||||||
|
|
||||||
static void LoadSignature (ZIO* Z)
|
static void LoadSignature (ZIO* Z)
|
||||||
{
|
{
|
||||||
char* s=SIGNATURE;
|
const char* s=SIGNATURE;
|
||||||
while (*s!=0 && ezgetc(Z)==*s)
|
while (*s!=0 && ezgetc(Z)==*s)
|
||||||
++s;
|
++s;
|
||||||
if (*s!=0) luaL_verror("bad signature in %s",zname(Z));
|
if (*s!=0) luaL_verror("bad signature in %s",zname(Z));
|
||||||
|
@ -231,9 +231,9 @@ TProtoFunc* luaU_undump1 (ZIO* Z)
|
||||||
/*
|
/*
|
||||||
* handle constants that cannot happen
|
* handle constants that cannot happen
|
||||||
*/
|
*/
|
||||||
void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf)
|
void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf)
|
||||||
{
|
{
|
||||||
int t=ttype(o);
|
int t=ttype(o);
|
||||||
char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
|
const char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
|
||||||
luaL_verror("cannot %s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC);
|
luaL_verror("cannot %s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lundump.h,v 1.15 1999/07/02 19:34:26 lhf Exp $
|
** $Id: lundump.h,v 1.9 1999/07/08 12:43:23 roberto Exp roberto $
|
||||||
** load pre-compiled Lua chunks
|
** load pre-compiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -11,9 +11,9 @@
|
||||||
#include "lzio.h"
|
#include "lzio.h"
|
||||||
|
|
||||||
TProtoFunc* luaU_undump1 (ZIO* Z); /* load one chunk */
|
TProtoFunc* luaU_undump1 (ZIO* Z); /* load one chunk */
|
||||||
void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf);
|
void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf);
|
||||||
/* handle cases that cannot happen */
|
/* handle cases that cannot happen */
|
||||||
double luaU_str2d (char* b, char* where);
|
double luaU_str2d (const char* b, const char* where);
|
||||||
/* convert number from text */
|
/* convert number from text */
|
||||||
|
|
||||||
/* definitions for headers of binary files */
|
/* definitions for headers of binary files */
|
||||||
|
|
39
lvm.c
39
lvm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp roberto $
|
** $Id: lvm.c,v 1.59 1999/08/10 12:55:47 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -114,7 +114,7 @@ void luaV_closure (int nelems) {
|
||||||
*/
|
*/
|
||||||
void luaV_gettable (void) {
|
void luaV_gettable (void) {
|
||||||
TObject *table = L->stack.top-2;
|
TObject *table = L->stack.top-2;
|
||||||
TObject *im;
|
const TObject *im;
|
||||||
if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */
|
if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */
|
||||||
im = luaT_getimbyObj(table, IM_GETTABLE);
|
im = luaT_getimbyObj(table, IM_GETTABLE);
|
||||||
if (ttype(im) == LUA_T_NIL)
|
if (ttype(im) == LUA_T_NIL)
|
||||||
|
@ -146,9 +146,9 @@ void luaV_gettable (void) {
|
||||||
/*
|
/*
|
||||||
** Receives table at *t, index at *(t+1) and value at top.
|
** Receives table at *t, index at *(t+1) and value at top.
|
||||||
*/
|
*/
|
||||||
void luaV_settable (TObject *t) {
|
void luaV_settable (const TObject *t) {
|
||||||
struct Stack *S = &L->stack;
|
struct Stack *S = &L->stack;
|
||||||
TObject *im;
|
const TObject *im;
|
||||||
if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */
|
if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */
|
||||||
im = luaT_getimbyObj(t, IM_SETTABLE);
|
im = luaT_getimbyObj(t, IM_SETTABLE);
|
||||||
if (ttype(im) == LUA_T_NIL)
|
if (ttype(im) == LUA_T_NIL)
|
||||||
|
@ -173,7 +173,7 @@ void luaV_settable (TObject *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaV_rawsettable (TObject *t) {
|
void luaV_rawsettable (const TObject *t) {
|
||||||
if (ttype(t) != LUA_T_ARRAY)
|
if (ttype(t) != LUA_T_ARRAY)
|
||||||
lua_error("indexed expression not a table");
|
lua_error("indexed expression not a table");
|
||||||
else {
|
else {
|
||||||
|
@ -186,7 +186,7 @@ void luaV_rawsettable (TObject *t) {
|
||||||
|
|
||||||
void luaV_getglobal (TaggedString *ts) {
|
void luaV_getglobal (TaggedString *ts) {
|
||||||
/* WARNING: caller must assure stack space */
|
/* WARNING: caller must assure stack space */
|
||||||
TObject *value = &ts->u.s.globalval;
|
const TObject *value = &ts->u.s.globalval;
|
||||||
switch (ttype(value)) {
|
switch (ttype(value)) {
|
||||||
/* only userdata, tables and nil can have getglobal tag methods */
|
/* only userdata, tables and nil can have getglobal tag methods */
|
||||||
case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: {
|
case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: {
|
||||||
|
@ -208,8 +208,8 @@ void luaV_getglobal (TaggedString *ts) {
|
||||||
|
|
||||||
|
|
||||||
void luaV_setglobal (TaggedString *ts) {
|
void luaV_setglobal (TaggedString *ts) {
|
||||||
TObject *oldvalue = &ts->u.s.globalval;
|
const TObject *oldvalue = &ts->u.s.globalval;
|
||||||
TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
|
const TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
|
||||||
if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
|
if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
|
||||||
luaS_rawsetglobal(ts, --L->stack.top);
|
luaS_rawsetglobal(ts, --L->stack.top);
|
||||||
else {
|
else {
|
||||||
|
@ -226,9 +226,9 @@ void luaV_setglobal (TaggedString *ts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void call_binTM (IMS event, char *msg)
|
static void call_binTM (IMS event, const char *msg) {
|
||||||
{
|
/* try first operand */
|
||||||
TObject *im = luaT_getimbyObj(L->stack.top-2, event);/* try first operand */
|
const TObject *im = luaT_getimbyObj(L->stack.top-2, event);
|
||||||
if (ttype(im) == LUA_T_NIL) {
|
if (ttype(im) == LUA_T_NIL) {
|
||||||
im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */
|
im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */
|
||||||
if (ttype(im) == LUA_T_NIL) {
|
if (ttype(im) == LUA_T_NIL) {
|
||||||
|
@ -242,14 +242,12 @@ static void call_binTM (IMS event, char *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void call_arith (IMS event)
|
static void call_arith (IMS event) {
|
||||||
{
|
|
||||||
call_binTM(event, "unexpected type in arithmetic operation");
|
call_binTM(event, "unexpected type in arithmetic operation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaV_strcomp (char *l, long ll, char *r, long lr)
|
static int luaV_strcomp (const char *l, long ll, const char *r, long lr) {
|
||||||
{
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
long temp = strcoll(l, r);
|
long temp = strcoll(l, r);
|
||||||
if (temp != 0) return temp;
|
if (temp != 0) return temp;
|
||||||
|
@ -268,8 +266,8 @@ static int luaV_strcomp (char *l, long ll, char *r, long lr)
|
||||||
void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal,
|
void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal,
|
||||||
lua_Type ttype_great, IMS op) {
|
lua_Type ttype_great, IMS op) {
|
||||||
struct Stack *S = &L->stack;
|
struct Stack *S = &L->stack;
|
||||||
TObject *l = S->top-2;
|
const TObject *l = S->top-2;
|
||||||
TObject *r = S->top-1;
|
const TObject *r = S->top-1;
|
||||||
real result;
|
real result;
|
||||||
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
|
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
|
||||||
result = nvalue(l)-nvalue(r);
|
result = nvalue(l)-nvalue(r);
|
||||||
|
@ -300,8 +298,7 @@ void luaV_pack (StkId firstel, int nvararg, TObject *tab) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void adjust_varargs (StkId first_extra_arg)
|
static void adjust_varargs (StkId first_extra_arg) {
|
||||||
{
|
|
||||||
TObject arg;
|
TObject arg;
|
||||||
luaV_pack(first_extra_arg,
|
luaV_pack(first_extra_arg,
|
||||||
(L->stack.top-L->stack.stack)-first_extra_arg, &arg);
|
(L->stack.top-L->stack.stack)-first_extra_arg, &arg);
|
||||||
|
@ -318,8 +315,8 @@ static void adjust_varargs (StkId first_extra_arg)
|
||||||
*/
|
*/
|
||||||
StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
|
StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
|
||||||
struct Stack *S = &L->stack; /* to optimize */
|
struct Stack *S = &L->stack; /* to optimize */
|
||||||
register Byte *pc = tf->code;
|
register const Byte *pc = tf->code;
|
||||||
TObject *consts = tf->consts;
|
const TObject *consts = tf->consts;
|
||||||
if (L->callhook)
|
if (L->callhook)
|
||||||
luaD_callHook(base, tf, 0);
|
luaD_callHook(base, tf, 0);
|
||||||
luaD_checkstack((*pc++)+EXTRA_STACK);
|
luaD_checkstack((*pc++)+EXTRA_STACK);
|
||||||
|
|
6
lvm.h
6
lvm.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.h,v 1.7 1998/12/30 17:26:49 roberto Exp roberto $
|
** $Id: lvm.h,v 1.8 1999/02/08 17:07:59 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -22,8 +22,8 @@ int luaV_tonumber (TObject *obj);
|
||||||
int luaV_tostring (TObject *obj);
|
int luaV_tostring (TObject *obj);
|
||||||
void luaV_setn (Hash *t, int val);
|
void luaV_setn (Hash *t, int val);
|
||||||
void luaV_gettable (void);
|
void luaV_gettable (void);
|
||||||
void luaV_settable (TObject *t);
|
void luaV_settable (const TObject *t);
|
||||||
void luaV_rawsettable (TObject *t);
|
void luaV_rawsettable (const TObject *t);
|
||||||
void luaV_getglobal (TaggedString *ts);
|
void luaV_getglobal (TaggedString *ts);
|
||||||
void luaV_setglobal (TaggedString *ts);
|
void luaV_setglobal (TaggedString *ts);
|
||||||
StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base);
|
StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base);
|
||||||
|
|
13
lzio.c
13
lzio.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lzio.c,v 1.6 1999/03/04 14:49:18 roberto Exp roberto $
|
** $Id: lzio.c,v 1.7 1999/03/05 13:15:50 roberto Exp roberto $
|
||||||
** a generic input stream interface
|
** a generic input stream interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,11 +20,10 @@ static int zmfilbuf (ZIO* z) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ZIO* zmopen (ZIO* z, char* b, int size, char *name)
|
ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) {
|
||||||
{
|
|
||||||
if (b==NULL) return NULL;
|
if (b==NULL) return NULL;
|
||||||
z->n = size;
|
z->n = size;
|
||||||
z->p= (unsigned char *)b;
|
z->p = (unsigned const char *)b;
|
||||||
z->filbuf = zmfilbuf;
|
z->filbuf = zmfilbuf;
|
||||||
z->u = NULL;
|
z->u = NULL;
|
||||||
z->name = name;
|
z->name = name;
|
||||||
|
@ -33,8 +32,7 @@ ZIO* zmopen (ZIO* z, char* b, int size, char *name)
|
||||||
|
|
||||||
/* ------------------------------------------------------------ strings --- */
|
/* ------------------------------------------------------------ strings --- */
|
||||||
|
|
||||||
ZIO* zsopen (ZIO* z, char* s, char *name)
|
ZIO* zsopen (ZIO* z, const char* s, const char *name) {
|
||||||
{
|
|
||||||
if (s==NULL) return NULL;
|
if (s==NULL) return NULL;
|
||||||
return zmopen(z,s,strlen(s),name);
|
return zmopen(z,s,strlen(s),name);
|
||||||
}
|
}
|
||||||
|
@ -52,8 +50,7 @@ static int zffilbuf (ZIO* z) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ZIO* zFopen (ZIO* z, FILE* f, char *name)
|
ZIO* zFopen (ZIO* z, FILE* f, const char *name) {
|
||||||
{
|
|
||||||
if (f==NULL) return NULL;
|
if (f==NULL) return NULL;
|
||||||
z->n = 0;
|
z->n = 0;
|
||||||
z->p = z->buffer;
|
z->p = z->buffer;
|
||||||
|
|
12
lzio.h
12
lzio.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lzio.h,v 1.3 1997/12/22 20:57:18 roberto Exp roberto $
|
** $Id: lzio.h,v 1.4 1998/01/09 14:57:43 roberto Exp roberto $
|
||||||
** Buffered streams
|
** Buffered streams
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -22,9 +22,9 @@
|
||||||
|
|
||||||
typedef struct zio ZIO;
|
typedef struct zio ZIO;
|
||||||
|
|
||||||
ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */
|
ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */
|
||||||
ZIO* zsopen (ZIO* z, char* s, char *name); /* string */
|
ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */
|
||||||
ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */
|
ZIO* zmopen (ZIO* z, const char* b, int size, const char *name); /* memory */
|
||||||
|
|
||||||
int zread (ZIO* z, void* b, int n); /* read next n bytes */
|
int zread (ZIO* z, void* b, int n); /* read next n bytes */
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@ int zread (ZIO* z, void* b, int n); /* read next n bytes */
|
||||||
|
|
||||||
struct zio {
|
struct zio {
|
||||||
int n; /* bytes still unread */
|
int n; /* bytes still unread */
|
||||||
unsigned char* p; /* current position in buffer */
|
const unsigned char* p; /* current position in buffer */
|
||||||
int (*filbuf)(ZIO* z);
|
int (*filbuf)(ZIO* z);
|
||||||
void* u; /* additional data */
|
void* u; /* additional data */
|
||||||
char *name;
|
const char *name;
|
||||||
unsigned char buffer[ZBSIZE]; /* buffer */
|
unsigned char buffer[ZBSIZE]; /* buffer */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue