hruby-0.3.8: Embed a Ruby intepreter in your Haskell program !

Safe HaskellNone
LanguageHaskell2010

Foreign.Ruby.Helpers

Synopsis

Documentation

class FromRuby a where Source #

The class of things that can be converted from Ruby values. Note that there are a ton of stuff that are Ruby values, hence the Maybe type, as the instances will probably be incomplete.

Methods

fromRuby :: RValue -> IO (Either String a) Source #

To define more instances, please look at the instances defined in Foreign.Ruby.Helpers.

Instances
FromRuby Double Source # 
Instance details

Defined in Foreign.Ruby.Helpers

FromRuby Int Source # 
Instance details

Defined in Foreign.Ruby.Helpers

FromRuby Integer Source # 
Instance details

Defined in Foreign.Ruby.Helpers

FromRuby ByteString Source # 
Instance details

Defined in Foreign.Ruby.Helpers

FromRuby Text Source # 
Instance details

Defined in Foreign.Ruby.Helpers

FromRuby Value Source #

This is the most complete instance that is provided in this module. Please note that it is far from being sufficient for even basic requirements. For example, the Value type can only encode dictionnaries with keys that can be converted to strings.

Instance details

Defined in Foreign.Ruby.Helpers

Methods

fromRuby :: RValue -> IO (Either String Value) Source #

FromRuby a => FromRuby [a] Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

fromRuby :: RValue -> IO (Either String [a]) Source #

class ToRuby a where Source #

Whenever you use ToRuby, don't forget to use something like freezeGC or you will get random segfaults.

Methods

toRuby :: a -> IO RValue Source #

Instances
ToRuby Double Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

toRuby :: Double -> IO RValue Source #

ToRuby Int Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

toRuby :: Int -> IO RValue Source #

ToRuby Integer Source # 
Instance details

Defined in Foreign.Ruby.Helpers

ToRuby ByteString Source # 
Instance details

Defined in Foreign.Ruby.Helpers

ToRuby Text Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

toRuby :: Text -> IO RValue Source #

ToRuby Value Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

toRuby :: Value -> IO RValue Source #

ToRuby Scientific Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

toRuby :: Scientific -> IO RValue Source #

ToRuby a => ToRuby [a] Source # 
Instance details

Defined in Foreign.Ruby.Helpers

Methods

toRuby :: [a] -> IO RValue Source #

embedHaskellValue :: a -> IO RValue Source #

An unsafe version of the corresponding Foreign.Ruby.Safe function.

freeHaskellValue :: RValue -> IO () Source #

Frees the Haskell value represented by the corresponding RValue. This is probably extremely unsafe to do, and will most certainly lead to exploitable security bug if you use something modified from Ruby land. You should always free the RValue you generated from embedHaskellValue.

extractHaskellValue :: RValue -> IO a Source #

This is unsafe as hell, so you'd better be certain this RValue has not been tempered with : GC frozen, bugfree Ruby scripts.

If it has been tempered by an attacker, you are probably looking at a good vector for arbitrary code execution.

safeGetClass :: String -> IO (Either (String, RValue) RValue) Source #

Gets a Ruby class, capturing errors.

safeMethodCall Source #

Arguments

:: String

Name of a class or a module.

-> String

Method name.

-> [RValue]

Arguments. Please note that the maximum number of arguments is 16.

-> IO (Either (String, RValue) RValue)

Returns either an error message / value couple, or the value returned by the function.

Runs a Ruby singleton method, capturing errors.

safeFunCall Source #

Arguments

:: RValue

Receiver.

-> String

Method name.

-> [RValue]

Arguments. Please note that the maximum number of arguments is 16.

-> IO (Either (String, RValue) RValue)

Returns either an error message / value couple, or the value returned by the function.

Runs a Ruby method, capturing errors.

showErrorStack :: IO String Source #

Gives a (multiline) error friendly string representation of the last error.

setGC Source #

Arguments

:: Bool

Set to True to enable GC, and to False to disable it.

-> IO (Either (String, RValue) RValue) 

Sets the current GC operation. Please note that this could be modified from Ruby scripts.

startGC :: IO () Source #

Runs the Ruby garbage collector.

freezeGC :: IO a -> IO a Source #

Runs a computation with the Ruby GC disabled. Once the computation is over, GC will be re-enabled and the startGC function run.