lua-users home
lua-l archive

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


I am currently using the framework Glua-X to bind my C function to the Lua interpreter.  I apologize if you can't answer questions regarding someone else's library, but I can't seem to find a contact address for the author.
 
I am utilizing Lua 4.0.
 
Here is the issue.  Say I have the following function :
  int foo (int x,int *y);
 
'y' will always return a pointer to a newly allocated value.  Say I have that function binded as such :
 
/////////////////////////////////////////////////////////////
GLUA_FUNC(FOO)
{
  int x  = glua_getInteger(1);
  glua_getDone();
 
  int *y;
  int r = foo(x,y);
 
  glua_pushUserdata( y );  // Here is how I want to pass it back
  // glua_pushUserdata( y, glua_newtag("y")); // This is the syntax Glua-X wants
}
GLUA_END
 
GLUA_FUNC(PRINTFOO)
{
  int *x  = glua_getUserdata(1);  // Here is the syntax I expected
  // int *x  = glua_getUserdata(1,tag);  // Here is how Glua-X wants the syntax
 
  glua_getDone();
  printf(*x);
}
GLUA_END
/////////////////////////////////////////////////////////////
 
I don't understand why I have to associate the pointer with a tag.  If I call the FOO function from Lua like this
 
  zzz = FOO(1)  
  PRINTFOO(zzz)
 
isn't zzz my tag? I want the return value to be assigned receiving userdata object.  I am confused.
 
Any help is GREATLY appreciated.
 
Jim