-
-
Save Papierkorb/55c32f9ad3aa61e20eeec6e045b9b582 to your computer and use it in GitHub Desktop.
This file contains 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 characters
#include <stdio.h> | |
struct CrystalString { | |
char *ptr; | |
int size; | |
}; | |
void dump(struct CrystalString str) { | |
printf("%iB @ %p\n", str.size, str.ptr); | |
} | |
void bla(void *eins, struct CrystalString zwei, struct CrystalString drei, struct CrystalString vier) { | |
printf("eins: %p\n", eins); // This is fine | |
printf("zwei: "); dump(zwei); // Same | |
printf("drei: "); dump(drei); // Great too | |
printf("vier: "); dump(vier); // What's going on?! | |
} |
This file contains 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 characters
@[Link(ldflags: "#{__DIR__}/foo.c")] # <- Don't try this at home | |
lib Bind | |
struct CrystalString | |
ptr : LibC::Char* | |
size : LibC::Int | |
end | |
fun bla(eins : Void*, zwei : CrystalString, drei : CrystalString, vier : CrystalString) : Void | |
end | |
def wrap(str) | |
Bind::CrystalString.new(ptr: str.to_unsafe, size: str.size) | |
end | |
Bind.bla(nil, wrap("Zwei"), wrap("Drei"), wrap("Vier")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment