-- Class helper routines
--
+-- Instantiates a class
+local function _instantiate(class, ...)
+ local inst = setmetatable({}, {__index = class})
+
+ if inst.__init__ then
+ inst:__init__(...)
+ end
+
+ return inst
+end
+
--- Create a Class object (Python-style object model).
-- The class object can be instantiated by calling itself.
-- Any class functions or shared parameters can be attached to this object.
-- @see instanceof
-- @see clone
function class(base)
- local class = {}
-
- local create = function(class, ...)
- local inst = setmetatable({}, {__index = class})
-
- if inst.__init__ then
- inst:__init__(...)
- end
-
- return inst
- end
-
- local classmeta = {__call = create}
-
- if base then
- classmeta.__index = base
- end
-
- setmetatable(class, classmeta)
- return class
+ return setmetatable({}, {
+ __call = _instantiate,
+ __index = base
+ })
end
--- Test whether the given object is an instance of the given class.
-- @param value String value containing the data to escape
-- @return String value containing the escaped data
function pcdata(value)
- if not value then return end
- value = tostring(value)
- value = value:gsub("&", "&")
- value = value:gsub('"', """)
- value = value:gsub("'", "'")
- value = value:gsub("<", "<")
- return value:gsub(">", ">")
+ return value and tostring(value):gsub("[&\"'<>]", {
+ ["&"] = "&",
+ ['"'] = """,
+ ["'"] = "'",
+ ["<"] = "<",
+ [">"] = ">"
+ })
end
--- Strip HTML tags from given string.
local s, e = str:find(pat, c, not regex)
max = max - 1
if s and max < 0 then
- table.insert(t, str:sub(c))
+ t[#t+1] = str:sub(c)
else
- table.insert(t, str:sub(c, s and s - 1))
+ t[#t+1] = str:sub(c, s and s - 1)
end
c = e and e + 1 or #str + 1
until not s or max < 0
local result = {}
for i, a in ipairs(arg) do
for j, v in ipairs(a) do
- table.insert(result, v)
+ result[#result+1] = v
end
end
return result
local keys = { }
if t then
for k, _ in kspairs(t) do
- table.insert( keys, k )
+ keys[#keys+1] = k
end
end
return keys
local keys = { }
for k, v in pairs(t) do
- table.insert( keys, k )
+ keys[#keys+1] = k
end
local _pos = 0
- local _len = table.getn( keys )
table.sort( keys, f )
return function()
_pos = _pos + 1
- if _pos <= _len then
+ if _pos <= #keys then
return keys[_pos], t[keys[_pos]]
end
end
while true do
line = pp:read()
if (line == nil) then break end
- table.insert(data, line)
+ data[#data+1] = line
end
pp:close()
local function helper (section)
if not comparator or comparator(section) then
- table.insert(del, section[".name"])
+ del[#del+1] = section[".name"]
end
end
function(section)
if section.affects then
for i, aff in ipairs(section.affects) do
- table.insert(deps, aff)
+ deps[#deps+1] = aff
end
end
end)
for i, dep in ipairs(deps) do
for j, add in ipairs(_resolve_deps(dep)) do
- table.insert(reload, add)
+ reload[#reload+1] = add
end
end
for j, config in ipairs(configlist) do
for i, e in ipairs(_resolve_deps(config)) do
if not util.contains(reloadlist, e) then
- table.insert(reloadlist, e)
+ reloadlist[#reloadlist+1] = e
end
end
end