mirror of https://github.com/koreader/koreader
parent
24d5c01a73
commit
34fd9f3efa
@ -0,0 +1,44 @@
|
||||
local DEBUG = require("dbg")
|
||||
-- lfs
|
||||
|
||||
local PluginLoader = {
|
||||
plugin_path = lfs.currentdir().."/plugins"
|
||||
}
|
||||
|
||||
function PluginLoader:loadPlugins()
|
||||
if self.plugins then return self.plugins end
|
||||
|
||||
self.plugins = {}
|
||||
for f in lfs.dir(self.plugin_path) do
|
||||
local path = self.plugin_path.."/"..f
|
||||
local mode = lfs.attributes(path, "mode")
|
||||
-- valid koreader plugin directory
|
||||
if mode == "directory" and f:find(".+%.koplugin$") then
|
||||
local mainfile = path.."/".."main.lua"
|
||||
local package_path = package.path
|
||||
local package_cpath = package.cpath
|
||||
package.path = path.."/?.lua;"..package.path
|
||||
package.cpath = path.."/lib/?.so;"..package.cpath
|
||||
local ok, module = pcall(require, "main")
|
||||
if not ok then
|
||||
DEBUG("Error when loading", mainfile, module)
|
||||
end
|
||||
package.path = package_path
|
||||
package.cpath = package_cpath
|
||||
if ok then
|
||||
module.path = path
|
||||
table.insert(self.plugins, module)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _,plugin in ipairs(self.plugins) do
|
||||
package.path = package.path..";"..plugin.path.."/?.lua"
|
||||
package.cpath = package.cpath..";"..plugin.path.."/lib/?.so"
|
||||
end
|
||||
|
||||
return self.plugins
|
||||
end
|
||||
|
||||
return PluginLoader
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Loading…
Reference in New Issue