diff options
| author | Khaled Hosny <khaledhosny@eglug.org> | 2010-05-21 06:22:29 +0300 | 
|---|---|---|
| committer | Khaled Hosny <khaledhosny@eglug.org> | 2010-05-21 06:22:29 +0300 | 
| commit | 5f2ef13d20837eb9c0fe84a378e70c5066e6d021 (patch) | |
| tree | 8da8eb76198b5015119d88aeb0480dedefa27e1d | |
| parent | 2ede45796e70760267e4928dfff04d3546a8f159 (diff) | |
| download | lualibs-5f2ef13d20837eb9c0fe84a378e70c5066e6d021.tar.gz | |
Sync with ConTeXt beta (beta 2010.05.20)
Needed to sync luaotfload.
| -rw-r--r-- | lualibs-dir.lua | 10 | ||||
| -rw-r--r-- | lualibs-file.lua | 2 | ||||
| -rw-r--r-- | lualibs-io.lua | 7 | ||||
| -rw-r--r-- | lualibs-lpeg.lua | 22 | ||||
| -rw-r--r-- | lualibs-string.lua | 7 | ||||
| -rw-r--r-- | lualibs-table.lua | 71 | ||||
| -rw-r--r-- | lualibs-unicode.lua | 12 | ||||
| -rw-r--r-- | lualibs-utils.lua | 11 | ||||
| -rw-r--r-- | lualibs.dtx | 25 | 
9 files changed, 135 insertions, 32 deletions
diff --git a/lualibs-dir.lua b/lualibs-dir.lua index 5828d99..2643f53 100644 --- a/lualibs-dir.lua +++ b/lualibs-dir.lua @@ -204,8 +204,9 @@ local make_indeed = true -- false  if string.find(os.getenv("PATH"),";") then -- os.type == "windows"      function dir.mkdirs(...) -        local str, pth = "", "" -        for _, s in ipairs({...}) do +        local str, pth, t = "", "", { ... } +        for i=1,#t do +            local s = t[i]              if s ~= "" then                  if str ~= "" then                      str = str .. "/" .. s @@ -303,8 +304,9 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows"  else      function dir.mkdirs(...) -        local str, pth = "", "" -        for _, s in ipairs({...}) do +        local str, pth, t = "", "", { ... } +        for i=1,#t do +            local s = t[i]              if s ~= "" then                  if str ~= "" then                      str = str .. "/" .. s diff --git a/lualibs-file.lua b/lualibs-file.lua index 6f5f5d0..2bfc070 100644 --- a/lualibs-file.lua +++ b/lualibs-file.lua @@ -297,7 +297,7 @@ function file.splitname(str) -- returns drive, path, base, suffix      return lpegmatch(pattern,str)  end --- function test(t) for k, v in pairs(t) do print(v, "=>", file.splitname(v)) end end +-- function test(t) for k, v in next, t do print(v, "=>", file.splitname(v)) end end  --  -- test { "c:", "c:/aa", "c:/aa/bb", "c:/aa/bb/cc", "c:/aa/bb/cc.dd", "c:/aa/bb/cc.dd.ee" }  -- test { "c:", "c:aa", "c:aa/bb", "c:aa/bb/cc", "c:aa/bb/cc.dd", "c:aa/bb/cc.dd.ee" } diff --git a/lualibs-io.lua b/lualibs-io.lua index 5a126da..66e2793 100644 --- a/lualibs-io.lua +++ b/lualibs-io.lua @@ -170,13 +170,14 @@ function io.ask(question,default,options)          elseif not options then              return answer          else -            for _,v in pairs(options) do -                if v == answer then +            for k=1,#options do +                if options[k] == answer then                      return answer                  end              end              local pattern = "^" .. answer -            for _,v in pairs(options) do +            for k=1,#options do +                local v = options[k]                  if find(v,pattern) then                      return v                  end diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index f060f3b..b107a8e 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -98,6 +98,15 @@ lpeg.splitat = splitat  local cache = { } +function lpeg.split(separator,str) +    local c = cache[separator] +    if not c then +        c = Ct(splitat(separator)) +        cache[separator] = c +    end +    return match(c,str) +end +  function string:split(separator)      local c = cache[separator]      if not c then @@ -107,8 +116,21 @@ function string:split(separator)      return match(c,self)  end +lpeg.splitters = cache +  local cache = { } +function lpeg.checkedsplit(separator,str) +    local c = cache[separator] +    if not c then +        separator = P(separator) +        local other = C((1 - separator)^0) +        c = Ct(separator^0 * other * (separator^1 * other)^0) +        cache[separator] = c +    end +    return match(c,str) +end +  function string:checkedsplit(separator)      local c = cache[separator]      if not c then diff --git a/lualibs-string.lua b/lualibs-string.lua index 25b8f8e..9856d52 100644 --- a/lualibs-string.lua +++ b/lualibs-string.lua @@ -230,7 +230,7 @@ function string:totable()      return lpegmatch(pattern,self)  end ---~ for _, str in ipairs { +--~ local t = {  --~     "1234567123456712345671234567",  --~     "a\tb\tc",  --~     "aa\tbb\tcc", @@ -238,7 +238,10 @@ end  --~     "aaaa\tbbbb\tcccc",  --~     "aaaaa\tbbbbb\tccccc",  --~     "aaaaaa\tbbbbbb\tcccccc", ---~ } do print(string.tabtospace(str)) end +--~ } +--~ for k,v do +--~     print(string.tabtospace(t[k])) +--~ end  function string.tabtospace(str,tab)      -- we don't handle embedded newlines diff --git a/lualibs-table.lua b/lualibs-table.lua index e8f72ed..ee395d0 100644 --- a/lualibs-table.lua +++ b/lualibs-table.lua @@ -11,8 +11,56 @@ table.join = table.concat  local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove  local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match  local getmetatable, setmetatable = getmetatable, setmetatable -local type, next, tostring, tonumber, ipairs, pairs = type, next, tostring, tonumber, ipairs, pairs -local unpack = unpack or table.unpack +local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs + +-- Starting with version 5.2 Lua no longer provide ipairs, which makes +-- sense. As we already used the for loop and # in most places the +-- impact on ConTeXt was not that large; the remaining ipairs already +-- have been replaced. In a similar fashio we also hardly used pairs. +-- +-- Just in case, we provide the fallbacks as discussed in Programming +-- in Lua (http://www.lua.org/pil/7.3.html): + +if not ipairs then + +    -- for k, v in ipairs(t) do                ... end +    -- for k=1,#t            do local v = t[k] ... end + +    local function iterate(a,i) +        i = i + 1 +        local v = a[i] +        if v ~= nil then +            return i, v --, nil +        end +    end + +    function ipairs(a) +        return iterate, a, 0 +    end + +end + +if not pairs then + +    -- for k, v in pairs(t) do ... end +    -- for k, v in next, t  do ... end + +    function pairs(t) +        return next, t -- , nil +    end + +end + +-- Also, unpack has been moved to the table table, and for compatiility +-- reasons we provide both now. + +if not table.unpack then +    table.unpack = _G.unpack +elseif not unpack then +    _G.unpack = table.unpack +end + +-- extra functions, some might go (when not used)  function table.strip(tab)      local lst = { } @@ -78,7 +126,7 @@ end  table.sortedkeys     = sortedkeys  table.sortedhashkeys = sortedhashkeys -function table.sortedpairs(t) +function table.sortedhash(t)      local s = sortedhashkeys(t) -- maybe just sortedkeys      local n = 0      local function kv(s) @@ -89,6 +137,8 @@ function table.sortedpairs(t)      return kv, s  end +table.sortedpairs = table.sortedhash +  function table.append(t, list)      for _,v in next, list do          insert(t,v) @@ -197,7 +247,7 @@ end  table.fastcopy = fastcopy  table.copy     = copy --- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) +-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)  function table.sub(t,i,j)      return { unpack(t,i,j) } @@ -211,18 +261,18 @@ end  -- slower than #t on indexed tables (#t only returns the size of the numerically indexed slice) -function table.is_empty(t) +function table.is_empty(t) -- obolete, use inline code instead      return not t or not next(t)  end -function table.one_entry(t) +function table.one_entry(t) -- obolete, use inline code instead      local n = next(t)      return n and not next(t,n)  end -function table.starts_at(t) -    return ipairs(t,1)(t,0) -end +--~ function table.starts_at(t) -- obsolete, not nice anyway +--~     return ipairs(t,1)(t,0) +--~ end  function table.tohash(t,value)      local h = { } @@ -326,7 +376,7 @@ local function do_serialize(root,name,depth,level,indexed)      end      -- we could check for k (index) being number (cardinal)      if root and next(root) then -        local first, last = nil, 0 -- #root cannot be trusted here +        local first, last = nil, 0 -- #root cannot be trusted here (will be ok in 5.2 when ipairs is gone)          if compact then              -- NOT: for k=1,#root do (we need to quit at nil)              for k,v in ipairs(root) do -- can we use next? @@ -857,3 +907,4 @@ function table.insert_after_value(t,value,extra)      end      insert(t,#t+1,extra)  end + diff --git a/lualibs-unicode.lua b/lualibs-unicode.lua index 290234d..0c5a601 100644 --- a/lualibs-unicode.lua +++ b/lualibs-unicode.lua @@ -48,14 +48,20 @@ unicode.utfname = {      [4] = 'utf-32-be'  } -function unicode.utftype(f) -- \000 fails ! +-- \000 fails in <= 5.0 but is valid in >=5.1 where %z is depricated + +function unicode.utftype(f)      local str = f:read(4)      if not str then          f:seek('set')          return 0 -    elseif find(str,"^%z%z\254\255") then + -- elseif find(str,"^%z%z\254\255") then            -- depricated + -- elseif find(str,"^\000\000\254\255") then        -- not permitted and bugged +    elseif find(str,"\000\000\254\255",1,true) then  -- seems to work okay (TH)          return 4 -    elseif find(str,"^\255\254%z%z") then + -- elseif find(str,"^\255\254%z%z") then            -- depricated + -- elseif find(str,"^\255\254\000\000") then        -- not permitted and bugged +    elseif find(str,"\255\254\000\000",1,true) then  -- seems to work okay (TH)          return 3      elseif find(str,"^\254\255") then          f:seek('set',2) diff --git a/lualibs-utils.lua b/lualibs-utils.lua index a5bc9d7..ebc27b8 100644 --- a/lualibs-utils.lua +++ b/lualibs-utils.lua @@ -10,6 +10,7 @@ if not modules then modules = { } end modules ['l-utils'] = {  local gsub = string.gsub  local concat = table.concat +local type, next = type, next  if not utils        then utils        = { } end  if not utils.merger then utils.merger = { } end @@ -85,9 +86,10 @@ function utils.merger._self_libs_(libs,list)      if type(libs) == 'string' then libs = { libs } end      if type(list) == 'string' then list = { list } end      local foundpath = nil -    for _, lib in ipairs(libs) do -        for _, pth in ipairs(list) do -            pth = gsub(pth,"\\","/") -- file.clean_path +    for i=1,#libs do +        local lib = libs[i] +        for j=1,#list do +            local pth = gsub(list[j],"\\","/") -- file.clean_path              utils.report("checking library path %s",pth)              local name = pth .. "/" .. lib              if lfs.isfile(name) then @@ -99,7 +101,8 @@ function utils.merger._self_libs_(libs,list)      if foundpath then          utils.report("using library path %s",foundpath)          local right, wrong = { }, { } -        for _, lib in ipairs(libs) do +        for i=1,#libs do +            local lib = libs[i]              local fullname = foundpath .. "/" .. lib              if lfs.isfile(fullname) then              --  right[#right+1] = lib diff --git a/lualibs.dtx b/lualibs.dtx index c34f8e3..97bce82 100644 --- a/lualibs.dtx +++ b/lualibs.dtx @@ -33,7 +33,7 @@  \input docstrip.tex  \Msg{************************************************************************}  \Msg{* Installation} -\Msg{* Package: lualibs 2010/01/11 v0.92 Lua additional functions.} +\Msg{* Package: lualibs 2010/05/21 v0.94 Lua additional functions.}  \Msg{************************************************************************}  \keepsilent @@ -90,7 +90,7 @@ and the derived file lualibs.lua.  %<*driver>  \NeedsTeXFormat{LaTeX2e}  \ProvidesFile{lualibs.drv} -  [2010/01/11 v0.92 Lua additional functions.] +  [2010/05/21 v0.94 Lua additional functions.]  \documentclass{ltxdoc}  \EnableCrossrefs  \CodelineIndex @@ -120,7 +120,7 @@ and the derived file lualibs.lua.  % \GetFileInfo{lualibs.drv}  %  % \title{The \textsf{lualibs} package} -% \date{2010/05/10 v0.93} +% \date{2010/05/21 v0.94}  % \author{Elie Roux \\ \texttt{elie.roux@telecom-bretagne.eu}}  %  % \maketitle @@ -172,8 +172,8 @@ module('lualibs', package.seeall)  do      local lualibs_module = {          name          = "lualibs", -        version       = 0.93, -        date          = "2010/05/10", +        version       = 0.94, +        date          = "2010/05/21",          description   = "Lua additional functions.",          author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux",          copyright     = "PRAGMA ADE / ConTeXt Development Team", @@ -402,6 +402,21 @@ end  %    \end{macrocode}  %  %    \end{macro} +%    \begin{macro}{table.starts_at} +% +% No idea what it was used for, but Hans depricated it with the comment +% \textit{obsolete, not nice anyway}, just restore it here until we have a +% process to deprecate unused functions like this. +% +%    \begin{macrocode} + +function table.starts_at(t) +    return ipairs(t,1)(t,0) +end + +%    \end{macrocode} +% +%    \end{macro}  %  % \iffalse  %</lua>  | 
