lua-users home
lua-l archive

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


On Tue, Jul 13, 2004 at 01:49:39AM -0500, Jim Jones wrote:
> 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.

That would be Asko Kauppi, who I'm sure will speak up if there's
anything to add.

> 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.

No. zzz is the name of the variable you are assigning the value to. A
tag is more like the type of the value. IIRC, tags are actually
numbers, but Glua-X gives them string names for convenience. You
should not be creating a new tag each time you pass a value back, but
instead creating a tag at the start of your program for each sort of
value you will use, e.g. for each different type of C struct. You then
specify that tag name when you create a userdata of that type. Doing
this will allow you to do two things:

- Allow you to specify the type of userdata a function is expecting to
  receive. GluaX will then flag an error if a script tries to call
  your functions with the wrong type of userdata, e.g. one created by
  a different library.

- Allow you to associate tag methods with your userdata. If you've
  used C++, this is the Lua equivalent of operator overloading.

-- Jamie Webb