aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-17 10:18:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-17 10:18:01 -0300
commit90fb2e18e84075972d1937a6c0a3c2624756a3db (patch)
tree78972c91056663b7532c2e2a1182ee95654e3d34
parent4365c31c89666bae24afd800ac3251527d9dc9c8 (diff)
downloadlua-90fb2e18e84075972d1937a6c0a3c2624756a3db.tar.gz
lua-90fb2e18e84075972d1937a6c0a3c2624756a3db.tar.bz2
lua-90fb2e18e84075972d1937a6c0a3c2624756a3db.zip
`pushref' is more efficient (and probably more useful) than `getref'.
-rw-r--r--lref.c13
-rw-r--r--lua.h10
2 files changed, 13 insertions, 10 deletions
diff --git a/lref.c b/lref.c
index 7f144ba6..c3fc57af 100644
--- a/lref.c
+++ b/lref.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lref.c,v 1.16 2000/08/07 20:21:34 roberto Exp roberto $ 2** $Id: lref.c,v 1.17 2000/08/09 19:16:57 roberto Exp roberto $
3** reference mechanism 3** reference mechanism
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include "lua.h" 8#include "lua.h"
9 9
10#include "lapi.h" 10#include "lapi.h"
11#include "ldo.h"
11#include "lmem.h" 12#include "lmem.h"
12#include "lref.h" 13#include "lref.h"
13#include "lstate.h" 14#include "lstate.h"
@@ -47,14 +48,16 @@ void lua_unref (lua_State *L, int ref) {
47} 48}
48 49
49 50
50lua_Object lua_getref (lua_State *L, int ref) { 51int lua_pushref (lua_State *L, int ref) {
51 if (ref == LUA_REFNIL) 52 if (ref == LUA_REFNIL)
52 return luaA_putluaObject(L, &luaO_nilobject); 53 ttype(L->top) = TAG_NIL;
53 else if (0 <= ref && ref < L->refSize && 54 else if (0 <= ref && ref < L->refSize &&
54 (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) 55 (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD))
55 return luaA_putluaObject(L, &L->refArray[ref].o); 56 *L->top = L->refArray[ref].o;
56 else 57 else
57 return LUA_NOOBJECT; 58 return 0;
59 incr_top;
60 return 1;
58} 61}
59 62
60 63
diff --git a/lua.h b/lua.h
index a655f29f..96f3597a 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.57 2000/08/09 19:16:57 roberto Exp roberto $ 2** $Id: lua.h,v 1.58 2000/08/14 19:10:14 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: lua@tecgraf.puc-rio.br 5** e-mail: lua@tecgraf.puc-rio.br
@@ -122,7 +122,7 @@ int lua_next (lua_State *L, lua_Object o, int i);
122 /* Out: index, value */ 122 /* Out: index, value */
123 123
124int lua_ref (lua_State *L, int lock); /* In: value */ 124int lua_ref (lua_State *L, int lock); /* In: value */
125lua_Object lua_getref (lua_State *L, int ref); 125int lua_pushref (lua_State *L, int ref); /* Out: value */
126void lua_unref (lua_State *L, int ref); 126void lua_unref (lua_State *L, int ref);
127 127
128lua_Object lua_createtable (lua_State *L); 128lua_Object lua_createtable (lua_State *L);
@@ -140,7 +140,7 @@ long lua_collectgarbage (lua_State *L, long limit);
140#ifndef LUA_SINGLESTATE 140#ifndef LUA_SINGLESTATE
141 141
142#define lua_call(L,name) lua_callfunction(L, lua_getglobal(L, name)) 142#define lua_call(L,name) lua_callfunction(L, lua_getglobal(L, name))
143#define lua_pushref(L,ref) lua_pushobject(L, lua_getref(L, ref)) 143#define lua_getref(L, ref) (lua_pushref(L, ref) ? lua_pop(L) : LUA_NOOBJECT)
144#define lua_refobject(L,o,l) (lua_pushobject(L, o), lua_ref(L, l)) 144#define lua_refobject(L,o,l) (lua_pushobject(L, o), lua_ref(L, l))
145#define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) 145#define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
146#define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0) 146#define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0)
@@ -150,7 +150,7 @@ long lua_collectgarbage (lua_State *L, long limit);
150#else 150#else
151 151
152#define lua_call(name) lua_callfunction(lua_getglobal(name)) 152#define lua_call(name) lua_callfunction(lua_getglobal(name))
153#define lua_pushref(ref) lua_pushobject(lua_getref(ref)) 153#define lua_getref(ref) (lua_pushref(ref) ? lua_pop() : LUA_NOOBJECT)
154#define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l)) 154#define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
155#define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n)) 155#define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
156#define lua_pushuserdata(u) lua_pushusertag(u, 0) 156#define lua_pushuserdata(u) lua_pushusertag(u, 0)
@@ -219,7 +219,7 @@ extern lua_State *lua_state;
219#define lua_tag(obj) (lua_tag)(lua_state, obj) 219#define lua_tag(obj) (lua_tag)(lua_state, obj)
220#define lua_next(o,i) (lua_next)(lua_state, o,i) 220#define lua_next(o,i) (lua_next)(lua_state, o,i)
221#define lua_ref(lock) (lua_ref)(lua_state, lock) 221#define lua_ref(lock) (lua_ref)(lua_state, lock)
222#define lua_getref(ref) (lua_getref)(lua_state, ref) 222#define lua_pushref(ref) (lua_pushref)(lua_state, ref)
223#define lua_unref(ref) (lua_unref)(lua_state, ref) 223#define lua_unref(ref) (lua_unref)(lua_state, ref)
224#define lua_createtable() (lua_createtable)(lua_state) 224#define lua_createtable() (lua_createtable)(lua_state)
225#define lua_collectgarbage(limit) (lua_collectgarbage)(lua_state, limit) 225#define lua_collectgarbage(limit) (lua_collectgarbage)(lua_state, limit)