Skip to content

Instantly share code, notes, and snippets.

@lukexi
Last active December 21, 2015 23:39
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lukexi/20b3aae6ac0f0f7892be to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
extern void hs_init (int *argc, char **argv[]);
extern void hs_exit (void);
@interface NSObject (HSInit)
@end
@implementation NSObject (HSInit)
+ (void)load {
hs_init(NULL, NULL);
atexit(&hs_exit);
}
@end
@schell
Copy link

schell commented Dec 16, 2013

What would the matching Haskell code look like? I'm not familiar with FFI.

@schell
Copy link

schell commented Dec 16, 2013

Nvm! I played with it and figured it out! Thanks for your work!

Just so others know - hs_init and hs_exit are already defined for you somewhere and they init and tear down the RTS, respectively.

This link helped me figure things out http://www.haskell.org/haskellwiki/Calling_Haskell_from_C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment