2014-09-21 01:20:43 +03:00
|
|
|
-- Buildat: client/extensions.lua
|
|
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
-- Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
2014-09-19 14:50:25 +03:00
|
|
|
local log = buildat.Logger("__client/extensions")
|
2014-09-19 11:29:23 +03:00
|
|
|
|
|
|
|
function __buildat_load_extension(name)
|
|
|
|
log:info("__buildat_load_extension(\""..name.."\")")
|
2014-09-27 07:44:54 +03:00
|
|
|
local path = __buildat_extension_path(name).."/init.lua"
|
2014-09-21 11:12:19 +03:00
|
|
|
local script, err = loadfile(path)
|
2014-09-21 10:18:11 +03:00
|
|
|
if script == nil then
|
2014-09-21 11:12:19 +03:00
|
|
|
log:error("Extension could not be opened: "..name.." at "..path..": "..err)
|
2014-09-21 10:18:11 +03:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local interface = script()
|
|
|
|
if interface == nil then
|
2014-09-21 11:12:19 +03:00
|
|
|
log:error("Extension returned nil: "..name.." at "..path)
|
2014-09-21 10:18:11 +03:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return interface
|
2014-09-19 11:29:23 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(package.loaders, function(name)
|
|
|
|
log:info("package.loader called with name=\""..name.."\"")
|
|
|
|
local m = string.match(name, '^buildat/extension/([a-zA-Z0-9_]+)$')
|
|
|
|
if m then
|
|
|
|
return function()
|
|
|
|
return __buildat_load_extension(m)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end)
|
2014-09-24 15:13:49 +03:00
|
|
|
-- vim: set noet ts=4 sw=4:
|