diff options
Diffstat (limited to 'tex/context/base/mkiv/mlib-lua.lua')
-rw-r--r-- | tex/context/base/mkiv/mlib-lua.lua | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/tex/context/base/mkiv/mlib-lua.lua b/tex/context/base/mkiv/mlib-lua.lua index 8074a6a4a..9b567da81 100644 --- a/tex/context/base/mkiv/mlib-lua.lua +++ b/tex/context/base/mkiv/mlib-lua.lua @@ -468,7 +468,6 @@ do runs = runs + 1 local f = cache[code] if not f then - -- f = loadstring(f_code(code)) f = loadstring(code .. " return mp._f_()") if f then cache[code] = f @@ -480,8 +479,10 @@ do end end if f then - local _buffer_, _n_ = buffer, n - buffer, n = { }, 0 + local _buffer_ = buffer + local _n_ = n + buffer = { } + n = 0 local result = f() if result then local t = type(result) @@ -493,17 +494,16 @@ do if trace then if #result == 0 then report_luarun("%i: no result",nesting) --- print(debug.traceback()) else report_luarun("%i: result: %s",nesting,result) end end - buffer, n = _buffer_, _n_ + buffer = _buffer_ + n = _n_ nesting = nesting - 1 return result elseif trace then report_luarun("%i: no result",nesting) --- print(debug.traceback()) end buffer, n = _buffer_, _n_ else @@ -1027,3 +1027,22 @@ do mp.mf_path_reset = mf_path_reset mp.pathreset = mf_path_reset end + +do + + -- if needed we can optimize the sub (cache last split) + + local utflen, utfsub = utf.len, utf.sub + + local mpnumeric = aux.numeric + local mpquoted = aux.quoted + + function mp.utflen(s) + mpnumeric(utflen(s)) + end + + function mp.utfsub(s,f,t) + mpquoted(utfsub(s,f,t or f)) + end + +end |