<crystal-gh>
[crystal] asterite pushed 1 new commit to master: http://git.io/vvK9C
<crystal-gh>
crystal/master 4ad4e47 Ary Borenszweig: Simplified abi specs, and made ArgType a struct
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
ponga has joined #crystal-lang
JBat has quit [Ping timeout: 256 seconds]
ismaelga has joined #crystal-lang
ismael__ has joined #crystal-lang
ismaelga has quit [Ping timeout: 272 seconds]
<a5i>
BlaXpirit: Are you using 0.6.1 or HEAD ?
<BlaXpirit>
i'm not doing anything
<BlaXpirit>
nvm
<BlaXpirit>
i installed 0.6.1
<a5i>
oh Okay, the fix is available at HEAD rn or in the next release
<a5i>
which I need to speak to asterite about :/
<BlaXpirit>
k
asterite has joined #crystal-lang
DerisiveLogic has quit [Ping timeout: 252 seconds]
ismael__ has quit [Remote host closed the connection]
leafybas_ has joined #crystal-lang
leafybasil has quit [Ping timeout: 276 seconds]
<BlaXpirit>
how do library wrappers typically work?
asterite has quit [Ping timeout: 246 seconds]
<BlaXpirit>
is a wrapper Reference to each Struct pretty much mandatory?
<a5i>
asterite: when do you think inline asm will be implemented?
<a5i>
.
<jhass>
BlaXpirit: not sure I follow what you're asking...
<BlaXpirit>
well i say that a C library has this and that type, this and that function
<BlaXpirit>
the syntax to use them is ugly
<BlaXpirit>
so i'm saying, am I supposed to wrap the syntax into a reference object?
ponga has quit [Quit: Leaving...]
<jhass>
you can whatever you want and skip that, but if you want to make a pleasant to use library you'd wrap it into an object oriented API, yeah
<BlaXpirit>
so make a type that has initialize: @this = MyLibrary.SomeType_create(args)
<jhass>
yeah, and define to_unsafe on it that returns @this
<BlaXpirit>
sure. thx.
asterite has joined #crystal-lang
<asterite>
BlaXpirit: you can take a look at how we wrapped LLVM. We usually wrap things and let users use crystal code, not c-binding code. It can be tedious to do once, but then the usage is more pleasant.
<asterite>
BlaXpirit: you can wrap things with crystal structs for efficiency, but if they need a finalizer you'll probably want a class and then define finalize. And then, if the library somehow lets you change their memory allocation/freeing functions, that's the best because you can use crystal structs for the wrappers and the memory will be managed by the GC
<BlaXpirit>
CSFML has a pretty clear separation of what is a struct and what is a class
<BlaXpirit>
has data - struct. has no data - class
<asterite>
Ah, ok. But how do you free that memory?
<BlaXpirit>
"classes" are passed exclusively by pointer
<BlaXpirit>
classes are always created with create and destroyed with destroy
<asterite>
a5i: inline asm will probably come in the future, I need to design it with waj when he comes back
<a5i>
asterite: cool !
<asterite>
BlaXpirit: So, you have two options: 1. make the users of your code explicitly call destroy, so they have to manage the memory or 2. wrap things with class and define a finalize method that calls destroy when the GC detects there are no references to it
<asterite>
The second option is more expensive in terms of memory, but easier to use
<asterite>
BlaXpirit: Sorry if I say things you know already, I tend to explain too much :-)
<BlaXpirit>
that's cool
<BlaXpirit>
but this reminds me of a problem
<BlaXpirit>
that sometimes you get objects for temporary use and you're not supposed to free them
ismaelga has joined #crystal-lang
Flaise has joined #crystal-lang
<a5i>
I never realized how similar python is to Ruby
<BlaXpirit>
i solved it by having an "is owned" boolean
<asterite>
BlaXpirit: why not?
<BlaXpirit>
asterite, well let's see. imagine like... an array
<BlaXpirit>
let's say CSFML has an array type, and you can get items by index. you can look at them, but you're not supposed to free them
<BlaXpirit>
so then, CSFML returns me a pointer, i wrap it in an object, and when it gets collected, the pointer is freed
<asterite>
I think I understand. So CSFML can give you the whole array or just part of them, and in the first case you need to free it but not in the second? (or something like that? And for that you use that bool?)
<BlaXpirit>
something like that...
<asterite>
Or maybe you ask an array from csfml but only keep a reference to one element. I think in that case the GC won't collect the entire array as you have a pointer to part of it, but not sure that's the case you are talking about
<BlaXpirit>
array was a bad example. the fact that it's an array is irrelevant
<asterite>
Don't worry, I think I understand. Maybe an object with properties instead of an array
<BlaXpirit>
the point is, returning a pointer can mean transferring ownership, or just letting you look at it
<BlaXpirit>
i think i can handle it this way, just asking if maybe there is a common solution for this
<asterite>
I don't think so, we don't have many bindings yet
asterite has quit [Ping timeout: 246 seconds]
leafybas_ has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<BlaXpirit>
amazing. unimaginably easy to build Crystal. CSFML works.
JBat has joined #crystal-lang
Ven has joined #crystal-lang
canhtak has quit [Quit: canhtak]
havenwood has joined #crystal-lang
ismaelga has quit [Remote host closed the connection]
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
canhtak has joined #crystal-lang
test1 has joined #crystal-lang
canhtak has quit [Client Quit]
DerisiveLogic has joined #crystal-lang
asterite has joined #crystal-lang
<asterite>
BlaXpirit: if there's anything that can still be improved to compile crystal (or any program) let us know! Our idea is that "crystal program.cr" should work out of the box
DerisiveLogic has quit [Ping timeout: 255 seconds]
DerisiveLogic has joined #crystal-lang
datanoise has joined #crystal-lang
asterite has quit [Ping timeout: 246 seconds]
ismaelga has joined #crystal-lang
DerisiveLogic has quit [Ping timeout: 276 seconds]
shama has joined #crystal-lang
BlaXpirit_ has joined #crystal-lang
BlaXpirit has quit [Ping timeout: 245 seconds]
asterite has joined #crystal-lang
havenn has joined #crystal-lang
leafybas_ has joined #crystal-lang
havenwood has quit [Ping timeout: 245 seconds]
leafybasil has quit [Ping timeout: 272 seconds]
leafybas_ has quit [Ping timeout: 245 seconds]
datanoise has quit [Quit: leaving]
asterite has quit [Ping timeout: 246 seconds]
<crystal-gh>
[crystal] asterite pushed 2 new commits to master: http://git.io/vvPBU
<BlaXpirit_>
if I have a String, how can I pass a pointer to an array of 32-bit Chars to C?
JBat has quit [Quit: Computer has gone to sleep.]
<asterite>
32-bit chars? What function needs that?
<BlaXpirit_>
unicode function
<asterite>
Are those codepoints?
<BlaXpirit_>
oh I forgot, i would need it to be 0-terminated to work
<asterite>
>> "hello".chars.map(&.ord)
<DeBot>
asterite: [104, 101, 108, 108, 111]
<BlaXpirit_>
that's pretty nice too.
<asterite>
and then you append 0 to that... the only drawback is that it creates two intermediate arrays, but in the next release we'll probably have iterators all over the place so it'll be more efficient, something like
<asterite>
>> "hello".each_char.map(&.ord).to_a
<DeBot>
asterite: Error in line 3: 'String#each_char' is expected to be invoked with a block, but no block was given
<asterite>
I think waj wants automatic conversion in C bindings too... well, maybe me too, but it's not that easy to do. With number literals we can probably do it as it's safe
<asterite>
BlaXpirit_: AWESOME!! I have a bird in my screen and I hit space and it goes up and down :)
<BlaXpirit_>
:)
<asterite>
By the way, how do you run it? I had to change some things to make it work
<BlaXpirit_>
i make a symlink :|
<asterite>
:-)
<BlaXpirit_>
dunno how to do it properly
<asterite>
I replaced your requires in the samples to this: