2 -- ion/share/ioncore_luaext.lua
4 -- Copyright (c) Tuomo Valkonen 2004-2006.
6 -- Ion is free software; you can redistribute it and/or modify it under
7 -- the terms of the GNU Lesser General Public License as published by
8 -- the Free Software Foundation; either version 2.1 of the License, or
9 -- (at your option) any later version.
14 -- Make \var{str} shell-safe.
15 function string.shell_safe(str)
16 return "'"..string.gsub(str, "'", "'\\''").."'"
21 -- Make copy of \var{table}. If \var{deep} is unset, shallow one-level
22 -- copy is made, otherwise a deep copy is made.
23 function table.copy(t, deep)
24 local function docopy(t, deep, seen)
26 for k, v in pairs(t) do
28 if deep and type(v)=="table" then
30 error(TR("Recursive table - unable to deepcopy"))
33 v2=docopy(v, deep, seen)
40 return docopy(t, deep, deep and {})
45 -- Add entries that do not exist in \var{t1} from \var{t2} to \var{t1}.
46 function table.append(t1, t2)
47 for k, v in pairs(t2) do
57 -- Create a table containing all entries from \var{t1} and those from
58 -- \var{t2} that are missing from \var{t1}.
59 function table.join(t1, t2)
60 return table.append(table.copy(t1, false), t2)
65 -- Insert all positive integer entries from t2 into t1.
66 function table.icat(t1, t2)
67 for _, v in ipairs(t2) do
75 -- Map all entries of \var{t} by \var{f}.
76 function table.map(f, t)
78 for k, v in pairs(t) do
86 -- Export a list of functions from \var{lib} into global namespace.
87 function export(lib, ...)
88 for k, v in pairs(arg) do