lua-users home
lua-l archive

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


Hi, men (and women) in the moon!

Finally, I find the time  to integrate lua  into  our projects.  I  am
trying to   implement an object-oriented  interface called  olua which
(olua  means "O  lua!"  or "Objective   lua") which somehow uses ideas
from CORBA  etc.    When things  work  well  I  will post   some  more
information about this interface. 

The basic idea  is  to use  the lua  table  mechanism to create  proxy
objects  to  C objects within lua.   Addresses  of C variables  can be
registered as lua table entries, and tag  methods ensure that lua code
like "x.a=3" ends up with writing 3 to  the location of the registered
C variable.  Objects can have an entry named "invoke", which should be
a cfunction.    I this  case  they are  treated  as methods   (using a
"function" tag method), the parameter passing mechanism is the same as
for table entries.

The problem is now when  I want to use  lua objects in the same manner
as numbers and strings as parameters in methods. 

To register an object with lua I am doing essentially the following: 

typedef lua_object oluaObject; 


void oluaRegisterObject(oluaObject obj,
			char *name,
			oluaObject *val, 
			char *docstring)
{
  oluaInit();
  lua_pushobject(obj);
  lua_pushstring(name);
  lua_pushusertag(val,oluaPObjectTag);
  lua_settable();
...
}

in settable:
...
  else if (tag==oluaPObjectTag)
    {
      oluaObject *val=lua_getuserdata(entry);
 
      if (oluaIsObject(lua_getparam(3)))
	{
	  *val=lua_getparam(3);
	  if (oluaDebug) 
	    {
	      char *xoname;
	      lua_pushobject(*val);
	      lua_pushstring("_name");
	      xoname=lua_getstring(lua_gettable());
	      oluaDebug(" %s.%s=%s\n",oname,ind,xoname);
	    }
	}
      elseif 
...

in gettable:
  else if (tag==oluaPObjectTag)
    {
      oluaObject *val=lua_getuserdata(entry);
      lua_pushobject(*val);
    }
  else if
...

Now I have the problem that sometimes, when accessing the value stored
in  the location  of  val,  I get  another  object reference  than the
reference I wrote into the location from lua code. I  am aware that my
code snippets are quite  fragmentary.  My question: Is there something
tricky to take  into  account when  using  pointers to  lua_objects as
userdata in tables ? 

Overall I am very satisfied with  lua, it lets me do  what I want, and
this is up to now the only point where I 've got problems. 


Best regards

Juergen


Dr. Juergen Fuhrmann                   mailto:fuhrmann@wias-berlin.de
                         Numerical Mathematics & Scientific Computing
    Weierstrass Institute for Applied Analysis and Stochastics Berlin
SOMETHING IS ROTTEN IN THIS AGE OF HOPE heiner mueller hamletmaschine