Import hs-plugins cvs
This commit is contained in:
		
							
								
								
									
										5
									
								
								examples/makewith/unsafeio/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								examples/makewith/unsafeio/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
 | 
			
		||||
TEST=makewith/unsafeio
 | 
			
		||||
 | 
			
		||||
TOP=../../..
 | 
			
		||||
include ../../build.mk
 | 
			
		||||
							
								
								
									
										3
									
								
								examples/makewith/unsafeio/README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								examples/makewith/unsafeio/README
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
hmm. on 6.3  we need to add 'mtl' to a package dependency, other
 | 
			
		||||
HSlang complains of a missing symbol. Is this a bug in the
 | 
			
		||||
package.conf for HSlang?
 | 
			
		||||
							
								
								
									
										17
									
								
								examples/makewith/unsafeio/Unsafe.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								examples/makewith/unsafeio/Unsafe.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
{-# GLOBALOPTIONS -package posix #-}
 | 
			
		||||
-- illustrates the use of static options in pragmas
 | 
			
		||||
 | 
			
		||||
import System.IO.Unsafe
 | 
			
		||||
import System.IO
 | 
			
		||||
import System.Process
 | 
			
		||||
 | 
			
		||||
resource = unsafe { field = date }
 | 
			
		||||
 | 
			
		||||
-- illustrates the use of the devil's work
 | 
			
		||||
date :: String
 | 
			
		||||
date = unsafePerformIO $ do
 | 
			
		||||
            (_,outh,_,proc) <- runInteractiveProcess "date" [] Nothing Nothing		
 | 
			
		||||
    	    waitForProcess proc
 | 
			
		||||
            s <- hGetContents outh
 | 
			
		||||
            return s
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								examples/makewith/unsafeio/Unsafe.stub
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								examples/makewith/unsafeio/Unsafe.stub
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
 | 
			
		||||
module Unsafe ( resource, resource_dyn )  where
 | 
			
		||||
 | 
			
		||||
import API
 | 
			
		||||
import Data.Dynamic
 | 
			
		||||
 | 
			
		||||
resource = unsafe
 | 
			
		||||
 | 
			
		||||
--
 | 
			
		||||
-- special
 | 
			
		||||
--
 | 
			
		||||
resource_dyn :: Dynamic
 | 
			
		||||
resource_dyn = toDyn resource
 | 
			
		||||
							
								
								
									
										13
									
								
								examples/makewith/unsafeio/api/API.hs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								examples/makewith/unsafeio/api/API.hs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
{-# OPTIONS -fglasgow-exts #-}
 | 
			
		||||
 | 
			
		||||
module API where
 | 
			
		||||
 | 
			
		||||
import Data.Dynamic
 | 
			
		||||
 | 
			
		||||
data Unsafe = Unsafe { 
 | 
			
		||||
                field :: String 
 | 
			
		||||
        }
 | 
			
		||||
   deriving (Typeable, Show)
 | 
			
		||||
 | 
			
		||||
unsafe :: Unsafe
 | 
			
		||||
unsafe = Unsafe { field = "default value" }
 | 
			
		||||
							
								
								
									
										20
									
								
								examples/makewith/unsafeio/prog/Main.hs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								examples/makewith/unsafeio/prog/Main.hs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
			
		||||
import Plugins
 | 
			
		||||
import API
 | 
			
		||||
import Data.Either
 | 
			
		||||
 | 
			
		||||
conf    = "../Unsafe.conf"
 | 
			
		||||
stub    = "../Unsafe.stub"
 | 
			
		||||
apipath = "../api"
 | 
			
		||||
 | 
			
		||||
main = do
 | 
			
		||||
        status <- makeWith conf stub ["-i"++apipath]
 | 
			
		||||
        o <- case status of
 | 
			
		||||
                MakeFailure e -> mapM_ putStrLn e >> error "failed"
 | 
			
		||||
                MakeSuccess _ o -> return o
 | 
			
		||||
        m_v   <- load o [apipath] [] "resource"
 | 
			
		||||
        v <- case m_v of
 | 
			
		||||
            LoadSuccess _ v -> return v
 | 
			
		||||
            _               -> error "load failed"
 | 
			
		||||
        let s = field v
 | 
			
		||||
        makeCleaner o
 | 
			
		||||
        if null s then print False else print True
 | 
			
		||||
							
								
								
									
										8
									
								
								examples/makewith/unsafeio/prog/README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								examples/makewith/unsafeio/prog/README
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
this is an example of an application that uses the HSConf library to
 | 
			
		||||
dynamically load compiled conf files.
 | 
			
		||||
 | 
			
		||||
We use the .conf file in the parent directory, and communicate with
 | 
			
		||||
the plugin via the API in the api_package/ directory.
 | 
			
		||||
 | 
			
		||||
The plugin is a .o file
 | 
			
		||||
The api is a GHC package archive
 | 
			
		||||
							
								
								
									
										1
									
								
								examples/makewith/unsafeio/prog/expected
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								examples/makewith/unsafeio/prog/expected
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
True
 | 
			
		||||
		Reference in New Issue
	
	Block a user