diff options
Diffstat (limited to 'lref.c')
| -rw-r--r-- | lref.c | 40 |
1 files changed, 32 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lref.c,v 1.2 1999/11/10 15:37:50 roberto Exp roberto $ | 2 | ** $Id: lref.c,v 1.3 1999/11/22 13:12:07 roberto Exp roberto $ |
| 3 | ** REF mechanism | 3 | ** REF mechanism |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -7,15 +7,17 @@ | |||
| 7 | 7 | ||
| 8 | #define LUA_REENTRANT | 8 | #define LUA_REENTRANT |
| 9 | 9 | ||
| 10 | #include "lapi.h" | ||
| 10 | #include "lmem.h" | 11 | #include "lmem.h" |
| 11 | #include "lref.h" | 12 | #include "lref.h" |
| 12 | #include "lstate.h" | 13 | #include "lstate.h" |
| 13 | #include "lua.h" | 14 | #include "lua.h" |
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | int luaR_ref (lua_State *L, const TObject *o, int lock) { | 17 | int lua_ref (lua_State *L, int lock) { |
| 17 | int ref; | 18 | int ref; |
| 18 | if (ttype(o) == LUA_T_NIL) | 19 | luaA_checkCparams(L, 1); |
| 20 | if (ttype(L->top-1) == LUA_T_NIL) | ||
| 19 | ref = LUA_REFNIL; | 21 | ref = LUA_REFNIL; |
| 20 | else { | 22 | else { |
| 21 | if (L->refFree != NONEXT) { /* is there a free place? */ | 23 | if (L->refFree != NONEXT) { /* is there a free place? */ |
| @@ -26,9 +28,10 @@ int luaR_ref (lua_State *L, const TObject *o, int lock) { | |||
| 26 | luaM_growvector(L, L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT); | 28 | luaM_growvector(L, L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT); |
| 27 | ref = L->refSize++; | 29 | ref = L->refSize++; |
| 28 | } | 30 | } |
| 29 | L->refArray[ref].o = *o; | 31 | L->refArray[ref].o = *(L->top-1); |
| 30 | L->refArray[ref].st = lock ? LOCK : HOLD; | 32 | L->refArray[ref].st = lock ? LOCK : HOLD; |
| 31 | } | 33 | } |
| 34 | L->top--; | ||
| 32 | return ref; | 35 | return ref; |
| 33 | } | 36 | } |
| 34 | 37 | ||
| @@ -43,17 +46,38 @@ void lua_unref (lua_State *L, int ref) { | |||
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | 48 | ||
| 46 | const TObject *luaR_getref (lua_State *L, int ref) { | 49 | lua_Object lua_getref (lua_State *L, int ref) { |
| 47 | if (ref == LUA_REFNIL) | 50 | if (ref == LUA_REFNIL) |
| 48 | return &luaO_nilobject; | 51 | return luaA_putluaObject(L, &luaO_nilobject); |
| 49 | else if (0 <= ref && ref < L->refSize && | 52 | else if (0 <= ref && ref < L->refSize && |
| 50 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) | 53 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) |
| 51 | return &L->refArray[ref].o; | 54 | return luaA_putluaObject(L, &L->refArray[ref].o); |
| 52 | else | 55 | else |
| 53 | return NULL; | 56 | return LUA_NOOBJECT; |
| 54 | } | 57 | } |
| 55 | 58 | ||
| 56 | 59 | ||
| 60 | void lua_beginblock (lua_State *L) { | ||
| 61 | luaM_growvector(L, L->Cblocks, L->numCblocks, 1, struct C_Lua_Stack, | ||
| 62 | "too many nested blocks", L->stacksize); | ||
| 63 | L->Cblocks[L->numCblocks] = L->Cstack; | ||
| 64 | L->numCblocks++; | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | void lua_endblock (lua_State *L) { | ||
| 69 | if (L->numCblocks <= 0) | ||
| 70 | lua_error(L, "API error - no block to end"); | ||
| 71 | --L->numCblocks; | ||
| 72 | L->Cstack = L->Cblocks[L->numCblocks]; | ||
| 73 | L->top = L->Cstack.base; | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 57 | static int ismarked (const TObject *o) { | 81 | static int ismarked (const TObject *o) { |
| 58 | /* valid only for locked objects */ | 82 | /* valid only for locked objects */ |
| 59 | switch (o->ttype) { | 83 | switch (o->ttype) { |
