[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature Request: type() consult __type for userdata
- From: David Manura <dm.lua@...>
- Date: Sat, 19 Jan 2008 05:57:21 +0000 (UTC)
Greg Fitzgerald writes:
> Would there be any downside to Lua's 'type()' returning the value of
> a '__type' metamethod if its type is 'userdata'?...I'd like to be able
> to create a C library that add new types in such a way that there would
> be no way for a Lua user to know those types were implemented with
> userdata and not by modifying the VM.
On a related note, consider how file objects are identified in Lua: rather than
type(io.stdout) == 'file', we instead have io.type(io.stdout) == 'file'. We
also have, I presume, type(F1) == 'userdata' and getmetatable(F1) ==
getmetatable(F2) for all files F1 and F2. Distinguishing types in this way has
limitations if we want to create an object the "virtualizes" (see
http://lua-users.org/wiki/LuaVirtualization ) a file, such as a string stream in
C++. It can be useful to recognize types in terms of capabilities: for example,
an output file is something that looks like a table and contains a field 'write'
that is a function.