aboutsummaryrefslogtreecommitdiff
path: root/lref.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-14 16:33:29 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-14 16:33:29 -0200
commit1b15206cf9aa7005fc3d48f78f60f66838f10eb5 (patch)
tree00a96c96d331417ba781b605c6c10d8daae01938 /lref.c
parente6d56cd2d844174bd40af4c44c0f68e2115e5876 (diff)
downloadlua-1b15206cf9aa7005fc3d48f78f60f66838f10eb5.tar.gz
lua-1b15206cf9aa7005fc3d48f78f60f66838f10eb5.tar.bz2
lua-1b15206cf9aa7005fc3d48f78f60f66838f10eb5.zip
many details + code redistribution
Diffstat (limited to 'lref.c')
-rw-r--r--lref.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/lref.c b/lref.c
index caaae400..c2e90d38 100644
--- a/lref.c
+++ b/lref.c
@@ -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
16int luaR_ref (lua_State *L, const TObject *o, int lock) { 17int 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
46const TObject *luaR_getref (lua_State *L, int ref) { 49lua_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
60void 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
68void 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
57static int ismarked (const TObject *o) { 81static 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) {