From 8fc3039c82d48605b5ca8b2eda3f4fdd755681e1 Mon Sep 17 00:00:00 2001 From: Taco Hoekwater Date: Sun, 23 Aug 2009 11:11:32 +0000 Subject: this is context 2009.08.19 17:10 git-svn-id: svn://tug.org/texlive/trunk@14827 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/context/base/luat-ini.lua | 130 +++++++++++++++++++++++- 1 file changed, 127 insertions(+), 3 deletions(-) (limited to 'Master/texmf-dist/tex/context/base/luat-ini.lua') diff --git a/Master/texmf-dist/tex/context/base/luat-ini.lua b/Master/texmf-dist/tex/context/base/luat-ini.lua index 092593541ae..34b59d7e8d5 100644 --- a/Master/texmf-dist/tex/context/base/luat-ini.lua +++ b/Master/texmf-dist/tex/context/base/luat-ini.lua @@ -6,15 +6,26 @@ if not modules then modules = { } end modules ['luat-ini'] = { license = "see context related readme files" } +--~ local ctxcatcodes = tex.ctxcatcodes + --[[ldx--

We cannot load anything yet. However what we will do us reserve a fewtables. These can be used for runtime user data or third party modules and will not be cluttered by macro package code.

--ldx]]-- -userdata = userdata or { } -thirddata = thirddata or { } -document = document or { } +userdata = userdata or { } -- might be used +thirddata = thirddata or { } -- might be used +moduledata = moduledata or { } -- might be used +document = document or { } +parametersets = parametersets or { } -- experimental + +--[[ldx-- +

These can be used/set by the caller program; mtx-context.lua does it.

+--ldx]]-- + +document.arguments = document.arguments or { } +document.files = document.files or { } --[[ldx--

Please create a namespace within these tables before using them!

@@ -24,3 +35,116 @@ userdata ['my.name'] = { } thirddata['tricks' ] = { } --ldx]]-- + +--[[ldx-- +

We could cook up a readonly model for global tables but it +makes more sense to invite users to use one of the predefined +namespaces. One can redefine the protector. After all, it's +just a lightweight suggestive system, not a watertight +one.

+--ldx]]-- + +local string, table, lpeg, math, io, system = string, table, lpeg, math, io, system +local next, setfenv = next, setfenv +local format = string.format + +local global = _G + +global.global = global + +local dummy = function() end + +local protected = { + -- global table + global = global, + -- user tables + userdata = userdata, + moduledata = moduledata, + thirddata = thirddata, + document = document, + -- reserved + protect = dummy, + unprotect = dummy, + -- luatex + tex = tex, + -- lua + string = string, + table = table, + lpeg = lpeg, + math = math, + io = io, + system = system, +} + +userdata, thirddata, moduledata = nil, nil, nil + +function protect(name) + if name == "isolateddata" then + local t = { } + for k, v in next, protected do + t[k] = v + end + setfenv(2,t) + else + if not name then + name = "shareddata" + end + local t = global[name] + if not t then + t = { } + for k, v in next, protected do + t[k] = v + end + global[name] = t + end + setfenv(2,t) + end +end + +lua.numbers = { } +lua.messages = { } + +function lua.registername(name,message) + local lnn = lua.numbers[name] + if not lnn then + lnn = #lua.messages + 1 + lua.messages[lnn] = message + lua.numbers[name] = lnn + end + lua.name[lnn] = message + tex.write(lnn) +end + +--~ function lua.checknames() +--~ lua.name[0] = "ctx" +--~ for k, v in next, lua.messages do +--~ lua.name[k] = v +--~ end +--~ end + +storage.register("lua/numbers", lua.numbers, "lua.numbers") +storage.register("lua/messages", lua.messages, "lua.messages") + +function document.setargument(key,value) + document.arguments[key] = value +end + +function document.setdefaultargument(key,default) + local v = document.arguments[key] + if v == nil or v == "" then + document.arguments[key] = default + end +end + +function document.getargument(key,default) + local v = document.arguments[key] + if type(v) == "boolean" then + v = (v and "yes") or "no" + document.arguments[key] = v + end + tex.sprint(tex.ctxcatcodes,v or default or "") +end + +function document.getfilename(i) + tex.sprint(tex.ctxcatcodes,document.files[i] or "") +end -- cgit v1.2.3