diff --git a/examples/loadCLib/null/Makefile b/examples/loadCLib/null/Makefile new file mode 100644 index 0000000..83999ad --- /dev/null +++ b/examples/loadCLib/null/Makefile @@ -0,0 +1,4 @@ +TEST= unloadAll/null +EXTRA_OBJS=Null.o Dep.o +TOP=../../.. +include ../../build.mk diff --git a/examples/loadCLib/null/Null.hs b/examples/loadCLib/null/Null.hs new file mode 100644 index 0000000..3c2a142 --- /dev/null +++ b/examples/loadCLib/null/Null.hs @@ -0,0 +1,12 @@ +module Null ( resource ) where + +import API +import Data.Dynamic +import Prelude hiding (null) +import Graphics.Rendering.OpenGL + +resource = null + +-- ! this has to be special: it can't be overridden by the user. +resource_dyn :: Dynamic +resource_dyn = toDyn resource diff --git a/examples/loadCLib/null/api/API.hs b/examples/loadCLib/null/api/API.hs new file mode 100644 index 0000000..a77126c --- /dev/null +++ b/examples/loadCLib/null/api/API.hs @@ -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 } + diff --git a/examples/loadCLib/null/prog/Main.hs b/examples/loadCLib/null/prog/Main.hs new file mode 100644 index 0000000..62e7b90 --- /dev/null +++ b/examples/loadCLib/null/prog/Main.hs @@ -0,0 +1,11 @@ + +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" + case m_v of + LoadFailure err -> error (unlines err) + LoadSuccess m v -> do putStrLn ( show (a v) ) ; unload m diff --git a/examples/loadCLib/null/prog/expected b/examples/loadCLib/null/prog/expected new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/examples/loadCLib/null/prog/expected @@ -0,0 +1 @@ +42 diff --git a/examples/unloadAll/null/prog/Main.hs b/examples/unloadAll/null/prog/Main.hs index b8fd0bb..5477edc 100644 --- a/examples/unloadAll/null/prog/Main.hs +++ b/examples/unloadAll/null/prog/Main.hs @@ -9,7 +9,7 @@ main = do 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 + LoadSuccess m v -> do putStrLn ( show (a v) ) ; unloadAll m -- unloads Null.o but not Dep.o since we're still using it. case t of LoadFailure err -> error (unlines err) LoadSuccess m v -> do putStrLn ( show (a v) ) ; unloadAll m