Update examples

This commit is contained in:
Don Stewart
2005-09-03 04:45:14 +00:00
parent 5321754614
commit dff0363224
421 changed files with 19 additions and 9 deletions

View File

@ -0,0 +1,41 @@
import System.Plugins
import StringProcessorAPI
import System.Console.Readline
import System.Exit
source = "Plugin.hs"
stub = "Plugin.stub"
symbol = "resource"
main = do s <- makeWith source stub []
o <- case s of
MakeSuccess _ obj -> do
ls <- load obj ["."] [] symbol
case ls of LoadSuccess m v -> return (m,v)
LoadFailure err -> error "load failed"
MakeFailure e -> mapM_ putStrLn e >> error "compile failed"
shell o
shell o@(m,plugin) = do
s <- readline "> "
cmd <- case s of
Nothing -> exitWith ExitSuccess
Just (':':'q':_) -> exitWith ExitSuccess
Just s -> addHistory s >> return s
s <- makeWith source stub [] -- maybe recompile the source
o' <- case s of
MakeSuccess ReComp o -> do
ls <- reload m symbol
case ls of LoadSuccess m' v' -> return (m',v')
LoadFailure err -> error "reload failed"
MakeSuccess NotReq _ -> return o
MakeFailure e -> mapM_ putStrLn e >> shell o
eval cmd o'
shell o'
eval ":?" _ = putStrLn ":?\n:q\n<string>"
eval s (_,plugin) = let fn = (stringProcessor plugin) in putStrLn (fn s)

View File

@ -0,0 +1,6 @@
OBJS=StringProcessorAPI.o
TOP=../../..
include ../../eval.mk
#all:
# @echo test disabled

View File

@ -0,0 +1,5 @@
import Char
resource = plugin {
stringProcessor = map toUpper
}

View File

@ -0,0 +1,19 @@
--
-- this is a "stub" file, containing default syntax we don't
-- want the user to have to write
--
-- for example, it constrains the module name and force the API to be
-- imported
module Plugin ( resource ) where
import StringProcessorAPI
import Data.Char
import Data.List
-- this is a default definition of 'resource'. it will be overridden
-- by anything the user writes. useful for default values
resource :: Interface
resource = plugin

View File

@ -0,0 +1,23 @@
$ make
$ ./a.out
Compiling plugin ... done
Loading package base ... linking ... done
Loading objects API Plugin ... done
> ?
"?"
"quit"
"clear"
"filter foo"
> filter adf adsf
fsda fda
> filter asd faSDFADSF
FSDAFDSaf dsa
-- at this point I edit the plugin and save the source
> filter asfdaSDFASD
Compiling plugin ... done
Reloading Plugin ... done
DSAFDSADFSA
-- it compiled and reloaded it for me. nice.

View File

@ -0,0 +1,8 @@
module StringProcessorAPI where
data Interface = Interface {
stringProcessor :: String -> String
}
plugin :: Interface
plugin = Interface { stringProcessor = id }

View File