asterite changed the topic of #crystal-lang to: #crystal-lang The Crystal programming language | http://crystal-lang.org | Crystal 0.6.1 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ - API: http://crystal-lang.org/api/ - Logs: http://irclog.whitequark.org/crystal-lang
DerisiveLogic has joined #crystal-lang
<a5i> >> if print("Hello") != nil;puts "Hello";else;puts "World";end
<DeBot> a5i: HelloWorld
ismaelga has quit [Remote host closed the connection]
waterlink has quit [Ping timeout: 265 seconds]
Excureo has quit [Read error: Connection reset by peer]
DerisiveLogic has quit [Ping timeout: 245 seconds]
Excureo has joined #crystal-lang
havenwood has joined #crystal-lang
sadin has joined #crystal-lang
sadin has quit [Ping timeout: 245 seconds]
havenwood has quit [Remote host closed the connection]
JBat has joined #crystal-lang
ponga has joined #crystal-lang
Flaise has quit [Quit: Leaving.]
colorados has quit [Ping timeout: 250 seconds]
colorados has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
havenwood has joined #crystal-lang
BlaXpirit has joined #crystal-lang
canhtak has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
havenwood has quit [Ping timeout: 272 seconds]
ponga has quit [Ping timeout: 264 seconds]
havenwood has joined #crystal-lang
Netfeed has joined #crystal-lang
Ven has joined #crystal-lang
DerisiveLogic has joined #crystal-lang
bcardiff has joined #crystal-lang
ponga has joined #crystal-lang
JBat has quit [Ping timeout: 256 seconds]
havenwood has quit [Remote host closed the connection]
drizz has quit [Ping timeout: 264 seconds]
a5i has quit [Quit: Connection closed for inactivity]
BlaXpirit has quit [Quit: Quit Konversation]
canhtak has quit [Ping timeout: 264 seconds]
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
ponga has quit [Ping timeout: 256 seconds]
ponga has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
canhtak has joined #crystal-lang
Ven has joined #crystal-lang
colorisco has joined #crystal-lang
colorisco has left #crystal-lang [#crystal-lang]
Ven has quit [Ping timeout: 256 seconds]
Ven has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
drizz has joined #crystal-lang
JBat has joined #crystal-lang
leafybasil has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
<flan3002> If the rest of Crystal is so similar to Ruby, why was "not" replaced with "!"?
<jhass> because not is less idiomatic ruby actually
<jhass> if you read through a ton of Ruby code, you'll notice it's less used
<jhass> Crystal dropped quite a few other things like that
canhtak has quit [Quit: canhtak]
<flan3002> jhass - Ah, I see. :)
ponga has quit [Remote host closed the connection]
canhtak has joined #crystal-lang
ponga has joined #crystal-lang
a5i has joined #crystal-lang
ponga has quit [Ping timeout: 245 seconds]
Ven has quit [Ping timeout: 264 seconds]
canhtak has quit [Quit: canhtak]
ponga has joined #crystal-lang
BlaXpirit has joined #crystal-lang
Ven has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
canhtak has joined #crystal-lang
ponga has quit [Ping timeout: 245 seconds]
<crystal-gh> [crystal] asterite pushed 5 new commits to master: http://git.io/vvK6x
<crystal-gh> crystal/master 4c773d8 Ary Borenszweig: Make sure Array @length and @capacity are Int32
<crystal-gh> crystal/master 39964b3 Ary Borenszweig: Implemented the X86-64 ABI logic for passing structs and other types to C
<crystal-gh> crystal/master de8e856 Ary Borenszweig: Also support the X86-64 ABI for varargs
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/vvKXl
<crystal-gh> crystal/master ca7a01c Ary Borenszweig: Contributing: say to uninstall LLVM from homebrew
<jhass> BlaXpirit: ^ ;D
<BlaXpirit> ye ye
<travis-ci> manastech/crystal#2240 (master - 03dcac3 : Ary Borenszweig): The build is still failing.
<travis-ci> manastech/crystal#2241 (master - ca7a01c : Ary Borenszweig): The build was fixed.
<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
<asterite> For example gmp lets you define the memory functions: https://github.com/manastech/crystal/blob/master/src/big_int/lib_gmp.cr#L69
<asterite> BlaXpirit: for example?
<a5i> asterite: on inline asm ?
<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> (we usually do that)
<BlaXpirit> yeah yeah, asterite
<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
<crystal-gh> crystal/master c0d21a4 Ary Borenszweig: Merge pull request #542 from Exilor/patch-1...
<crystal-gh> crystal/master a14fabe Jacob: Removed a non-breaking space...
leafybasil has joined #crystal-lang
sandelius has joined #crystal-lang
ismaelga has quit [Remote host closed the connection]
bcardiff has quit [Quit: Leaving.]
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
bcardiff has joined #crystal-lang
bcardiff has quit [Client Quit]
<BlaXpirit_> can one `lib` get access to declarations in another lib?
sandelius has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> BlaXpirit_: what do you mean?
<BlaXpirit_> talking about C bindings
<BlaXpirit_> csfml-window depends on some declarations in csfml-system
<BlaXpirit_> and i was hoping to not put the whole CSFML in one lib but separate by these suffixes
<asterite> Ah, yes, you can put declarations in any lib
<asterite> It works like this: if a lib function is used (invoked) in your code, the link attribute name will be passed as a -l flag
<asterite> For structs and other types this doesn't matter, the lib just acts as a way of grouping related code
<BlaXpirit_> asterite, again i should be more clear. here is an example. https://bpaste.net/show/582362ebfba3
<BlaXpirit_> should i require the first file in the 2nd one?
canhtak has joined #crystal-lang
<asterite> Yes, and then you need to use the full name in the return type: CSFMLSystem::Vector2i
<BlaXpirit_> aww that's gonna be tough
<asterite> Yes... I think it's easier if you put everything in one lib. Or, you can split the lib in many files if that's what you are looking for
<asterite> That is, you can do `lib CSFMLWindow; ... end` in two different files
<BlaXpirit_> you mean `lib CSFML; ... end` in two different files
<asterite> Ah, yes, that :-)
<BlaXpirit_> and different parts of it can be required
<BlaXpirit_> that's cool. thank you.
<asterite> Yes. It usually is OK to require everything, the compiler is pretty fast to parse those and type those
<asterite> Hm, there's one thing. You can't add @[Link] declarations to an existing lib. Well, you can, but they are ignored. I'll fix that
<jhass> asterite: maybe handle supplying the same twice too while at it ;P
<jhass> or maybe it does already, I didn't check tbh
<asterite> Good idea. I don't think it removes duplicates
<asterite> I wonder why Ruby doesn't have Set#concat
<BlaXpirit_> asterite, there is no such thing
<BlaXpirit_> in math and in most languages i know
<BlaXpirit_> sets have union
<asterite> Oh, there's Set#merge
<asterite> Apparently Set#union returns a new set, hmmm...
canhtak has quit [Quit: canhtak]
<BlaXpirit_> basically concatenation is a concept defined only with ordered sequences
<asterite> Makes sense
canhtak has joined #crystal-lang
<BlaXpirit_> I don't see how to do callbacks with multiple arguments
asterite has quit [Ping timeout: 246 seconds]
asterite has joined #crystal-lang
<asterite> BlaXpirit_: what's the C function?
<BlaXpirit_> typedef sfInt64 (*sfInputStreamReadFunc)(void* data, sfInt64 size, void* userData);
<BlaXpirit_> is it (Void*, size, Void*) -> Int64
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<asterite> yes
<asterite> you can also do alias F = Void*, Int64, Void* -> Int64
<BlaXpirit_> oh, that's what i was missing
JBat has quit [Ping timeout: 240 seconds]
JBat has joined #crystal-lang
a5i has quit [Quit: Connection closed for inactivity]
ismaelga has joined #crystal-lang
<BlaXpirit_> simple lib bindings are almost done https://github.com/BlaXpirit/crsfml
<BlaXpirit_> problem is, it doesn't work
<BlaXpirit_> with this simple example https://bpaste.net/show/e2d610ecd6b2
<BlaXpirit_> main_module:(.text+0x2a2): undefined reference «sfWindow_create»
<jhass> BlaXpirit_: I think that's the bug asterite mentioned earlier
<jhass> attacking @Link to a reopened lib definition is ignored
<BlaXpirit_> i don't know what you're referring to
<jhass> er, attaching
<BlaXpirit_> any workaround?
<BlaXpirit_> oh, maybe add link to main file
<asterite> Oh, I forgot to push
<jhass> yeah, add all of them to all/the first one
<BlaXpirit_> yeah, that did it
<BlaXpirit_> cool
<BlaXpirit_> well there's that
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/vvXAl
<crystal-gh> crystal/master e862e36 Ary Borenszweig: Allow reopening a lib and adding more @[Link] attributes to it, and remove duplicate attributes
<jhass> and now it's fixed :D
<BlaXpirit_> and now it works :D
test1 has quit [Ping timeout: 246 seconds]
<asterite> :-)
<asterite> Does your test do something already in that window? I'm just curious :-)
<BlaXpirit_> i'm porting a couple examples
<travis-ci> manastech/crystal#2244 (master - e862e36 : Ary Borenszweig): The build was broken.
<asterite> cool
Flaise has quit [Ping timeout: 256 seconds]
<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> Mmm... right now you can also do
<asterite> >> chars = [] of Int32; "hello".each_char { |c| chars << c.ord }; chars << 0; chars
<DeBot> asterite: [104, 101, 108, 108, 111, 0]
<BlaXpirit_> i still need to take its address
<BlaXpirit_> how to pass this array as UInt32*
<asterite> Oh, it's UInt32. So first declare the array as UInt32, then
<asterite> >> a = [] of Int32; a.to_unsafe
<DeBot> asterite: Pointer(Int32)@9297FF0
<asterite> >> a = [] of UInt32; a.to_unsafe
<DeBot> asterite: Pointer(UInt32)@9197FF0
<asterite> Well, that. But since its called "to_unsafe", you just pass the array directly
<BlaXpirit_> oh i actually wrapped it as Char*
<asterite> >> 'a'.ord.class
<DeBot> asterite: Int32
<BlaXpirit_> wooops
<asterite> Hmmm... I guess that should be UInt32
<BlaXpirit_> why so?
<asterite> Or maybe not, can't remember the range of unicode values
<jhass> 4 bytes iirc
<jhass> so UInt32 seems right
<BlaXpirit_> conversion from float64 to float32 would be damn nice :|
<jhass> >> 1.0_f64.to_f32
<DeBot> jhass: 1
<BlaXpirit_> YES
<BlaXpirit_> works like a charm
<BlaXpirit_> and by conversion i mean automatic conversion
<jhass> mh, 32 -> 64 I can see, but automatically clipping values? not sure
<BlaXpirit_> well that's correct too
<BlaXpirit_> but what about literals?
<jhass> I know for integer literals it automatically uses the fitting one, never checked for float
<BlaXpirit_> if I have a constructor that takes UInt8 I must write 6u8
<BlaXpirit_> CSFML::Color.new(r: 112u8, g: 197u8, b: 206u8)
<jhass> oh, that's what you mean
<BlaXpirit_> well if this fails here, i thought it was the same everywhere
<jhass> I think that's something you'd probably do in the wrapper
<jhass> def initialize(x, y, z); @x = x.to_u8; @y = y.to_u8; @z = z.to_u8; end;
<BlaXpirit_> mmh
<jhass> and then I could even pass whatever responds to to_u8
<BlaXpirit_> that's nice
<jhass> yeah, crystal actually allows quite a good deal of duck typing for a compilied language
<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:
<asterite> require "../src/csfml_window_lib"; require "../src/csfml_graphics_lib"
<BlaXpirit_> well yeah but ideally it would be require "csfml/csfml_window_lib"
<asterite> so that's relative and will always work
<BlaXpirit_> it's relative but i want them to also work for an installed lib
<asterite> Ah... that's not explained anywhere, but recently someone contributed an "init" command that sets up the project's layout
<asterite> So, you'd normally put the code you have in src/cfsml/
<asterite> Mmm... kind of hard to explain here. It doesn't matter, they are just some little details :-)
<BlaXpirit_> yeah
<BlaXpirit_> i'm just gonna see what init does
<asterite> At first I thought there was something wrong with the windows' title :-P
colorados has quit [Ping timeout: 256 seconds]
asterite has quit [Quit: Page closed]
colorados has joined #crystal-lang
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
Flaise has joined #crystal-lang
<BlaXpirit_> symlink "libs" is a better trick
<BlaXpirit_> https://github.com/BlaXpirit/crsfml u guys want to star it maybe? isn't this an interesting project? :p
<jhass> mh, I made a bird flip, so I guess you earned it :D
BlaXpirit_ has quit [Quit: Quit Konversation]
a5i has joined #crystal-lang
havenwood has joined #crystal-lang
havenn has quit [Ping timeout: 264 seconds]
canhtak has quit [Quit: canhtak]