commit 0a87d9d3346bcf74d84e4d6bae775bceecef096f
parent f856fdeabde61ee2f020d5fea799e4f5cd85cb44
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 5 Feb 2002 20:35:36 -0200
new function `lua_replace'
Diffstat:
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -137,6 +137,15 @@ LUA_API void lua_insert (lua_State *L, int index) {
}
+LUA_API void lua_replace (lua_State *L, int index) {
+ lua_lock(L);
+ api_checknelems(L, 1);
+ setobj(luaA_index(L, index), L->top - 1);
+ L->top--;
+ lua_unlock(L);
+}
+
+
LUA_API void lua_pushvalue (lua_State *L, int index) {
lua_lock(L);
setobj(L->top, luaA_index(L, index));
@@ -172,7 +181,7 @@ LUA_API int lua_iscfunction (lua_State *L, int index) {
LUA_API int lua_isnumber (lua_State *L, int index) {
TObject n;
TObject *o = luaA_indexAcceptable(L, index);
- return (o != NULL && (ttype(o) == LUA_TNUMBER || luaV_tonumber(o, &n)));
+ return (o != NULL && luaV_tonumber(o, &n));
}
@@ -213,8 +222,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
TObject n;
const TObject *o = luaA_indexAcceptable(L, index);
- if (o != NULL &&
- (ttype(o) == LUA_TNUMBER || (o = luaV_tonumber(o, &n)) != NULL))
+ if (o != NULL && (o = luaV_tonumber(o, &n)) != NULL)
return nvalue(o);
else
return 0;
@@ -477,17 +485,6 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) {
}
-LUA_API void lua_setglobals (lua_State *L) {
- StkId newtable;
- lua_lock(L);
- api_checknelems(L, 1);
- newtable = --L->top;
- api_check(L, ttype(newtable) == LUA_TTABLE);
- setobj(gt(L), newtable);
- lua_unlock(L);
-}
-
-
LUA_API void lua_setmetatable (lua_State *L, int objindex) {
StkId obj, mt;
lua_lock(L);
diff --git a/lua.h b/lua.h
@@ -108,6 +108,7 @@ LUA_API void lua_settop (lua_State *L, int index);
LUA_API void lua_pushvalue (lua_State *L, int index);
LUA_API void lua_remove (lua_State *L, int index);
LUA_API void lua_insert (lua_State *L, int index);
+LUA_API void lua_replace (lua_State *L, int index);
LUA_API int lua_stackspace (lua_State *L);
@@ -163,7 +164,6 @@ LUA_API void lua_setstr (lua_State *L, int index, const char *name);
LUA_API void lua_settable (lua_State *L, int index);
LUA_API void lua_rawset (lua_State *L, int index);
LUA_API void lua_rawseti (lua_State *L, int index, int n);
-LUA_API void lua_setglobals (lua_State *L);
LUA_API void lua_setmetatable (lua_State *L, int objindex);
@@ -186,7 +186,7 @@ LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size,
*/
LUA_API void lua_cobegin (lua_State *L, int nargs);
LUA_API int lua_yield (lua_State *L, int nresults);
-LUA_API void lua_resume (lua_State *L, lua_State *co);
+LUA_API int lua_resume (lua_State *L, lua_State *co);
/*
** Garbage-collection functions
@@ -234,6 +234,7 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u);
#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
#define lua_getglobals(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
+#define lua_setglobals(L) lua_replace(L, LUA_GLOBALSINDEX)
#define lua_getglobal(L,s) lua_getstr(L, LUA_GLOBALSINDEX, s)
#define lua_setglobal(L,s) lua_setstr(L, LUA_GLOBALSINDEX, s)