Hi, once in a while I find surprises in the luatex reference manual, such as the user_defined whatsits (great!). 1) Is the user_id field completely up to me? So I can use it somewhat as an attribute? 2) Will the user_defined whatsit stay in LuaTeX (I know, nothing is fixed, but the developers might have a tendency) 3) am I dreaming or is this really real? Patrick
Hi, On 09/09/2010 01:14 PM, Patrick Gundlach wrote:
Hi,
once in a while I find surprises in the luatex reference manual, such as the user_defined whatsits (great!).
1) Is the user_id field completely up to me? So I can use it somewhat as an attribute?
Yes.
2) Will the user_defined whatsit stay in LuaTeX (I know, nothing is fixed, but the developers might have a tendency)
Yes, I think it will stay. At least, I see no reason to ever remote it.
3) am I dreaming or is this really real?
Both could be true at the same time, depending on how well the actual reality -- interpreted reality link works in your brain :) Best wishes, Taco
On 9-9-2010 1:14, Patrick Gundlach wrote:
Hi,
once in a while I find surprises in the luatex reference manual, such as the user_defined whatsits (great!).
1) Is the user_id field completely up to me? So I can use it somewhat as an attribute?
yes
2) Will the user_defined whatsit stay in LuaTeX (I know, nothing is fixed, but the developers might have a tendency)
yes
3) am I dreaming or is this really real?
yes ----------------------------------------------------------------- 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 -----------------------------------------------------------------
While I am at the user_defined whatsit. Is there a way to store a function? I can dump the function to a string, but that doesn't sound too efficient. The manual states that the table is a token list, so I am not trying to do n.value = { function () do whatever I want until the end } Any ideas? Patrick
Am 09.09.2010 um 18:29 schrieb Patrick Gundlach:
While I am at the user_defined whatsit. Is there a way to store a function? I can dump the function to a string, but that doesn't sound too efficient. The manual states that the table is a token list, so I am not trying to do
n.value = { function () do whatever I want until the end }
Any ideas?
my idea with string.dump somehow doesn't work for two reasons: 1) the dumped string must not contain upvalues (lua limitation) 2) i get an error when loading the string back: "binary string: unexpected end in precompiled chun k" this is how I store the function: n.value = string.dump(function() print("a") end) and this is how I read it: fun = assert(loadstring(head.value)) fun() I guess that n.value "chokes" on \0 in strings. So any idea on how to store a function? Patrick
On 09/09/2010 07:17 PM, Patrick Gundlach wrote:
this is how I store the function:
n.value = string.dump(function() print("a") end)
and this is how I read it:
fun = assert(loadstring(head.value)) fun()
I guess that n.value "chokes" on \0 in strings.
Yes, and that is because internally the user_defined node has no room to store the string length in. I can fix that (later), but it is not intended usage and regardless it does not help you right now.
So any idea on how to store a function?
Put the functions in a global lua table and store the index to it? That allows upvalues, and faster too if the function is non-trivial. Best wishes, Taco
On 9-9-2010 6:29, Patrick Gundlach wrote:
While I am at the user_defined whatsit. Is there a way to store a function? I can dump the function to a string, but that doesn't sound too efficient. The manual states that the table is a token list, so I am not trying to do
n.value = { function () do whatever I want until the end }
maybe use an indirect method: list, last= { }, 0 ... set .... last = last + 1 list[last] = fnc n.value = last .... whatever ... after usage list[n.value] = nil ... use and forget ... ----------------------------------------------------------------- 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