|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
-** $Id: lapi.c,v 2.19 2004/09/15 20:39:42 roberto Exp roberto $
|
|
|
+** $Id: lapi.c,v 2.20 2004/11/24 18:55:56 roberto Exp roberto $
|
|
|
** Lua API
|
|
|
** See Copyright Notice in lua.h
|
|
|
*/
|
|
@@ -45,7 +45,7 @@ const char lua_ident[] =
|
|
|
|
|
|
|
|
|
|
|
|
-static TValue *luaA_index (lua_State *L, int idx) {
|
|
|
+static TValue *index2adr (lua_State *L, int idx) {
|
|
|
if (idx > 0) {
|
|
|
TValue *o = L->base + (idx - 1);
|
|
|
api_check(L, idx <= L->ci->top - L->base);
|
|
@@ -160,7 +160,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
|
|
|
LUA_API void lua_remove (lua_State *L, int idx) {
|
|
|
StkId p;
|
|
|
lua_lock(L);
|
|
|
- p = luaA_index(L, idx);
|
|
|
+ p = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, p);
|
|
|
while (++p < L->top) setobjs2s(L, p-1, p);
|
|
|
L->top--;
|
|
@@ -172,7 +172,7 @@ LUA_API void lua_insert (lua_State *L, int idx) {
|
|
|
StkId p;
|
|
|
StkId q;
|
|
|
lua_lock(L);
|
|
|
- p = luaA_index(L, idx);
|
|
|
+ p = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, p);
|
|
|
for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
|
|
|
setobjs2s(L, p, L->top);
|
|
@@ -184,7 +184,7 @@ LUA_API void lua_replace (lua_State *L, int idx) {
|
|
|
StkId o;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 1);
|
|
|
- o = luaA_index(L, idx);
|
|
|
+ o = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, o);
|
|
|
setobj(L, o, L->top - 1);
|
|
|
if (idx < LUA_GLOBALSINDEX) /* function upvalue? */
|
|
@@ -196,7 +196,7 @@ LUA_API void lua_replace (lua_State *L, int idx) {
|
|
|
|
|
|
LUA_API void lua_pushvalue (lua_State *L, int idx) {
|
|
|
lua_lock(L);
|
|
|
- setobj2s(L, L->top, luaA_index(L, idx));
|
|
|
+ setobj2s(L, L->top, index2adr(L, idx));
|
|
|
api_incr_top(L);
|
|
|
lua_unlock(L);
|
|
|
}
|
|
@@ -209,7 +209,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) {
|
|
|
|
|
|
|
|
|
LUA_API int lua_type (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o);
|
|
|
}
|
|
|
|
|
@@ -221,14 +221,14 @@ LUA_API const char *lua_typename (lua_State *L, int t) {
|
|
|
|
|
|
|
|
|
LUA_API int lua_iscfunction (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
return iscfunction(o);
|
|
|
}
|
|
|
|
|
|
|
|
|
LUA_API int lua_isnumber (lua_State *L, int idx) {
|
|
|
TValue n;
|
|
|
- const TValue *o = luaA_index(L, idx);
|
|
|
+ const TValue *o = index2adr(L, idx);
|
|
|
return tonumber(o, &n);
|
|
|
}
|
|
|
|
|
@@ -240,14 +240,14 @@ LUA_API int lua_isstring (lua_State *L, int idx) {
|
|
|
|
|
|
|
|
|
LUA_API int lua_isuserdata (lua_State *L, int idx) {
|
|
|
- const TValue *o = luaA_index(L, idx);
|
|
|
+ const TValue *o = index2adr(L, idx);
|
|
|
return (ttisuserdata(o) || ttislightuserdata(o));
|
|
|
}
|
|
|
|
|
|
|
|
|
LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
|
|
|
- StkId o1 = luaA_index(L, index1);
|
|
|
- StkId o2 = luaA_index(L, index2);
|
|
|
+ StkId o1 = index2adr(L, index1);
|
|
|
+ StkId o2 = index2adr(L, index2);
|
|
|
return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
|
|
|
: luaO_rawequalObj(o1, o2);
|
|
|
}
|
|
@@ -257,8 +257,8 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) {
|
|
|
StkId o1, o2;
|
|
|
int i;
|
|
|
lua_lock(L); /* may call tag method */
|
|
|
- o1 = luaA_index(L, index1);
|
|
|
- o2 = luaA_index(L, index2);
|
|
|
+ o1 = index2adr(L, index1);
|
|
|
+ o2 = index2adr(L, index2);
|
|
|
i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
|
|
|
: equalobj(L, o1, o2);
|
|
|
lua_unlock(L);
|
|
@@ -270,8 +270,8 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
|
|
|
StkId o1, o2;
|
|
|
int i;
|
|
|
lua_lock(L); /* may call tag method */
|
|
|
- o1 = luaA_index(L, index1);
|
|
|
- o2 = luaA_index(L, index2);
|
|
|
+ o1 = index2adr(L, index1);
|
|
|
+ o2 = index2adr(L, index2);
|
|
|
i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
|
|
|
: luaV_lessthan(L, o1, o2);
|
|
|
lua_unlock(L);
|
|
@@ -282,7 +282,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
|
|
|
|
|
|
LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
|
|
|
TValue n;
|
|
|
- const TValue *o = luaA_index(L, idx);
|
|
|
+ const TValue *o = index2adr(L, idx);
|
|
|
if (tonumber(o, &n))
|
|
|
return nvalue(o);
|
|
|
else
|
|
@@ -292,7 +292,7 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
|
|
|
|
|
|
LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
|
|
|
TValue n;
|
|
|
- const TValue *o = luaA_index(L, idx);
|
|
|
+ const TValue *o = index2adr(L, idx);
|
|
|
if (tonumber(o, &n)) {
|
|
|
lua_Integer res;
|
|
|
lua_number2integer(res, nvalue(o));
|
|
@@ -304,13 +304,13 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
|
|
|
|
|
|
|
|
|
LUA_API int lua_toboolean (lua_State *L, int idx) {
|
|
|
- const TValue *o = luaA_index(L, idx);
|
|
|
+ const TValue *o = index2adr(L, idx);
|
|
|
return !l_isfalse(o);
|
|
|
}
|
|
|
|
|
|
|
|
|
LUA_API const char *lua_tostring (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
if (ttisstring(o))
|
|
|
return svalue(o);
|
|
|
else {
|
|
@@ -325,7 +325,7 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) {
|
|
|
|
|
|
|
|
|
LUA_API size_t lua_objsize (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
if (ttisstring(o))
|
|
|
return tsvalue(o)->len;
|
|
|
else if (ttisuserdata(o))
|
|
@@ -341,13 +341,13 @@ LUA_API size_t lua_objsize (lua_State *L, int idx) {
|
|
|
|
|
|
|
|
|
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;
|
|
|
}
|
|
|
|
|
|
|
|
|
LUA_API void *lua_touserdata (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
switch (ttype(o)) {
|
|
|
case LUA_TUSERDATA: return (rawuvalue(o) + 1);
|
|
|
case LUA_TLIGHTUSERDATA: return pvalue(o);
|
|
@@ -357,13 +357,13 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) {
|
|
|
|
|
|
|
|
|
LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
return (!ttisthread(o)) ? NULL : thvalue(o);
|
|
|
}
|
|
|
|
|
|
|
|
|
LUA_API const void *lua_topointer (lua_State *L, int idx) {
|
|
|
- StkId o = luaA_index(L, idx);
|
|
|
+ StkId o = index2adr(L, idx);
|
|
|
switch (ttype(o)) {
|
|
|
case LUA_TTABLE: return hvalue(o);
|
|
|
case LUA_TFUNCTION: return clvalue(o);
|
|
@@ -498,7 +498,7 @@ LUA_API int lua_pushthread (lua_State *L) {
|
|
|
LUA_API void lua_gettable (lua_State *L, int idx) {
|
|
|
StkId t;
|
|
|
lua_lock(L);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, t);
|
|
|
luaV_gettable(L, t, L->top - 1, L->top - 1, NULL);
|
|
|
lua_unlock(L);
|
|
@@ -509,7 +509,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
|
|
|
StkId t;
|
|
|
TValue key;
|
|
|
lua_lock(L);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, t);
|
|
|
setsvalue(L, &key, luaS_new(L, k));
|
|
|
luaV_gettable(L, t, &key, L->top, NULL);
|
|
@@ -521,7 +521,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
|
|
|
LUA_API void lua_rawget (lua_State *L, int idx) {
|
|
|
StkId t;
|
|
|
lua_lock(L);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_check(L, ttistable(t));
|
|
|
setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
|
|
|
lua_unlock(L);
|
|
@@ -531,7 +531,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) {
|
|
|
LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
|
|
|
StkId o;
|
|
|
lua_lock(L);
|
|
|
- o = luaA_index(L, idx);
|
|
|
+ o = index2adr(L, idx);
|
|
|
api_check(L, ttistable(o));
|
|
|
setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
|
|
|
api_incr_top(L);
|
|
@@ -553,7 +553,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
|
|
|
Table *mt = NULL;
|
|
|
int res;
|
|
|
lua_lock(L);
|
|
|
- obj = luaA_index(L, objindex);
|
|
|
+ obj = index2adr(L, objindex);
|
|
|
switch (ttype(obj)) {
|
|
|
case LUA_TTABLE:
|
|
|
mt = hvalue(obj)->metatable;
|
|
@@ -577,7 +577,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
|
|
|
LUA_API void lua_getfenv (lua_State *L, int idx) {
|
|
|
StkId o;
|
|
|
lua_lock(L);
|
|
|
- o = luaA_index(L, idx);
|
|
|
+ o = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, o);
|
|
|
setobj2s(L, L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L));
|
|
|
api_incr_top(L);
|
|
@@ -594,7 +594,7 @@ LUA_API void lua_settable (lua_State *L, int idx) {
|
|
|
StkId t;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 2);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, t);
|
|
|
luaV_settable(L, t, L->top - 2, L->top - 1, NULL);
|
|
|
L->top -= 2; /* pop index and value */
|
|
@@ -607,7 +607,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
|
|
|
TValue key;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 1);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, t);
|
|
|
setsvalue(L, &key, luaS_new(L, k));
|
|
|
luaV_settable(L, t, &key, L->top - 1, NULL);
|
|
@@ -620,7 +620,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
|
|
|
StkId t;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 2);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_check(L, ttistable(t));
|
|
|
setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
|
|
|
luaC_barriert(L, hvalue(t), L->top-1);
|
|
@@ -633,7 +633,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
|
|
|
StkId o;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 1);
|
|
|
- o = luaA_index(L, idx);
|
|
|
+ o = index2adr(L, idx);
|
|
|
api_check(L, ttistable(o));
|
|
|
setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
|
|
|
luaC_barriert(L, hvalue(o), L->top-1);
|
|
@@ -648,7 +648,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
|
|
|
int res = 1;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 1);
|
|
|
- obj = luaA_index(L, objindex);
|
|
|
+ obj = index2adr(L, objindex);
|
|
|
api_checkvalidindex(L, obj);
|
|
|
if (ttisnil(L->top - 1))
|
|
|
mt = NULL;
|
|
@@ -685,7 +685,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {
|
|
|
int res = 0;
|
|
|
lua_lock(L);
|
|
|
api_checknelems(L, 1);
|
|
|
- o = luaA_index(L, idx);
|
|
|
+ o = index2adr(L, idx);
|
|
|
api_checkvalidindex(L, o);
|
|
|
api_check(L, ttistable(L->top - 1));
|
|
|
if (isLfunction(o)) {
|
|
@@ -751,7 +751,7 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
|
|
|
if (errfunc == 0)
|
|
|
func = 0;
|
|
|
else {
|
|
|
- StkId o = luaA_index(L, errfunc);
|
|
|
+ StkId o = index2adr(L, errfunc);
|
|
|
api_checkvalidindex(L, o);
|
|
|
func = savestack(L, o);
|
|
|
}
|
|
@@ -898,7 +898,7 @@ LUA_API int lua_next (lua_State *L, int idx) {
|
|
|
StkId t;
|
|
|
int more;
|
|
|
lua_lock(L);
|
|
|
- t = luaA_index(L, idx);
|
|
|
+ t = index2adr(L, idx);
|
|
|
api_check(L, ttistable(t));
|
|
|
more = luaH_next(L, hvalue(t), L->top - 1);
|
|
|
if (more) {
|
|
@@ -970,7 +970,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
|
|
|
const char *name;
|
|
|
TValue *val;
|
|
|
lua_lock(L);
|
|
|
- name = aux_upvalue(L, luaA_index(L, funcindex), n, &val);
|
|
|
+ name = aux_upvalue(L, index2adr(L, funcindex), n, &val);
|
|
|
if (name) {
|
|
|
setobj2s(L, L->top, val);
|
|
|
api_incr_top(L);
|
|
@@ -985,7 +985,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
|
|
|
TValue *val;
|
|
|
StkId fi;
|
|
|
lua_lock(L);
|
|
|
- fi = luaA_index(L, funcindex);
|
|
|
+ fi = index2adr(L, funcindex);
|
|
|
api_checknelems(L, 1);
|
|
|
name = aux_upvalue(L, fi, n, &val);
|
|
|
if (name) {
|