summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/core-env.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/core-env.lua')
-rw-r--r--tex/context/base/mkiv/core-env.lua50
1 files changed, 24 insertions, 26 deletions
diff --git a/tex/context/base/mkiv/core-env.lua b/tex/context/base/mkiv/core-env.lua
index 23f7ca178..ea7bbcb8e 100644
--- a/tex/context/base/mkiv/core-env.lua
+++ b/tex/context/base/mkiv/core-env.lua
@@ -40,14 +40,27 @@ 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)
--- undefined: mode == 0 or cmdname = "undefined_cs"
-
local cache = tokens.cache
-- we can have a modes cache too
-local iftrue = cache["iftrue"].mode
-local undefined = cache["*undefined*crap*"].mode -- is this ok?
+local iftrue = cache["iftrue"].mode
+
+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",
+}
setmetatableindex(texmodes, function(t,k)
local m = modes[k]
@@ -55,16 +68,17 @@ setmetatableindex(texmodes, function(t,k)
return m()
elseif k then
local n = "mode>" .. k
- if cache[n].mode == 0 then
- return false
- else
+ if is_defined then
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)
@@ -75,11 +89,11 @@ setmetatableindex(texsystemmodes, function(t,k)
return m()
else
local n = "mode>*" .. k
- if cache[n].mode == 0 then
- return false
- else
+ if is_defined(n) then
rawset(systemmodes,k,function() return texgetcount(n) == 1 end)
return texgetcount(n) == 1 -- 2 is prevented
+ else
+ return false
end
end
end)
@@ -118,22 +132,6 @@ 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]
return hit.command == dimencode and hit.index or true