The core of Yogurt, consisting of the Mud monad and all functions manipulating this monad.
- type Mud = StateT MudState IO
- data MudState
- type RunMud = forall a. Mud a -> IO a
- type Output = Destination -> String -> IO ()
- data Hook
- data Destination
- type Pattern = String
- data Var a
- emptyMud :: RunMud -> Output -> MudState
- runMud :: MVar MudState -> RunMud
- mkHook :: Destination -> Pattern -> Mud a -> Mud Hook
- mkPrioHook :: Int -> Destination -> Pattern -> Mud a -> Mud Hook
- setHook :: Hook -> Mud ()
- rmHook :: Hook -> Mud ()
- allHooks :: Mud [Hook]
- hPriority :: Hook -> Int
- hDestination :: Hook -> Destination
- hPattern :: Hook -> Pattern
- hAction :: Hook -> Mud ()
- triggeredHook :: Mud Hook
- matchedLine :: Mud String
- before :: Mud String
- group :: Int -> Mud String
- after :: Mud String
- mkVar :: a -> Mud (Var a)
- setVar :: Var a -> a -> Mud ()
- readVar :: Var a -> Mud a
- modifyVar :: Var a -> (a -> a) -> Mud ()
- trigger :: Destination -> String -> Mud ()
- triggerJust :: (Hook -> Bool) -> Destination -> String -> Mud ()
- io :: Destination -> String -> Mud ()
- liftIO :: MonadIO m => forall a. IO a -> m a
- forkWithCallback :: (RunMud -> IO ()) -> Mud ThreadId
Run a Mud computation in IO. A common implementation of this function is
Hook type. For every pair of hooks
h1 == h2iff they were created by the same call to
h1 < h2iff
h1will match earlier than
The direction in which a message is going.
The message is headed towards the user's terminal.
The message is headed towards the remote MUD server.
Running Mud computations
A hook watches a channel for messages matching a specific regular expression.
When a hook fires, the triggering message is consumed and the hook's action is executed.
When a message doesn't trigger any hooks, it is sent on to its destination.
A hook's action may query for match-specific data; see section Match information.
At most one hook fires for each message, unless the hook's action explicitly sends the message through
trigger again. If several hooks match, only the hook with the highest priority fires. If there is still a tie, the hook that was defined last (using
Creates and installs a hook that watches messages headed to the specified destination and match the specified pattern.
Hook record fields
Use these in combination with
setHook to update hooks.
Yields the part of the triggering message that comes before the matched pattern.
Yields the regex group from the matched pattern.
group 0 yields the complete match; higher indices correspond to the parenthesized groups.
Yields the part of the triggering message that comes after the matched pattern.
If the message triggers a hook that passes the specified test, it is fired. Otherwise, the message is passed on to the destination using
Immediately write a message to a destination, without triggering hooks.
Used when you want a forked thread to be able to call back into the
Note that when using the
RunMud argument, the forked thread will have to contend
with the threads for the user input and MUD input, because only one
can run at any given time. The id of the forked thread is returned.