Safe Haskell | None |
---|
This modules materializes the ruby interpreters as the
RubyInterpreter
data type. All the calls using these APIs are
garanteed to run in the OS thread that the interpreter expects.
- startRubyInterpreter :: IO RubyInterpreter
- closeRubyInterpreter :: RubyInterpreter -> IO ()
- data RubyError
- type RValue = Ptr CULong
- data RubyInterpreter
- loadFile :: RubyInterpreter -> FilePath -> IO (Either RubyError ())
- embedHaskellValue :: RubyInterpreter -> a -> IO (Either RubyError RValue)
- safeMethodCall :: RubyInterpreter -> String -> String -> [RValue] -> IO (Either RubyError RValue)
- makeSafe :: RubyInterpreter -> IO a -> IO (Either RubyError a)
- type RubyFunction1 = RValue -> IO RValue
- type RubyFunction2 = RValue -> RValue -> IO RValue
- type RubyFunction3 = RValue -> RValue -> RValue -> IO RValue
- type RubyFunction4 = RValue -> RValue -> RValue -> RValue -> IO RValue
- type RubyFunction5 = RValue -> RValue -> RValue -> RValue -> RValue -> IO RValue
- registerGlobalFunction1 :: RubyInterpreter -> String -> RubyFunction1 -> IO (Either RubyError ())
- registerGlobalFunction2 :: RubyInterpreter -> String -> RubyFunction2 -> IO (Either RubyError ())
- registerGlobalFunction3 :: RubyInterpreter -> String -> RubyFunction3 -> IO (Either RubyError ())
- registerGlobalFunction4 :: RubyInterpreter -> String -> RubyFunction4 -> IO (Either RubyError ())
- registerGlobalFunction5 :: RubyInterpreter -> String -> RubyFunction5 -> IO (Either RubyError ())
Initialization and finalization
startRubyInterpreter :: IO RubyInterpreterSource
Initializes a Ruby interpreter. This should only be called once. It actually runs an internal server in a dedicated OS thread.
closeRubyInterpreter :: RubyInterpreter -> IO ()Source
This will shut the internal server down.
Data types
type RValue = Ptr CULongSource
This is the type of Ruby values. It is defined as a pointer to some unsigned long, just like Ruby does. The actual value is either pointed to, or encoded in the pointer.
data RubyInterpreter Source
This is acutally a newtype around a TQueue
.
Safe variants of other funtions
embedHaskellValue :: RubyInterpreter -> a -> IO (Either RubyError RValue)Source
A safe version of the corresponding Foreign.Ruby function.
safeMethodCall :: RubyInterpreter -> String -> String -> [RValue] -> IO (Either RubyError RValue)Source
A safe version of the corresponding Foreign.Ruby function.
makeSafe :: RubyInterpreter -> IO a -> IO (Either RubyError a)Source
Runs an arbitrary computation in the Ruby interpreter thread. This is useful if you want to embed calls from lower level functions. You still need to be careful about the GC's behavior.
Wrapping Haskell function and registering them
type RubyFunction1 = RValue -> IO RValueSource
All those function types can be used to register functions to the Ruby
runtime. Please note that the first argument is always set (it is
"self"). For this reason, there is no RubyFunction0
type.
registerGlobalFunction1 :: RubyInterpreter -> String -> RubyFunction1 -> IO (Either RubyError ())Source
registerGlobalFunction2 :: RubyInterpreter -> String -> RubyFunction2 -> IO (Either RubyError ())Source
registerGlobalFunction3 :: RubyInterpreter -> String -> RubyFunction3 -> IO (Either RubyError ())Source
registerGlobalFunction4 :: RubyInterpreter -> String -> RubyFunction4 -> IO (Either RubyError ())Source
registerGlobalFunction5 :: RubyInterpreter -> String -> RubyFunction5 -> IO (Either RubyError ())Source