buildat/client/extensions.lua

36 lines
1.0 KiB
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
-- Don't use package.loaders because for whatever reason it doesn't work in the
-- Windows version at least in Wine
local old_require = require
function require(name)
log:debug("require 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 __buildat_load_extension(m)
2014-09-19 11:29:23 +03:00
end
return old_require(name)
end
-- vim: set noet ts=4 sw=4: