lua-users home
lua-l archive

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



Just because your userdata object has the same value, doesn't mean that it
is the same object.  AFAIK the table lookup occurs by reference, not by
value.  Therefore, two different userdata objects could both be refering
to the same guid, but still be two refering to two different lua objects.  
An example from my engine...

foo = GO.create( "obj_barrel_exploding" )
print( tostring(foo) )

 --> go_ptr: obj_barrel_exploding (49.50, -8.12, 4.66)

bar = {}
bar[foo] = "yippee"
print (bar[foo])

 --> yippee

footoo = foo
print(tostring(footoo))

 --> go_ptr: obj_barrel_exploding (49.50, -8.12, 4.66)

print( bar[footoo] )

 --> yippee

objs = Scene.getObjectsInRange( Actor.getPos("player"), 10 )

 -(omitted debug dump here to find index of new barrell)-

print( objs[2] )

 --> go_ptr: obj_barrel_exploding (49.50, -8.12, 4.66)

print( tostring(bar[objs[2]]) )

 --> nil

So, the first lookup worked because foo and footoo were references to the
same userdata.  But the second lookup failed because, although objs[2] has
the same value as footoo, it isn't the same object.  Any chance you are
seeing something similar?

scott

-- 
------------------------------------------------------------------------
scott jacobs                                   scott+lua@escherichia.net
------------------------------------------------------------------------