Hi,
is there a unique "node id" which I could use for example as a key in a table? Using the node directly somehow doesn't work. I am thinking of something like
n = node.new("glyph")
n.unique_id
Something similar like this would suffice:
print( tostring({}) )
table: 0x100106da0
this id doesn't change for that table.
Is the following 172 something like I need? How would I access that (besides string.gsub())?
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
This number uniquely identifies a node for as long as it stays allocated, yes. If it is freed, a new node may have the same number. Best wishes, Taco
On 29-8-2010 9:03, Taco Hoekwater wrote:
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
This number uniquely identifies a node for as long as it stays allocated, yes. If it is freed, a new node may have the same number.
but for storing the node's id one can as well use the nodes user object itself as it's equally unique during the livespan of a node and one can compare pointers so the 'id' snippet in the string is not giving more uniqueness than the node user object itself Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 29.08.2010 um 13:15 schrieb Hans Hagen:
On 29-8-2010 9:03, Taco Hoekwater wrote:
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
This number uniquely identifies a node for as long as it stays allocated, yes. If it is freed, a new node may have the same number.
but for storing the node's id one can as well use the nodes user object itself as it's equally unique during the livespan of a node and one can compare pointers so the 'id' snippet in the string is not giving more uniqueness than the node user object itself
I need to generate some unique text for that node (I am creating a visual representation of a nodelist using graphviz), so I see two choices: a) get some id string or b) create a look table with the nodes as an index and some random string as the value for each node. But somehow b) didn't work. Is there a way to get the "value of a pointer" as a text string in Lua? Such as when you do tostring({}). Patrick
On 29-8-2010 1:22, Patrick Gundlach wrote:
Am 29.08.2010 um 13:15 schrieb Hans Hagen:
On 29-8-2010 9:03, Taco Hoekwater wrote:
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
This number uniquely identifies a node for as long as it stays allocated, yes. If it is freed, a new node may have the same number.
but for storing the node's id one can as well use the nodes user object itself as it's equally unique during the livespan of a node and one can compare pointers so the 'id' snippet in the string is not giving more uniqueness than the node user object itself
I need to generate some unique text for that node (I am creating a visual representation of a nodelist using graphviz), so I see two choices: a) get some id string or b) create a look table with the nodes as an index and some random string as the value for each node. But somehow b) didn't work. Is there a way to get the "value of a pointer" as a text string in Lua? Such as when you do tostring({}).
isn't tostring(n) unique enough then? as long is the node is not freed ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 08/29/2010 01:15 PM, Hans Hagen wrote:
On 29-8-2010 9:03, Taco Hoekwater wrote:
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
This number uniquely identifies a node for as long as it stays allocated, yes. If it is freed, a new node may have the same number.
but for storing the node's id one can as well use the nodes user object itself as it's equally unique during the livespan of a node and one can compare pointers so the 'id' snippet in the string is not giving more uniqueness than the node user object itself
Not necessarily: there can be different userdata objects for the same node. (I only just now realized that) Best wishes, Taco
On 29-8-2010 1:29, Taco Hoekwater wrote:
On 08/29/2010 01:15 PM, Hans Hagen wrote:
On 29-8-2010 9:03, Taco Hoekwater wrote:
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
This number uniquely identifies a node for as long as it stays allocated, yes. If it is freed, a new node may have the same number.
but for storing the node's id one can as well use the nodes user object itself as it's equally unique during the livespan of a node and one can compare pointers so the 'id' snippet in the string is not giving more uniqueness than the node user object itself
Not necessarily: there can be different userdata objects for the same node. (I only just now realized that)
Sure, and in the beginning we even had problems with the comparison (and I know of a few places in my code that I need to deal with it) but I think that for patricks case the only thing that matters is uniqueness during a certain period (this graph creation i guess) Anyhow, a way out is: local t = {} for ... loop over fields in node ... do t[k] = ... end hash = table.concat(t) -- maybe with some sort on keys beforehand Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 29-8-2010 8:48, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
thinking of it ... luatex could have a flag that would inhibit freeing of nodes (making free a nil-op so to say) so you would get a large mem footprint but that's ok for special cases Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
Not now. Perhaps I should alter tostring() to return only the middle bit.
On 29-8-2010 1:42, Taco Hoekwater wrote:
On 08/29/2010 08:48 AM, Patrick Gundlach wrote:
Is the following 172 something like I need? How would I access that (besides string.gsub())?
nil : hlist 2> I am currently using this number in the middle via tostring() and gsub(). But I'd still like to know if this can be used as an id.
Not now. Perhaps I should alter tostring() to return only the middle bit.
no. as it's really helpful to see what the nodes point to .. better would be to have a node.tonumber that reports the number Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Patrick Gundlach
-
Taco Hoekwater