lua-users home
lua-l archive

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


Roberto,

Roberto Ierusalimschy <roberto@inf.puc-rio.br>:

> I think the main issue here is what to compare the metatable with,
> that is, how to specify which metatable we want. Your suggestion of
> comparing the metatable against a given upvalue is interesting, but
> it clashes with light C functions. (Most C functions using userdata
> would need to be heavy.)

Right; that's why I abandoned that in favor of C pointer comparisons.
Library init code could create a metatable, ref it so that it doesn't
go away, call lua_topointer on it and store the pointer in a C
variable, then use it for comparison inside the C metamethod.

> We would
> need to test first to know how much could we gain with that.

That depends on how often the metamethod is called and how much other
work it does. In case of tuples, the gain seems significant; granted,
that's not the common use case, but multiple uservalues have only been
introduced recently.

A realistic benchmark could be the file stream in liolib. For an
example of a function that essentially does nothing except for the
metatable check, see io.type().

In general, let me know what measurements exactly you'd like to see:)

Best regards,

-- 
DoubleF