diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-02-05 20:35:58 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-02-05 20:35:58 -0200 |
| commit | 0a87d9d3346bcf74d84e4d6bae775bceecef096f (patch) | |
| tree | e81f26ef510ce349fe1ad6008c888e919c35d074 | |
| parent | f856fdeabde61ee2f020d5fea799e4f5cd85cb44 (diff) | |
| download | lua-0a87d9d3346bcf74d84e4d6bae775bceecef096f.tar.gz lua-0a87d9d3346bcf74d84e4d6bae775bceecef096f.tar.bz2 lua-0a87d9d3346bcf74d84e4d6bae775bceecef096f.zip | |
new function `lua_replace'
| -rw-r--r-- | lapi.c | 25 | ||||
| -rw-r--r-- | lua.h | 5 |
2 files changed, 14 insertions, 16 deletions
| @@ -137,6 +137,15 @@ LUA_API void lua_insert (lua_State *L, int index) { | |||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | 139 | ||
| 140 | LUA_API void lua_replace (lua_State *L, int index) { | ||
| 141 | lua_lock(L); | ||
| 142 | api_checknelems(L, 1); | ||
| 143 | setobj(luaA_index(L, index), L->top - 1); | ||
| 144 | L->top--; | ||
| 145 | lua_unlock(L); | ||
| 146 | } | ||
| 147 | |||
| 148 | |||
| 140 | LUA_API void lua_pushvalue (lua_State *L, int index) { | 149 | LUA_API void lua_pushvalue (lua_State *L, int index) { |
| 141 | lua_lock(L); | 150 | lua_lock(L); |
| 142 | setobj(L->top, luaA_index(L, index)); | 151 | setobj(L->top, luaA_index(L, index)); |
| @@ -172,7 +181,7 @@ LUA_API int lua_iscfunction (lua_State *L, int index) { | |||
| 172 | LUA_API int lua_isnumber (lua_State *L, int index) { | 181 | LUA_API int lua_isnumber (lua_State *L, int index) { |
| 173 | TObject n; | 182 | TObject n; |
| 174 | TObject *o = luaA_indexAcceptable(L, index); | 183 | TObject *o = luaA_indexAcceptable(L, index); |
| 175 | return (o != NULL && (ttype(o) == LUA_TNUMBER || luaV_tonumber(o, &n))); | 184 | return (o != NULL && luaV_tonumber(o, &n)); |
| 176 | } | 185 | } |
| 177 | 186 | ||
| 178 | 187 | ||
| @@ -213,8 +222,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | |||
| 213 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | 222 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { |
| 214 | TObject n; | 223 | TObject n; |
| 215 | const TObject *o = luaA_indexAcceptable(L, index); | 224 | const TObject *o = luaA_indexAcceptable(L, index); |
| 216 | if (o != NULL && | 225 | if (o != NULL && (o = luaV_tonumber(o, &n)) != NULL) |
| 217 | (ttype(o) == LUA_TNUMBER || (o = luaV_tonumber(o, &n)) != NULL)) | ||
| 218 | return nvalue(o); | 226 | return nvalue(o); |
| 219 | else | 227 | else |
| 220 | return 0; | 228 | return 0; |
| @@ -477,17 +485,6 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) { | |||
| 477 | } | 485 | } |
| 478 | 486 | ||
| 479 | 487 | ||
| 480 | LUA_API void lua_setglobals (lua_State *L) { | ||
| 481 | StkId newtable; | ||
| 482 | lua_lock(L); | ||
| 483 | api_checknelems(L, 1); | ||
| 484 | newtable = --L->top; | ||
| 485 | api_check(L, ttype(newtable) == LUA_TTABLE); | ||
| 486 | setobj(gt(L), newtable); | ||
| 487 | lua_unlock(L); | ||
| 488 | } | ||
| 489 | |||
| 490 | |||
| 491 | LUA_API void lua_setmetatable (lua_State *L, int objindex) { | 488 | LUA_API void lua_setmetatable (lua_State *L, int objindex) { |
| 492 | StkId obj, mt; | 489 | StkId obj, mt; |
| 493 | lua_lock(L); | 490 | lua_lock(L); |
| @@ -108,6 +108,7 @@ LUA_API void lua_settop (lua_State *L, int index); | |||
| 108 | LUA_API void lua_pushvalue (lua_State *L, int index); | 108 | LUA_API void lua_pushvalue (lua_State *L, int index); |
| 109 | LUA_API void lua_remove (lua_State *L, int index); | 109 | LUA_API void lua_remove (lua_State *L, int index); |
| 110 | LUA_API void lua_insert (lua_State *L, int index); | 110 | LUA_API void lua_insert (lua_State *L, int index); |
| 111 | LUA_API void lua_replace (lua_State *L, int index); | ||
| 111 | LUA_API int lua_stackspace (lua_State *L); | 112 | LUA_API int lua_stackspace (lua_State *L); |
| 112 | 113 | ||
| 113 | 114 | ||
| @@ -163,7 +164,6 @@ LUA_API void lua_setstr (lua_State *L, int index, const char *name); | |||
| 163 | LUA_API void lua_settable (lua_State *L, int index); | 164 | LUA_API void lua_settable (lua_State *L, int index); |
| 164 | LUA_API void lua_rawset (lua_State *L, int index); | 165 | LUA_API void lua_rawset (lua_State *L, int index); |
| 165 | LUA_API void lua_rawseti (lua_State *L, int index, int n); | 166 | LUA_API void lua_rawseti (lua_State *L, int index, int n); |
| 166 | LUA_API void lua_setglobals (lua_State *L); | ||
| 167 | LUA_API void lua_setmetatable (lua_State *L, int objindex); | 167 | LUA_API void lua_setmetatable (lua_State *L, int objindex); |
| 168 | 168 | ||
| 169 | 169 | ||
| @@ -186,7 +186,7 @@ LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, | |||
| 186 | */ | 186 | */ |
| 187 | LUA_API void lua_cobegin (lua_State *L, int nargs); | 187 | LUA_API void lua_cobegin (lua_State *L, int nargs); |
| 188 | LUA_API int lua_yield (lua_State *L, int nresults); | 188 | LUA_API int lua_yield (lua_State *L, int nresults); |
| 189 | LUA_API void lua_resume (lua_State *L, lua_State *co); | 189 | LUA_API int lua_resume (lua_State *L, lua_State *co); |
| 190 | 190 | ||
| 191 | /* | 191 | /* |
| 192 | ** Garbage-collection functions | 192 | ** Garbage-collection functions |
| @@ -234,6 +234,7 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u); | |||
| 234 | 234 | ||
| 235 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) | 235 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) |
| 236 | #define lua_getglobals(L) lua_pushvalue(L, LUA_GLOBALSINDEX) | 236 | #define lua_getglobals(L) lua_pushvalue(L, LUA_GLOBALSINDEX) |
| 237 | #define lua_setglobals(L) lua_replace(L, LUA_GLOBALSINDEX) | ||
| 237 | #define lua_getglobal(L,s) lua_getstr(L, LUA_GLOBALSINDEX, s) | 238 | #define lua_getglobal(L,s) lua_getstr(L, LUA_GLOBALSINDEX, s) |
| 238 | #define lua_setglobal(L,s) lua_setstr(L, LUA_GLOBALSINDEX, s) | 239 | #define lua_setglobal(L,s) lua_setstr(L, LUA_GLOBALSINDEX, s) |
| 239 | 240 | ||
