Skip to content

Instantly share code, notes, and snippets.

@malte-v
Last active November 26, 2018 15:11
Show Gist options
  • Save malte-v/3623a21e1977f562baf6dcf44df2ef08 to your computer and use it in GitHub Desktop.
Save malte-v/3623a21e1977f562baf6dcf44df2ef08 to your computer and use it in GitHub Desktop.
Crystal shared library demo
fun init = crystal_init(argc : Int32, argv : UInt8**) : Void
GC.init
LibCrystalMain.__crystal_main(argc, argv)
end
fun log = crystal_log(text: UInt8*): Void
puts String.new(text)
end
LIBRARY logger
EXPORTS
crystal_init
crystal_log
#ifndef _CRYSTAL_LOGGER_H
#define _CRYSTAL_LOGGER_H
void crystal_init(int argc, char *argv[]);
void crystal_log(char* text);
#endif
#include "logger.h"
int main(int argc, char *argv[]) {
crystal_init(argc, argv);
crystal_log("Hello world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment