jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
postmodern has quit [Quit: Leaving]
_whitelogger has joined #crystal-lang
<oprypin> [00:48:59] <8e55e9@dscottboggs_gitlab> How to link with a single-header library?
<oprypin> compile it as not a header
<oprypin> rename it to .c basically :D
<oprypin> in terms of c++, just show it to me, I'll tell you how bad it is
<FromGitter> <naqvis> Crystal bindings to Webview
alexherbo2 has joined #crystal-lang
zorp_ has joined #crystal-lang
<FromGitter> <michalgritzbach> hi, i'm just starting with crystal and have a very beginner question – i've got type alias `alias FilterParams = {name: String?, status: Status?, gender: Gender?, species: String?, race: String?}`, but don't know how to use it
<FromGitter> <michalgritzbach> when i do something like `Character::FilterParams{"name" => "Rick", "status" => :dead}`, I get `Error: no overload matches 'NamedTuple(name: String | Nil, status: Character::Status | Nil, gender: Character::Gender | Nil, species: String | Nil, race: String | Nil).new'`
<FromGitter> <michalgritzbach> (i get the same error when even when i try the "full" version, with all the attributes)
<FromGitter> <michalgritzbach> can you point me in the right direction please? O:)
<FromGitter> <naqvis> @michalgritzbach Welcome aboard
<FromGitter> <naqvis> NamedTuple (https://crystal-lang.org/api/0.35.1/NamedTuple.html) is fixed-size, immutable, stack-allocated mapping of a fixed set of keys to values.
<FromGitter> <naqvis> if you need a custom type, you should look into `Struct` or `Class`
<FromGitter> <naqvis> for example you can use `record` macro to define a `Struct` like below ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f40ea4149148b41c9654c9d]
<yxhuvud> oprypin: *renaming* to .c is not sufficient in the general case. But creating a shim .c that include the .h which create functions that exposes the functions you need should work. The same strategy is needed for any functions defined in a .h with a static inline modifier.
<oprypin> yxhuvud, i dont get it
<oprypin> 'static inline' - sure, but who would do such a thing
<yxhuvud> a .h file may have arbitrary amounts of preprocessor macros, which simply won't work to link with.
<yxhuvud> oprypin: The lib I write bindings against does such a thing :D
<oprypin> D:
<oprypin> lemme know if u need help
<yxhuvud> thanks but I have it handled. It took a while to figure it out, but in the end it was pretty simple. Less simple is keeping up with the evolving structs at the heart of it. https://github.com/axboe/liburing/blob/master/src/include/liburing/io_uring.h#L21-L66 is not the funniest thing to define in crystal..
<oprypin> ooooh
<oprypin> yxhuvud, cant you use an autogenerator for that struct?
<yxhuvud> the autogenerators I've found gave up on the static inline stuff :), but as I now mostly have to handle updates to it it's manageable. https://github.com/yxhuvud/ior/blob/master/src/lib/liburing.cr#L125
<yxhuvud> having to invent names for unnamed unions is no fun though :(
alexherbo24 has joined #crystal-lang
<oprypin> you know whats better than parsing c++ code with regex? parsing it with regex after having run clang-format and clang-tidy 😌
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <michalgritzbach> @naqvis awesome, thank you!
<FromGitter> <naqvis> 👍
yxhuvud has quit [Remote host closed the connection]
yxhuvud has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> oprypin, I linked the code in the original comment. It's the `webview/webview` library. ⏎ ⏎ yxhuvud, thanks for your advice ⏎ ⏎ The original header declares and documents the `extern` functions at the top of the file, so I'm gonna try cutting that out, putting it in a separate `.h` file, and renaming the (edited) original to `.cc`, then compile a `.o` with clang. ...
<oprypin> dscottboggs_gitlab, wait what about https://github.com/naqvis/webview indeed
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <j8r> @wyhaines thanks for the summary!
<FromGitter> <j8r> AFAIK the default dictionary is trained with lots of different type of data
<FromGitter> <j8r> I think a general purposed dictionary is less perfomant than a specialised dictionary.
<FromGitter> <alexherbo2> how about the ruby syntax `fn[args]` as a shorcut to `fn.call(args)`?
<FromGitter> <Blacksmoke16> you can do `fn *args` if `args` is a tuple
<FromGitter> <alexherbo2> no it's not splat
<FromGitter> <Blacksmoke16> i know, but that isnt possible. Splat would be your closest option
<FromGitter> <alexherbo2> `fn[a, b, c]`
<FromGitter> <alexherbo2> like `fn.call(a, b, c)`
<FromGitter> <alexherbo2> only for procs/lambda
<FromGitter> <Blacksmoke16> there isnt call in crystal
<FromGitter> <alexherbo2> how my code work xD
<FromGitter> <Blacksmoke16> so you'll just have to do `fn.call a, b, c` where `fn` is a proc
<FromGitter> <alexherbo2> ```format_content.call(snippet.content)```
<FromGitter> <Blacksmoke16> sorry, there isnt the actual `call` method, for calling arbitrary methods on an obj
<FromGitter> <Blacksmoke16> in this case `call` is what invokes the proc
<FromGitter> <alexherbo2> yep
<FromGitter> <Blacksmoke16> doesnt exist
<FromGitter> <Blacksmoke16> prob could add it as an alias to `call`, but whats the benefit?
<FromGitter> <alexherbo2> it's just a syntax sugar
<FromGitter> <sardaukar> if I have a custom class and define a `to_s` method on it, it will be used inside string interpolation, right?
<FromGitter> <naqvis> yes
<FromGitter> <Blacksmoke16> make sure you define `to_s(io : IO) : Nil`, not `to_s : String`
<FromGitter> <sardaukar> Nil ?
<FromGitter> <sardaukar> I don't get output with that
<FromGitter> <Blacksmoke16> you have to write the content to the io
<FromGitter> <sardaukar> oh ok
<FromGitter> <sardaukar> hmm ok that works with io.puts xxxx
<FromGitter> <sardaukar> TIL
<FromGitter> <sardaukar> not super intuitive
<FromGitter> <Blacksmoke16> https://github.com/crystal-ameba/ameba/issues/165 yes, the reasoning is they invoke two diff methods ^
<FromGitter> <dscottboggs_gitlab> oprypin, shit, hate when I do that
<FromGitter> <dscottboggs_gitlab> hm, my shard actually takes a different approach, and I'm hoping to make it a little more ergonomic, in ways that wouldn't exactly work with how he's set it up.
<FromGitter> <dscottboggs_gitlab> it's a tiny library so the bindings were easy.
postmodern has joined #crystal-lang
<FromGitter> <grkek> Do you guys like Grip at all?
<FromGitter> <grkek> I am having double thoughts about my work
<FromGitter> <grkek> Good side and bad side, I sure know I might just go ahead and delete the github repo, github profile and then cry alone :D
<FromGitter> <dscottboggs_gitlab> idk it's nice to have a simple router, it's not bad. I'm just not excited about web frameworks in Crystal because they're so damn common
<FromGitter> <grkek> I made an UI framework too
<FromGitter> <dscottboggs_gitlab> Oh??
<FromGitter> <grkek> It just needs tests to get accepted to the crystal awesome list
<FromGitter> <grkek> 1 sec
<FromGitter> <grkek> https://github.com/grkek/iu
<FromGitter> <grkek> here you go
<FromGitter> <grkek> It is a bit clustered and needs refining but its not a bad idea
<FromGitter> <grkek> > nice to have a simple router
<FromGitter> <dscottboggs_gitlab> That's awesome! Just looking at the example here, and I wonder why you do `on_close = ->(window)` instead of `on_close do |window|`
<FromGitter> <grkek> I really like it because of the simplicity
<FromGitter> <grkek> ah that
<FromGitter> <grkek> I don't really know how to use procs
<FromGitter> <grkek> I hate procs
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <grkek> I just couldn't use anything else
<FromGitter> <grkek> so I do it in a way I know
<FromGitter> <grkek> now on I know a better way to do it thanks to you
<FromGitter> <grkek> :)
<FromGitter> <dscottboggs_gitlab> you can keep everything the way it is but add ⏎ ⏎ ```def on_close ⏎ @on_close = ->(window : Iu::Ui::Window) { yield window } ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f413d9059ac794e02bbe13c]
<FromGitter> <grkek> That looks really cool
<FromGitter> <grkek> Do you like the layer approach?
<FromGitter> <grkek> Also one guy on reddit told me that oop with web frameworks makes no sense, what did he mean by that?
<FromGitter> <dscottboggs_gitlab> > Do you like the layer approach? ⏎ ⏎ I'll have to look more ⏎ ⏎ > what did he mean by that? ... [https://gitter.im/crystal-lang/crystal?at=5f413df69566774dfe263b76]
<FromGitter> <grkek> He told me he liked the Kemal approach better and didn't understand why I did the oop approach for structure
<FromGitter> <dscottboggs_gitlab> I really like athena. I see the appeal of lucky but I don't want to spend the time to learn it unless I have a reason to (i.e. for a job). Athena seemed like it was gonna be a lot, but it's actually really easy to just use the router component and then reach of other tools from it only when you need it, so the learning curve is more gradual instead of having to learn a bunch of stuff up front like
<FromGitter> ... with lucky or other big monolithic frameworks like rails
<FromGitter> <dscottboggs_gitlab> so like...by being easy to get started with and *really* well documented, Athena kinda makes the whole class of router-only web frameworks obsolete in crystal, because you can just only use the router part of it and not have to learn the rest
<FromGitter> <dscottboggs_gitlab> sorry :(
<FromGitter> <grkek> Hm
<FromGitter> <grkek> I wonder what
<FromGitter> <grkek> You don't really need to learn anything to use grip
<FromGitter> <grkek> define controller => define route => ??? => profit
<FromGitter> <dscottboggs_gitlab> well, you need to learn the DSL and how to define routes, which is the same as for any other web-router.
<FromGitter> <dscottboggs_gitlab> I'm saying athena doesn't require you to learn *more* than that to get started, but it also comes with a slew of other useful tools
<FromGitter> <dscottboggs_gitlab> and you never know what tools you're gonna need until you go solve something and realize there's already a tool to help with that.
<FromGitter> <grkek> Oh that is so cool
<FromGitter> <grkek> well I might actually try using athena
<FromGitter> <dscottboggs_gitlab> nice 😀
<FromGitter> <dscottboggs_gitlab> Re: IU layers ⏎ ⏎ I like it but I would do the naming a bit different.
<FromGitter> <grkek> Likewhat
<FromGitter> <dscottboggs_gitlab> instead of `do` and `undo` I would use...idk, I want to say `initialize` and `finalize` but those are already taken. `create` and `destroy`, perhaps?
<FromGitter> <grkek> Sounds wise and interesting, I was just messing around with it and didn't even mean to do anything serious
<FromGitter> <grkek> it works nicely
<FromGitter> <grkek> I might continue my efforts with the UI framework
<FromGitter> <grkek> I think I am done with Grip for a while now
<FromGitter> <dscottboggs_gitlab> in general, though, I'm super excited to see a Crystal UI framework based on libui.
<FromGitter> <dscottboggs_gitlab> > I think I am done with Grip for a while now ⏎ ⏎ You did just release 1.0, nothing wrong with calling it "done" haha
<FromGitter> <grkek> Is there something wrong with actually doing that?
<FromGitter> <grkek> I am new to this so I am not quite sure what I am doing via the versioning
<FromGitter> <grkek> I just built the framework for myself and since others began to like it I thought it would be nice to put more effort in it
<FromGitter> <dscottboggs_gitlab> no, not at all. Plenty of projects reach a point where the creator says "this has all the features I want, I'll just fix bugs and move on to other stuff"
<FromGitter> <grkek> Sounds cute
<FromGitter> <grkek> thank you :)
<FromGitter> <grkek> Ill continue work on IU
<FromGitter> <dscottboggs_gitlab> 😀
<FromGitter> <grkek> Other UI frameworks piss me off
<FromGitter> <dscottboggs_gitlab> oh?
<FromGitter> <grkek> the GObject one has no documentation
<FromGitter> <grkek> hedron has no support
<FromGitter> <grkek> libui is literally bones
<FromGitter> <dscottboggs_gitlab> well, it does if you know C ;) lol
<FromGitter> <grkek> That is the problem here, I know C but I hate C at the same time
<FromGitter> <dscottboggs_gitlab> yeah that was kinda what I was thinking tbh, I wish libui/hedron weas in a better state
<FromGitter> <grkek> Basically I took hedron and slapped bunch of stuff on it
<FromGitter> <dscottboggs_gitlab> > I hate C ⏎ ⏎ I can feel you there.
<FromGitter> <grkek> It is a love hate relationship
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab ❤️ welcome to the dark side :S
<FromGitter> <dscottboggs_gitlab> 😀
<FromGitter> <grkek> @Blacksmoke16 I pissed you off with the comment on the Kemal issue didn't I
<FromGitter> <Blacksmoke16> i'll just say going into another project and basically saying "you should try my project instead since it's better and has more features" probably isn't the most conscientious thing to do
<FromGitter> <grkek> Sorry, I explained I am autistic and I can't help it
<FromGitter> <dscottboggs_gitlab> oof, yeah, that's not very nice. But this seems like a discussion that could've been had privately....
<FromGitter> <Blacksmoke16> meh, not really a big deal. Maybe a bit frowned upon but it could be worse :S
<FromGitter> <dscottboggs_gitlab> does anybody know what this means? ⏎ ⏎ > `Program received and didn't handle signal IOT (6)`
<FromGitter> <grkek> You sent a kill code of 6
<FromGitter> <Blacksmoke16> esp since kemal dev isnt super active atm, having alternatives is a good thing. Just could have worded it a bit better 😉
<FromGitter> <grkek> and the program doesn't know hot handle
<FromGitter> <dscottboggs_gitlab> All I can find online is "you're doing something not thread safe, specifically in Crystal, not some other language"
<FromGitter> <grkek> @Blacksmoke16 You are right I am not good with words:p
<FromGitter> <dscottboggs_gitlab> yes, i know, but `man signal.h` doesn't document a signal IOT
<FromGitter> <mwlang> I see Crystal has Colorize for colorizing outputs to terminal, but what about TTY Cursor functionality for clearing screens, moving cursor around, etc?
<FromGitter> <dscottboggs_gitlab> @grkek I wouldn't worry too much about it. we all fuck up and step on each other's toes once in a while. Best thing to do is apologize and move on, and try not to do the samme thing again
<FromGitter> <dscottboggs_gitlab> @mwlang there is a curses library but I'm not sure about ANSI codes
<FromGitter> <Blacksmoke16> too bad you cant write minecrat mods in crystal :S
<FromGitter> <dscottboggs_gitlab> you can just look up the code for what you want to do and print the control code to stdout
<FromGitter> <mwlang> is that in a shard or a class of Crystals?
<FromGitter> <dscottboggs_gitlab> it's a shard
<FromGitter> <mwlang> ok thanks. I will hunt it down.
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16, why not?
<FromGitter> <Blacksmoke16> has to be a `.jar` afaik?
<FromGitter> <Blacksmoke16> aka java/kotlin
<FromGitter> <dscottboggs_gitlab> ooh
<FromGitter> <dscottboggs_gitlab> kotlin's nice though
<FromGitter> <grkek> You can write
<FromGitter> <grkek> minecraft mods
<FromGitter> <grkek> in crystal
<FromGitter> <grkek> with a bit of dedication
<FromGitter> <grkek> :p
<FromGitter> <Blacksmoke16> https://github.com/davidar/lljvm :thinking:
<FromGitter> <Blacksmoke16> wew, a bit old tho
<FromGitter> <grkek> There we go
<FromGitter> <grkek> Just compile Crystal to Java
<FromGitter> <dscottboggs_gitlab> oh no
<FromGitter> <dscottboggs_gitlab> pls don't lol
<FromGitter> <grkek> Ikr
<FromGitter> <grkek> Fucking java
<FromGitter> <grkek> lmao
<FromGitter> <grkek> public static protected const ps4 xboxone skyrim FunctionName()
<FromGitter> <dscottboggs_gitlab> > LLVM 2.7 ⏎ ⏎ Yeahh...that's not gonna work
<FromGitter> <Blacksmoke16> 😆
<FromGitter> <grkek> Look at me making fun of Java when I used to be a C# dev for a while
<FromGitter> <grkek> @Blacksmoke16 how do you deal with multiple controllers in ART?
<FromGitter> <Blacksmoke16> deal with them how?
<FromGitter> <grkek> Like they each need a route defined in the controller right?
<FromGitter> <Blacksmoke16> a controller is simply a logical grouping of actions (endpoints)
<FromGitter> <Blacksmoke16> can have 1 or more
<FromGitter> <Blacksmoke16> the actions are simply methods and the controller is just a class
<FromGitter> <grkek> What I mean is that when you separate them into files
<FromGitter> <grkek> dont you just have to go searching for single file of the controllers just to view the route?
<FromGitter> <Blacksmoke16> like in terms of the implementation, or a dev wanting to find one of their endpoints?
<FromGitter> <grkek> Dev wanting to find a route
<FromGitter> <grkek> Imagine, I am new to the project and I wanna see the routes
<FromGitter> <grkek> like 5 times an hour through a huge ass project
<FromGitter> <grkek> :D
<FromGitter> <Blacksmoke16> i mean ideally the project would be like `src/controllers/article_controller` or whatever
<FromGitter> <Blacksmoke16> or something along those lines, or just grep the path
<FromGitter> <grkek> So each controller has the routes
<FromGitter> <grkek> I like the grip approach more you group routes in one file
<FromGitter> <Blacksmoke16> i have plans for a cli that could be used to debug stuff, like
<FromGitter> <Blacksmoke16> `./bin/athena debug:routes`
<FromGitter> <grkek> Oh thats really nice
<FromGitter> <grkek> the annotations will allow you to do that
<FromGitter> <grkek> pretty strong stuff
<FromGitter> <Blacksmoke16> yes, symfony has it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f4147049bad075eaccd593e]
<FromGitter> <Blacksmoke16> so yea, could show name/path/controller etc
<FromGitter> <grkek> I used to do that with grip
<FromGitter> <grkek> then thought it was stupid and did the now controller thing
<FromGitter> <Blacksmoke16> main use for controllers in my case is DI
<FromGitter> <grkek> I wish crystal had hot reloading
<FromGitter> <Blacksmoke16> as well as the logical/organization grouping
<FromGitter> <grkek> DI is nice I think you have a shard as I recall yes?
<FromGitter> <Blacksmoke16> i do
<FromGitter> <grkek> @Blacksmoke16 I fixed up the IU and fixed the CI
<FromGitter> <grkek> added the compile test with github actions so it should comply with the awesome list
hightower2 has joined #crystal-lang
<FromGitter> <Blacksmoke16> can you setup a periodic build as well? Like once a week or something
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <mwlang> trying to figure out how to parse a json from websocket where the stream name must be used to discriminate the payload. I found `JSON::Serializable.use_json_discriminator` but the examples I saw expected a fairly simple value.
<FromGitter> <mwlang> I have to split the stream name into two parts to then determine payload.
<FromGitter> <mwlang> for example, if it's a ticker stream, the name of the stream is `market_symbol@ticker` (i.e. `btcusdt@ticker`) and 'ticker' would be the discriminator
<FromGitter> <mwlang> any thoughts on how I might approach this?
<FromGitter> <mwlang> I thought about a converter that splits up that stream name into two string properties, but not sure how to do that, either. :-/
<FromGitter> <j8r> the stream name?
<FromGitter> <mwlang> I do know how to convert into a struct with two properties, though!
<FromGitter> <j8r> how do you get it?
<FromGitter> <mwlang> for example: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f418640d4f0f55ebbd4231f]
<FromGitter> <j8r> ha inside the JSON
<FromGitter> <mwlang> yup
<FromGitter> <j8r> I'd say "just" to a custom `from_json`
<FromGitter> <j8r> making a carc.in
<FromGitter> <mwlang> carc.in? what's that?
<FromGitter> <j8r> the snippet site to execute crystal
<FromGitter> <mwlang> oh, I see!
<FromGitter> <mwlang> actually, I just realized something... that "e" field is on all the different "data" points, so that could be the discriminator.
<FromGitter> <j8r> got it, I struggle as a noob with your example
<FromGitter> <j8r> that's because of the last `,`, that's invalid JSON
<FromGitter> <mwlang> oh, delete that last comma, I redacted about 10 more fields.
<FromGitter> <mwlang> I figured once it's flowing this far, easy to extend.
<FromGitter> <j8r> https://carc.in/#/r/9ktr
<FromGitter> <j8r> so this way you can do whatever you want
alexherbo24 has joined #crystal-lang
<FromGitter> <j8r> in your case, you can `#partition('@')`
<FromGitter> <mwlang> thanks for that. that gets me going in a solid direction.
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <mwlang> is `partition` better than `split` in this case?
<oprypin> mwlang, are u looking to get two items? then parition is better
<oprypin> split needs to make an array which is somewhat expensive
zorp_ has quit [Ping timeout: 265 seconds]
<oprypin> not to mention that partition is often more convenient for 2 items
<FromGitter> <mwlang> yes, two items.
<FromGitter> <mwlang> ok, I'll read up on partition -- definitely sounds like the right way to go.
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 265 seconds]
<FromGitter> <j8r> yep, plus don't have to set the `limit: 2` in case of `split`
<FromGitter> <j8r> the only little annoying thing is the `_`: `first, _, second` - no big deal though
postmodern has quit [Quit: Leaving]
<FromGitter> <mwlang> Ugh. I can't quite make the leap from your example to a full-fledged solution: https://carc.in/#/r/9ktu
<FromGitter> <j8r> @mwlang : https://carc.in/#/r/9ktz
<FromGitter> <j8r> Beware of the global `from_json` pollution on all objects, it makes harder to debug :(
<FromGitter> <j8r> I hate this, this methods are not even working when they don't implement `new(pull )`
<FromGitter> <j8r> A bit better: https://carc.in/#/r/9ku1
<FromGitter> <mwlang> Argh! I remember this from last year now that I see your solution.
<FromGitter> <j8r> honestly, the stdlib should only have had the pull parsers, IMO
<FromGitter> <mwlang> I forgot about the need to implement a `#new`
<FromGitter> <mwlang> but you're right. It's pretty aggravating and challenging to debug.
<FromGitter> <j8r> Side note, Steam can be struct because immutable, and and in the initializer you can do `initialize(@stream : String, @symbol : String, @name : String, @data : Data)`
_whitelogger has joined #crystal-lang
<oprypin> Free ebook access to SFML Game Development for the next hour: https://www.packtpub.com/free-learning
<oprypin> I'm sure it will be a pleasure to follow with Crystal lang instead 😊
<FromGitter> <dscottboggs_gitlab> it's not like you can finish it in the next 40 minutes, what a tease
<oprypin> lol oh no i think the access is permanent
<FromGitter> <dscottboggs_gitlab> > Unhandled exception: passing a closure to C is not allowed (Exception) ⏎ ⏎ 😡
<FromGitter> <dscottboggs_gitlab> > The reason is that a Proc is internally represented as two void pointers, one having the function pointer and another the closure data. If just the function pointer is passed, the closure data will be missing at invocation time. ⏎ ⏎ Ah, that actually makes sense. I just wish there was some way around it... :(