new macros + new names to facilitate compilation of threaded version

This commit is contained in:
Roberto Ierusalimschy 2001-01-26 09:45:51 -02:00
parent a53d9b66ca
commit bce6572579
9 changed files with 190 additions and 176 deletions

208
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.119 2001/01/24 15:45:33 roberto Exp roberto $
** $Id: lapi.c,v 1.120 2001/01/25 16:45:36 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -55,9 +55,9 @@ void luaA_pushobject (lua_State *L, const TObject *o) {
LUA_API int lua_stackspace (lua_State *L) {
int i;
LUA_ENTRY;
LUA_LOCK;
i = (L->stack_last - L->top);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
@ -70,49 +70,49 @@ LUA_API int lua_stackspace (lua_State *L) {
LUA_API int lua_gettop (lua_State *L) {
int i;
LUA_ENTRY;
LUA_LOCK;
i = (L->top - L->Cbase);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
LUA_API void lua_settop (lua_State *L, int index) {
LUA_ENTRY;
LUA_LOCK;
if (index >= 0)
luaD_adjusttop(L, L->Cbase, index);
else
L->top = L->top+index+1; /* index is negative */
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_remove (lua_State *L, int index) {
StkId p;
LUA_ENTRY;
LUA_LOCK;
p = luaA_index(L, index);
while (++p < L->top) setobj(p-1, p);
L->top--;
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_insert (lua_State *L, int index) {
StkId p;
StkId q;
LUA_ENTRY;
LUA_LOCK;
p = luaA_index(L, index);
for (q = L->top; q>p; q--) setobj(q, q-1);
setobj(p, L->top);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_pushvalue (lua_State *L, int index) {
LUA_ENTRY;
LUA_LOCK;
setobj(L->top, luaA_index(L, index));
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
@ -125,19 +125,19 @@ LUA_API void lua_pushvalue (lua_State *L, int index) {
LUA_API int lua_type (lua_State *L, int index) {
StkId o;
int i;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
i = (o == NULL) ? LUA_TNONE : ttype(o);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
LUA_API const char *lua_typename (lua_State *L, int t) {
const char *s;
LUA_ENTRY;
LUA_LOCK;
s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t);
LUA_EXIT;
LUA_UNLOCK;
return s;
}
@ -145,10 +145,10 @@ LUA_API const char *lua_typename (lua_State *L, int t) {
LUA_API const char *lua_xtype (lua_State *L, int index) {
StkId o;
const char *type;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
type = (o == NULL) ? "no value" : luaT_typename(G(L), o);
LUA_EXIT;
LUA_UNLOCK;
return type;
}
@ -156,20 +156,20 @@ LUA_API const char *lua_xtype (lua_State *L, int index) {
LUA_API int lua_iscfunction (lua_State *L, int index) {
StkId o;
int i;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
i = (o == NULL) ? 0 : iscfunction(o);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
LUA_API int lua_isnumber (lua_State *L, int index) {
TObject *o;
int i;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
i = (o == NULL) ? 0 : (tonumber(o) == 0);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
@ -182,34 +182,34 @@ LUA_API int lua_isstring (lua_State *L, int index) {
LUA_API int lua_tag (lua_State *L, int index) {
StkId o;
int i;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
i = (o == NULL) ? LUA_NOTAG : luaT_tag(o);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
LUA_API int lua_equal (lua_State *L, int index1, int index2) {
StkId o1, o2;
int i;
LUA_ENTRY;
LUA_LOCK;
o1 = luaA_indexAcceptable(L, index1);
o2 = luaA_indexAcceptable(L, index2);
i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */
: luaO_equalObj(o1, o2);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
StkId o1, o2;
int i;
LUA_ENTRY;
LUA_LOCK;
o1 = luaA_indexAcceptable(L, index1);
o2 = luaA_indexAcceptable(L, index2);
i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */
: luaV_lessthan(L, o1, o2, L->top);
LUA_EXIT;
LUA_UNLOCK;
return i;
}
@ -218,58 +218,58 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
StkId o;
lua_Number n;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
n = (o == NULL || tonumber(o)) ? 0 : nvalue(o);
LUA_EXIT;
LUA_UNLOCK;
return n;
}
LUA_API const char *lua_tostring (lua_State *L, int index) {
StkId o;
const char *s;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
s = (o == NULL || tostring(L, o)) ? NULL : svalue(o);
LUA_EXIT;
LUA_UNLOCK;
return s;
}
LUA_API size_t lua_strlen (lua_State *L, int index) {
StkId o;
size_t l;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len;
LUA_EXIT;
LUA_UNLOCK;
return l;
}
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) {
StkId o;
lua_CFunction f;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c;
LUA_EXIT;
LUA_UNLOCK;
return f;
}
LUA_API void *lua_touserdata (lua_State *L, int index) {
StkId o;
void *p;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL :
tsvalue(o)->u.d.value;
LUA_EXIT;
LUA_UNLOCK;
return p;
}
LUA_API const void *lua_topointer (lua_State *L, int index) {
StkId o;
const void *p;
LUA_ENTRY;
LUA_LOCK;
o = luaA_indexAcceptable(L, index);
if (o == NULL) p = NULL;
else {
@ -285,7 +285,7 @@ LUA_API const void *lua_topointer (lua_State *L, int index) {
break;
}
}
LUA_EXIT;
LUA_UNLOCK;
return p;
}
@ -297,26 +297,26 @@ LUA_API const void *lua_topointer (lua_State *L, int index) {
LUA_API void lua_pushnil (lua_State *L) {
LUA_ENTRY;
LUA_LOCK;
setnilvalue(L->top);
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
LUA_ENTRY;
LUA_LOCK;
setnvalue(L->top, n);
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
LUA_ENTRY;
LUA_LOCK;
setsvalue(L->top, luaS_newlstr(L, s, len));
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
@ -329,20 +329,20 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) {
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
LUA_ENTRY;
LUA_LOCK;
luaV_Cclosure(L, fn, n);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) {
LUA_ENTRY;
LUA_LOCK;
/* ORDER LUA_T */
if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag)))
luaO_verror(L, "invalid tag for a userdata (%d)", tag);
setuvalue(L->top, luaS_createudata(L, u, tag));
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
@ -354,58 +354,58 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) {
LUA_API void lua_getglobal (lua_State *L, const char *name) {
StkId top;
LUA_ENTRY;
LUA_LOCK;
top = L->top;
setobj(top, luaV_getglobal(L, luaS_new(L, name)));
L->top = top;
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_gettable (lua_State *L, int index) {
StkId t, top;
LUA_ENTRY;
LUA_LOCK;
t = Index(L, index);
top = L->top;
setobj(top-1, luaV_gettable(L, t));
L->top = top; /* tag method may change top */
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_rawget (lua_State *L, int index) {
StkId t;
LUA_ENTRY;
LUA_LOCK;
t = Index(L, index);
lua_assert(ttype(t) == LUA_TTABLE);
setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1));
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_rawgeti (lua_State *L, int index, int n) {
StkId o;
LUA_ENTRY;
LUA_LOCK;
o = Index(L, index);
lua_assert(ttype(o) == LUA_TTABLE);
setobj(L->top, luaH_getnum(hvalue(o), n));
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_getglobals (lua_State *L) {
LUA_ENTRY;
LUA_LOCK;
sethvalue(L->top, L->gt);
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API int lua_getref (lua_State *L, int ref) {
int status = 1;
LUA_ENTRY;
LUA_LOCK;
if (ref == LUA_REFNIL) {
setnilvalue(L->top);
api_incr_top(L);
@ -417,16 +417,16 @@ LUA_API int lua_getref (lua_State *L, int ref) {
}
else
status = 0;
LUA_EXIT;
LUA_UNLOCK;
return status;
}
LUA_API void lua_newtable (lua_State *L) {
LUA_ENTRY;
LUA_LOCK;
sethvalue(L->top, luaH_new(L, 0));
api_incr_top(L);
LUA_EXIT;
LUA_UNLOCK;
}
@ -438,60 +438,60 @@ LUA_API void lua_newtable (lua_State *L) {
LUA_API void lua_setglobal (lua_State *L, const char *name) {
StkId top;
LUA_ENTRY;
LUA_LOCK;
top = L->top;
luaV_setglobal(L, luaS_new(L, name));
L->top = top-1; /* remove element from the top */
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_settable (lua_State *L, int index) {
StkId t, top;
LUA_ENTRY;
LUA_LOCK;
t = Index(L, index);
top = L->top;
luaV_settable(L, t, top-2);
L->top = top-2; /* pop index and value */
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_rawset (lua_State *L, int index) {
StkId t;
LUA_ENTRY;
LUA_LOCK;
t = Index(L, index);
lua_assert(ttype(t) == LUA_TTABLE);
setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1));
L->top -= 2;
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_rawseti (lua_State *L, int index, int n) {
StkId o;
LUA_ENTRY;
LUA_LOCK;
o = Index(L, index);
lua_assert(ttype(o) == LUA_TTABLE);
setobj(luaH_setnum(L, hvalue(o), n), (L->top-1));
L->top--;
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_setglobals (lua_State *L) {
StkId newtable;
LUA_ENTRY;
LUA_LOCK;
newtable = --L->top;
lua_assert(ttype(newtable) == LUA_TTABLE);
L->gt = hvalue(newtable);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API int lua_ref (lua_State *L, int lock) {
int ref;
LUA_ENTRY;
LUA_LOCK;
if (ttype(L->top-1) == LUA_TNIL)
ref = LUA_REFNIL;
else {
@ -508,7 +508,7 @@ LUA_API int lua_ref (lua_State *L, int lock) {
G(L)->refArray[ref].st = lock ? LOCK : HOLD;
}
L->top--;
LUA_EXIT;
LUA_UNLOCK;
return ref;
}
@ -519,9 +519,9 @@ LUA_API int lua_ref (lua_State *L, int lock) {
*/
LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) {
LUA_ENTRY;
LUA_LOCK;
luaD_call(L, L->top-(nargs+1), nresults);
LUA_EXIT;
LUA_UNLOCK;
}
@ -535,28 +535,28 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) {
LUA_API int lua_getgcthreshold (lua_State *L) {
int threshold;
LUA_ENTRY;
LUA_LOCK;
threshold = GCscale(G(L)->GCthreshold);
LUA_EXIT;
LUA_UNLOCK;
return threshold;
}
LUA_API int lua_getgccount (lua_State *L) {
int count;
LUA_ENTRY;
LUA_LOCK;
count = GCscale(G(L)->nblocks);
LUA_EXIT;
LUA_UNLOCK;
return count;
}
LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
LUA_ENTRY;
LUA_LOCK;
if (newthreshold > GCscale(ULONG_MAX))
G(L)->GCthreshold = ULONG_MAX;
else
G(L)->GCthreshold = GCunscale(newthreshold);
luaC_checkGC(L);
LUA_EXIT;
LUA_UNLOCK;
}
@ -566,7 +566,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) {
int tag;
LUA_ENTRY;
LUA_LOCK;
if (basictype != LUA_TNONE &&
basictype != LUA_TTABLE &&
basictype != LUA_TUSERDATA)
@ -574,7 +574,7 @@ LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) {
tag = luaT_newtag(L, name, basictype);
if (tag == LUA_TNONE)
luaO_verror(L, "type name '%.30s' already exists", name);
LUA_EXIT;
LUA_UNLOCK;
return tag;
}
@ -582,22 +582,22 @@ LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) {
LUA_API int lua_type2tag (lua_State *L, const char *name) {
int tag;
const TObject *v;
LUA_ENTRY;
LUA_LOCK;
v = luaH_getstr(G(L)->type2tag, luaS_new(L, name));
if (ttype(v) == LUA_TNIL)
tag = LUA_TNONE;
else {
lua_assert(ttype(v) == LUA_TNUMBER);
tag = nvalue(v);
tag = (int)nvalue(v);
}
LUA_EXIT;
LUA_UNLOCK;
return tag;
}
LUA_API void lua_settag (lua_State *L, int tag) {
int basictype;
LUA_ENTRY;
LUA_LOCK;
if (tag < 0 || tag >= G(L)->ntag)
luaO_verror(L, "%d is not a valid tag", tag);
basictype = G(L)->TMtable[tag].basictype;
@ -615,25 +615,25 @@ LUA_API void lua_settag (lua_State *L, int tag) {
luaO_verror(L, "cannot change the tag of a %.20s",
luaT_typename(G(L), L->top-1));
}
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_error (lua_State *L, const char *s) {
LUA_ENTRY;
LUA_LOCK;
luaD_error(L, s);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_unref (lua_State *L, int ref) {
LUA_ENTRY;
LUA_LOCK;
if (ref >= 0) {
lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0);
G(L)->refArray[ref].st = G(L)->refFree;
G(L)->refFree = ref;
}
LUA_EXIT;
LUA_UNLOCK;
}
@ -641,7 +641,7 @@ LUA_API int lua_next (lua_State *L, int index) {
StkId t;
Node *n;
int more;
LUA_ENTRY;
LUA_LOCK;
t = luaA_index(L, index);
lua_assert(ttype(t) == LUA_TTABLE);
n = luaH_next(L, hvalue(t), luaA_index(L, -1));
@ -655,7 +655,7 @@ LUA_API int lua_next (lua_State *L, int index) {
L->top -= 1; /* remove key */
more = 0;
}
LUA_EXIT;
LUA_UNLOCK;
return more;
}
@ -664,7 +664,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
Hash *h;
const TObject *value;
int n;
LUA_ENTRY;
LUA_LOCK;
h = hvalue(luaA_index(L, index));
value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */
if (ttype(value) == LUA_TNUMBER)
@ -682,31 +682,31 @@ LUA_API int lua_getn (lua_State *L, int index) {
}
n = (int)max;
}
LUA_EXIT;
LUA_UNLOCK;
return n;
}
LUA_API void lua_concat (lua_State *L, int n) {
StkId top;
LUA_ENTRY;
LUA_LOCK;
top = L->top;
luaV_strconc(L, n, top);
L->top = top-(n-1);
luaC_checkGC(L);
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
TString *ts;
void *p;
LUA_ENTRY;
LUA_LOCK;
ts = luaS_newudata(L, size, NULL);
setuvalue(L->top, ts);
api_incr_top(L);
p = ts->u.d.value;
LUA_EXIT;
LUA_UNLOCK;
return p;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.55 2001/01/24 15:45:33 roberto Exp roberto $
** $Id: ldebug.c,v 1.56 2001/01/25 16:45:36 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -42,20 +42,20 @@ static int isLmark (StkId o) {
LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) {
lua_Hook oldhook;
LUA_ENTRY;
LUA_LOCK;
oldhook = L->callhook;
L->callhook = func;
LUA_EXIT;
LUA_UNLOCK;
return oldhook;
}
LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
lua_Hook oldhook;
LUA_ENTRY;
LUA_LOCK;
oldhook = L->linehook;
L->linehook = func;
LUA_EXIT;
LUA_UNLOCK;
return oldhook;
}
@ -76,14 +76,14 @@ static StkId aux_stackedfunction (lua_State *L, int level, StkId top) {
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
StkId f;
int status;
LUA_ENTRY;
LUA_LOCK;
f = aux_stackedfunction(L, level, L->top);
if (f == NULL) status = 0; /* there is no such level */
else {
ar->_func = f;
status = 1;
}
LUA_EXIT;
LUA_UNLOCK;
return status;
}
@ -162,7 +162,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name;
StkId f;
Proto *fp;
LUA_ENTRY;
LUA_LOCK;
name = NULL;
f = ar->_func;
fp = getluaproto(f);
@ -171,7 +171,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
if (name)
luaA_pushobject(L, (f+1)+(n-1)); /* push value */
}
LUA_EXIT;
LUA_UNLOCK;
return name;
}
@ -180,7 +180,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name;
StkId f;
Proto *fp;
LUA_ENTRY;
LUA_LOCK;
name = NULL;
f = ar->_func;
fp = getluaproto(f);
@ -192,7 +192,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
else
setobj((f+1)+(n-1), L->top);
}
LUA_EXIT;
LUA_UNLOCK;
return name;
}
@ -272,7 +272,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
StkId func;
int isactive;
int status = 1;
LUA_ENTRY;
LUA_LOCK;
isactive = (*what != '>');
if (isactive)
func = ar->_func;
@ -309,7 +309,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
}
}
if (!isactive) L->top--; /* pop function */
LUA_EXIT;
LUA_UNLOCK;
return status;
}

18
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.115 2001/01/19 13:20:30 roberto Exp roberto $
** $Id: ldo.c,v 1.116 2001/01/24 15:45:33 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -94,9 +94,9 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) {
StkId old_top = L->Cbase = L->top;
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
L->allowhooks = 0; /* cannot call hooks inside a hook */
LUA_EXIT;
LUA_UNLOCK;
(*hook)(L, ar);
LUA_ENTRY;
LUA_LOCK;
lua_assert(L->allowhooks == 0);
L->allowhooks = 1;
L->top = old_top;
@ -135,9 +135,9 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) {
luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */
for (n=0; n<nup; n++) /* copy upvalues as extra arguments */
setobj(L->top++, &cl->upvalue[n]);
LUA_EXIT;
LUA_UNLOCK;
n = (*cl->f.c)(L); /* do the actual call */
LUA_ENTRY;
LUA_LOCK;
L->Cbase = old_Cbase; /* restore old C base */
return L->top - n; /* return index of first result */
}
@ -219,13 +219,13 @@ LUA_API int lua_call (lua_State *L, int nargs, int nresults) {
StkId func;
struct CallS c;
int status;
LUA_ENTRY;
LUA_LOCK;
func = L->top - (nargs+1); /* function to be called */
c.func = func; c.nresults = nresults;
status = luaD_runprotected(L, f_call, &c);
if (status != 0) /* an error occurred? */
L->top = func; /* remove parameters from the stack */
LUA_EXIT;
LUA_UNLOCK;
return status;
}
@ -249,7 +249,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
struct ParserS p;
mem_int old_blocks;
int status;
LUA_ENTRY;
LUA_LOCK;
p.z = z; p.bin = bin;
luaC_checkGC(L);
old_blocks = G(L)->nblocks;
@ -261,7 +261,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
}
else if (status == LUA_ERRRUN) /* an error occurred: correct error code */
status = LUA_ERRSYNTAX;
LUA_EXIT;
LUA_UNLOCK;
return status;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.99 2001/01/18 15:59:09 roberto Exp roberto $
** $Id: liolib.c,v 1.100 2001/01/25 16:45:36 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -86,13 +86,14 @@ static int pushresult (lua_State *L, int i) {
static FILE *getopthandle (lua_State *L, int inout) {
FILE *p = (FILE *)lua_touserdata(L, 1);
if (p != NULL) { /* is it a userdata ? */
if (!checkfile(L,1)) {
if (!checkfile(L, 1)) {
if (strcmp(lua_xtype(L, 1), "ClosedFileHandle") == 0)
luaL_argerror(L, 1, "file is closed");
else
luaL_argerror(L, 1, "(invalid value)");
}
lua_remove(L, 1); /* remove it from stack */
/* move it to stack top */
lua_pushvalue(L, 1); lua_remove(L, 1);
}
else if (inout != NOFILE) { /* try global value */
lua_getglobal(L, filenames[inout]);
@ -100,9 +101,8 @@ static FILE *getopthandle (lua_State *L, int inout) {
luaL_verror(L, "global variable `%.10s' is not a valid file handle",
filenames[inout]);
p = (FILE *)lua_touserdata(L, -1);
lua_pop(L, 1); /* remove global value from stack */
}
return p;
return p; /* leave handle at stack top to avoid GC */
}
@ -295,7 +295,7 @@ static int read_chars (lua_State *L, FILE *f, size_t n) {
static int io_read (lua_State *L) {
FILE *f = getopthandle(L, INFILE);
int nargs = lua_gettop(L);
int nargs = lua_gettop(L)-1;
int success;
int n;
if (nargs == 0) { /* no arguments? */
@ -347,7 +347,7 @@ static int io_read (lua_State *L) {
static int io_write (lua_State *L) {
FILE *f = getopthandle(L, OUTFILE);
int nargs = lua_gettop(L);
int nargs = lua_gettop(L)-1;
int arg;
int status = 1;
for (arg=1; arg<=nargs; arg++) {

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 1.53 2001/01/24 15:45:33 roberto Exp roberto $
** $Id: lstate.c,v 1.54 2001/01/25 16:45:36 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -91,7 +91,7 @@ static void f_luaopen (lua_State *L, void *ud) {
luaX_init(L);
luaT_init(L);
G(L)->GCthreshold = 4*G(L)->nblocks;
LUA_EXIT; /* temporary exit to use the API */
LUA_UNLOCK; /* temporary exit to use the API */
lua_newtable(L);
lua_ref(L, 1); /* create registry */
lua_register(L, LUA_ERRORMESSAGE, errormessage);
@ -100,7 +100,7 @@ static void f_luaopen (lua_State *L, void *ud) {
if (lua_state == NULL) lua_state = L; /* keep first state to be opened */
lua_assert(lua_gettop(L) == 0);
#endif
LUA_ENTRY; /* go back inside */
LUA_LOCK; /* go back inside */
}
}
@ -108,7 +108,7 @@ static void f_luaopen (lua_State *L, void *ud) {
LUA_API lua_State *lua_open (lua_State *OL, int stacksize) {
struct Sopen so;
lua_State *L;
LUA_ENTRY;
LUA_LOCK;
L = luaM_new(OL, lua_State);
if (L) { /* allocation OK? */
L->G = NULL;
@ -127,7 +127,7 @@ LUA_API lua_State *lua_open (lua_State *OL, int stacksize) {
L = NULL;
}
}
LUA_EXIT;
LUA_UNLOCK;
return L;
}
@ -158,9 +158,9 @@ static void close_state (lua_State *L) {
LUA_API void lua_close (lua_State *L) {
lua_assert(L != lua_state || lua_gettop(L) == 0);
LUA_ENTRY;
LUA_LOCK;
close_state(L);
LUA_EXIT;
LUA_UNLOCK;
lua_assert(L != lua_state || memdebug_numblocks == 0);
lua_assert(L != lua_state || memdebug_total == 0);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 1.46 2001/01/24 15:45:33 roberto Exp roberto $
** $Id: lstate.h,v 1.47 2001/01/25 16:45:36 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -15,8 +15,8 @@
#ifdef LUA_DEBUG
extern int islocked;
#define LUA_ENTRY lua_assert(islocked++ == 0)
#define LUA_EXIT lua_assert(--islocked == 0)
#define LUA_LOCK lua_assert(islocked++ == 0)
#define LUA_UNLOCK lua_assert(--islocked == 0)
#endif
@ -24,12 +24,12 @@ extern int islocked;
** macros that control all entries and exits from Lua core machine
** (mainly for thread syncronization)
*/
#ifndef LUA_ENTRY
#define LUA_ENTRY
#ifndef LUA_LOCK
#define LUA_LOCK
#endif
#ifndef LUA_EXIT
#define LUA_EXIT
#ifndef LUA_UNLOCK
#define LUA_UNLOCK
#endif

14
ltm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ltm.c,v 1.62 2001/01/24 15:45:33 roberto Exp roberto $
** $Id: ltm.c,v 1.63 2001/01/25 16:45:36 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@ -111,14 +111,14 @@ static void checktag (lua_State *L, int tag) {
LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
int e;
LUA_ENTRY;
LUA_LOCK;
checktag(L, tagto);
checktag(L, tagfrom);
for (e=0; e<TM_N; e++) {
if (luaT_validevent(tagto, e))
luaT_gettm(G(L), tagto, e) = luaT_gettm(G(L), tagfrom, e);
}
LUA_EXIT;
LUA_UNLOCK;
return tagto;
}
@ -156,7 +156,7 @@ const char *luaT_typename (global_State *G, const TObject *o) {
LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) {
int e;
LUA_ENTRY;
LUA_LOCK;
e = luaI_checkevent(L, event, t);
checktag(L, t);
if (luaT_validevent(t, e) && luaT_gettm(G(L), t, e)) {
@ -165,13 +165,13 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) {
else
setnilvalue(L->top);
incr_top;
LUA_EXIT;
LUA_UNLOCK;
}
LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) {
int e;
LUA_ENTRY;
LUA_LOCK;
e = luaI_checkevent(L, event, t);
checktag(L, t);
if (!luaT_validevent(t, e))
@ -190,6 +190,6 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) {
luaD_error(L, "tag method must be a function (or nil)");
}
L->top--;
LUA_EXIT;
LUA_UNLOCK;
}

36
lua.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.56 2001/01/10 16:58:11 roberto Exp roberto $
** $Id: lua.c,v 1.57 2001/01/22 18:01:38 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@ -16,17 +16,27 @@
#include "lualib.h"
static lua_State *L = NULL;
#ifdef _POSIX_SOURCE
#include <unistd.h>
#else
static int isatty (int x) { return x==0; } /* assume stdin is a tty */
#endif
#ifndef PROMPT
#define PROMPT "> "
#endif
#ifdef _POSIX_SOURCE
#include <unistd.h>
#else
static int isatty (int x) { return x==0; } /* assume stdin is a tty */
#ifndef LUA_USERINIT
#define LUA_USERINIT(L) (lua_baselibopen(L), lua_iolibopen(L), \
lua_strlibopen(L), lua_mathlibopen(L), lua_dblibopen(L))
#endif
#ifndef LUA_USERFINI
#define LUA_USERFINI
#endif
@ -39,6 +49,9 @@ struct Options {
};
static lua_State *L = NULL;
typedef void (*handler)(int); /* type for signal actions */
static void laction (int i);
@ -48,15 +61,6 @@ static lua_Hook old_linehook = NULL;
static lua_Hook old_callhook = NULL;
static void userinit (void) {
lua_baselibopen(L);
lua_iolibopen(L);
lua_strlibopen(L);
lua_mathlibopen(L);
lua_dblibopen(L);
/* add your libraries here */
}
static handler lreset (void) {
return signal(SIGINT, laction);
@ -312,7 +316,7 @@ int main (int argc, char *argv[]) {
opt.toclose = 0;
getstacksize(argc, argv, &opt); /* handle option `-s' */
L = lua_open(NULL, opt.stacksize); /* create state */
userinit(); /* open libraries */
LUA_USERINIT(L); /* open libraries */
register_getargs(argv); /* create `getargs' function */
status = handle_argv(argv+1, &opt);
if (opt.toclose)

22
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.83 2001/01/22 18:01:38 roberto Exp roberto $
** $Id: lua.h,v 1.84 2001/01/25 16:45:36 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br
@ -16,11 +16,6 @@
#include <stddef.h>
/* mark for all API functions */
#ifndef LUA_API
#define LUA_API extern
#endif
#define LUA_VERSION "Lua 4.1 (work)"
#define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio"
@ -77,6 +72,21 @@ typedef int (*lua_CFunction) (lua_State *L);
#define LUA_TFUNCTION 5
/*
** generic extra include file
*/
#ifdef LUA_USER_H
#include LUA_USER_H
#endif
/* mark for all API functions */
#ifndef LUA_API
#define LUA_API extern
#endif
/*
** state manipulation