summaryrefslogtreecommitdiff
path: root/tex/context/base/luat-cod.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/luat-cod.lua')
-rw-r--r--tex/context/base/luat-cod.lua28
1 files changed, 18 insertions, 10 deletions
diff --git a/tex/context/base/luat-cod.lua b/tex/context/base/luat-cod.lua
index b022f31c3..87b2c0059 100644
--- a/tex/context/base/luat-cod.lua
+++ b/tex/context/base/luat-cod.lua
@@ -6,6 +6,7 @@ if not modules then modules = { } end modules ['luat-cod'] = {
license = "see context related readme files"
}
+local type, loadfile = type, loadfile
local match, gsub, find, format = string.match, string.gsub, string.find, string.format
local texconfig, lua = texconfig, lua
@@ -19,11 +20,13 @@ texconfig.max_in_open = 127
-- registering bytecode chunks
-lua.bytecode = lua.bytecode or { } -- built in anyway
-lua.bytedata = lua.bytedata or { }
-lua.bytedone = lua.bytedone or { }
+local bytecode = lua.bytecode or { }
+local bytedata = lua.bytedata or { }
+local bytedone = lua.bytedone or { }
-local bytecode, bytedata, bytedone = lua.bytecode, lua.bytedata, lua.bytedone
+lua.bytecode = bytecode -- built in anyway
+lua.bytedata = bytedata
+lua.bytedone = bytedone
lua.firstbytecode = 501
lua.lastbytecode = lua.lastbytecode or (lua.firstbytecode - 1) -- as we load ourselves again ... maybe return earlier
@@ -32,18 +35,19 @@ function lua.registeredcodes()
return lua.lastbytecode - lua.firstbytecode + 1
end
+-- no file.* functions yet
+
function lua.registercode(filename,version)
local barename = gsub(filename,"%.[%a%d]+$","")
if barename == filename then filename = filename .. ".lua" end
local basename = match(barename,"^.+[/\\](.-)$") or barename
- if not bytedone[barename] then
+ if not bytedone[basename] then
local code = environment.luafilechunk(filename)
if code then
- assert(code)()
- bytedone[barename] = true
+ bytedone[basename] = true
if environment.initex then
local n = lua.lastbytecode + 1
- bytedata[n] = { barename, version }
+ bytedata[n] = { barename, version or "0.000" }
bytecode[n] = code
lua.lastbytecode = n
end
@@ -54,10 +58,11 @@ end
local finalizers = { }
function lua.registerfinalizer(f,comment)
+ comment = comment or "unknown"
if type(f) == "function" then
finalizers[#finalizers+1] = { action = f, comment = comment }
else
- print(format("fatal error: invalid finalizer, action: %s",finalizer.comment or "unknown"))
+ texio.write_nl(format("fatal error: invalid finalizer, action: %s",comment))
os.exit()
end
end
@@ -98,12 +103,15 @@ if not environment.luafilechunk then
end
local data = loadfile(filename)
texio.write("<",data and "+ " or "- ",filename,">")
+ if data then
+ data()
+ end
return data
end
end
-if not environment.engineflags then
+if not environment.engineflags then -- raw flags
local engineflags = { }
for i=-10,#arg do
local a = arg[i]