Files
epq-old/app/WM/Mruby.hs
T

36 lines
945 B
Haskell

{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module WM.Mruby where
import Foreign.C (CChar, CInt (CInt), CString, withCString)
import Foreign.Ptr
data MrbState
foreign import capi "mruby.h mrb_open"
mrb_open :: IO (Ptr MrbState)
foreign import capi "mruby.h mrb_close"
mrb_close :: Ptr MrbState -> IO ()
foreign import capi "mruby/compile.h mrb_load_string"
c_mrb_load_string :: Ptr MrbState -> CString -> IO ()
runRuby :: Ptr MrbState -> String -> IO ()
runRuby mrb code =
withCString code $ \cstr ->
c_mrb_load_string mrb cstr
foreign import capi "ruby_compiled.h value mgems"
c_mgems :: Ptr CChar
foreign import capi "ruby_compiled.h value mgems_len"
c_mgems_len :: CInt
foreign import capi "mruby/irep.h mrb_load_irep_buf"
c_mrb_load_irep_buf :: Ptr MrbState -> Ptr CChar -> CInt -> IO ()
loadRubyLibs :: Ptr MrbState -> IO ()
loadRubyLibs mrb = c_mrb_load_irep_buf mrb c_mgems c_mgems_len