Skip to content

Instantly share code, notes, and snippets.

@mitsuji
Created July 17, 2011 05:53
Show Gist options
  • Save mitsuji/1087248 to your computer and use it in GitHub Desktop.
Save mitsuji/1087248 to your computer and use it in GitHub Desktop.
module HDaemon.Foreign where
import System.Environment
import Foreign
import HDaemon.Server
foreignStart :: IO(StablePtr(SHandle))
foreignStart = do
logPath <- getLogPath
handle <- start logPath
ptr <- newStablePtr handle
return ptr
where
getLogPath :: IO(String)
getLogPath = do
args <- getArgs
return(args !! 0)
foreignStop :: StablePtr(SHandle) -> IO()
foreignStop ptr = do
handle <- deRefStablePtr ptr
stop handle
freeStablePtr ptr
foreign export stdcall foreignStart :: IO (StablePtr (SHandle))
foreign export stdcall foreignStop :: StablePtr (SHandle) -> IO()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment