[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: the purpose of lightuserdata
- From: David Manura <dm.lua@...>
- Date: Fri, 14 Jan 2011 00:58:44 -0500
On Mon, Jan 10, 2011 at 11:46 PM, David Manura <dm.lua@math2.org> wrote:
> Traditionally, lightuserdata has been intended as a way to represent C
> pointers (or even handles [2]) in Lua, often as keys in a Lua table [1]
FWIW, one inconsistency between the manual [1] and implementation is
that the __eq metamethod is ignored on lightuserdata:
> mt = {__eq = function() print 'eq' end, __lt = function() print 'lt' end}
> debug.setmetatable(123u, mt)
> =123u == 124u, 123u < 124u
lt
false, true
See luaV_equalval: case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); .
The same can also be said concerning boolean:
> debug.setmetatable(true, mt)
> =false == true
false
Also, the "type" function referred to in the manual's pseudocode is a
form of type() that differentiates between LUA_TUSERDATA and
LUA_TLIGHTUSERDATA.
[1] http://www.lua.org/manual/5.1/manual.html#2.2