From a36f9abf1e0fd7de609dd1840d75bea56ec9e926 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Sat, 21 May 2016 02:52:16 +0200 Subject: 2016-05-20 18:46:00 --- tex/context/base/mkiv/node-res.lua | 111 +++++++++++++++---------------------- 1 file changed, 44 insertions(+), 67 deletions(-) (limited to 'tex/context/base/mkiv/node-res.lua') diff --git a/tex/context/base/mkiv/node-res.lua b/tex/context/base/mkiv/node-res.lua index 4d25314ad..89ffd1ff5 100644 --- a/tex/context/base/mkiv/node-res.lua +++ b/tex/context/base/mkiv/node-res.lua @@ -27,6 +27,7 @@ local kerncodes = nodes.kerncodes local rulecodes = nodes.rulecodes local nodecodes = nodes.nodecodes local boundarycodes = nodes.boundarycodes +local usercodes = nodes.usercodes local glyph_code = nodecodes.glyph @@ -150,11 +151,15 @@ local textdir = register_nut(new_nut("dir")) local latelua = register_nut(new_nut("whatsit",whatsitcodes.latelua)) local special = register_nut(new_nut("whatsit",whatsitcodes.special)) -local user_n = register_nut(new_nut("whatsit",whatsitcodes.userdefined)) setfield(user_n,"type",100) -- 44 -local user_l = register_nut(new_nut("whatsit",whatsitcodes.userdefined)) setfield(user_l,"type",110) -- 44 -local user_s = register_nut(new_nut("whatsit",whatsitcodes.userdefined)) setfield(user_s,"type",115) -- 44 -local user_t = register_nut(new_nut("whatsit",whatsitcodes.userdefined)) setfield(user_t,"type",116) -- 44 ------ user_c = register_nut(new_nut("whatsit",whatsitcodes.userdefined)) setfield(user_c,"type",108) -- 44 + +local user_node = new_nut("whatsit",whatsitcodes.userdefined) + +local user_number = register_nut(copy_nut(user_node)) setfield(user_number, "type",usercodes.number) +local user_nodes = register_nut(copy_nut(user_node)) setfield(user_nodes, "type",usercodes.nodes) +local user_string = register_nut(copy_nut(user_node)) setfield(user_string, "type",usercodes.string) +local user_tokens = register_nut(copy_nut(user_node)) setfield(user_tokens, "type",usercodes.tokens) +----- user_lua = register_nut(copy_nut(user_node)) setfield(user_lua, "type",usercodes.lua) -- in > 0.95 +local user_attributes = register_nut(copy_nut(user_node)) setfield(user_attributes,"type",usercodes.attributes) local left_margin_kern = register_nut(new_nut("margin_kern",0)) local right_margin_kern = register_nut(new_nut("margin_kern",1)) @@ -417,9 +422,7 @@ if context and _cldo_ then -- a typical case where we have more nodes than nuts - local context = context - - local f_cldo = string.formatters["_cldo_(%i)"] + local context = context local register = context.registerfunction local latelua_node = register_node(new_node("whatsit",whatsitcodes.latelua)) @@ -428,20 +431,6 @@ if context and _cldo_ then local setfield_node = nodes.setfield local setfield_nut = nuts .setfield - -- function nodepool.lateluafunction(f) - -- local n = copy_node(latelua_node) - -- setfield_node(n,"string",f_cldo(register(f))) - -- return n - -- end - - -- function nutpool.lateluafunction(f) - -- local n = copy_nut(latelua_nut) - -- setfield_nut(n,"string",f_cldo(register(f))) - -- return n - -- end - - -- when function in latelua: - function nodepool.lateluafunction(f) local n = copy_node(latelua_node) setfield_node(n,"string",f) @@ -454,37 +443,16 @@ if context and _cldo_ then return n end - local latefunction = nodepool.lateluafunction - local flushnode = context.flushnode - - -- function context.lateluafunction(f) - -- flushnode(latefunction(f)) -- hm, quite some indirect calls - -- end - - -- when function in latelua: - -- function context.lateluafunction(f) -- local n = copy_node(latelua_node) -- setfield_node(n,"string",f) - -- flushnode(n) - -- end - - -- local contextsprint = context.sprint - -- local ctxcatcodes = tex.ctxcatcodes - -- local storenode = context.storenode - - -- when 0.79 is out: - - -- function context.lateluafunction(f) - -- contextsprint(ctxcatcodes,"\\cldl",storenode(latefunction(f))," ") + -- contextsprint(ctxcatcodes,"\\cldl",storenode(n)," ") -- end - -- when function in latelua: + local new_latelua_node = nodes.pool.latelua - function context.lateluafunction(f) - local n = copy_node(latelua_node) - setfield_node(n,"string",f) - contextsprint(ctxcatcodes,"\\cldl",storenode(n)," ") + function context.lateluafunction(f) -- not used anyway + context(new_latelua_node(f)) end end @@ -571,7 +539,7 @@ end -- local str = userids[num] function nutpool.usernumber(id,num) - local n = copy_nut(user_n) + local n = copy_nut(user_number) if num then setfield(n,"user_id",id) setfield(n,"value",num) @@ -582,7 +550,7 @@ function nutpool.usernumber(id,num) end function nutpool.userlist(id,list) - local n = copy_nut(user_l) + local n = copy_nut(user_nodes) if list then setfield(n,"user_id",id) setfield(n,"value",list) @@ -593,7 +561,7 @@ function nutpool.userlist(id,list) end function nutpool.userstring(id,str) - local n = copy_nut(user_s) + local n = copy_nut(user_string) if str then setfield(n,"user_id",id) setfield(n,"value",str) @@ -604,7 +572,7 @@ function nutpool.userstring(id,str) end function nutpool.usertokens(id,tokens) - local n = copy_nut(user_t) + local n = copy_nut(user_tokens) if tokens then setfield(n,"user_id",id) setfield(n,"value",tokens) @@ -614,16 +582,27 @@ function nutpool.usertokens(id,tokens) return n end --- function nutpool.usercode(id,code) --- local n = copy_nut(user_c) --- if code then --- setfield(n,"user_id",id) --- setfield(n,"value",code) --- else --- setfield(n,"value",id) --- end --- return n --- end +function nutpool.userlua(id,code) + local n = copy_nut(user_lua) + if code then + setfield(n,"user_id",id) + setfield(n,"value",code) + else + setfield(n,"value",id) + end + return n +end + +function nutpool.userattributes(id,attr) + local n = copy_nut(user_attributes) + if attr then + setfield(n,"user_id",id) + setfield(n,"value",attr) + else + setfield(n,"value",id) + end + return n +end function nutpool.special(str) local n = copy_nut(special) @@ -637,24 +616,22 @@ local function cleanup(nofboxes) -- todo if nodes.tracers.steppers then -- to be resolved nodes.tracers.steppers.reset() -- todo: make a registration subsystem end - local nl, nr = 0, nofreserved + local nl = 0 + local nr = nofreserved for i=1,nofreserved do local ri = reserved[i] - -- if not (getid(ri) == glue_spec and not getfield(ri,"is_writable")) then - free_nut(reserved[i]) - -- end + free_nut(reserved[i]) end if nofboxes then for i=0,nofboxes do local l = getbox(i) if l then --- print(nodes.listtoutf(getlist(l))) free_nut(l) -- also list ? nl = nl + 1 end end end - reserved = { } + reserved = { } nofreserved = 0 return nr, nl, nofboxes -- can be nil end -- cgit v1.2.3