lua-users home
lua-l archive

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


It was thus said that the Great Soni L. once stated:
> 
> On 14/07/16 02:09 PM, Dirk Laurie wrote:
> >2016-07-14 17:27 GMT+02:00 Soni L. <fakedme@gmail.com>:
> >
> >>(Empty reply so someone sees this. The table vs array threads kill all 
> >>other
> >>threads :/)
> >I'm not usually shy to participate but I have not been able to understand
> >what __key is supposed to do that lua_setuservalue and its exposure
> >in the  debug library can't. Could you explain that from scratch?
> >
> To put it simply, it lets you use bigints as table keys as if they were 
> plain lua ints or floats. E.g.
> 
> local b1 = require("bigint").one
> local i = 1
> local f = 1.0
> local t = {"one"}
> 
> print(t[b1], t[i], t[f]) --> one one one
> print(type(b1), math.type(i), math.type(f)) --> userdata integer float

  Oh, so to clarify (kind of making the bigint library up):

	bi = require "bigint"

	x = bi.make(2^128) -- syntax issues but I want something
	y = bi.make(2^128) -- really really large

	t = {}
	t[x] = "booya!"
	print(t[y])
	booya!

  As it stands now, Lua will treat x and y as distinct values whereas Soni
doesn't consider them distinct values (because they're distinct uservalues).

  Oddly enough, Common Lisp *may* treat to values as distinct, i.e. 2 does
not necessarily eq 2 in CL (they may eql and equal, but not eq).  Common
Lisp gets around this by using different forms of equality testing.

  -spc (Not saying we should have an __eql or __equal method though)