4 luatexbase.provides_module({
5 name = 'luatexja.tangle',
10 module('luatexja.tangle', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
15 local _DONE, _TEX, _STOP = 0, 1, 2
16 local _current_co, _interrupted
20 "\\directlua{".._NAME..".resume()}\\relax"
22 function execute(func, ...)
24 err("tangle is going now")
27 local co = coroutine.create(function()
28 return _DONE, { func(unpack(args)) }
32 return _check(coroutine.resume(co, ...))
44 coroutine.yield(_TEX, {})
48 local intr = coroutine.yield(_STOP, { ... })
51 error("*INTR*") -- this error is caught later
55 function _resume(intr)
56 if not _current_co then
57 err("tangle is not going")
59 local co = _current_co
60 return _check(coroutine.resume(co, intr))
63 function _check(costat, tstat, extra)
64 if not costat then -- error in coroutine
66 if _interrupted then return end
68 elseif tstat == _DONE then
70 elseif tstat == _TEX then
71 tex.print(resume_code)