Created
July 25, 2015 21:00
-
-
Save keplersj/3bd3aadd71db206e828f to your computer and use it in GitHub Desktop.
Revisions
-
keplersj created this gist
Jul 25, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ #[link(name = "logger")] extern { fn CrystalLog(text: *const u8); } fn log(text: &'static str) { unsafe{ CrystalLog(text.as_bytes().as_ptr()) }; } fn main() { log("Hello Crystal, from Rust!"); log("Logging from Crystal, using Rust, totally works twice, by the way."); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ require "colorize" fun log = CrystalLog(text: UInt8*): Void # We need to initialize the GC GC.init # We need to invoke Crystal's "main" function, the one that initializes # all constants and runs the top-level code (none in this case, but without # constants like STDOUT and others the last line will crash). # We pass 0 and null to argc and argv. LibCrystalMain.__crystal_main(0, Pointer(Pointer(UInt8)).null) #puts "#{"Pointer Recieved:".colorize.bold} #{text}" #puts "#{"Value of Pointer:".colorize.bold} #{String.new(text)}" puts String.new(text) end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ crystal logger.cr --link-flags "-dynamiclib" -o lib/x86_64-apple-darwin/liblogger.dylib rustc logged.rs ./logged