RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.21.0 | Fund Crystal's 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
elia has quit [Quit: Computer has gone to sleep.]
bjz has joined #crystal-lang
gk_-1wm_- has joined #crystal-lang
gk_-1wm_- has left #crystal-lang [#crystal-lang]
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 240 seconds]
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…]
splitty_ has quit [Read error: Connection reset by peer]
splitty_ has joined #crystal-lang
gk_-1wm has joined #crystal-lang
gk_-1wm has left #crystal-lang [#crystal-lang]
bjz has joined #crystal-lang
<FromGitter> <mosop> jokke, try --link-flags "-Wl,-Bstatic `gpgme-config --libs` -Wl,-Bdynamic”. Sometimes I encounter the weird ‘_end’ error. On that case, I always do static link.
akwiatkowski has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 260 seconds]
snsei has joined #crystal-lang
splitty__ has joined #crystal-lang
BlaXpirit_ has joined #crystal-lang
badeball_ has joined #crystal-lang
dostoyev1ky has joined #crystal-lang
stnly_ has joined #crystal-lang
A124 has quit [Disconnected by services]
A124 has joined #crystal-lang
VectorGraphics has joined #crystal-lang
rkeene_ has joined #crystal-lang
tatey has quit [Ping timeout: 260 seconds]
BlaXpirit has quit [Ping timeout: 260 seconds]
miketheman has quit [Ping timeout: 260 seconds]
rkeene has quit [Ping timeout: 260 seconds]
stnly has quit [Ping timeout: 260 seconds]
adam12 has quit [Ping timeout: 260 seconds]
g3funk has quit [Ping timeout: 260 seconds]
CompanionCube has quit [Ping timeout: 240 seconds]
yopp has quit [Ping timeout: 240 seconds]
badeball has quit [Ping timeout: 240 seconds]
dostoyevsky has quit [Ping timeout: 240 seconds]
splitty_ has quit [Ping timeout: 240 seconds]
swav has quit [Ping timeout: 240 seconds]
BlaXpirit_ is now known as BlaXpirit
miketheman_ has joined #crystal-lang
yopp has joined #crystal-lang
miketheman_ is now known as miketheman
tatey has joined #crystal-lang
adam- has joined #crystal-lang
CompanionCube has joined #crystal-lang
swav has joined #crystal-lang
manveru has quit [Ping timeout: 240 seconds]
ome has quit [Ping timeout: 240 seconds]
g3funk has joined #crystal-lang
ome has joined #crystal-lang
manveru has joined #crystal-lang
snsei has quit [Remote host closed the connection]
ome has quit [Excess Flood]
ome has joined #crystal-lang
tatey_ has joined #crystal-lang
adam| has joined #crystal-lang
CompanionCube has quit [Ping timeout: 260 seconds]
adam- has quit [Ping timeout: 260 seconds]
samis has joined #crystal-lang
braidn_ has joined #crystal-lang
g3funk has quit [Ping timeout: 240 seconds]
tatey has quit [Ping timeout: 240 seconds]
tatey_ is now known as tatey
samis is now known as CompanionCube
Philpax_ has quit [Ping timeout: 268 seconds]
VectorGraphics has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
VectorGraphics has joined #crystal-lang
pawnbox has quit [Ping timeout: 268 seconds]
zaiste has joined #crystal-lang
VectorGraphics has quit [Quit: Leaving]
Qchmqs has joined #crystal-lang
triangles has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox_ has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
akwiatkowski has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
Raimondii has joined #crystal-lang
soveran has quit [Ping timeout: 240 seconds]
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<FromGitter> <crisward> @Rinkana try the run extension in VSCode, you can highlight a line of code, right click and run. It can be occasionally quite useful. Have you found anything which formats on save like the sublime plugin?
elia has joined #crystal-lang
<FromGitter> <Rinkana> @crisward no i haven't found anything like that. But i guess i'ts just using the built-in formatter
elia has quit [Quit: Computer has gone to sleep.]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<FromGitter> <crisward> @Rinkana probably... It does it by default in sublime, I really like it. Shame neither of the crystal extensions for vscode seem to offer it. I really like the git tools in vsc.
<FromGitter> <molovo> I use guardian (https://github.com/f/guardian) to trigger a compile, format, spec run and doc generation whenever the source changes. That works really well and is separate from the editor
<FromGitter> <crisward> @molovo I was doing that, but vscode kept saying I had a conflict when I tried to save, something about the file has changed on disk, would your like to overwrite, it was very annoying. Not tried it for a while, they may have fixed it.
bjz has joined #crystal-lang
bjz has quit [Client Quit]
bjz has joined #crystal-lang
<FromGitter> <crisward> Vscode seems to have fixed that. I'm using sentry to rebuild my app on save, I'll add it to that.
akwiatkowski has quit [Ping timeout: 260 seconds]
dostoyev1ky is now known as dostoyevsky
<jokke> @mosop thanks for the hint! If i do that, i get the following error: https://p.jreinert.com/ZGh/
<jokke> oh!
<jokke> yess!
<jokke> had to deinstall libgc-dev
<jokke> how can i use --link-flags with spec?
<jokke> ah ok
<jokke> i can just compile spec/gpg_spec.cr and run it
jabb has joined #crystal-lang
<jabb> heyo, if i have an alias over an int type, and i'm declaring constants, how can i declare those ints?
j2k has joined #crystal-lang
bjz has quit [Ping timeout: 240 seconds]
<jabb> is it possible to cast Char to UInt32 for interacting with C?
bjz_ has joined #crystal-lang
Philpax has joined #crystal-lang
soveran has quit [Remote host closed the connection]
<Papierkorb> jabb: sure: `the_char.ord.to_u32`
olbat has quit [Ping timeout: 264 seconds]
bjz has joined #crystal-lang
bjz_ has quit [Ping timeout: 260 seconds]
olbat has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
pawnbox_ has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Philpax has quit [Read error: Connection reset by peer]
Philpax has joined #crystal-lang
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
j2k_ has joined #crystal-lang
j2k has quit [Read error: Connection reset by peer]
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 240 seconds]
j2k_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
Philpax__ has joined #crystal-lang
Philpax_ has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Philpax__ has quit [Read error: Connection reset by peer]
Philpax__ has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Philpax__ has quit [Read error: Connection reset by peer]
Philpax__ has joined #crystal-lang
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
Qchmqs has quit [Ping timeout: 260 seconds]
snsei has joined #crystal-lang
Philpax__ has quit [Ping timeout: 240 seconds]
FromGitter has quit [Ping timeout: 240 seconds]
FromGitter has joined #crystal-lang
A124 has quit [Quit: '']
A124 has joined #crystal-lang
rkeene_ is now known as rkeene
<jabb> is windows support on the crystal 1.0 roadmap?
<adam|> I believe so
<adam|> You see the latest posts about it?
<adam|> I think they even have some programs compiling.
adam| is now known as adam12
<jabb> yeah, there's a pull request open
<jabb> i would contribute, but my only windows computer is being borrowed for the next couple months lol
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<RX14> so aparrently building all_spec requires more than 4gb of ram
<RX14> but that's weird to me as it doesn't fail in travis
<RX14> ohh....
<RX14> 7.5gb ram
<RX14> sudo:required
<Yxhuvud> That is a bit much.
<RX14> yeah
soveran has quit [Remote host closed the connection]
<RX14> i kinda expect to be able to build in a t2.medium...
<RX14> well
<RX14> t2.large it is then I guess
<RX14> somehow it manages on OSX with only 4gb however
<jhass> is it crystal allocating that much or just llvm?
<RX14> the combination
<RX14> those are two crystal builds
<RX14> the latter is with a clean ~/.cache/crystal
<jhass> I wonder how much just crystal allocates, that whether there should focus on optimizing crystals own representations of stuff or how it uses LLVM
<RX14> hmm
<jhass> also how do we compare against say go compiling go?
<RX14> no idea...
<jhass> mh, given the GC warns that kinda hints at the former
<RX14> thats only a 4mb alloc jhass
<RX14> it's both
<RX14> as I said
<RX14> crystal uses 2gb ram
<RX14> llvm takes up the rest
<jhass> mh
<jhass> btw nightly.crystal-lang.org is probably going down quite soon (and currently broken anyway I think) as the server is not mine and being repurposed
<FromGitter> <sdogruyol> ugh that's sad
<RX14> we'll have nightlies on jenkins soon enough I hope
<jhass> RX14: so if you can't reach the responsible folk I can repoint the cname target to your CI or so
<jhass> just ping me here, I'll get it
<RX14> don't manas control the DNS for that?
<jhass> yes, it's nightly.crystal-lang.org CNAME crystal-dist.aeshna.de
<RX14> well it's not set up yet
<jhass> so I point the latter to whatever temporarily
<jhass> until the cname is changed
<RX14> and i'll need to discuss how we're setting it up
<RX14> and what exactly we want to build
<jhass> just saying in case they take some time to update it
<RX14> well it worked this time
<RX14> with 8gb ram :/
<jhass> oh I guess I could also share the repo keys with you
<jhass> (they're derived from the official repo key)
<jhass> just so you know
snsei has quit [Remote host closed the connection]
<jabb> is there a defer statement? i have something that needs to be run when at the end of a block
<Papierkorb> jabb: concurrently run or an anonymous function to call later?
<jabb> some function to call later, yeah
<RX14> jabb, no, just use a wrapper block
<jabb> synchronous. so "whenever the gc gets around to it" doesn't work
<RX14> a function which creates the resource, yields a block, and then destroys the resource
<jabb> say i have an "init" method, and a "shutdown" method. how do i guarantee shutdown gets called?
<Papierkorb> jabb: with what RX14 says. Make sure the call #shutdown in an ensure block.
<jabb> i see
<jabb> so wrap the whole program in a block?
<RX14> well just the part you need the object in...
<jabb> it's something that's needed for the entire lifetime
<jabb> but also needs to be cleaned up
<jabb> also, the init method could cause an exception
<RX14> thats why the new call is outside the ensure block
<Papierkorb> the init in the begin block, and then remove the begin keyword, and the corresponding end keyword too
<RX14> jabb, exactly
<RX14> isn't that what you want?
<jabb> i suppose, slightly less clean than something like defer which is 2 lines of code
<jabb> Papierkorb: example?
<Papierkorb> jabb: ^
<jabb> ahh, if init throws an exception though, no need to shutdown
<Papierkorb> If the #init is atomic in the sense of, if it raises there's nothing to clean up, outside
<jabb> it's atomic
<jabb> no half way steps. it either fully works, or nothing works
<RX14> jabb, yeah then the original code
<RX14> because init is outside of the begin/ensure/end block
<jabb> right exactly
<RX14> then shutdown won't be called if it raises
<RX14> jabb, the problem with defer is that you can forget it
<jabb> you can forget ensure too, plus they will be logically far apart
greengriminal has joined #crystal-lang
<jabb> defers they're coupled right next to each other
<jabb> this is fine though. :)
<RX14> but you use defer at every callsite
<RX14> ensure is only used once in some boilerplate
<RX14> and then it's as easy as Foo.open(args) do |foo| / end
<jabb> what about the case where you're trying to make an operator more atomic? having one ensure block will run ALL cleanup methods
<jabb> you'd have to embed begins/ensures
<jabb> a defer puts the call on the cleanup stack as needed
<jabb> an operation*
<FromGitter> <sdogruyol> why defer?
<RX14> if you need all of that in 1 method, then split it into multiple methods
<Papierkorb> jabb: And when is it cleaned up in that case? when the GC eats it?
<RX14> Papierkorb, no...
<Papierkorb> RX14: ?
<Papierkorb> I don't know of a `defer` mechanism
<RX14> i assume jabb has come from go
<jabb> i have go experience yes :D
<jabb> but it's not specific to go, it's a form of RAII
<Papierkorb> RAII would do that in the destructor
<jabb> as soon as it's put on the stack, when it goes out of scope it cleans itself up
<Papierkorb> which is at least comparable to "when the GC eats it"
<jabb> correct, which is guaranteed to run in C++, not so in a GC language
<jabb> guaranteed to run immediate*
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<RX14> Papierkorb, but defer is guaranteed to run immediately in go iirc
<jabb> yes
<FromGitter> <sdogruyol> @RX14 congrats :+1:
greengriminal has quit [Quit: Leaving]
<RX14> jabb, but you wouldn't do it that way in crystal
<jabb> what's the preferred way?
soveran has quit [Ping timeout: 255 seconds]
<RX14> r1, r2 and r3 would be objects
<RX14> and they would have .open methods
<jabb> this doesn't guarantee instant distruction
<RX14> jabb, yes it does
<RX14> listen
<RX14> then it's be R1.open do |r1|, R2.open do |r2|, R3.open do |r3|
<RX14> each of those open methods would use ensure to resuce
<jabb> i see, so it's somewhat limited horizontally regarding number of resources?
<RX14> horizontally? like screen space
<jabb> right, lots of inner scopes
<RX14> sure, but you typically don't have too many of those in practice
<jabb> yeah, true
<jabb> and then main would sit right in the center of that
<RX14> personally if I had 3, i'd split that out into another method
<RX14> which just ypieded all 3
<RX14> and put whatever in there
<RX14> or split the main out into a method
<jabb> okay, yeah. that's basically what i just wrote
<jabb> http://sprunge.us/UaWX doesn't this look simpler though? :P
<RX14> i guess, for that example
pawnbox has quit [Remote host closed the connection]
<jabb> also, is there a way to break out of an outer loop while i'm in a yielding block? :D
<RX14> jabb, typically i'd say at that point you want to refactor your code
<jabb> right now i have a main loop, with a function that polls for an event and calls a block. in the block i'd like to quit the loop
<RX14> return from the function
soveran has joined #crystal-lang
pawnbox has joined #crystal-lang
soveran has quit [Ping timeout: 268 seconds]
snsei has joined #crystal-lang
kubaxvx has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<jabb> i have a couple what seem to be run away processes on mac
<jabb> utilizing 95% cpu
<jabb> crystal-run-main.tmp
<FromGitter> <rishavs> hi guys. i need some help with implementing oauth. i have a simple webapp using Kemal, with crud operations. I have added the google login js into my frontend. what do i do next? I have an d token but know how do i use that to authenticate and authorise the user. can someone give me the broad pointers?
<FromGitter> <Rinkana> You need to save the token you get somewhere. It is used to communicate to the servers the token was from. With that token you can do requests on behalf of that user.
<FromGitter> <Rinkana> So: ⏎ ⏎ 1) You get the token from Google ⏎ 2) Save the token ⏎ 3) Use the token to access userdata from Google [https://gitter.im/crystal-lang/crystal?at=58b1e01c872fc8ce6283d36d]
<FromGitter> <rishavs> ok so, i send the token via http post to my backend and then save it in memory. how do i check if the user i the correct one?
<FromGitter> <rishavs> should i make a get request from my backend to a google api url and see if the tokens match?
<FromGitter> <Rinkana> Yeah you can do an GET request to Google with the auth token you get to validate it.
<FromGitter> <Rinkana> But does't the crystal Oauth2 already have this?
<FromGitter> <rishavs> in that example, "some_access_token" is where i put in the token id i got from the browser, right?
<FromGitter> <Rinkana> Correct
<FromGitter> <rishavs> so, i dont ad any more code at all? the oauth lib handles everything like failed auth ?
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
<FromGitter> <Rinkana> It seems that the std-lib OAuth2 only adds authentication headers. You still need to parse the result yourself (and so check if it was valid)
snsei has joined #crystal-lang
soveran has quit [Remote host closed the connection]
snsei has quit [Remote host closed the connection]
<FromGitter> <tekjar> Hi. How do I intialize an existing repo into a crystal lib?
<FromGitter> <Rinkana> @tekjar what do you mean?
triangles has joined #crystal-lang
<FromGitter> <tekjar> @Rinkana I'll create my repo from github ui and clone it. Now I want to do crystal init on this repo
<jabb> curious, what's the advantage to gitter over irc?
<RX14> it's easier to set up, essentially
<RX14> and you can paste multiple lines
<RX14> although thats dumb
<RX14> damn, even using --threads=1 I can't compile even std_spec with 4gb ram
mooe has joined #crystal-lang
mooe has left #crystal-lang [#crystal-lang]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter> <tekjar> Hi. How do I convert a `String` to `Slice(UInt8)` ?
<RX14> @tekjar use to_slice on the string
<FromGitter> <tekjar> RX14: Thanks alot
<FromGitter> <tekjar> I was searching for `Slice(UInt8)` in the `String` documentation
<RX14> yeah unfrtunately most methods don't have return types annotated
<RX14> would potentially be possible to suss out some simple return types for the docs in the future
<FromGitter> <tekjar> Yep. Helps newcomers like me to not bother you guys much :)
<FromGitter> <tekjar> One last question for the day
<FromGitter> <tekjar> How do I create tagged unions in crystal?
<BlaXpirit> tekjar, i don't get it
<BlaXpirit> or rather havent heard of this term
<FromGitter> <tekjar> BlaXpirit : Something similar to rust's enums
<BlaXpirit> ... could you provide a direct explanation?
<BlaXpirit> oh well, looking at it
<FromGitter> <tekjar> I'll try
<BlaXpirit> no, i don't think there is anything similar
<FromGitter> <tekjar> Ohhhh
<BlaXpirit> there's just unions which have data but no names and enums which have names but no data
<FromGitter> <tekjar> Ohh. I can get away with unions I guess
<BlaXpirit> you can put tuples in unions
<BlaXpirit> hm i wonder...
<BlaXpirit> tekjar, could try unions of namedtuples but it can get annoying to work with https://carc.in/#/r/1ob4
<FromGitter> <tekjar> I've never written crystal code before apart from some hello world progs. Can you please point me to an example ?
<FromGitter> <tekjar> Thanks. I'll try that
<BlaXpirit> tekjar, and for a simpler example that someone might actually write :| https://carc.in/#/r/1ob5
<FromGitter> <tekjar> Rust's way is to create enums and pattern match against the cases to extract its contents (also making sure that user handles all the cases). Do we have any such plans for crystal?
<BlaXpirit> tekjar, yeah unions make you consider all cases. but crystal usually avoids big unions and people never even think about needing tagged unions
<BlaXpirit> i recommend reading all of https://crystal-lang.org/docs/ , then you'll see the vision regarding this
<FromGitter> <tekjar> Oh cool thanks. I'll do that
<BlaXpirit> well, until the C bindings section, anyway
<FromGitter> <tekjar> Your last example link is redirecting to empty page though :)
<RX14> technically, crystal's unions are tagged unions
onionhammer has joined #crystal-lang
<RX14> just tagged with the type
<FromGitter> <schoening> If I have two arrays and I pop one item off the first one and insert it into the second one, there is not gonna be any GC, right? Just moving around reference "pointers" ?
<RX14> so typically you would just create a class/record/something for every possiblity, then stick them in a union
<RX14> @tekjar ^
<RX14> @schoening there can be
<RX14> you're decreasing the size of one, and increasing the size of another
<RX14> if there's not enough space to grow the other one it will call realloc
<RX14> and *may* get moved around
<FromGitter> <tekjar> Ohh. Sounds cool
<BlaXpirit> schoening, if these are Reference types, yeah, the objects have no reason to be collected because you keep a reference to them in the process of moving
<BlaXpirit> RX14 is talking about possible reallocation of memory for the array of pointers
<jabb> there isn't a huge amount of info on the docs on how the gc keeps track of stuff. do pointers not hold ownership of the data?
<jabb> what if i pass stuff to C, which expects an object to remain allocated
<RX14> @tekjar I guess doing what I said is a bit awkward but crystal programs tend not to grow that way, if you know what I mean
<FromGitter> <schoening> I was thinking about this today: I hope I am right in that an array *removing* elements from an array wont cause realloc? ⏎ @RX14, @BlaXpirit thanks for the answers :) I rather have a realloc than a lot of GC action I think :D preferably neither ofc
<RX14> removing elements can cause a realloc
<FromGitter> <schoening> Damn.
<RX14> wait, no it can't
<BlaXpirit> do arrays actually shrink? I'm not sure
<FromGitter> <schoening> Whew :p
<FromGitter> <schoening> That would kinda suck. Better safe than sorry I hope. If it got big once, it might again
bjz has joined #crystal-lang
<RX14> concat, push, unshift
<RX14> it should resize when it gets smaller
<RX14> i consider that a bug
<RX14> don't rely on it
<RX14> jabb, GC is a rather complicated topic, but essentially it scans the whole heap, looking for numbers which looks like pointers
<FromGitter> <schoening> I thought those things work like an "object pool" and they got an actual size that does not shrink back and a "fake" @size that is increased / decreased with those functions. But I haven't looked at the source code! That was just a wild guess.
<RX14> and if they point to an allocation, it's considered as visible
<jabb> i'm aware :P i'm curious about crossing the C barrier and which objects actually keep a reference so the GC holds onto it
<RX14> well calling a C function is usually fine as the references are on the stack
<RX14> however there are a few issues with C and the GC
<jabb> right, not seeing any reference to those. don't want to do something bad :P
<jabb> i expect objects on the heap coming from C are not accounted for, but passing an object to C which expects it to last awhile...?
<jabb> also, are there any weak references?
<RX14> there's WeakRef(T)
<BlaXpirit> jabb, well you need to have at least one variable pointing to an object so it's not collected, for C to be able to use it
<RX14> it's not in the docs
<jabb> ahh, just found it
<RX14> jabb, except 99% of the stuff that you pass into C is on the stack
<RX14> so it's not a huge issue
<BlaXpirit> jabb, only GC.alloc or whatever it's called is accounted for
<jabb> RX14: stuff on stack could go out of scope no?
<BlaXpirit> if memory is allocated by C, the GC does not track it, at least not intentionally
<RX14> what do you mean?
<RX14> the GC doesn't work on the stack...
<RX14> that just wouldn't work
<BlaXpirit> jabb, yes, i think you understand the situation but RX14 might be understanding your question differently
<RX14> pointers on the stack always count, the stack will never be GCed
<BlaXpirit> if u create something, give it to C code which keeps the pointer, and say exit the function, there will be breakage
<jabb> int a def: foo = 5; c_function_that_keeps_passed(pointerof(foo))
<RX14> as long as you don't pass a pointer to a *crystal* object to a *C* function you're ok
<jabb> BlaXpirit: gotcha
<RX14> well yeah thats just dangling pointers
<RX14> C 101
<jabb> right
<jabb> what about
<RX14> if you're using C bindings you still have to follow C rules
<jabb> can a C struct be allocated on the heap?
<jabb> a crystal C struct
<RX14> well technically yes
<RX14> but it involves a manual GC.malloc
<jabb> gotcha
<RX14> and some pointer fudging
<RX14> so typically no
<jabb> and i would have to keep a reference for as long as C needs that
<BlaXpirit> or array of 1 item
<RX14> or that BlaXpirit lol
<BlaXpirit> jabb, yes, usually in an instance variable
<jabb> makes sense
<RX14> typically the GC/C issue comes when you're passing a callback to C
<jabb> a closure?
<RX14> and want to pass in some sort of "payload data" as a void*
<jabb> ahhh, yeah
<RX14> (typically a closure)
<BlaXpirit> yeah closures happen too
<RX14> jabb, read the "passing a proc to a C function" bit
<jabb> yep reading it
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 268 seconds]
elia has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]