lua-users home
lua-l archive

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


The 0x12345678 value produces by tostring is the pointer to the
object. As the table is being regenerated each time, this value will
vary:

> a = {1,2,3}
> b = {1,2,3}
> = tostring(a)
table: 003297C8
> = tostring(b)
table: 003299F0
> a = {1,2,3}
> = tostring(a)
table: 0032B138

On 14/11/2007, Patrick Donnelly <batrick.donnelly@gmail.com> wrote:
> I'm not saying this is the most efficient way, but here's something you can do:
>
> > hold = {}
> > somenewtable = {}
> > hold[somenewtable] = true
> > hold[tostring(somenewtable)] = somenewtable
> > print(tostring(somenewtable))
>
> > print(tostring(somenewtable))
> table: 0x807b6a0
>
> Notice tostring on a table produces a unique string identifier for
> that table... You can use it as your "hash".
>
> --
> -Patrick Donnelly
>
> "One of the lessons of history is that nothing is often a good thing
> to do and always a clever thing to say."
>
> -Will Durant
>