[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [5.3] Converting a floating point number to integer.
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 19 Nov 2014 20:13:30 +0200
2014-11-19 19:03 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:
> It seems that, so long as 'subtype' is not a formalized concept that is
> consistently applied and also available for use by the programmer, any
> solution will be an abstraction that leaks and therefore open to endless
> debate. As it is, "subtype" is a concept that you can *mostly* forget about,
> which are, in my world view, the worst kind of concepts.
'subtype' is an utterly familiar concept to anyone who has ever
used userdata. Examples from the manual:
io.type (obj)
Checks whether obj is a valid file handle. Returns the string "file" if obj is
an open file handle, "closed file" if obj is a closed file handle, or nil if obj
is not a file handle.
luaL_checkudata [-0, +0, v]
void *luaL_checkudata (lua_State *L, int arg, const char *tname);
Checks whether the function argument arg is a userdata of the type tname
(see luaL_newmetatable) and returns the userdata address
(see lua_touserdata).
Examples from a session started by "lua -l lpeg":
> =io.type(io.stdin)
file
> =lpeg.P(5):type()
pattern
Although nothing is cast in stone, people whio write code for object-oriented
tables tend to do the same sort of thing, with obj:type() returning something
understandable and unique.
So we already have it for 'table' and 'userdata'. All that is new is
also getting
it for 'number'.