2 -- ion/share/ioncore_luaext.lua
4 -- Copyright (c) Tuomo Valkonen 2004-2007.
6 -- See the included file LICENSE for details.
11 -- Make \var{str} shell-safe.
12 function string.shell_safe(str)
13 return "'"..string.gsub(str, "'", "'\\''").."'"
18 -- Make copy of \var{table}. If \var{deep} is unset, shallow one-level
19 -- copy is made, otherwise a deep copy is made.
20 function table.copy(t, deep)
21 local function docopy(t, deep, seen)
23 for k, v in pairs(t) do
25 if deep and type(v)=="table" then
27 error(TR("Recursive table - unable to deepcopy"))
30 v2=docopy(v, deep, seen)
37 return docopy(t, deep, deep and {})
42 -- Add entries that do not exist in \var{t1} from \var{t2} to \var{t1}.
43 function table.append(t1, t2)
44 for k, v in pairs(t2) do
54 -- Create a table containing all entries from \var{t1} and those from
55 -- \var{t2} that are missing from \var{t1}.
56 function table.join(t1, t2)
57 return table.append(table.copy(t1, false), t2)
62 -- Insert all positive integer entries from t2 into t1.
63 function table.icat(t1, t2)
64 for _, v in ipairs(t2) do
72 -- Map all entries of \var{t} by \var{f}.
73 function table.map(f, t)
75 for k, v in pairs(t) do
83 -- Export a list of functions from \var{lib} into global namespace.
84 function export(lib, ...)
85 for k, v in pairs(arg) do