Example program for 'unloadAll'.
This commit is contained in:
parent
fc58e81ed6
commit
7dbaf7fe88
7
examples/unloadAll/null/Dep.hs
Normal file
7
examples/unloadAll/null/Dep.hs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module Dep ( resource ) where
|
||||||
|
|
||||||
|
import API
|
||||||
|
import Data.Dynamic
|
||||||
|
import Prelude hiding (null)
|
||||||
|
|
||||||
|
resource = null
|
4
examples/unloadAll/null/Makefile
Normal file
4
examples/unloadAll/null/Makefile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
TEST= unloadAll/null
|
||||||
|
EXTRA_OBJS=Null.o Dep.o
|
||||||
|
TOP=../../..
|
||||||
|
include ../../build.mk
|
12
examples/unloadAll/null/Null.hs
Normal file
12
examples/unloadAll/null/Null.hs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module Null ( resource ) where
|
||||||
|
|
||||||
|
import API
|
||||||
|
import Data.Dynamic
|
||||||
|
import Prelude hiding (null)
|
||||||
|
import qualified Dep
|
||||||
|
|
||||||
|
resource = Dep.resource
|
||||||
|
|
||||||
|
-- ! this has to be special: it can't be overridden by the user.
|
||||||
|
resource_dyn :: Dynamic
|
||||||
|
resource_dyn = toDyn resource
|
12
examples/unloadAll/null/api/API.hs
Normal file
12
examples/unloadAll/null/api/API.hs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{-# OPTIONS -fglasgow-exts #-}
|
||||||
|
|
||||||
|
module API where
|
||||||
|
|
||||||
|
import Data.Dynamic
|
||||||
|
|
||||||
|
data Null = Null { a, b :: Int }
|
||||||
|
deriving (Typeable, Show)
|
||||||
|
|
||||||
|
null :: Null
|
||||||
|
null = Null { a = 42 , b = 1 }
|
||||||
|
|
15
examples/unloadAll/null/prog/Main.hs
Normal file
15
examples/unloadAll/null/prog/Main.hs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
import System.Plugins
|
||||||
|
import API
|
||||||
|
|
||||||
|
-- an example where we just want to load an object and run it
|
||||||
|
|
||||||
|
main = do
|
||||||
|
m_v <- load_ "../Null.o" ["../api",".."] "resource"
|
||||||
|
t <- load_ "../Dep.o" ["../api"] "resource"
|
||||||
|
case m_v of
|
||||||
|
LoadFailure err -> error (unlines err)
|
||||||
|
LoadSuccess m v -> do putStrLn ( show (a v) ) ; unloadAll m
|
||||||
|
case t of
|
||||||
|
LoadFailure err -> error (unlines err)
|
||||||
|
LoadSuccess m v -> do putStrLn ( show (a v) ) ; unloadAll m
|
2
examples/unloadAll/null/prog/expected
Normal file
2
examples/unloadAll/null/prog/expected
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
42
|
||||||
|
42
|
Loading…
x
Reference in New Issue
Block a user