lua-users home
lua-l archive

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




On Thursday, October 3, 2013, liam mail wrote:

On 4 October 2013 00:26, Sean Conner <sean@conman.org> wrote:
It was thus said that the Great liam mail once stated:
>
> I agree with Justin here for userdata types, in fact a certain library[1]
> does not even know the types of userdata[2] in C++ which is not so
> unusual[3]. If you really wanted to check the type then using the debug
> library seems very very wrong to me; just don't set a __metatable entry to
> hide it, grab the metatable and check against the type you want.

  Be careful, because that isn't always true.  I wrote code to bind Xlib to
Lua [4], and each userdata created gets its own distinct metatable. [5]  Of
course, that metatable has a _TYPE field associated with it ...

For the case I would personally set a __metatable entry to return one specific table for all instances of the same _TYPE.

--Liam

At the risk of sounding argumentative, I believe that all if you are proving my point, which is not that in service if some solution that I'm advocating.

It's that the consumer of a library that is designed to provide a special value "type" is left with some acceptable methods to deal with a common question that would otherwise be answered by calling "type", if the value type was native, AND that none of those methods will be consistent between any two libraries.

Yes, I can proffer some more examples and all of you can show me how it isn't wise to do whatever it is I'm doing. 

Following this logic, I'd propose that "type" is unnecessary in all cases and could be removed, instead replaced by pcall, whenever we would otherwise need it. 

I think that my point more or less stands: extending Lua with values that behave as functions that are imported from the host language is as good as it gets, as far as transparency and interop goes. 

Importing values that behave more like new "types" is not transperent, at least in some real-live cases that come up when non 30+ year veterans are attempting to solve the problem in front of them. 

-Andrew