diff options
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 206 |
1 files changed, 103 insertions, 103 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.133 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.134 2001/02/23 17:28:12 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -70,9 +70,9 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
| 70 | 70 | ||
| 71 | LUA_API int lua_stackspace (lua_State *L) { | 71 | LUA_API int lua_stackspace (lua_State *L) { |
| 72 | int i; | 72 | int i; |
| 73 | LUA_LOCK(L); | 73 | lua_lock(L); |
| 74 | i = (L->stack_last - L->top); | 74 | i = (L->stack_last - L->top); |
| 75 | LUA_UNLOCK(L); | 75 | lua_unlock(L); |
| 76 | return i; | 76 | return i; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| @@ -85,51 +85,51 @@ LUA_API int lua_stackspace (lua_State *L) { | |||
| 85 | 85 | ||
| 86 | LUA_API int lua_gettop (lua_State *L) { | 86 | LUA_API int lua_gettop (lua_State *L) { |
| 87 | int i; | 87 | int i; |
| 88 | LUA_LOCK(L); | 88 | lua_lock(L); |
| 89 | i = (L->top - L->Cbase); | 89 | i = (L->top - L->Cbase); |
| 90 | LUA_UNLOCK(L); | 90 | lua_unlock(L); |
| 91 | return i; | 91 | return i; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | LUA_API void lua_settop (lua_State *L, int index) { | 95 | LUA_API void lua_settop (lua_State *L, int index) { |
| 96 | LUA_LOCK(L); | 96 | lua_lock(L); |
| 97 | if (index >= 0) | 97 | if (index >= 0) |
| 98 | luaD_adjusttop(L, L->Cbase, index); | 98 | luaD_adjusttop(L, L->Cbase, index); |
| 99 | else { | 99 | else { |
| 100 | api_check(L, -(index+1) <= (L->top - L->Cbase)); | 100 | api_check(L, -(index+1) <= (L->top - L->Cbase)); |
| 101 | L->top = L->top+index+1; /* index is negative */ | 101 | L->top = L->top+index+1; /* index is negative */ |
| 102 | } | 102 | } |
| 103 | LUA_UNLOCK(L); | 103 | lua_unlock(L); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | 106 | ||
| 107 | LUA_API void lua_remove (lua_State *L, int index) { | 107 | LUA_API void lua_remove (lua_State *L, int index) { |
| 108 | StkId p; | 108 | StkId p; |
| 109 | LUA_LOCK(L); | 109 | lua_lock(L); |
| 110 | p = luaA_index(L, index); | 110 | p = luaA_index(L, index); |
| 111 | while (++p < L->top) setobj(p-1, p); | 111 | while (++p < L->top) setobj(p-1, p); |
| 112 | L->top--; | 112 | L->top--; |
| 113 | LUA_UNLOCK(L); | 113 | lua_unlock(L); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | 116 | ||
| 117 | LUA_API void lua_insert (lua_State *L, int index) { | 117 | LUA_API void lua_insert (lua_State *L, int index) { |
| 118 | StkId p; | 118 | StkId p; |
| 119 | StkId q; | 119 | StkId q; |
| 120 | LUA_LOCK(L); | 120 | lua_lock(L); |
| 121 | p = luaA_index(L, index); | 121 | p = luaA_index(L, index); |
| 122 | for (q = L->top; q>p; q--) setobj(q, q-1); | 122 | for (q = L->top; q>p; q--) setobj(q, q-1); |
| 123 | setobj(p, L->top); | 123 | setobj(p, L->top); |
| 124 | LUA_UNLOCK(L); | 124 | lua_unlock(L); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | 127 | ||
| 128 | LUA_API void lua_pushvalue (lua_State *L, int index) { | 128 | LUA_API void lua_pushvalue (lua_State *L, int index) { |
| 129 | LUA_LOCK(L); | 129 | lua_lock(L); |
| 130 | setobj(L->top, luaA_index(L, index)); | 130 | setobj(L->top, luaA_index(L, index)); |
| 131 | api_incr_top(L); | 131 | api_incr_top(L); |
| 132 | LUA_UNLOCK(L); | 132 | lua_unlock(L); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | 135 | ||
| @@ -142,19 +142,19 @@ LUA_API void lua_pushvalue (lua_State *L, int index) { | |||
| 142 | LUA_API int lua_type (lua_State *L, int index) { | 142 | LUA_API int lua_type (lua_State *L, int index) { |
| 143 | StkId o; | 143 | StkId o; |
| 144 | int i; | 144 | int i; |
| 145 | LUA_LOCK(L); | 145 | lua_lock(L); |
| 146 | o = luaA_indexAcceptable(L, index); | 146 | o = luaA_indexAcceptable(L, index); |
| 147 | i = (o == NULL) ? LUA_TNONE : ttype(o); | 147 | i = (o == NULL) ? LUA_TNONE : ttype(o); |
| 148 | LUA_UNLOCK(L); | 148 | lua_unlock(L); |
| 149 | return i; | 149 | return i; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | LUA_API const l_char *lua_typename (lua_State *L, int t) { | 153 | LUA_API const l_char *lua_typename (lua_State *L, int t) { |
| 154 | const l_char *s; | 154 | const l_char *s; |
| 155 | LUA_LOCK(L); | 155 | lua_lock(L); |
| 156 | s = (t == LUA_TNONE) ? l_s("no value") : basictypename(G(L), t); | 156 | s = (t == LUA_TNONE) ? l_s("no value") : basictypename(G(L), t); |
| 157 | LUA_UNLOCK(L); | 157 | lua_unlock(L); |
| 158 | return s; | 158 | return s; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| @@ -162,10 +162,10 @@ LUA_API const l_char *lua_typename (lua_State *L, int t) { | |||
| 162 | LUA_API const l_char *lua_xtype (lua_State *L, int index) { | 162 | LUA_API const l_char *lua_xtype (lua_State *L, int index) { |
| 163 | StkId o; | 163 | StkId o; |
| 164 | const l_char *type; | 164 | const l_char *type; |
| 165 | LUA_LOCK(L); | 165 | lua_lock(L); |
| 166 | o = luaA_indexAcceptable(L, index); | 166 | o = luaA_indexAcceptable(L, index); |
| 167 | type = (o == NULL) ? l_s("no value") : luaT_typename(G(L), o); | 167 | type = (o == NULL) ? l_s("no value") : luaT_typename(G(L), o); |
| 168 | LUA_UNLOCK(L); | 168 | lua_unlock(L); |
| 169 | return type; | 169 | return type; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| @@ -173,20 +173,20 @@ LUA_API const l_char *lua_xtype (lua_State *L, int index) { | |||
| 173 | LUA_API int lua_iscfunction (lua_State *L, int index) { | 173 | LUA_API int lua_iscfunction (lua_State *L, int index) { |
| 174 | StkId o; | 174 | StkId o; |
| 175 | int i; | 175 | int i; |
| 176 | LUA_LOCK(L); | 176 | lua_lock(L); |
| 177 | o = luaA_indexAcceptable(L, index); | 177 | o = luaA_indexAcceptable(L, index); |
| 178 | i = (o == NULL) ? 0 : iscfunction(o); | 178 | i = (o == NULL) ? 0 : iscfunction(o); |
| 179 | LUA_UNLOCK(L); | 179 | lua_unlock(L); |
| 180 | return i; | 180 | return i; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | LUA_API int lua_isnumber (lua_State *L, int index) { | 183 | LUA_API int lua_isnumber (lua_State *L, int index) { |
| 184 | TObject *o; | 184 | TObject *o; |
| 185 | int i; | 185 | int i; |
| 186 | LUA_LOCK(L); | 186 | lua_lock(L); |
| 187 | o = luaA_indexAcceptable(L, index); | 187 | o = luaA_indexAcceptable(L, index); |
| 188 | i = (o == NULL) ? 0 : (tonumber(o) == 0); | 188 | i = (o == NULL) ? 0 : (tonumber(o) == 0); |
| 189 | LUA_UNLOCK(L); | 189 | lua_unlock(L); |
| 190 | return i; | 190 | return i; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| @@ -199,34 +199,34 @@ LUA_API int lua_isstring (lua_State *L, int index) { | |||
| 199 | LUA_API int lua_tag (lua_State *L, int index) { | 199 | LUA_API int lua_tag (lua_State *L, int index) { |
| 200 | StkId o; | 200 | StkId o; |
| 201 | int i; | 201 | int i; |
| 202 | LUA_LOCK(L); | 202 | lua_lock(L); |
| 203 | o = luaA_indexAcceptable(L, index); | 203 | o = luaA_indexAcceptable(L, index); |
| 204 | i = (o == NULL) ? LUA_NOTAG : luaT_tag(o); | 204 | i = (o == NULL) ? LUA_NOTAG : luaT_tag(o); |
| 205 | LUA_UNLOCK(L); | 205 | lua_unlock(L); |
| 206 | return i; | 206 | return i; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { | 209 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { |
| 210 | StkId o1, o2; | 210 | StkId o1, o2; |
| 211 | int i; | 211 | int i; |
| 212 | LUA_LOCK(L); | 212 | lua_lock(L); |
| 213 | o1 = luaA_indexAcceptable(L, index1); | 213 | o1 = luaA_indexAcceptable(L, index1); |
| 214 | o2 = luaA_indexAcceptable(L, index2); | 214 | o2 = luaA_indexAcceptable(L, index2); |
| 215 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ | 215 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ |
| 216 | : luaO_equalObj(o1, o2); | 216 | : luaO_equalObj(o1, o2); |
| 217 | LUA_UNLOCK(L); | 217 | lua_unlock(L); |
| 218 | return i; | 218 | return i; |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | 221 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { |
| 222 | StkId o1, o2; | 222 | StkId o1, o2; |
| 223 | int i; | 223 | int i; |
| 224 | LUA_LOCK(L); | 224 | lua_lock(L); |
| 225 | o1 = luaA_indexAcceptable(L, index1); | 225 | o1 = luaA_indexAcceptable(L, index1); |
| 226 | o2 = luaA_indexAcceptable(L, index2); | 226 | o2 = luaA_indexAcceptable(L, index2); |
| 227 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ | 227 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ |
| 228 | : luaV_lessthan(L, o1, o2); | 228 | : luaV_lessthan(L, o1, o2); |
| 229 | LUA_UNLOCK(L); | 229 | lua_unlock(L); |
| 230 | return i; | 230 | return i; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| @@ -235,58 +235,58 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | |||
| 235 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | 235 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { |
| 236 | StkId o; | 236 | StkId o; |
| 237 | lua_Number n; | 237 | lua_Number n; |
| 238 | LUA_LOCK(L); | 238 | lua_lock(L); |
| 239 | o = luaA_indexAcceptable(L, index); | 239 | o = luaA_indexAcceptable(L, index); |
| 240 | n = (o == NULL || tonumber(o)) ? 0 : nvalue(o); | 240 | n = (o == NULL || tonumber(o)) ? 0 : nvalue(o); |
| 241 | LUA_UNLOCK(L); | 241 | lua_unlock(L); |
| 242 | return n; | 242 | return n; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | LUA_API const l_char *lua_tostring (lua_State *L, int index) { | 245 | LUA_API const l_char *lua_tostring (lua_State *L, int index) { |
| 246 | StkId o; | 246 | StkId o; |
| 247 | const l_char *s; | 247 | const l_char *s; |
| 248 | LUA_LOCK(L); | 248 | lua_lock(L); |
| 249 | o = luaA_indexAcceptable(L, index); | 249 | o = luaA_indexAcceptable(L, index); |
| 250 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); | 250 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); |
| 251 | LUA_UNLOCK(L); | 251 | lua_unlock(L); |
| 252 | return s; | 252 | return s; |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | LUA_API size_t lua_strlen (lua_State *L, int index) { | 255 | LUA_API size_t lua_strlen (lua_State *L, int index) { |
| 256 | StkId o; | 256 | StkId o; |
| 257 | size_t l; | 257 | size_t l; |
| 258 | LUA_LOCK(L); | 258 | lua_lock(L); |
| 259 | o = luaA_indexAcceptable(L, index); | 259 | o = luaA_indexAcceptable(L, index); |
| 260 | l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; | 260 | l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; |
| 261 | LUA_UNLOCK(L); | 261 | lua_unlock(L); |
| 262 | return l; | 262 | return l; |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { | 265 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { |
| 266 | StkId o; | 266 | StkId o; |
| 267 | lua_CFunction f; | 267 | lua_CFunction f; |
| 268 | LUA_LOCK(L); | 268 | lua_lock(L); |
| 269 | o = luaA_indexAcceptable(L, index); | 269 | o = luaA_indexAcceptable(L, index); |
| 270 | f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; | 270 | f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; |
| 271 | LUA_UNLOCK(L); | 271 | lua_unlock(L); |
| 272 | return f; | 272 | return f; |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | LUA_API void *lua_touserdata (lua_State *L, int index) { | 275 | LUA_API void *lua_touserdata (lua_State *L, int index) { |
| 276 | StkId o; | 276 | StkId o; |
| 277 | void *p; | 277 | void *p; |
| 278 | LUA_LOCK(L); | 278 | lua_lock(L); |
| 279 | o = luaA_indexAcceptable(L, index); | 279 | o = luaA_indexAcceptable(L, index); |
| 280 | p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : | 280 | p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : |
| 281 | tsvalue(o)->u.d.value; | 281 | tsvalue(o)->u.d.value; |
| 282 | LUA_UNLOCK(L); | 282 | lua_unlock(L); |
| 283 | return p; | 283 | return p; |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | LUA_API const void *lua_topointer (lua_State *L, int index) { | 286 | LUA_API const void *lua_topointer (lua_State *L, int index) { |
| 287 | StkId o; | 287 | StkId o; |
| 288 | const void *p; | 288 | const void *p; |
| 289 | LUA_LOCK(L); | 289 | lua_lock(L); |
| 290 | o = luaA_indexAcceptable(L, index); | 290 | o = luaA_indexAcceptable(L, index); |
| 291 | if (o == NULL) p = NULL; | 291 | if (o == NULL) p = NULL; |
| 292 | else { | 292 | else { |
| @@ -302,7 +302,7 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
| 302 | break; | 302 | break; |
| 303 | } | 303 | } |
| 304 | } | 304 | } |
| 305 | LUA_UNLOCK(L); | 305 | lua_unlock(L); |
| 306 | return p; | 306 | return p; |
| 307 | } | 307 | } |
| 308 | 308 | ||
| @@ -314,26 +314,26 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
| 314 | 314 | ||
| 315 | 315 | ||
| 316 | LUA_API void lua_pushnil (lua_State *L) { | 316 | LUA_API void lua_pushnil (lua_State *L) { |
| 317 | LUA_LOCK(L); | 317 | lua_lock(L); |
| 318 | setnilvalue(L->top); | 318 | setnilvalue(L->top); |
| 319 | api_incr_top(L); | 319 | api_incr_top(L); |
| 320 | LUA_UNLOCK(L); | 320 | lua_unlock(L); |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | 323 | ||
| 324 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 324 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
| 325 | LUA_LOCK(L); | 325 | lua_lock(L); |
| 326 | setnvalue(L->top, n); | 326 | setnvalue(L->top, n); |
| 327 | api_incr_top(L); | 327 | api_incr_top(L); |
| 328 | LUA_UNLOCK(L); | 328 | lua_unlock(L); |
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | 331 | ||
| 332 | LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { | 332 | LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { |
| 333 | LUA_LOCK(L); | 333 | lua_lock(L); |
| 334 | setsvalue(L->top, luaS_newlstr(L, s, len)); | 334 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
| 335 | api_incr_top(L); | 335 | api_incr_top(L); |
| 336 | LUA_UNLOCK(L); | 336 | lua_unlock(L); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | 339 | ||
| @@ -346,19 +346,19 @@ LUA_API void lua_pushstring (lua_State *L, const l_char *s) { | |||
| 346 | 346 | ||
| 347 | 347 | ||
| 348 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | 348 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { |
| 349 | LUA_LOCK(L); | 349 | lua_lock(L); |
| 350 | api_checknelems(L, n); | 350 | api_checknelems(L, n); |
| 351 | luaV_Cclosure(L, fn, n); | 351 | luaV_Cclosure(L, fn, n); |
| 352 | LUA_UNLOCK(L); | 352 | lua_unlock(L); |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | 355 | ||
| 356 | LUA_API int lua_pushuserdata (lua_State *L, void *u) { | 356 | LUA_API int lua_pushuserdata (lua_State *L, void *u) { |
| 357 | int isnew; | 357 | int isnew; |
| 358 | LUA_LOCK(L); | 358 | lua_lock(L); |
| 359 | isnew = luaS_createudata(L, u, L->top); | 359 | isnew = luaS_createudata(L, u, L->top); |
| 360 | api_incr_top(L); | 360 | api_incr_top(L); |
| 361 | LUA_UNLOCK(L); | 361 | lua_unlock(L); |
| 362 | return isnew; | 362 | return isnew; |
| 363 | } | 363 | } |
| 364 | 364 | ||
| @@ -370,54 +370,54 @@ LUA_API int lua_pushuserdata (lua_State *L, void *u) { | |||
| 370 | 370 | ||
| 371 | 371 | ||
| 372 | LUA_API void lua_getglobal (lua_State *L, const l_char *name) { | 372 | LUA_API void lua_getglobal (lua_State *L, const l_char *name) { |
| 373 | LUA_LOCK(L); | 373 | lua_lock(L); |
| 374 | luaV_getglobal(L, luaS_new(L, name), L->top); | 374 | luaV_getglobal(L, luaS_new(L, name), L->top); |
| 375 | api_incr_top(L); | 375 | api_incr_top(L); |
| 376 | LUA_UNLOCK(L); | 376 | lua_unlock(L); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | 379 | ||
| 380 | LUA_API void lua_gettable (lua_State *L, int index) { | 380 | LUA_API void lua_gettable (lua_State *L, int index) { |
| 381 | StkId t; | 381 | StkId t; |
| 382 | LUA_LOCK(L); | 382 | lua_lock(L); |
| 383 | t = luaA_index(L, index); | 383 | t = luaA_index(L, index); |
| 384 | luaV_gettable(L, t, L->top-1, L->top-1); | 384 | luaV_gettable(L, t, L->top-1, L->top-1); |
| 385 | LUA_UNLOCK(L); | 385 | lua_unlock(L); |
| 386 | } | 386 | } |
| 387 | 387 | ||
| 388 | 388 | ||
| 389 | LUA_API void lua_rawget (lua_State *L, int index) { | 389 | LUA_API void lua_rawget (lua_State *L, int index) { |
| 390 | StkId t; | 390 | StkId t; |
| 391 | LUA_LOCK(L); | 391 | lua_lock(L); |
| 392 | t = luaA_index(L, index); | 392 | t = luaA_index(L, index); |
| 393 | api_check(L, ttype(t) == LUA_TTABLE); | 393 | api_check(L, ttype(t) == LUA_TTABLE); |
| 394 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 394 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
| 395 | LUA_UNLOCK(L); | 395 | lua_unlock(L); |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | 398 | ||
| 399 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 399 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
| 400 | StkId o; | 400 | StkId o; |
| 401 | LUA_LOCK(L); | 401 | lua_lock(L); |
| 402 | o = luaA_index(L, index); | 402 | o = luaA_index(L, index); |
| 403 | api_check(L, ttype(o) == LUA_TTABLE); | 403 | api_check(L, ttype(o) == LUA_TTABLE); |
| 404 | setobj(L->top, luaH_getnum(hvalue(o), n)); | 404 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
| 405 | api_incr_top(L); | 405 | api_incr_top(L); |
| 406 | LUA_UNLOCK(L); | 406 | lua_unlock(L); |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | 409 | ||
| 410 | LUA_API void lua_getglobals (lua_State *L) { | 410 | LUA_API void lua_getglobals (lua_State *L) { |
| 411 | LUA_LOCK(L); | 411 | lua_lock(L); |
| 412 | sethvalue(L->top, L->gt); | 412 | sethvalue(L->top, L->gt); |
| 413 | api_incr_top(L); | 413 | api_incr_top(L); |
| 414 | LUA_UNLOCK(L); | 414 | lua_unlock(L); |
| 415 | } | 415 | } |
| 416 | 416 | ||
| 417 | 417 | ||
| 418 | LUA_API int lua_getref (lua_State *L, int ref) { | 418 | LUA_API int lua_getref (lua_State *L, int ref) { |
| 419 | int status = 1; | 419 | int status = 1; |
| 420 | LUA_LOCK(L); | 420 | lua_lock(L); |
| 421 | if (ref == LUA_REFNIL) { | 421 | if (ref == LUA_REFNIL) { |
| 422 | setnilvalue(L->top); | 422 | setnilvalue(L->top); |
| 423 | api_incr_top(L); | 423 | api_incr_top(L); |
| @@ -431,16 +431,16 @@ LUA_API int lua_getref (lua_State *L, int ref) { | |||
| 431 | api_incr_top(L); | 431 | api_incr_top(L); |
| 432 | } | 432 | } |
| 433 | } | 433 | } |
| 434 | LUA_UNLOCK(L); | 434 | lua_unlock(L); |
| 435 | return status; | 435 | return status; |
| 436 | } | 436 | } |
| 437 | 437 | ||
| 438 | 438 | ||
| 439 | LUA_API void lua_newtable (lua_State *L) { | 439 | LUA_API void lua_newtable (lua_State *L) { |
| 440 | LUA_LOCK(L); | 440 | lua_lock(L); |
| 441 | sethvalue(L->top, luaH_new(L, 0)); | 441 | sethvalue(L->top, luaH_new(L, 0)); |
| 442 | api_incr_top(L); | 442 | api_incr_top(L); |
| 443 | LUA_UNLOCK(L); | 443 | lua_unlock(L); |
| 444 | } | 444 | } |
| 445 | 445 | ||
| 446 | 446 | ||
| @@ -451,63 +451,63 @@ LUA_API void lua_newtable (lua_State *L) { | |||
| 451 | 451 | ||
| 452 | 452 | ||
| 453 | LUA_API void lua_setglobal (lua_State *L, const l_char *name) { | 453 | LUA_API void lua_setglobal (lua_State *L, const l_char *name) { |
| 454 | LUA_LOCK(L); | 454 | lua_lock(L); |
| 455 | api_checknelems(L, 1); | 455 | api_checknelems(L, 1); |
| 456 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); | 456 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); |
| 457 | L->top--; /* remove element from the top */ | 457 | L->top--; /* remove element from the top */ |
| 458 | LUA_UNLOCK(L); | 458 | lua_unlock(L); |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | 461 | ||
| 462 | LUA_API void lua_settable (lua_State *L, int index) { | 462 | LUA_API void lua_settable (lua_State *L, int index) { |
| 463 | StkId t; | 463 | StkId t; |
| 464 | LUA_LOCK(L); | 464 | lua_lock(L); |
| 465 | api_checknelems(L, 2); | 465 | api_checknelems(L, 2); |
| 466 | t = luaA_index(L, index); | 466 | t = luaA_index(L, index); |
| 467 | luaV_settable(L, t, L->top - 2, L->top - 1); | 467 | luaV_settable(L, t, L->top - 2, L->top - 1); |
| 468 | L->top -= 2; /* pop index and value */ | 468 | L->top -= 2; /* pop index and value */ |
| 469 | LUA_UNLOCK(L); | 469 | lua_unlock(L); |
| 470 | } | 470 | } |
| 471 | 471 | ||
| 472 | 472 | ||
| 473 | LUA_API void lua_rawset (lua_State *L, int index) { | 473 | LUA_API void lua_rawset (lua_State *L, int index) { |
| 474 | StkId t; | 474 | StkId t; |
| 475 | LUA_LOCK(L); | 475 | lua_lock(L); |
| 476 | api_checknelems(L, 2); | 476 | api_checknelems(L, 2); |
| 477 | t = luaA_index(L, index); | 477 | t = luaA_index(L, index); |
| 478 | api_check(L, ttype(t) == LUA_TTABLE); | 478 | api_check(L, ttype(t) == LUA_TTABLE); |
| 479 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); | 479 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
| 480 | L->top -= 2; | 480 | L->top -= 2; |
| 481 | LUA_UNLOCK(L); | 481 | lua_unlock(L); |
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | 484 | ||
| 485 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 485 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
| 486 | StkId o; | 486 | StkId o; |
| 487 | LUA_LOCK(L); | 487 | lua_lock(L); |
| 488 | api_checknelems(L, 1); | 488 | api_checknelems(L, 1); |
| 489 | o = luaA_index(L, index); | 489 | o = luaA_index(L, index); |
| 490 | api_check(L, ttype(o) == LUA_TTABLE); | 490 | api_check(L, ttype(o) == LUA_TTABLE); |
| 491 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); | 491 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
| 492 | L->top--; | 492 | L->top--; |
| 493 | LUA_UNLOCK(L); | 493 | lua_unlock(L); |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | 496 | ||
| 497 | LUA_API void lua_setglobals (lua_State *L) { | 497 | LUA_API void lua_setglobals (lua_State *L) { |
| 498 | StkId newtable; | 498 | StkId newtable; |
| 499 | LUA_LOCK(L); | 499 | lua_lock(L); |
| 500 | api_checknelems(L, 1); | 500 | api_checknelems(L, 1); |
| 501 | newtable = --L->top; | 501 | newtable = --L->top; |
| 502 | api_check(L, ttype(newtable) == LUA_TTABLE); | 502 | api_check(L, ttype(newtable) == LUA_TTABLE); |
| 503 | L->gt = hvalue(newtable); | 503 | L->gt = hvalue(newtable); |
| 504 | LUA_UNLOCK(L); | 504 | lua_unlock(L); |
| 505 | } | 505 | } |
| 506 | 506 | ||
| 507 | 507 | ||
| 508 | LUA_API int lua_ref (lua_State *L, int lock) { | 508 | LUA_API int lua_ref (lua_State *L, int lock) { |
| 509 | int ref; | 509 | int ref; |
| 510 | LUA_LOCK(L); | 510 | lua_lock(L); |
| 511 | api_checknelems(L, 1); | 511 | api_checknelems(L, 1); |
| 512 | if (ttype(L->top-1) == LUA_TNIL) | 512 | if (ttype(L->top-1) == LUA_TNIL) |
| 513 | ref = LUA_REFNIL; | 513 | ref = LUA_REFNIL; |
| @@ -525,7 +525,7 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
| 525 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; | 525 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; |
| 526 | } | 526 | } |
| 527 | L->top--; | 527 | L->top--; |
| 528 | LUA_UNLOCK(L); | 528 | lua_unlock(L); |
| 529 | return ref; | 529 | return ref; |
| 530 | } | 530 | } |
| 531 | 531 | ||
| @@ -536,10 +536,10 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
| 536 | */ | 536 | */ |
| 537 | 537 | ||
| 538 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | 538 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { |
| 539 | LUA_LOCK(L); | 539 | lua_lock(L); |
| 540 | api_checknelems(L, nargs+1); | 540 | api_checknelems(L, nargs+1); |
| 541 | luaD_call(L, L->top-(nargs+1), nresults); | 541 | luaD_call(L, L->top-(nargs+1), nresults); |
| 542 | LUA_UNLOCK(L); | 542 | lua_unlock(L); |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | 545 | ||
| @@ -553,28 +553,28 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
| 553 | 553 | ||
| 554 | LUA_API int lua_getgcthreshold (lua_State *L) { | 554 | LUA_API int lua_getgcthreshold (lua_State *L) { |
| 555 | int threshold; | 555 | int threshold; |
| 556 | LUA_LOCK(L); | 556 | lua_lock(L); |
| 557 | threshold = GCscale(G(L)->GCthreshold); | 557 | threshold = GCscale(G(L)->GCthreshold); |
| 558 | LUA_UNLOCK(L); | 558 | lua_unlock(L); |
| 559 | return threshold; | 559 | return threshold; |
| 560 | } | 560 | } |
| 561 | 561 | ||
| 562 | LUA_API int lua_getgccount (lua_State *L) { | 562 | LUA_API int lua_getgccount (lua_State *L) { |
| 563 | int count; | 563 | int count; |
| 564 | LUA_LOCK(L); | 564 | lua_lock(L); |
| 565 | count = GCscale(G(L)->nblocks); | 565 | count = GCscale(G(L)->nblocks); |
| 566 | LUA_UNLOCK(L); | 566 | lua_unlock(L); |
| 567 | return count; | 567 | return count; |
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | 570 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { |
| 571 | LUA_LOCK(L); | 571 | lua_lock(L); |
| 572 | if (newthreshold > GCscale(ULONG_MAX)) | 572 | if (newthreshold > GCscale(ULONG_MAX)) |
| 573 | G(L)->GCthreshold = ULONG_MAX; | 573 | G(L)->GCthreshold = ULONG_MAX; |
| 574 | else | 574 | else |
| 575 | G(L)->GCthreshold = GCunscale(newthreshold); | 575 | G(L)->GCthreshold = GCunscale(newthreshold); |
| 576 | luaC_checkGC(L); | 576 | luaC_checkGC(L); |
| 577 | LUA_UNLOCK(L); | 577 | lua_unlock(L); |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | 580 | ||
| @@ -584,7 +584,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
| 584 | 584 | ||
| 585 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { | 585 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { |
| 586 | int tag; | 586 | int tag; |
| 587 | LUA_LOCK(L); | 587 | lua_lock(L); |
| 588 | if (basictype != LUA_TNONE && | 588 | if (basictype != LUA_TNONE && |
| 589 | basictype != LUA_TTABLE && | 589 | basictype != LUA_TTABLE && |
| 590 | basictype != LUA_TUSERDATA) | 590 | basictype != LUA_TUSERDATA) |
| @@ -592,7 +592,7 @@ LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { | |||
| 592 | tag = luaT_newtag(L, name, basictype); | 592 | tag = luaT_newtag(L, name, basictype); |
| 593 | if (tag == LUA_TNONE) | 593 | if (tag == LUA_TNONE) |
| 594 | luaO_verror(L, l_s("type name '%.30s' already exists"), name); | 594 | luaO_verror(L, l_s("type name '%.30s' already exists"), name); |
| 595 | LUA_UNLOCK(L); | 595 | lua_unlock(L); |
| 596 | return tag; | 596 | return tag; |
| 597 | } | 597 | } |
| 598 | 598 | ||
| @@ -600,7 +600,7 @@ LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { | |||
| 600 | LUA_API int lua_type2tag (lua_State *L, const l_char *name) { | 600 | LUA_API int lua_type2tag (lua_State *L, const l_char *name) { |
| 601 | int tag; | 601 | int tag; |
| 602 | const TObject *v; | 602 | const TObject *v; |
| 603 | LUA_LOCK(L); | 603 | lua_lock(L); |
| 604 | v = luaH_getstr(G(L)->type2tag, luaS_new(L, name)); | 604 | v = luaH_getstr(G(L)->type2tag, luaS_new(L, name)); |
| 605 | if (ttype(v) == LUA_TNIL) | 605 | if (ttype(v) == LUA_TNIL) |
| 606 | tag = LUA_TNONE; | 606 | tag = LUA_TNONE; |
| @@ -608,14 +608,14 @@ LUA_API int lua_type2tag (lua_State *L, const l_char *name) { | |||
| 608 | lua_assert(ttype(v) == LUA_TNUMBER); | 608 | lua_assert(ttype(v) == LUA_TNUMBER); |
| 609 | tag = (int)nvalue(v); | 609 | tag = (int)nvalue(v); |
| 610 | } | 610 | } |
| 611 | LUA_UNLOCK(L); | 611 | lua_unlock(L); |
| 612 | return tag; | 612 | return tag; |
| 613 | } | 613 | } |
| 614 | 614 | ||
| 615 | 615 | ||
| 616 | LUA_API void lua_settag (lua_State *L, int tag) { | 616 | LUA_API void lua_settag (lua_State *L, int tag) { |
| 617 | int basictype; | 617 | int basictype; |
| 618 | LUA_LOCK(L); | 618 | lua_lock(L); |
| 619 | api_checknelems(L, 1); | 619 | api_checknelems(L, 1); |
| 620 | if (tag < 0 || tag >= G(L)->ntag) | 620 | if (tag < 0 || tag >= G(L)->ntag) |
| 621 | luaO_verror(L, l_s("%d is not a valid tag"), tag); | 621 | luaO_verror(L, l_s("%d is not a valid tag"), tag); |
| @@ -634,25 +634,25 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
| 634 | luaO_verror(L, l_s("cannot change the tag of a %.20s"), | 634 | luaO_verror(L, l_s("cannot change the tag of a %.20s"), |
| 635 | luaT_typename(G(L), L->top-1)); | 635 | luaT_typename(G(L), L->top-1)); |
| 636 | } | 636 | } |
| 637 | LUA_UNLOCK(L); | 637 | lua_unlock(L); |
| 638 | } | 638 | } |
| 639 | 639 | ||
| 640 | 640 | ||
| 641 | LUA_API void lua_error (lua_State *L, const l_char *s) { | 641 | LUA_API void lua_error (lua_State *L, const l_char *s) { |
| 642 | LUA_LOCK(L); | 642 | lua_lock(L); |
| 643 | luaD_error(L, s); | 643 | luaD_error(L, s); |
| 644 | LUA_UNLOCK(L); | 644 | lua_unlock(L); |
| 645 | } | 645 | } |
| 646 | 646 | ||
| 647 | 647 | ||
| 648 | LUA_API void lua_unref (lua_State *L, int ref) { | 648 | LUA_API void lua_unref (lua_State *L, int ref) { |
| 649 | LUA_LOCK(L); | 649 | lua_lock(L); |
| 650 | if (ref >= 0) { | 650 | if (ref >= 0) { |
| 651 | api_check(L, ref < G(L)->nref && G(L)->refArray[ref].st < 0); | 651 | api_check(L, ref < G(L)->nref && G(L)->refArray[ref].st < 0); |
| 652 | G(L)->refArray[ref].st = G(L)->refFree; | 652 | G(L)->refArray[ref].st = G(L)->refFree; |
| 653 | G(L)->refFree = ref; | 653 | G(L)->refFree = ref; |
| 654 | } | 654 | } |
| 655 | LUA_UNLOCK(L); | 655 | lua_unlock(L); |
| 656 | } | 656 | } |
| 657 | 657 | ||
| 658 | 658 | ||
| @@ -660,7 +660,7 @@ LUA_API int lua_next (lua_State *L, int index) { | |||
| 660 | StkId t; | 660 | StkId t; |
| 661 | Node *n; | 661 | Node *n; |
| 662 | int more; | 662 | int more; |
| 663 | LUA_LOCK(L); | 663 | lua_lock(L); |
| 664 | t = luaA_index(L, index); | 664 | t = luaA_index(L, index); |
| 665 | api_check(L, ttype(t) == LUA_TTABLE); | 665 | api_check(L, ttype(t) == LUA_TTABLE); |
| 666 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 666 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
| @@ -674,7 +674,7 @@ LUA_API int lua_next (lua_State *L, int index) { | |||
| 674 | L->top -= 1; /* remove key */ | 674 | L->top -= 1; /* remove key */ |
| 675 | more = 0; | 675 | more = 0; |
| 676 | } | 676 | } |
| 677 | LUA_UNLOCK(L); | 677 | lua_unlock(L); |
| 678 | return more; | 678 | return more; |
| 679 | } | 679 | } |
| 680 | 680 | ||
| @@ -683,7 +683,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
| 683 | Hash *h; | 683 | Hash *h; |
| 684 | const TObject *value; | 684 | const TObject *value; |
| 685 | int n; | 685 | int n; |
| 686 | LUA_LOCK(L); | 686 | lua_lock(L); |
| 687 | h = hvalue(luaA_index(L, index)); | 687 | h = hvalue(luaA_index(L, index)); |
| 688 | value = luaH_getstr(h, luaS_newliteral(L, l_s("n"))); /* = h.n */ | 688 | value = luaH_getstr(h, luaS_newliteral(L, l_s("n"))); /* = h.n */ |
| 689 | if (ttype(value) == LUA_TNUMBER) | 689 | if (ttype(value) == LUA_TNUMBER) |
| @@ -701,13 +701,13 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
| 701 | } | 701 | } |
| 702 | n = (int)max; | 702 | n = (int)max; |
| 703 | } | 703 | } |
| 704 | LUA_UNLOCK(L); | 704 | lua_unlock(L); |
| 705 | return n; | 705 | return n; |
| 706 | } | 706 | } |
| 707 | 707 | ||
| 708 | 708 | ||
| 709 | LUA_API void lua_concat (lua_State *L, int n) { | 709 | LUA_API void lua_concat (lua_State *L, int n) { |
| 710 | LUA_LOCK(L); | 710 | lua_lock(L); |
| 711 | api_checknelems(L, n); | 711 | api_checknelems(L, n); |
| 712 | if (n >= 2) { | 712 | if (n >= 2) { |
| 713 | luaV_strconc(L, n, L->top); | 713 | luaV_strconc(L, n, L->top); |
| @@ -719,20 +719,20 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
| 719 | api_incr_top(L); | 719 | api_incr_top(L); |
| 720 | } | 720 | } |
| 721 | /* else n == 1; nothing to do */ | 721 | /* else n == 1; nothing to do */ |
| 722 | LUA_UNLOCK(L); | 722 | lua_unlock(L); |
| 723 | } | 723 | } |
| 724 | 724 | ||
| 725 | 725 | ||
| 726 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | 726 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { |
| 727 | TString *ts; | 727 | TString *ts; |
| 728 | void *p; | 728 | void *p; |
| 729 | LUA_LOCK(L); | 729 | lua_lock(L); |
| 730 | if (size == 0) size = 1; | 730 | if (size == 0) size = 1; |
| 731 | ts = luaS_newudata(L, size, NULL); | 731 | ts = luaS_newudata(L, size, NULL); |
| 732 | setuvalue(L->top, ts); | 732 | setuvalue(L->top, ts); |
| 733 | api_incr_top(L); | 733 | api_incr_top(L); |
| 734 | p = ts->u.d.value; | 734 | p = ts->u.d.value; |
| 735 | LUA_UNLOCK(L); | 735 | lua_unlock(L); |
| 736 | return p; | 736 | return p; |
| 737 | } | 737 | } |
| 738 | 738 | ||
