lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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
  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()


This should be faster than other ways of simulating
OO, right?


Yahoo! doce lar. Faça do Yahoo! sua homepage.