2011-08-20 22:30:41 +02:00
|
|
|
function print(...)
|
|
|
|
local msg = ""
|
|
|
|
for i,v in ipairs(arg) do
|
|
|
|
msg = msg .. tostring(v) .. "\t"
|
|
|
|
end
|
|
|
|
Logger.log(LogInfo, msg)
|
2011-08-21 03:01:46 +02:00
|
|
|
end
|
|
|
|
|
2011-12-07 01:31:55 +01:00
|
|
|
function fatal(msg)
|
|
|
|
Logger.log(LogFatal, msg)
|
2011-08-29 21:35:58 +02:00
|
|
|
end
|
|
|
|
|
2011-12-05 19:27:07 +01:00
|
|
|
function connect(object, signalsAndSlots, pushFront)
|
2011-08-29 21:35:58 +02:00
|
|
|
for signal,slot in pairs(signalsAndSlots) do
|
|
|
|
if not object[signal] then
|
|
|
|
object[signal] = slot
|
|
|
|
elseif type(object[signal]) == 'function' then
|
|
|
|
object[signal] = { object[signal], slot }
|
2011-11-03 21:54:53 +01:00
|
|
|
elseif type(object[signal]) == 'table' then
|
2011-12-05 19:27:07 +01:00
|
|
|
if pushFront then
|
|
|
|
table.insert(object[signal], 1, slot)
|
|
|
|
else
|
|
|
|
table.insert(object[signal], #object[signal]+1, slot)
|
|
|
|
end
|
2011-08-29 21:35:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-11-01 19:32:48 +01:00
|
|
|
|
2011-12-07 01:31:55 +01:00
|
|
|
function createEnvironment()
|
|
|
|
local env = { }
|
|
|
|
setmetatable(env, { __index = _G} )
|
|
|
|
return env
|
2011-11-01 19:32:48 +01:00
|
|
|
end
|
2011-11-17 21:40:31 +01:00
|
|
|
|
2011-12-30 07:05:32 +01:00
|
|
|
function getCallingScriptSourcePath(depth)
|
|
|
|
depth = depth or 2
|
|
|
|
local info = debug.getinfo(1+depth, "Sn")
|
|
|
|
local path
|
|
|
|
if info.short_src then
|
|
|
|
path = info.short_src:match("(.*)/.*")
|
|
|
|
end
|
|
|
|
if not path then
|
|
|
|
path = '/'
|
|
|
|
elseif path:sub(0, 1) ~= '/' then
|
|
|
|
path = '/' .. path
|
|
|
|
end
|
|
|
|
return path
|
|
|
|
end
|
|
|
|
|
2011-11-17 21:40:31 +01:00
|
|
|
function resolveFileFullPath(filePath, depth)
|
|
|
|
depth = depth or 1
|
|
|
|
if filePath:sub(0, 1) ~= '/' then
|
2011-12-30 07:05:32 +01:00
|
|
|
return getCallingScriptSourcePath(depth+1) .. '/' .. filePath
|
2011-11-17 21:40:31 +01:00
|
|
|
else
|
|
|
|
return filePath
|
|
|
|
end
|
|
|
|
end
|
2011-12-28 20:38:29 +01:00
|
|
|
|
|
|
|
function extends(base)
|
|
|
|
local derived = {}
|
|
|
|
function derived.internalCreate()
|
|
|
|
local instance = base.create()
|
|
|
|
for k,v in pairs(derived) do
|
|
|
|
instance[k] = v
|
|
|
|
end
|
|
|
|
return instance
|
|
|
|
end
|
|
|
|
derived.create = derived.internalCreate
|
|
|
|
return derived
|
|
|
|
end
|
|
|
|
|