[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Fast way of store and retrieve a value in a table
- From: Jose Marin <jose_marin2@...>
- Date: Fri, 16 Dec 2005 11:48:37 +0000 (GMT)
Hi!
Lua provides some way of fastly store and retrieve a
value in a table?
Based on the fact that t:func() is t.func(t), I'm
thinking on create the table in C++, create the
object, store it on the table and store the methods
callers on the table also.
It would work like this:
"retrieveObj" gets the integer (the object pointer)
stored on the table
int VectorLenght(lua_State* L){
Vector* v = (Vector*)retrieveObj(L);
lua_pushnumber(L, v->lenght());
return 1;
}
int VectorDestroy(lua_State* L){
Vector* v = (Vector*)retrieveObj(L);
delete v;
return 0;
}
int VectorCreate(lua_State* L){
create the table
store the pointer returned by new Vector in the
table, as a integer: lua_somefunction(L, (int)(new
Vector));
store VectorLenght as field "lenght" on the table
store VectorDestroy as field "destroy" on the table
return 1;
}
In Lua:
v = VectorCreate()
populate v
l = v:lenght()
v:destroy()
This should be faster than other ways of simulating
OO, right?
_______________________________________________________
Yahoo! doce lar. Faça do Yahoo! sua homepage.
http://br.yahoo.com/homepageset.html