chachasmooth_ has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
lanodan has joined #crystal-lang
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 246 seconds]
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 265 seconds]
<FromGitter>
<erdnaxeli:cervoi.se> hi, in a macro, when iterating on instance vars, how can I get the `Int32` type in `Array(Int32)` ?
<FromGitter>
<erdnaxeli:cervoi.se> `ivar.type` is `Array(Int32)`, but is there a way to access to `Int32`? The goal is to check if it inherits from `Int` to support all `IntX` types
<FromGitter>
<erdnaxeli:cervoi.se> oh I just found it, it's `ivar.type.type_vars`
yxhuvud has quit [Read error: Connection reset by peer]
hendursa1 has joined #crystal-lang
yxhuvud has joined #crystal-lang
hendursa1 has quit [Remote host closed the connection]
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
_ht has joined #crystal-lang
hendursa1 has quit [Remote host closed the connection]
DTZUZU_ has quit [Read error: Connection reset by peer]
<hsh>
hi everyone. I'm using `icr` as a lib and at some point I get a result with is a PNG. The value I get is the string representation of the bytes (but escaped), so for instance I get `data = "\x89PNG\r\n\u001A\n\u0000\u0000 ... "`, such that `data[1..7] == "\\x89PNG"` is true. How can I save this String as Bytes to a file?
<hsh>
I mean, I know how to save to a file, the question is how to convert the String to Bytes (given how it's encoded)
<FromGitter>
<HertzDevil> depends on what set of escape sequences are present
<FromGitter>
<HertzDevil> if it's crystal's or json's, you could follow the lexer code in the crystal compiler/stdlib
<FromGitter>
<jrei:matrix.org> If you save to a file, and then File.read("file").to_bytes
<FromGitter>
<jrei:matrix.org> to_slice I mean
<hsh>
I'll try it, thanks!
<FromGitter>
<HertzDevil> no that alone doesn't unescape the sequences
<hsh>
yeah, was thinking about it... the point is how to transform `"\\x89"` into `"\x89"`
<FromGitter>
<jrei:matrix.org> I see
<FromGitter>
<oprypin:matrix.org> hsh, for what reason
<FromGitter>
<jrei:matrix.org> would be simpler not to have the string representation, just have bytes directly
<FromGitter>
<oprypin:matrix.org> > I'm using icr as a lib ⏎ why?????????????????
<hsh>
I'm writing something for fun that reads crystal code blocks in documents and runs them
<FromGitter>
<oprypin:matrix.org> uh cool, and what does `icr` have to do with anything?
<hsh>
well, it's the best I could find that run arbitrary crystal code. just pass it as a command and execute. not claiming it's perfect :)
<oprypin>
just `crystal eval` does that
<hsh>
@oprypin ah, nice! wasn't aware, thanks.
<FromGitter>
<jrei:matrix.org> Could be possible to call it directly in crystal by requiring the compiler
<FromGitter>
<jrei:matrix.org> without creating a subprocess
<straight-shoota>
Subprocess shouldn't do any harm. On the contrary, it might help to release memory used by the compiler sooner.
<straight-shoota>
The main benefit of embedding the compiler instead of shelling out is easier deployment
<straight-shoota>
But if the compiler is available anyways in the path, there's not much reason to embed it
<FromGitter>
<jrei:matrix.org> it will depends of what hsh wants to do.
<hsh>
it's something like RMarkdown, don't know if you're familiar
<FromGitter>
<jrei:matrix.org> just calling `crystal eval` is definitely the simplest
<hsh>
so basically, I would just extract the code blocks, eval them in a subprocess and get the result back. Since everything is in place (just need to replace the call to `icr` with one to `crystal eval`) should be easy
<hsh>
I'm interesting in seeing what the result with the PNG will look like for `crystal eval`
<hsh>
*interested
<FromGitter>
<oprypin:matrix.org> same probably, the way it looks depends on what the producing code does
<FromGitter>
<oprypin:matrix.org> just don't print the inspect (of a malformed string at that) and you'll be fine
<FromGitter>
<oprypin:matrix.org> dump the bytes directly maybe?
<hsh>
oprypin: thanks, I'll give it go
<FromGitter>
<oprypin:matrix.org> hsh, `STDOUT.write(bytes)` rather than `p bytes`
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 240 seconds]
<hsh>
ok, so my first attempt at `crystal eval` didn't work
<hsh>
because I want to capture the last return of the block (no extra code in there), and I definitely had to put something to dump the PNG. and also because I was having trouble passing a multiline block to eval's process. But it was just a quick attempt, I'll look at it properly later on
<hsh>
but ... I did manage to make it work with the hackiest/ugliest way possible XD
<hsh>
so I get a "dumped" string, so I just call `irc` again with `execute("File.write(\"#{image_path}\", #{dumped_string})")` :P
<hsh>
*icr
<FromGitter>
<oprypin:matrix.org> welp i just added 1400 type annotations throughout stdlib. no idea who's gonna review that lol
<FromGitter>
<Blacksmoke16> yey type restrictions
<FromGitter>
<jrei:matrix.org> it shouldn't has been quick...