[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metatable check helper API proposal
- From: Sergey Zakharchenko <doublef.mobile@...>
- Date: Wed, 19 Aug 2020 18:19:29 +0400
Roberto Ierusalimschy <firstname.lastname@example.org>:
> 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
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:)