jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.18.7 | Fund Crystals development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Read error: Connection reset by peer]
Philpax has joined #crystal-lang
Oliphaunte has joined #crystal-lang
sija has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
sija has quit [Remote host closed the connection]
JRogers has joined #crystal-lang
<FromGitter> <binary132> what kind of expectations should I have about threaded Crystal?
<FromGitter> <binary132> (os threads)
<FromGitter> <kofno> Here's a long discussion on Threading in Crystal --> https://github.com/crystal-lang/crystal/issues/1967
Philpax has quit [Ping timeout: 250 seconds]
Philpax has joined #crystal-lang
JRogers has quit [Quit: Page closed]
Philpax has quit [Ping timeout: 244 seconds]
onethirtyfive has joined #crystal-lang
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
Oliphaunte has joined #crystal-lang
willl has quit [Quit: Connection closed for inactivity]
am_ has quit [Ping timeout: 240 seconds]
Oliphaunte has quit [Remote host closed the connection]
Yxhvd has quit [Ping timeout: 258 seconds]
pawnbox has joined #crystal-lang
onethirtyfive has quit [Remote host closed the connection]
nickc1 is now known as nickc
pawnbox has quit [Ping timeout: 265 seconds]
pawnbox has joined #crystal-lang
Philpax has joined #crystal-lang
txdv_ is now known as txdv
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Client Quit]
Yxhuvud has joined #crystal-lang
Philpax has quit [Ping timeout: 244 seconds]
<jhass> binary123: the plan is that the runtime spawns a pool of threads on which the fibers/coroutines are run, so you wouldn't deal with them yourself, your concurrency primitives are spawn and Channel
bjz has joined #crystal-lang
ponga has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
mark_66 has joined #crystal-lang
Kurisu has joined #crystal-lang
pawnbox has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
Kurisu has quit [Ping timeout: 264 seconds]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Philpax has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
mkl0501 has joined #crystal-lang
Oliphaunte has joined #crystal-lang
<jeromegn> hmm, 500 internal server error when playing with this: https://play.crystal-lang.org/#/r/178h/edit
<txdv> no inernal error here
<jeromegn> I mean, when running it
<jeromegn> the xhr request returns a 500 with JSON containing the error message
Oliphaunte has quit [Remote host closed the connection]
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
<jhass> not for me
<pawnbox> not for me too
<jeromegn> mmm
<jeromegn> weird
<jeromegn> jhass: hmm that playground wasn’t updated with the code that causes the issue
<jeromegn> here’s a curl
<jeromegn> curl 'https://play.crystal-lang.org/run_requests' -H 'Origin: https://play.crystal-lang.org' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8,fr;q=0.6' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36' -H 'Content-Type: application/json;
<jeromegn> charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: https://play.crystal-lang.org/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data-binary '{"run_request":{"language":"crystal","version":"0.18.7","code":"arr = [113u8, 9u8, 113u8, 113u8, 60u8, 62u8, 113u8, 50u8, 38u8, 1u8, 255u8]\nslice =
<jeromegn> StaticArray(UInt8, 11).new {|i| arr[i] }.to_slice\n#slice = \"q\\tqq<>q2&\\001\\377\".encode(\"UTF-8\")\nputs String.new(slice)"}}' --compressed
<jhass> jeromegn: this is impossible to read or copy paste
<jeromegn> oh
<jhass> use a pastebin
<jeromegn> I’m sure this could be simplified, I just copied the curl from Chrome’s inspector
mkl0501 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
<jeromegn> I can crystal eval fine
<jeromegn> but not from the online playground
<jeromegn> this one line is a smaller example: puts String.new StaticArray[113u8, 9u8, 113u8, 113u8, 60u8, 62u8, 113u8, 50u8, 38u8, 1u8, 255u8].to_slice
<jeromegn> > puts String.new StaticArray[113u8, 9u8, 113u8, 113u8, 60u8, 62u8, 113u8, 50u8, 38u8, 1u8, 255u8].to_slice
steenuil has quit [Ping timeout: 244 seconds]
mkl0501 has joined #crystal-lang
<FromGitter> <sumproxy> jeromegn did you try from a different browser? clear cache, cookies?
<jeromegn> yea
<jeromegn> tried chrome and safari, and tried private mode on chrome
ponga has quit []
<FromGitter> <sumproxy> firefox?
<jeromegn> haven’t, but even the curl fails. so any browser will fail at it
<FromGitter> <sumproxy> yeah, right
<jeromegn> anyway, was trying to debug some Crystal :) I get a UTF 8 error from trying to get that string from a slice
<jhass> hmpf invalid byte sequence for encoding "UTF8": 0xff (PQ::PQError)
mkl0501 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
<jhass> not sure how to handle this properly
<jhass> don't really want to do UTF-8 detection on the output and then hexdump or whatever
<jhass> and oh well, IMO String.new should already bail on it
<jeromegn> jhass: that’s the error I was trying to get haha! I’m getting this in my program, but I can’t figure out why. so I was trying to show it here and get some help :)
<jeromegn> because this works fine: crystal eval "puts String.new StaticArray[113u8, 9u8, 113u8, 113u8, 60u8, 62u8, 113u8, 50u8, 38u8, 1u8, 255u8].to_slice"
<jhass> yeah IMO it shouldn't
<jeromegn> right, I’m working on a protobuf decoder (I’m real close) and for some reason this UTF 8 string is difficult to decode and parse into a crystal string
<jhass> it's not a UTF-8 string
<jhass> 0xff (255) is not a valid UTF-8 byte
<jhass> the highest valid UTF-8 byte is 0xf7 or something
<jeromegn> mmm
<jeromegn> "q\tqq<>q2&\001\377"
<jeromegn> I can’t replicate it when not decoding from protobuf… which is the hard part of debugging this
<jhass> 377 is octal for 255
Oliphaunte has joined #crystal-lang
<jhass> where is that from? what do you get for the source when decoding with an existing implementation?
<jeromegn> good question, let’s see
<jeromegn> looks like it’s parsed correctly
<jhass> well then your test data is bullshit
<jeromegn> I encoded it initially from the test.data.raw
<jeromegn> using protoc
<jeromegn> haha yes
<jeromegn> I’ll just change it, considering protobuf is supposed to only support utf 8 strings
<jeromegn> not sure why that works at all
<jhass> yeah
<FromGitter> <sumproxy> @jhass isn't it a bug in crystal's utf8 handling?
<jhass> what exactly?
<FromGitter> <sumproxy> I see no errors when running it
<pabs> crystal doesn't validate that the contents of a slice are valid utf8 when initializing a string from a slice
<FromGitter> <sumproxy> I mean the 255u8 from slice
<pabs> so if that's how you're initializing the string then that's probably what's happening
<FromGitter> <sumproxy> being invalid utf8 char
<FromGitter> <sumproxy> oh that makes sense @pabs
<Papierkorb> In C, I'd have a struct{ .. }, which I'd fread(2) into the data to access its contents easily. How do I do that in Crystal?
<Papierkorb> (oh, fread() is in section 3, not 2)
<jhass> Papierkorb: untested, but something like foo = unitialized LibC::Foo; slice = pointerof(foo).as(UInt8*).to_slice(sizeof(LibC::Foo)); io.read(slice)
<Papierkorb> https://crystal-lang.org/api/0.18.7/Struct.html The example fails with 0.18.7, the #initialize wants @value to have a type
<Papierkorb> jhass: I don't have a C lib behind this, just used it as example what I'm trying to do, sorry for the confusion
<jhass> well, doesn't have to be a lib struct
<Papierkorb> jhass: Thanks. Is order of the properties/fields guaranteed?
mkl0501 has joined #crystal-lang
<jhass> probably not tbh, for non lib structs that is
<jhass> I mean it's stable within a release atm I think
<jhass> but not necessarily future proof
<jhass> I wouldn't rely on it as a serialization
<Papierkorb> What would you use then? I have a binary 'structure' I want to parse. Only need to read it.
<jhass> a lib struct I guess
<jhass> may become available outside lib via an @[Extern] attribute btw
<Papierkorb> Ah, now I understand what you mean. Thans
Philpax has quit [Ping timeout: 250 seconds]
<FromGitter> <sumproxy> I have a question about 'moves': does crystal support them. I mean if I have a struct which is stack allocated that has a pointer to heap allocated data will the data on the heap be copied or just the pointer. Anyway I'm looking for clarifications on this topic if there's any
<jhass> pretty sure only the pointer
<jhass> anything else wouldn't make any sense to me
<BlaXpirit> sumproxy, seems quite clear to me and should be clear to you because you understand how pointers work. the default copy operation is to copy all data byte by byte, so the pointer is copied, and data it points to has no reason to be copied
<FromGitter> <sumproxy> right, so the same would be if I had a struct with a class member?
<jhass> that's just never copied, it's a global
<BlaXpirit> it makes you think for a moment, but yes
<FromGitter> <sumproxy> a class member is a global?
<BlaXpirit> jhass misunderstood the question
<jhass> what's a class member then?
<BlaXpirit> a member which is a class
<jhass> oh
<FromGitter> <sumproxy> exactly
<jhass> I thought you meant class variable
<FromGitter> <sumproxy> no
<FromGitter> <sumproxy> thanks guys
<jhass> mh, I'm actually not sure what the crystal generates for class, I guess the type tag?
<Papierkorb> can I use StaticArray(T,N) inside a lib struct to? Or should I do something like "unused1, unused2, ... : UInt8" ?
<Papierkorb> -to
<BlaXpirit> Papierkorb, sure, you can use, there's even a special syntax T[N]
<jhass> struct Foo; _dummy : UInt8[48]; end is in fact a common way to define an opaque struct you have to allocate still
<BlaXpirit> if only that size was always predictable
<jhass> well, thank the C folks :P
<Papierkorb> it adds padding at the end?
<BlaXpirit> Papierkorb, i dunno, probably
<BlaXpirit> does whatever C does
<Papierkorb> Next issue: I have a string in the structure exactly 22 bytes in length. In C, I'd just do `char name[22];` - Is there something better than `name : UInt8[22]` in crystal for that?
<BlaXpirit> LibC::Char[22] but it's exactly the same
mark_66 has quit [Quit: Leaving.]
pawnbox has quit [Remote host closed the connection]
Yxhuvud has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
Yxhuvud has joined #crystal-lang
pawnbox has joined #crystal-lang
<Papierkorb> Is it possible to have a generic method inside a non-generic class?
<RX14> Papierkorb, yes, i'm pretty sure
<Papierkorb> currently trying things. Just accepting `type : T` as argument did not work :P
<RX14> does for me
<BlaXpirit> Papierkorb, as usual, give a reproducible example so we can help
<Papierkorb> BlaXpirit: I was just being stupid. Wrote UInt32 instead of Int32
<Papierkorb> Thanks all. Just had to look harder at the output of crystal
sija has joined #crystal-lang
<jhass> Papierkorb: if you see an opportunity to (easily) clarify output somewhere, make sure to open an issue ;)
sija has quit [Quit: leaving]
<Papierkorb> The atom-editor integration plugins are awesome btw, they're really helping me out
Oliphaunte has quit [Remote host closed the connection]
pawnbox has quit [Ping timeout: 265 seconds]
steenuil has joined #crystal-lang
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
steenuil has quit [Ping timeout: 258 seconds]
steenuil has joined #crystal-lang
onethirtyfive has joined #crystal-lang
<FromGitter> <crisward> Does crytal HTTP::static not do mime types?
<RX14> no
Oliphaunte has joined #crystal-lang
onethirtyfive has quit [Remote host closed the connection]
<FromGitter> <crisward> thanks...
<RX14> we don't have a mime type database like nginx does
<FromGitter> <Sija> @crisward There's https://github.com/Rinkana/Crystal-MimeTypes
<FromGitter> <crisward> I'll hack in some common ones for now based on file extension
<FromGitter> <crisward> cool, I'll take a look
<BlaXpirit> Sija, I don't think maintaining a separate database is viable https://github.com/Rinkana/Crystal-MimeTypes/blob/master/src/mime/types.json
<FromGitter> <Sija> @BlaXpirit it's discussable indeed but it's not my lib so... it's not for me to discuss ;)
kulelu88 has joined #crystal-lang
<BlaXpirit> sigh, turns out libmagic source code is huge
<FromGitter> <Sija> right, there's also https://github.com/pablotron/libmagic-crystal
<BlaXpirit> yes, that's the viable library. but i mean it would be nice to have native
<FromGitter> <Sija> like with most of the things: native is *gooood*
<crystal-gh> [crystal] endSly opened pull request #3163: Integer exponentiation should avoid use float (master...master) https://git.io/v6wLO
pawnbox has quit [Remote host closed the connection]
<Papierkorb> Can't the compiler deduce that @bar is not used anywhere in the called method on line 5?
<jhass> no it can't
<jhass> it might in the future but for now it's intentionally kept simple to be fast and robust
Ven has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven has quit [Ping timeout: 276 seconds]
steenuil has quit [Ping timeout: 276 seconds]
steenuil has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
steenuil has quit [Ping timeout: 250 seconds]
steenuil has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bjz has quit [Ping timeout: 258 seconds]
steenuil has quit [Read error: Connection reset by peer]
mkl0501 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
<jeromegn> I’m not sure how I can expand a type within a macro: https://play.crystal-lang.org/#/r/17a0
<jeromegn> if I try wrapping {{_type_for(...)}}, I get an undefined macro error
Renich has joined #crystal-lang
<FromGitter> <acterhd> why you use "u32" notation instead of "ui32"?
Philpax has joined #crystal-lang