ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter> <> Might be a dumb question, but specs gives an internal error when i switch my code to use struct instead of class, saying `same?` method is undefined, probably from using the spectation `should be`.
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> makes sense
<FromGitter> <> Yeah thought so, since they are pbv
<FromGitter> <> ok
<FromGitter> <Blacksmoke16> you could use `should be` if your struct implemented that method
<FromGitter> <Blacksmoke16> but at that point its basically the same as `should eq`
<FromGitter> <> Right
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <> I'm just experimenting by removing all those "into" methods and making the types structs
<FromGitter> <> It would surely be a lot less code to maintain and probably less room for user error
<FromGitter> <Blacksmoke16> indeed
ua_ has quit [Ping timeout: 272 seconds]
ua_ has joined #crystal-lang
ur5us has joined #crystal-lang
sagax has joined #crystal-lang
ur5us has quit [Ping timeout: 272 seconds]
echoSMILE has left #crystal-lang [#crystal-lang]
f1refly has quit [Read error: Connection reset by peer]
f1refly has joined #crystal-lang
Nik- has joined #crystal-lang
<FromGitter> <> is there a better way to write this? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I think there must be a better way to convert the string back... []
<FromGitter> <HertzDevil> ```code paste, see link``` []
<FromGitter> <> oh, nice :)
<FromGitter> <> i really wish there was a finished libgit2 crystal binding... but for now this'll have to do
<FromGitter> <> finally got cloning and checking out a commit working :D
f1refly has quit [Quit: see ya in hell]
f1refly has joined #crystal-lang
<FromGitter> <Blacksmoke16> is this something we should also do?
<FromGitter> <> heh this library is only 1500 lines, but test boilerplate is about 5000
deavmi has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> :P sounds about right
<FromGitter> <mattrberry> `out` just creates an uninitialized variable for whatever type is being pointed to, right?
<FromGitter> <mattrberry> So `out` for an argument that's a `Pointer(Char)` effectively just creates an `uninitialized Char` then passes its pointer as an argument, right?
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
<FromGitter> <mattrberry> If I want to allocate space for a string, I'd need to allocate that myself using something like Pointer.malloc or just `buffer = " " * 512` then pass the pointer
<FromGitter> <mattrberry> When I just use `out` in the case where I *know* it's filling many characters it's still working, but I'm guessing that it's just writing to memory that's still addressable so it's getting lucky and not segfaulting. I just wanted to make sure the Crystal compiler wasn't doing anything tricky with the `out` syntax that I wasn't expecting
<FromGitter> <mattrberry> So I'll stick to just allocating space myself first
<FromGitter> <Blacksmoke16> could you do something with a slice?
<FromGitter> <Blacksmoke16> like ` size`, then pass a pointer to that buffer to fill it?
<FromGitter> <Blacksmoke16> then you'd be able to do ` bytes`
<FromGitter> <mattrberry> The benefit of just setting `buffer = " " * n` is that to_unsafe already gives me a Pointer(UInt8), so I can just pass it directly to the c binding, and in Crystal it's already a string so I don't need to do anything funky with it
<FromGitter> <Blacksmoke16> thats fair, the other option would be to `maloc` a pointer and use the ` ptr, size` constructor
<FromGitter> <Blacksmoke16> `malloc`*
<FromGitter> <mattrberry> Yeah that was my other thought too. Any thought if there's any perf concern with `" " * n`? It's not in a hotpath so I'm not overly concerned, but worth considering at least
<FromGitter> <mattrberry> Currently I'm just sticking with this since it's pretty simple ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <Blacksmoke16> prob be fine
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <mattrberry> Yeah same haha
Guest13 has joined #crystal-lang
<Guest13> hi all. i am wondering if constants can be defined with leading underscores. For example are both Hmm, and __Hmm both considered constants
<Guest13> i saw there are psudo constants such as __LINE__ defined so i would think such a variable definition would be considered a constant?