summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/core-env.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/core-env.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/core-env.lua67
1 files changed, 40 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/core-env.lua b/Master/texmf-dist/tex/context/base/mkiv/core-env.lua
index 50759dd1941..0ef37a6d6b2 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/core-env.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/core-env.lua
@@ -26,7 +26,6 @@ local setmetatablenewindex = table.setmetatablenewindex
local setmetatablecall = table.setmetatablecall
local createtoken = token.create
-local isdefined = tokens.isdefined
texmodes = allocate { } tex.modes = texmodes
texsystemmodes = allocate { } tex.systemmodes = texsystemmodes
@@ -41,27 +40,18 @@ local systemmodes = { }
-- we could use the built-in tex.is[count|dimen|skip|toks] here but caching
-- at the lua end is not that bad (and we need more anyway)
-local cache = tokens.cache
+-- undefined: mode == 0 or cmdname = "undefined_cs"
--- we can have a modes cache too
+local cache = setmetatableindex(function(t,k)
+ local v = createtoken(k)
+ t[k] = v
+ return v
+end)
-local iftrue = cache["iftrue"].mode
+-- we can have a modes cache too
-local dimencode = cache["scratchdimen"] .command
-local countcode = cache["scratchcounter"] .command
-local tokencode = cache["scratchtoken"] .command
-local skipcode = cache["scratchskip"] .command
-local muskipcode = cache["scratchmuskip"] .command
------ attributecode = cache["scratchattribute"].command
-
-local types = {
- [dimencode] = "dimen",
- [countcode] = "count",
- [tokencode] = "token",
- [skipcode] = "skip",
- [muskipcode] = "muskip",
- -- [attributecode] = "attribute",
-}
+local iftrue = cache["iftrue"].mode
+local undefined = cache["*undefined*crap*"].mode -- is this ok?
setmetatableindex(texmodes, function(t,k)
local m = modes[k]
@@ -69,17 +59,16 @@ setmetatableindex(texmodes, function(t,k)
return m()
elseif k then
local n = "mode>" .. k
- if isdefined(n) then
+ if cache[n].mode == 0 then
+ return false
+ else
rawset(modes,k, function() return texgetcount(n) == 1 end)
return texgetcount(n) == 1 -- 2 is prevented
- else
- return false
end
else
return false
end
end)
-
setmetatablenewindex(texmodes, function(t,k)
report_mode("you cannot set the %s named %a this way","mode",k)
end)
@@ -90,11 +79,11 @@ setmetatableindex(texsystemmodes, function(t,k)
return m()
else
local n = "mode>*" .. k
- if isdefined(n) then
+ if cache[n].mode == 0 then
+ return false
+ else
rawset(systemmodes,k,function() return texgetcount(n) == 1 end)
return texgetcount(n) == 1 -- 2 is prevented
- else
- return false
end
end
end)
@@ -123,7 +112,31 @@ setmetatablenewindex(texifs, function(t,k)
-- just ignore
end)
-tex.isdefined = isdefined
+setmetatableindex(texisdefined, function(t,k)
+ return k and cache[k].mode ~= 0
+end)
+setmetatablecall(texisdefined, function(t,k)
+ return k and cache[k].mode ~= 0
+end)
+setmetatablenewindex(texisdefined, function(t,k)
+ -- just ignore
+end)
+
+local dimencode = cache["scratchdimen"] .command
+local countcode = cache["scratchcounter"] .command
+local tokencode = cache["scratchtoken"] .command
+local skipcode = cache["scratchskip"] .command
+local muskipcode = cache["scratchmuskip"] .command
+---- attributecode = cache["scratchattribute"].command
+
+local types = {
+ [dimencode] = "dimen",
+ [countcode] = "count",
+ [tokencode] = "token",
+ [skipcode] = "skip",
+ [muskipcode] = "muskip",
+ -- [attributecode] = "attribute",
+}
function tex.isdimen(name)
local hit = cache[name]