Update examples
This commit is contained in:
41
testsuite/shell/simple/Main.hs
Normal file
41
testsuite/shell/simple/Main.hs
Normal 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)
|
||||
|
||||
|
6
testsuite/shell/simple/Makefile
Normal file
6
testsuite/shell/simple/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
OBJS=StringProcessorAPI.o
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
||||
|
||||
#all:
|
||||
# @echo test disabled
|
5
testsuite/shell/simple/Plugin.hs
Normal file
5
testsuite/shell/simple/Plugin.hs
Normal file
@ -0,0 +1,5 @@
|
||||
import Char
|
||||
|
||||
resource = plugin {
|
||||
stringProcessor = map toUpper
|
||||
}
|
19
testsuite/shell/simple/Plugin.stub
Normal file
19
testsuite/shell/simple/Plugin.stub
Normal 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
|
||||
|
23
testsuite/shell/simple/README
Normal file
23
testsuite/shell/simple/README
Normal 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.
|
8
testsuite/shell/simple/StringProcessorAPI.hs
Normal file
8
testsuite/shell/simple/StringProcessorAPI.hs
Normal file
@ -0,0 +1,8 @@
|
||||
module StringProcessorAPI where
|
||||
|
||||
data Interface = Interface {
|
||||
stringProcessor :: String -> String
|
||||
}
|
||||
|
||||
plugin :: Interface
|
||||
plugin = Interface { stringProcessor = id }
|
0
testsuite/shell/simple/dont_test
Normal file
0
testsuite/shell/simple/dont_test
Normal file
Reference in New Issue
Block a user