buildat/client/extensions.lua

33 lines
950 B
Lua
Raw Normal View History

-- 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)
2014-09-28 00:44:45 +03:00
log:debug("__buildat_load_extension(\""..name.."\")")
2014-09-27 07:44:54 +03:00
local path = __buildat_extension_path(name).."/init.lua"
local script, err = loadfile(path)
if script == nil then
log:error("Extension could not be opened: "..name.." at "..path..": "..err)
return nil
end
local interface = script()
if interface == nil then
log:error("Extension returned nil: "..name.." at "..path)
return nil
end
return interface
2014-09-19 11:29:23 +03:00
end
table.insert(package.loaders, 1, function(name)
2014-09-28 00:44:45 +03:00
log:debug("package.loader called with name=\""..name.."\"")
2014-09-19 11:29:23 +03:00
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)
-- vim: set noet ts=4 sw=4: