diff options
author | Hans Hagen <pragma@wxs.nl> | 2019-07-04 13:50:48 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2019-07-04 13:50:48 +0200 |
commit | 4bc28891615011ed3581836e9259434720e25830 (patch) | |
tree | 4a753013e7b1e5b83a76c2708939d40b13972240 /doc/context/sources/general/manuals/onandon/onandon-execute.tex | |
parent | 739710f590371de17ae0debb4dc38b0de270b9f3 (diff) | |
download | context-4bc28891615011ed3581836e9259434720e25830.tar.gz |
2019-07-04 12:36:00
Diffstat (limited to 'doc/context/sources/general/manuals/onandon/onandon-execute.tex')
-rw-r--r-- | doc/context/sources/general/manuals/onandon/onandon-execute.tex | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/doc/context/sources/general/manuals/onandon/onandon-execute.tex b/doc/context/sources/general/manuals/onandon/onandon-execute.tex index abb3b4d8a..bd11dfa73 100644 --- a/doc/context/sources/general/manuals/onandon/onandon-execute.tex +++ b/doc/context/sources/general/manuals/onandon/onandon-execute.tex @@ -134,14 +134,17 @@ which can also be achieved by \directlua{print("Hi there!")} \stoptyping -which sometimes can be more convenient. Anyway, a function call is what we can -use for our purpose as it doesn't involve interpretation and effectively behaves -like a tail call. The following snippet shows what we have in mind: +which sometimes can be more convenient. Don't overestimate the gain in speed +because \type {directlua} is quite efficient too, and on an average run a user +doesn't call it that often (millions of times that is). Anyway, a function call +is what we can use for our purpose as it doesn't involve interpretation and +effectively behaves like a tail call. The following snippet shows what we have in +mind: \startbuffer[code] local stepper = nil local stack = { } -local fid = 0xFFFFFF +local fid = 2 -- make sure to take a frees slot local goback = "\\luafunction" .. fid .. "\\relax" function tex.resume() @@ -166,6 +169,14 @@ function tex.routine(f) stepper = coroutine.create(f) tex.sprint(goback) end + +-- Because we protect against abuse and overload of functions, in ConTeXt we +-- need to do the following: + +if context then + fid = context.functions.register(tex.resume) + goback = "\\luafunction" .. fid .. "\\relax" +end \stopbuffer \ctxluabuffer[code] @@ -238,7 +249,7 @@ course figuring it out took a while): \startbuffer[code] local stepper = nil local stack = { } -local fid = 0xFFFFFF +local fid = 3 -- make sure to take a frees slot local goback = "\\luafunction" .. fid .. "\\relax" function tex.resume() @@ -270,6 +281,13 @@ function tex.routine(f) stepper = coroutine.create(f) tex.sprint(goback) end + +-- Again we need to do it as follows in ConTeXt: + +if context then + fid = context.functions.register(tex.resume) + goback = "\\luafunction" .. fid .. "\\relax" +end \stopbuffer \ctxluabuffer[code] |