1-- license:BSD-3-Clause 2-- copyright-holders:Miodrag Milanovic 3require('lfs') 4 5-- add helper to lfs for plugins to use 6function lfs.env_replace(str) 7 local pathsep = package.config:sub(1,1) 8 local function dorep(val) 9 ret = os.getenv(val) 10 if ret then 11 return ret 12 end 13 return val 14 end 15 16 if pathsep == '\\' then 17 str = str:gsub("%%([%w_]+)%%", dorep) 18 else 19 str = str:gsub("%$([%w_]+)", dorep) 20 end 21 return str 22end 23 24_G._ = emu.lang_translate 25_G.emu.plugin = {} -- table to contain plugin interfaces 26-- substitute environment variables in the plugins path from options 27local dirs = lfs.env_replace(manager:options().entries.pluginspath:value()) 28 29-- and split the paths apart and make them suitable for package.path 30package.path = "" 31for dir in string.gmatch(dirs, "([^;]+)") do 32 if (package.path ~= "") then 33 package.path = package.path .. ";" 34 end 35 package.path = package.path .. dir .. "/?.lua;" .. dir .. "/?/init.lua" 36end 37 38for _,entry in pairs(manager:plugins()) do 39 if (entry.type == "plugin" and entry.start) then 40 emu.print_verbose("Starting plugin " .. entry.name .. "...") 41 plugin = require(entry.name) 42 if plugin.set_folder~=nil then plugin.set_folder(entry.directory) end 43 plugin.startplugin(); 44 end 45end 46