
Hi, I would like to use the API for ghc, so that a running program can load a module (Foo.o) and use a function defined in that module. From the documentation available, it seems like thatś possible, but I can´t figure out how to do it. There is an example on the wiki, but the explanation just says the code is equivalent to ghc --make. That example does indeed work, but there is no hint as to whether the running program can then access anything defined in the module it has just loaded. Is there any available documentation on how to load a plugin, or any working example somewhere? Thanks in advance, John O´Donnell

John O'Donnell wrote:
Hi,
I would like to use the API for ghc, so that a running program can load a module (Foo.o) and use a function defined in that module. From the documentation available, it seems like thatś possible, but I can´t figure out how to do it. There is an example on the wiki, but the explanation just says the code is equivalent to ghc --make. That example does indeed work, but there is no hint as to whether the running program can then access anything defined in the module it has just loaded.
Is there any available documentation on how to load a plugin, or any working example somewhere?
Hi John, Once you have your module loaded, you can call dynCompileExpr :: GhcMonad m => String -> m Dynamic to compile an arbitrary expression, yielding a Dynamic value that you can cast to the appropriate type. Cheers, Simon

John O'Donnell wrote:
That example does indeed work, but there is no hint as to whether the running program can then access anything defined in the module it has just loaded.
I think the running program can only access things *exported* from the module (other functions in that module might even have been optimized away!).... Is it okay to require those plugin-modules to export everything you're going to use from them? -Isaac
participants (3)
-
Isaac Dupree
-
John O'Donnell
-
Simon Marlow