Update examples
This commit is contained in:
4
testsuite/dynload/simple/Makefile
Normal file
4
testsuite/dynload/simple/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST=dynload/simple
|
||||
EXTRA_OBJS=Plugin.o
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
11
testsuite/dynload/simple/Plugin.hs
Normal file
11
testsuite/dynload/simple/Plugin.hs
Normal file
@ -0,0 +1,11 @@
|
||||
{-# OPTIONS -fglasgow-exts #-}
|
||||
module Plugin where
|
||||
|
||||
import API
|
||||
import AltData.Dynamic
|
||||
|
||||
my_fun = plugin { function = "plugin says \"hello\"" }
|
||||
|
||||
resource_dyn :: Dynamic
|
||||
resource_dyn = toDyn my_fun
|
||||
|
20
testsuite/dynload/simple/api/API.hs
Normal file
20
testsuite/dynload/simple/api/API.hs
Normal file
@ -0,0 +1,20 @@
|
||||
{-# OPTIONS -cpp #-}
|
||||
|
||||
module API where
|
||||
|
||||
import AltData.Typeable
|
||||
|
||||
data Interface = Interface {
|
||||
function :: String
|
||||
}
|
||||
|
||||
instance Typeable Interface where
|
||||
#if __GLASGOW_HASKELL__ >= 603
|
||||
typeOf i = mkTyConApp (mkTyCon "API.Interface") []
|
||||
#else
|
||||
typeOf i = mkAppTy (mkTyCon "API.Interface") []
|
||||
#endif
|
||||
|
||||
plugin :: Interface
|
||||
plugin = Interface { function = "goodbye" }
|
||||
|
15
testsuite/dynload/simple/prog/Main.hs
Normal file
15
testsuite/dynload/simple/prog/Main.hs
Normal file
@ -0,0 +1,15 @@
|
||||
{-# OPTIONS -cpp #-}
|
||||
|
||||
#include "../../../../config.h"
|
||||
|
||||
import System.Plugins
|
||||
import API
|
||||
|
||||
main = do
|
||||
m_v <- dynload "../Plugin.o" ["../api"]
|
||||
[]
|
||||
"resource_dyn"
|
||||
case m_v of
|
||||
LoadFailure _ -> error "didn't compile"
|
||||
LoadSuccess _ v -> putStrLn $ (function v)
|
||||
|
1
testsuite/dynload/simple/prog/expected
Normal file
1
testsuite/dynload/simple/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
plugin says "hello"
|
Reference in New Issue
Block a user