--- /dev/null
+-- lib/import.lua
+--
+-- import returns some or all definitions from file
+-- global_import defines some or all definitions from file globally
+--
+-- examples:
+-- local lib = import "library.lua" {} -- same as local lib = dofile "library.lua"
+-- local lib = import "library.lua" { "foo", "bar", } -- defines lib.foo and lib.bar
+-- import_global "module.lua" { "baz" } -- defines baz globally
+-- mod = import_global "module.lua" { "baz" } -- defines mod.baz globally
+
+import = function(path)
+ return function(list)
+ local m = dofile(path)
+ if #list == 0 then
+ return m
+ else
+ local d = {}
+ for _, k in ipairs(list) do d[k] = m[k] end
+ return d
+ end
+ end
+end
+
+
+global_import = function(path)
+ return function(list)
+ for k, v in pairs(import(path)(list)) do _G[k] = v end
+ end
+end
--- /dev/null
+local log = {}
+
+-- printing
+-- log.enable_printing = false
+-- log.print_format = function() end
+-- log.print = function(...) print(...) end
+
+
+-- inserting
+log.on_insert = nil -- function to run on entry on insertion
+log.insert = function(self, status, a)
+ local entry = { epoch = os.epoch("local")/1000, status = status, entry = a }
+ table.insert(self, 1, entry)
+ if self.on_insert then self.on_insert(entry) end
+ return entry
+end
+log.ok = function(self, str) return self:insert("ok", str) end
+log.warn = function(self, str) return self:insert("warn", str) end
+log.err = function(self, str) return self:insert("err", str) end
+
+log.pwarn = function(self, warning, f, ...)
+ local ok, err = pcall(f, ...)
+ if not ok then self:warn(warning..": "..err) end
+ return ok
+end
+
+log.perr = function(self, warning, f, ...)
+ local ok, err = pcall(f, ...)
+ if not ok then self:err(warning..": "..err) end
+ return ok
+end
+
+log.queue_event = function(event)
+ return function(entry)
+ os.queueEvent(event, entry.epoch, entry.status, entry.entry)
+ end
+end
+
+
+-- viewing
+log.view = function(self, i)
+ if i then
+ self.print(self.print_format(self[i]))
+ else
+ for _,t in ipairs(self) do
+ self.print(self.print_format(t))
+ end
+ end
+end
+
+return log