我一直在玩插件包.我希望主机应用程序在沙盒环境中动态编译和加载Haskell源文件.编译工作正常.只要插件仅引用沙箱中可用的模块,加载就会失败.这是我为插件所获得的:
module Plugin (resource) where
import ServerAPI
import System.Plugins -- this module is only available in the sandbox
resource = Interface { action = timesTwo }
timesTwo :: Integer -> IO Integer
timesTwo n = return $ n * 2
Run Code Online (Sandbox Code Playgroud)
从宿主应用程序加载插件如下所示:
pkgConfDir = "/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
loadedOk <- pdynload "Plugin.o" ["."] [pkgConfDir] "ServerAPI.Interface" "resource"
Run Code Online (Sandbox Code Playgroud)
这就是我在沙盒中得到的:
> cabal sandbox hc-pkg list
…
/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
plugins-1.5.4.0
…
Run Code Online (Sandbox Code Playgroud)
这是我在运行主机应用程序时得到的:
Failed to load interface for ‘System.Plugins.Env’
no package matching ‘plugins-1.5.4.0’ was found
Run Code Online (Sandbox Code Playgroud)
如上所述,当我摆脱import System.Plugins …