<FromGitter>
<j8r> What's the common way to expose an immutable stdlib object, like Array or Hash?
<FromGitter>
<j8r> I usually make my own methods, but that's a bit redundant...
<FromGitter>
<j8r> The problem is using a getter exposes a reference, which can be modified... I may create a shard to have an "immutable" wrapper struct, or using another macro-fu solution
<FromGitter>
<Blacksmoke16> i know some libs return a cloned instance
HumanG33k has quit [Remote host closed the connection]
<oprypin>
j8r, write in docs "don't modify it"
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter>
<incognitorobito> Is it possible to alias LibC functions?
<FromGitter>
<mattrberry> `Error: can't take address of pointerof(source)`
<FromGitter>
<Blacksmoke16> oof
<FromGitter>
<mattrberry> When I do `pointerof(pointerof(source))`
<FromGitter>
<Blacksmoke16> right, need to do it in two separate calls like i ahd
<FromGitter>
<mattrberry> Ahh sorry, thanks
<FromGitter>
<mattrberry> Sort of related: This function seems like it's taking a Pointer(Pointer(UInt8)), which is supposed to be the pointer to a pointer of a String. In crystal, when I get the pointer to the pointer of a string, I end up with Pointer(Pointer(String)), which makes sense.. Why do you think this function is expecting a Pointer(Pointer(UInt8))?
<FromGitter>
<mattrberry> I don't really know C or OpenGL, so I guess I'll know if it works once it works :p
<FromGitter>
<Blacksmoke16> :P gl
zorp has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
_whitelogger has joined #crystal-lang
melthelesbian has quit [Ping timeout: 240 seconds]
kevinsjoberg has quit [Ping timeout: 240 seconds]
r0bby has quit [Ping timeout: 264 seconds]
jetpack_joe has quit [Ping timeout: 260 seconds]
issyl0 has quit [Ping timeout: 260 seconds]
jetpack_joe has joined #crystal-lang
r0bby has joined #crystal-lang
melthelesbian has joined #crystal-lang
kevinsjoberg has joined #crystal-lang
issyl0 has joined #crystal-lang
<FromGitter>
<pebauer68> How could I get also the type of the instance vars ? ⏎ def list_instance_vars : String ⏎ ⏎ ```res = {{ @type.instance_vars.map &.name.stringify }}.each { |elem| puts elem }.to_s``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5fa7bb002a35440715113774]
<FromGitter>
<asterite> Matthew: A crystal string can be turned into pointer(UInt8) by calling to_unsafe on it. If you need a pointer of that, you can assign that to_unsafe call to a variable x and then pass pointerof(x) to C
<FromGitter>
<Sija> any1 knows is there an easy way to run GHA CI against crystal nightlies (as in Travis)?
JuanMiguel has joined #crystal-lang
_whitelogger has joined #crystal-lang
JuanMiguel has quit [Quit: This computer has gone to sleep]
<FromGitter>
<j8r> It is doable to create a new type, and iterate over methods of Array an reject those inducing a mutation
<FromGitter>
<j8r> or, having a more generic Enumerable/Indexable wrapper type
<oprypin>
j8r, just make it implement Indexable and thats it. should be a `struct`.
<FromGitter>
<j8r> yep
<FromGitter>
<j8r> there are some specific methods related to Array that won't be present, though. May not be a big deal, because there is `Indexable#to_a`
<FromGitter>
<j8r> the same cannot be said for Hash
<oprypin>
yea 😬
duane has joined #crystal-lang
<FromGitter>
<HertzDevil> more the reason to have an associative container module distinct from `Indexable`
sagax has quit [Ping timeout: 240 seconds]
<oprypin>
yea
<oprypin>
seems liek a perfect post-1.0 feature request 😊
go|dfish has quit [Ping timeout: 246 seconds]
<Andriamanitra>
is there a shorthand for "arr.map{|x| fun(x)}"? similarly as with methods you could write simply "arr.map(&.fun)"
<FromGitter>
<j8r> no
<Andriamanitra>
that's unfortunate :(
<FromGitter>
<Blacksmoke16> there is actually
<FromGitter>
<Blacksmoke16> `arr.map &->fun(String)` where `String` is the type of each array element
<Andriamanitra>
nice, although i assume you can't give the function additional parameters?
<oprypin>
mattrberry, literally all you need (going from the former example) is `source_ptr = source.to_unsafe`
<FromGitter>
<mattrberry> Does String.to_unsafe null-terminate the string? @oprypin
<oprypin>
mattrberry, yes
<FromGitter>
<mattrberry> Or does it just take the pointer?
<FromGitter>
<mattrberry> Interesting, so I guess that's not my problem..
<oprypin>
well yes it does just take the pointer, but string is guaranteed to have that null pointer at the end of the memory even though it's not necessary for its operation
<oprypin>
s/null pointer/null byte/
<FromGitter>
<mattrberry> Oh I didn't realize that Crystal strings were guaranteed to be null-terminated
<oprypin>
mattrberry, also im not sure u may have some misunderstanding between `pointerof( )` and `to_unsafe`
<oprypin>
so a Crystal type might happen to have some internal data that's useful to be given to C, then that type can have a `to_unsafe` method, which could be the only way to access that internal data
<oprypin>
meanwhile, `pointerof( )` has nothing to do with that, it's quite simply a pointer *to* (on top of) the Crystal type
<FromGitter>
<mattrberry> Sorry yeah I see that haha
<FromGitter>
<mattrberry> @oprypin You have some experience with opengl, right?
<oprypin>
minimal
<FromGitter>
<mattrberry> That's specifically what I'm trying to use this for right now
<FromGitter>
<mattrberry> I'm trying to pass a shader into glShaderSource
<oprypin>
still not using sfml (which makes that trivial)?
<FromGitter>
<mattrberry> sfml makes other stuff harder
<FromGitter>
<mattrberry> It's not strictly an improvement
<oprypin>
sorry for my plugging lol. well anyway i think i can help if you show me what you have on Crystal side and also the docs of the opengl function
<oprypin>
mattrberry, so have u noticed that glShaderSource expects an array of strings? i don't understand, why is it an *array* what is the meaning behind string 1, string 2, string 3, ...?
<oprypin>
in any case let's assume you do have an array of strings in crystal: a = ["a", "b", "c"]
<FromGitter>
<mattrberry> This answer seems to imply that you can just give it the pointer to a null-terminated string https://stackoverflow.com/a/22100409
<oprypin>
... then the call is `glShaderSource(handle, a.size, a.map(&.to_unsafe), a.map(&.size))`
<oprypin>
(for the last two, an implicit `.to_unsafe` is added by crystal)
<oprypin>
"you can just give it the pointer to a null-terminated string" - that, i guess, is true, but it still looks at it as an array of 1 null-terminated string
<oprypin>
ok so you have 1 string after all. `s = "a"`
<FromGitter>
<mattrberry> > *<oprypin>* ok so you have 1 string after all. `s = "a"` ⏎ ⏎ Hmm?
<oprypin>
... then the call is `sp = s.to_unsafe; glShaderSource(handle, 1, pointerof(sp), nil)`
<FromGitter>
<mattrberry> > *<oprypin>* ... alternatively `sp = s.to_unsafe; ss = s.size; glShaderSource(handle, 1, pointerof(sp), pointerof(ss))` ⏎ ⏎ Okay by doing this I don't get any errors from gl!
<FromGitter>
<mattrberry> So the difference was calling `s.to_unsafe` rather than `pointerof(s)`
<FromGitter>
<asterite> I think my previous message didn't go out
<FromGitter>
<asterite> by calling to_unsafe on a string you get pointer(uint8), which is how a C "string" is represented
<FromGitter>
<asterite> if you then assign that to a variable x and do `pointerof(x)` you get `pointer(pointer(uint8))` which is what you need for the C function you have there
<FromGitter>
<mattrberry> Yep that's exactly what my problem was and is working now, thanks :)
duane has quit [Ping timeout: 260 seconds]
<yxhuvud>
AHA! Just found the root of the issue I've been fighting with for several sessions. The tie-in to libevent is so hard I understand why the people that tried to do windows io want a rewrite of the event loop.
duane has joined #crystal-lang
<FromGitter>
<incognitorobito> @yxhuvud Are you working on getting the event loop working on windows?
<yxhuvud>
No. I'm working on monketpatching the normal libevent based event loop to instead use io_uring.
<yxhuvud>
but a lot of the problems you run into is the same.
duane has quit [Ping timeout: 260 seconds]
<FromGitter>
<j8r> yxhuvud you'll submit a PR/patch to libevent?!
<FromGitter>
<j8r> I'm curious about what gain can yield io_uring, I doubt much