summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2012-04-24 00:13:14 +0000
committerNorbert Preining <preining@logic.at>2012-04-24 00:13:14 +0000
commit8f29bdce0bdd08ec81df555e98692d1f288c3289 (patch)
treec4f9a6b00a587f635e55fc4068c1961780c90591 /Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua
parent74e624196144ae218a63a4c35672fc7a0e7b18dc (diff)
new package luatexja (24apr)
adapt ctan2tds to deal with it git-svn-id: svn://tug.org/texlive/trunk@26115 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua77
1 files changed, 77 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua
new file mode 100644
index 00000000000..7914c936a63
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-tangle.lua
@@ -0,0 +1,77 @@
+--
+-- luatexja/tangle.lua
+--
+luatexbase.provides_module({
+ name = 'luatexja.tangle',
+ date = '2011/04/01',
+ version = '0.1',
+ description = '',
+})
+module('luatexja.tangle', package.seeall)
+local err, warn, info, log = luatexbase.errwarinf(_NAME)
+
+--! ixbase0 からの移植
+
+local _DONE, _TEX, _STOP = 0, 1, 2
+local _current_co, _interrupted
+local _resume, _check
+
+local resume_code =
+ "\\directlua{".._NAME..".resume()}\\relax"
+
+function execute(func, ...)
+ if _current_co then
+ err("tangle is going now")
+ end
+ local args = { ... }
+ local co = coroutine.create(function()
+ return _DONE, { func(unpack(args)) }
+ end)
+ _current_co = co
+ _interrupted = false
+ return _check(coroutine.resume(co, ...))
+end
+
+function resume()
+ return _resume(false)
+end
+
+function interrupt()
+ return _resume(true)
+end
+
+function run_tex()
+ coroutine.yield(_TEX, {})
+end
+
+function suspend(...)
+ local intr = coroutine.yield(_STOP, { ... })
+ if intr then
+ _interrupted = true
+ error("*INTR*") -- this error is caught later
+ end
+end
+
+function _resume(intr)
+ if not _current_co then
+ err("tangle is not going")
+ end
+ local co = _current_co
+ return _check(coroutine.resume(co, intr))
+end
+
+function _check(costat, tstat, extra)
+ if not costat then -- error in coroutine
+ _current_co = nil
+ if _interrupted then return end
+ err(tstat)
+ elseif tstat == _DONE then
+ _current_co = nil
+ elseif tstat == _TEX then
+ tex.print(resume_code)
+ end
+ return unpack(extra)
+end
+
+-- EOF
+