4 luatexbase.provides_module({
5 name = 'luatexja.tangle',
9 module('luatexja.tangle', package.seeall)
10 local err, warn, info, log = luatexbase.errwarinf(_NAME)
14 local _DONE, _TEX, _STOP = 0, 1, 2
15 local _current_co, _interrupted
19 "\\directlua{".._NAME..".resume()}\\relax"
21 function execute(func, ...)
23 err("tangle is going now")
26 local co = coroutine.create(function()
27 return _DONE, { func(unpack(args)) }
31 return _check(coroutine.resume(co, ...))
43 coroutine.yield(_TEX, {})
47 local intr = coroutine.yield(_STOP, { ... })
50 error("*INTR*") -- this error is caught later
54 function _resume(intr)
55 if not _current_co then
56 err("tangle is not going")
58 local co = _current_co
59 return _check(coroutine.resume(co, intr))
62 function _check(costat, tstat, extra)
63 if not costat then -- error in coroutine
65 if _interrupted then return end
67 elseif tstat == _DONE then
69 elseif tstat == _TEX then
70 tex.print(resume_code)