module Metaplug.Eval (eval) where import Metaplug.Initialize import System.Directory import System.FilePath import Metaplug.Loader import Metaplug.Types import Data.Typeable import System.IO import GHC tmpsym = "eval" eval :: (Typeable a) => String -> FilePath -> IO a eval str lp = do -- setup our file, for starters tmpd <- getTemporaryDirectory (f,h) <- openTempFile tmpd "Eval.hs" hClose h sym <- initFile f str -- get our Dynamic and whatnot s <- (initSession lp [] InteractiveMode >>= loadFiles [f]) e <- compileCall sym s -- delete and return removeFile f return e where initFile :: FilePath -> String -> IO String initFile f str = do let x = takeBaseName f writeFile f $ "module "++x++" where\n" appendFile f $ tmpsym++" = "++str++"\n" return $ x++"."++tmpsym