summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib/luamplib.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua167
1 files changed, 46 insertions, 121 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index 2ff14676ff2..f5c7ef12141 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
@@ -5,158 +5,84 @@
-- The original source files were:
--
-- luamplib.dtx (with options: `lua')
--- This is a generated file.
--
--- Copyright (C) 2008-2009 by Hans Hagen, Taco Hoekwater and Elie Roux
--- <elie.roux@telecom-bretagne.eu>. (Support: <lualatex-dev@tug.org>.)
+-- See source file 'luamplib.dtx' for licencing and contact information.
--
--- This work is under the CC0 license.
---
--- This Current Maintainer of this work is Elie Roux.
---
--- This work consists of the main source file luamplib.dtx
--- and the derived files
--- luamplib.sty, luamplib.lua, luamplib-createmem.lua and luamplib.pdf.
---
-
module('luamplib', package.seeall)
-
-luamplib.module = {
+local err, warn, info, log = luatexbase.provides_module({
name = "luamplib",
- version = 1.06,
- date = "2010/10/17",
+ version = 1.07,
+ date = "2010/12/28",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
- author = "Hans Hagen, Taco Hoekwater & Elie Roux",
- copyright = "ConTeXt Development Team & Elie Roux",
- license = "CC0",
-}
-
-luatexbase.provides_module(luamplib.module)
+})
+local function term(...)
+ texio.write_nl('term', 'luamplib: ' .. string.format(...))
+end
local format, concat, abs = string.format, table.concat, math.abs
+local data = ""
-luamplib.currentformat = "plain"
-luamplib.currentmem = "mplib-luatex"
-
-local currentformat = luamplib.currentformat
-local currentmem = luamplib.currentmem
-
-function luamplib.setformat (name)
- luamplib.currentformat = name
+local function resetdata()
+ data = ""
end
-
-function luamplib.setmemfile(name)
- luamplib.currentmem = name
+function addline(line)
+ data = data .. '\n' .. line
+end
+function processlines()
+ process(data)
+ resetdata()
end
+local mpkpse = kpse.new("luatex", "mpost")
-local mpkpse = kpse.new("luatex","mpost")
-
-function luamplib.finder(name, mode, ftype)
+local function finder(name, mode, ftype)
if mode == "w" then
return name
else
- local result = mpkpse:find_file(name,ftype)
- if not result and ftype == "mem" then
- result = mpkpse:find_file("metapost/"..name,ftype)
- end
- return result
+ return mpkpse:find_file(name,ftype)
end
end
-function luamplib.info (...)
- luatexbase.module_info('luamplib', format(...))
-end
-
-function luamplib.log (...)
- luatexbase.module_log('luamplib', format(...))
-end
-
-function luamplib.term (...)
- luatexbase.module_term('luamplib', format(...))
-end
+local currentformat = "plain"
-function luamplib.warning (...)
- luatexbase.module_warning('luamplib', format(...))
+function setformat (name)
+ currentformat = name
end
-function luamplib.error (...)
- luatexbase.module_error('luamplib', format(...))
-end
-
-
-luamplib.data = ""
-
-function luamplib.resetdata()
- luamplib.data = ""
-end
-
-function luamplib.addline(line)
- luamplib.data = luamplib.data .. '\n' .. line
-end
-
-function luamplib.processlines()
- luamplib.process(luamplib.data)
- luamplib.resetdata()
-end
-
-
-function luamplib.input_mp(name)
+function load()
local mpx = mplib.new {
+ find_file = finder,
ini_version = true,
- find_file = luamplib.finder,
- job_name = name,
- }
- mpx:execute(format("input %s ;",name))
- return mpx
-end
-
-
-function luamplib.load()
- local mpx = mplib.new {
- ini_version = false,
- mem_name = currentmem,
- find_file = luamplib.finder
}
- if mpx then
- luamplib.log("using mem file %s", luamplib.finder(currentmem, 'r', 'mem'))
- else
- mpx = luamplib.input_mp(currentformat)
- if mpx then
- luamplib.log("using mp file %s", luamplib.finder(currentformat, 'r', 'mp'))
- else
- luamplib.error("unable to load the metapost format.")
- end
- end
+ mpx:execute(format("input %s ;", currentformat))
return mpx
end
-
-function luamplib.report(result)
+function report(result)
if not result then
- luamplib.error("no result object")
+ err("no result object")
elseif result.status > 0 then
local t, e, l, f = result.term, result.error, result.log
if l then
- luamplib.log(l)
+ log(l)
end
if t then
- luamplib.term(t)
+ term(t)
end
if e then
if result.status == 1 then
- luamplib.warning(e)
+ warn(e)
else
- luamplib.error(e)
+ err(e)
end
end
if not t and not e and not l then
if result.status == 1 then
- luamplib.warning("unknown error, no error, terminal or log messages, maybe missing beginfig/endfig")
+ warn("unknown error, no error, terminal or log messages, maybe missing beginfig/endfig")
else
- luamplib.error("unknown error, no error, terminal or log messages, maybe missing beginfig/endfig")
+ err("unknown error, no error, terminal or log messages, maybe missing beginfig/endfig")
end
end
else
@@ -165,20 +91,20 @@ function luamplib.report(result)
return false
end
-function luamplib.process(data)
+function process(data)
local converted, result = false, {}
- local mpx = luamplib.load()
+ local mpx = load()
if mpx and data then
local result = mpx:execute(data)
- if luamplib.report(result) then
+ if report(result) then
if result.fig then
- converted = luamplib.convert(result)
+ converted = convert(result)
else
- luamplib.warning("no figure output")
+ warn("no figure output")
end
end
else
- luamplib.error("Mem file unloadable. Maybe generated with a different version of mplib?")
+ err("Mem file unloadable. Maybe generated with a different version of mplib?")
end
return converted, result
end
@@ -187,8 +113,8 @@ local function getobjects(result,figure,f)
return figure:objects()
end
-function luamplib.convert(result, flusher)
- luamplib.flush(result, flusher)
+function convert(result, flusher)
+ flush(result, flusher)
return true -- done
end
@@ -301,13 +227,12 @@ local function flushconcatpath(path,open)
return t
end
-
-function luamplib.flush(result,flusher)
+function flush(result,flusher)
if result then
local figures = result.fig
if figures then
for f=1, #figures do
- luamplib.log("flushing figure %s",f)
+ log("flushing figure %s",f)
local figure = figures[f]
local objects = getobjects(result,figure,f)
local fignum = tonumber((figure:filename()):match("([%d]+)$") or figure:charcode() or 0)
@@ -344,7 +269,7 @@ function luamplib.flush(result,flusher)
else
local cs = object.color
if cs and #cs > 0 then
- pdf_literalcode(luamplib.colorconverter(cs))
+ pdf_literalcode(colorconverter(cs))
end
local ml = object.miterlimit
if ml and ml ~= miterlimit then
@@ -442,7 +367,7 @@ function luamplib.flush(result,flusher)
end
end
-function luamplib.colorconverter(cr)
+function colorconverter(cr)
local n = #cr
if n == 4 then
local c, m, y, k = cr[1], cr[2], cr[3], cr[4]