ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<_tsound> is there anyway to require variables?
<_tsound> (ex. john = "doe" require john)?
<_tsound> doing it that way throws an error
<FromGitter> <picatz> You can put them in a module in a file and then require that file with the module with the variables in another file I'd imagine.
<FromGitter> <picatz> Not even sure you need to put them in a module. Or if that's what you're going for :O
<_tsound> really I want to interpolate the require file, but you can't do that
<_tsound> (ex. require "#{foo}/bar")
<FromGitter> <faustinoaq> You can use macros
<_tsound> thanks, that works
<_tsound> oh no it doesn't
<_tsound> still can't require with it
<FromGitter> <faustinoaq> ```{% if true %} ⏎ {% foo = "son" %} ⏎ require {{"j#{foo.id}"}} ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=597bd965210ac2692035c08e]
<FromGitter> <faustinoaq> https://carc.in/#/r/2fsh
<_tsound> oh I c :D
<_tsound> thanks again faustinoaq
<FromGitter> <mgarciaisaia> Not sure if Ruby bindings are the best starting point for porting to Crystal. Ruby has all the RubyObject<-->C struct interop that Crystal doesn't need at all. Take a look at crystal_lib, use any existing Ruby binding as API interface "guidance", but think in Crystal - not Ruby :)
Philpax_ has joined #crystal-lang
<FromGitter> <faustinoaq> @mgarciaisaia Would be posible to do a Ruby implementation in Crystal?
<FromGitter> <mgarciaisaia> What do you mean?
<FromGitter> <mgarciaisaia> Implementing a Ruby interpreter in Crystal?
<FromGitter> <faustinoaq> yeah
<FromGitter> <mgarciaisaia> Isn't it enough work to do *one* language? RLY? :P
<FromGitter> <faustinoaq> Would be funny, ruby -> crystal, crystal -> crystal, crystal -> ruby πŸ˜„
<FromGitter> <mgarciaisaia> I don't see why it would be different from doing, say, JRuby or any other non-MRI implementation
<FromGitter> <mgarciaisaia> I *think* I've read there's no formal Ruby spec, so basicaly "Do what MRI does" is the spec. That usually gives implementors soooooo many headaches... ⏎ But you *could* do it if you wanted, I think
<_tsound> so does this crystal_lib work with ruby bindings?
<FromGitter> <faustinoaq> Could be named CrRuby πŸ˜…
<Papierkorb> Sure it's possible to build a ruby interpret in Crystal.
<Papierkorb> But ruby is completely insane
<Papierkorb> Fun is something else
<FromGitter> <mgarciaisaia> I'd rather have you invest that effort in Crystal itself - but I'm not your boss Β―\\\_(ツ)\_/Β―
<FromGitter> <mgarciaisaia> "_Disney_'s fun" says a friend
<_tsound> i dont like it all that much either, but that native C gtk looks daunting :(
<FromGitter> <mgarciaisaia> @_tsound crystal_lib generates the boilerplate for exposing C functions (from their `.h`s) to Crystal syntax. Basically, the `lib` and `fun` declarations.
<FromGitter> <mgarciaisaia> But I think it's always been a messy project, so it may work or not
<_tsound> i'll try, but I doubt it would handle the entire gtk3 lib
<FromGitter> <mgarciaisaia> I'd give it a try anyway, at least - maybe it doesn't work, maybe it produces wrong Crystal code that's easy to fix, maybe it does the whole project for you...
<FromGitter> <mgarciaisaia> (Spoiler: it'll *most probably* won't do the whole project for you)
<FromGitter> <picatz> :P
<_tsound> :P that's a given, if that was the case it would've been done already
<FromGitter> <picatz> *Only one way to find out!*
<FromGitter> <mgarciaisaia> But it used to generate the boilerplate reeeeaaaaaaaaaly well. You only needed to fix some names here and there, and then write your own convenience wrappers to give a more OOP approach to the C libraries
alibby1 has quit [Read error: No route to host]
alibby has joined #crystal-lang
<FromGitter> <mgarciaisaia> My https://github.com/matiasgarciaisaia/crystal-git used that - but it was Crystal 0.16, so it's dated. But I think the makefile showed how to use the lib
<FromGitter> <faustinoaq> @mgarciaisaia How is going internal crystal team with parallelism?
<FromGitter> <picatz> ^ Also interested in this, as are most people I'm sure :P
<FromGitter> <fridgerator> it a secret
<FromGitter> <faustinoaq> πŸ˜…
<FromGitter> <picatz> I've gotten some work done on porting https://github.com/ring0lab/catphish to Crystal ✨
w-p has quit [Ping timeout: 258 seconds]
<FromGitter> <picatz> Gotten ever method ported over put the punycode...
<FromGitter> <picatz> But I just found https://github.com/kostya/simple_idn
<FromGitter> <picatz> So, that should be fixed up shortly I think :D
w-p has joined #crystal-lang
<_tsound> do i link crystal_lib to the makefile?
<_tsound> (sorry if that sounds dumb, but I really don't know much about this lib)
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <codenoid> haha, my hofesh (crystal app <3 ) will download all of this comics http://www.webtoons.com/id/genre
saadq has quit [Ping timeout: 276 seconds]
snsei has quit [Remote host closed the connection]
<FromGitter> <codenoid> is there anybody have crystal t-shirt design ?
<FromGitter> <codenoid> like @sdogruyol shirt
<_tsound> can't you make your own?
saadq has joined #crystal-lang
<FromGitter> <codenoid> i just want to use it,
<FromGitter> <codenoid> ** international crystal t-shirt design **
<FromGitter> <codenoid> ok, i'll make it, https://youtu.be/OkM42UKhjsk :shipit:
<FromGitter> <mgarciaisaia> > @mgarciaisaia How is going internal crystal team with parallelism? ⏎ If I tould you, then I had to _silence_ you... 😎
<FromGitter> <codenoid> :shipit:
<FromGitter> <mgarciaisaia> I really don't know - I've been out of the office for a couple of weeks, so I've lost track of that. But I can try to get you an answer next week (assuming I recall actually doing it).
<FromGitter> <codenoid> ✨
<FromGitter> <mgarciaisaia> That T-Shirt Serdar is wearing on the video is the ones we've made for the CodeCamp. I think we're not selling them *yet*, but its one of the things we'll probably do soon-ish.
<FromGitter> <mgarciaisaia> I hope you could get that very same logo from crystal-lang.org - maybe even with that text?
<FromGitter> <mgarciaisaia> If you print one for yourself, *please* make the URL https for us :P
<FromGitter> <codenoid> okkk ^^ πŸ˜„
deep-book-gk_ has joined #crystal-lang
deep-book-gk_ has left #crystal-lang [#crystal-lang]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
w-p has quit [Ping timeout: 240 seconds]
deep-book-gk_ has joined #crystal-lang
deep-book-gk_ has left #crystal-lang [#crystal-lang]
snsei_ has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
_tsound has quit [Quit: WeeChat 1.9]
snsei_ has quit [Remote host closed the connection]
DTZUZO has quit [Ping timeout: 246 seconds]
DTZUZO has joined #crystal-lang
_whitelogger has joined #crystal-lang
pabs has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <oprypin> @bararchy https://github.com/hugoabonizio/timeout.cr
dhk has joined #crystal-lang
<FromGitter> <bararchy> Thanks @oprypin , I thought that `select` should never ever be used because it screws with the event loop
pwned has quit [Ping timeout: 246 seconds]
<FromGitter> <bararchy> @mgarciaisaia you are some kind of community manager from Manas right ?
<FromGitter> <bararchy> I guess real Timeout cannot be used until Fibers and Threads learn to play with eachother
alibby has quit [Ping timeout: 240 seconds]
schovi has joined #crystal-lang
schovi has quit [Client Quit]
dhk has quit [Quit: Leaving]
Qchmqs__ has joined #crystal-lang
Qchmqs__ has quit [Client Quit]
Groogy2 has joined #crystal-lang
Groogy has quit [Disconnected by services]
Groogy2 is now known as Groogy
<Groogy> Morning!
Groogy_ has joined #crystal-lang
hightower3 has joined #crystal-lang
<FromGitter> <bararchy> Morning Groovy
<FromGitter> <bararchy> Ahh Groogy , damn auto correct
<FromGitter> <sdogruyol> Morning everyone
olbat has quit [Ping timeout: 255 seconds]
<Groogy> Well I am quite groovy so it's fine bararchy (β€’_β€’) ( β€’_β€’)>βŒβ– -β–  (βŒβ– _β– )
<FromGitter> <bararchy> XD
<FromGitter> <oprypin> @bararchy select is perfectly fine, it's a core syntax feature
<FromGitter> <oprypin> IO. select blocked the event loop so was removed
<FromGitter> <bararchy> Wait, select != IO.select ?
<FromGitter> <Qwerp-Derp> Is it possible to make arbitrarily nested arrays in Crystal?
<FromGitter> <Qwerp-Derp> I want to create a new type called `Foo`, and it's essentially an array, but it contains either `String` or `Array(Foo)`
<FromGitter> <Qwerp-Derp> It may only contain one of either `String` or `Array(Foo)`
<FromGitter> <Qwerp-Derp> Is this possible in Crystal?
<FromGitter> <straight-shoota> `alias Foo = String | Array(Foo)` @Qwerp-Derp
alibby has joined #crystal-lang
<FromGitter> <sdogruyol> @bararchy nope
<FromGitter> <Qwerp-Derp> @straight-shoota Won't work
<FromGitter> <Qwerp-Derp> ```alias Foo = String | Array(Foo) ⏎ temp : Foo = ["abcd", ["abcd"]]``` [https://gitter.im/crystal-lang/crystal?at=597c6b1845fc670746d8a260]
<FromGitter> <Qwerp-Derp> Errors with `temp must be of type Foo, not Array(Array(String) | String)`
<FromGitter> <sdogruyol> that's an `String | Array(String)`
<FromGitter> <sdogruyol> there you go @Qwerp-Derp https://play.crystal-lang.org/#/r/2fux
<FromGitter> <Qwerp-Derp> Well yeah @sdogruyol, but `["abcd", ["abcd"]]` should work under what I want to achieve, as well as any nesting of strings and arrays containing strings
<FromGitter> <Qwerp-Derp> With your implementation I can only have `Array(String)` nested 2 layers deep, not arbitrarily deep (which is what I want)
<FromGitter> <sdogruyol> then you need to specify those too
<FromGitter> <sdogruyol> without knowing what you're going to put into array the compiler can't infer
<FromGitter> <watzon> Thinking of a new shard. Who would be down to help with bindings to libgit2 (https://libgit2.github.com/) in the future?
<FromGitter> <watzon> I'm going to need it for a project I'm getting ready to start on
<FromGitter> <sdogruyol> @watzon that'd be great
<FromGitter> <sdogruyol> have you seen https://github.com/mosop/git yet @watzon
<FromGitter> <watzon> There's already bindings in a ton of other languages
<FromGitter> <sdogruyol> it's pretty much functional and would be great if you contribute :P
<FromGitter> <watzon> I didn't! Looks like it already exists haha
<FromGitter> <watzon> I will definitely be contributing
<FromGitter> <sdogruyol> great πŸ˜„
<FromGitter> <watzon> I'm going to, hopefully, be starting a pretty large Crystal-backed project this week
<FromGitter> <sdogruyol> Awesome. Please feel to reach out for any issue
<FromGitter> <watzon> It's going to basically manage docker containers and allow code uploads via git-push, so libgit2 bindings are going to be a huge help
<FromGitter> <watzon> And of course!
<FromGitter> <watzon> Also thinking about starting a local Crystal meetup here in Phoenix, but I'd need to find people around here that are interested
<FromGitter> <watzon> Btw @sdogruyol , I will most likely be using Kemal as well. Thanks for the awesomeness!
<FromGitter> <sdogruyol> Thank you @watzon, I'd like to make Kemal better for everyone :) Hopefully we got some great PRs soon to be merged for that purpose πŸ’―
<FromGitter> <watzon> @sdogruyol what would you suggest as a good ORM for Postgres?
hightower3 has quit [Ping timeout: 260 seconds]
<FromGitter> <sdogruyol> crecto by @fridgerator
<FromGitter> <watzon> Awesome I was just looking at that
<FromGitter> <sdogruyol> https://github.com/Crecto/crecto
<FromGitter> <GetRektByMe> Oh it's Kemal dev
<FromGitter> <GetRektByMe> Nice framework dude πŸ‘
<FromGitter> <sdogruyol> Thank you @GetRektByMe
<FromGitter> <watzon> Hahahaha, that handle though @GetRektByMe
<FromGitter> <sdogruyol> hehe :D
<FromGitter> <GetRektByMe> Yeah I had to swap handles because people didn't get it was ironic though sadly
<FromGitter> <GetRektByMe> I go by Recchan now but it was taken on GitHub already :(
<FromGitter> <sdogruyol> Really, i thought it's pretty obvious
<FromGitter> <GetRektByMe> Yeah apparently not
<FromGitter> <watzon> Hater's gonna hate
<FromGitter> <watzon> Is it possible to reinstall crystal on ubuntu with LLVM 4 instead of 3?
<FromGitter> <watzon> Or would I have to compile it myself?
tzekid has joined #crystal-lang
tzekid has quit [Remote host closed the connection]
tzekid has joined #crystal-lang
<FromGitter> <Qwerp-Derp> I'm thinking of making a `RecursiveArray` thing, which addresses the problem I want to solve, but I don't have much of an idea where to start :P
hightower3 has joined #crystal-lang
<hightower3> sdogruyol: if I am to connect from Kemal to postgres as each individual user who is logged in (rather than having a single/common connection to the DB), how would I best approach this?
<FromGitter> <sdogruyol> @hightower3 use a connection pool and dynamically connect to different dbs
<FromGitter> <sdogruyol> or preallocate the connection pool
<hightower3> Modules for this exist or I should hack a simple prototype myself?
<FromGitter> <sdogruyol> Well you can use https://github.com/ysbaddaden/pool for conneciton pooling
<hightower3> Looks like that would work... Using a connection pool and switching to the appropriate user on already-existing Pg connections as explained in https://stackoverflow.com/questions/2998597/switch-role-after-connecting-to-database
<hightower3> For flash messages, do I use kemal-flash?
<hightower3> For OAuth2 login, I remember someone mentioned a good/functional library, but I can't find it now. Any hints?
w-p has joined #crystal-lang
<FromGitter> <sdogruyol> @hightower3 https://github.com/msa7/multi_auth
<hightower3> sdogruyol: can I wrap Kemal inside my class?
<FromGitter> <sdogruyol> you can use it in anywhere you want
<FromGitter> <sdogruyol> ```class MyClass ⏎ get "/" do ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=597c86311c8697534a6e258d]
<hightower3> But in the end I run Kemal.run?
<FromGitter> <sdogruyol> yup
alibby1 has joined #crystal-lang
alibby has quit [Ping timeout: 268 seconds]
<hightower3> sdogruyol: looks like crystal-db already contains a pool: https://crystal-lang.org/docs/database/connection_pool.html
<FromGitter> <sdogruyol> yeah it does :)
<FromGitter> <sdogruyol> and it's pretty good
<hightower3> sdogruyol: ok so I can use 'get' within a class, but the problem is I can't use instance variables in it, since I'm in the class, outside of any method. What's the way to make that possible?
alibby1 has quit [Ping timeout: 276 seconds]
alibby has joined #crystal-lang
<FromGitter> <sdogruyol> well your scope is within request - response lifecycle
<FromGitter> <sdogruyol> check out `env.context.set` and `env.context.get`
alibby has quit [Ping timeout: 240 seconds]
alibby has joined #crystal-lang
<hightower3> you mean env.set/env.get? I don't see env.context mentioned anywhere in kemal checkout
<hightower3> sdogruyol: what I am trying to do is have a "before_all" block in which I take a DB connection from the pool, set user on it, and save it in context. But I can't do that since the connection is of type DB::Connection
<hightower3> (so I can't save it in context)
<FromGitter> <mgarciaisaia> > @mgarciaisaia you are some kind of community manager from Manas right ? ⏎ ⏎ @bararchy I was supposed to be something like that, but I'm not sure I've taken care of that role enough. ⏎ I'll try and help with whatever I can if you need something, though :) [https://gitter.im/crystal-lang/crystal?at=597c955242d2f61025883fa6]
<hightower3> I am trying to pass a block with 1 arg to a method. I call accepts_block(){ |arg| puts arg}, where accepts_block is defined as def accepts_block( *block) block.call( argument) end. But when I run this, in the call to accepts_block() I get an error wrong number of block arguments (given 1, expected 0)
<hightower3> What am I missing?
pabs has joined #crystal-lang
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
tzekid has quit [Ping timeout: 258 seconds]
alibby1 has joined #crystal-lang
<FromGitter> <bararchy> @mgarciaisaia Well, TBH I was just wandering, as a long time member of the community it sometimes feel like there is not enough comunication between the core team (mostly manas) and the other contributers\users, One part that really helped was the bi-weekly blog posts that Ary used to write, I know he is no longer part of the core team , but maybe someone who is good in that aspec can take this role ? I would
<FromGitter> ... nomine @sdogruyol If it was my choise hahah as he already does much in the regards of pushing Crystal forward via PR's (not the github kind) and blogs\posts\tweets etc .. ⏎ ⏎ Anyway, regardless of who will do that, I feel that It's a "hole" that is being felt by more then only me
alibby has quit [Ping timeout: 240 seconds]
<FromGitter> <bararchy> Just a quick disclaimer though, I know you guys are super busy, I know you need to run a company with Crystal as a "side project" , it's just that I really wan to see the project floruish
<FromGitter> <bararchy> (Also, using Crystal in prod and want to be sure at where it's headed)
tzekid has joined #crystal-lang
cyberarm has quit [Ping timeout: 248 seconds]
<FromGitter> <bararchy> I hope I didn't send any "bad vibes" with that, It's was really a question in "good faith"
<Papierkorb> A lack of communication is sure noticable. As far the state of information is concerned, no one in the community knows if Crystal as manas project will be around in a year, or not. Which is terrifying, and a much bigger issue than getting to v1.0 - for me, that is. I completely understand that comms take a huge time investment: But I'm also pretty sure that instead of a super polished article every 6 months, something less polished would
<Papierkorb> do the job pretty well. I'm pretty sure that there are a few in the community who would love to take that task of writing polished articles for you.
<FromGitter> <bararchy> I would even agree to a "support plan" for production Crystal users that will give more info regarding advancments, tasks , people whos working on ... , etc..
cyberarm has joined #crystal-lang
<FromGitter> <bararchy> Just so I can tell my co-workers that "you see, this project is stable and going forward, we should use it for X"
<Papierkorb> ^ Exactly that
<Papierkorb> I can't blame someone for looking at the project page and thinking "it's dead, better use something else". Community content on there, written by .. err .. "Community ambassadors" or whatever .. about Crystal, challenges, improvements, etc., would change that picture completely, for except some quality control (Those publishers should be hand picked in any case), shouldn't be too costly time-wise.
<FromGitter> <bararchy> I know that some in the comunity fear that an "IO.js" will happen (https://iojs.org/en/faq.html)
<FromGitter> <faustinoaq> I agree with you @bararchy
<FromGitter> <faustinoaq> We should take as example the sucess of languages as Elixir
<Papierkorb> Would actually make it kinda interesting, cause people would focus on many different things you can do with crystal. Sure lots of webdev, but tons of other things too. I'd wager there are more than a few seriously interesting (from a technology POV) weekend-projects: We had operating systems, bunch of emulators, tons of arcane hacks. We had people in here doing stuff on Bitcoin. What people already do today with crystal is great, and we
<Papierkorb> could show-case that
<Papierkorb> bararchy, wasn't that just a fork of nodejs, cause of a enterprise vs community "battle"? Didn't they merge already soon afterwards?
<FromGitter> <faustinoaq> Plataformatec (the company behind elixir) now is a Professional Consulting for Elixir.
<FromGitter> <sdogruyol> Thanks @bararchy I totally agree
<FromGitter> <sdogruyol> And also @papierkorb there are already great things built with Crystal which are not web
<Papierkorb> sdogruyol, yeah I listed a few I think ;)
<FromGitter> <faustinoaq> Also I would like to see books related to Kemal and Amber, but after the first Crystal Book https://groups.google.com/forum/#!topic/crystal-lang/kFGGhoNF55s
<FromGitter> <sdogruyol> Yup
<FromGitter> <sdogruyol> Hopefully we'll have one more Crystal book :)
<FromGitter> <faustinoaq> We can give some ideas to Ivo Balbaert
<FromGitter> <sdogruyol> It's not official yet but I will also start writing a Crystal book
<Papierkorb> Fixed: <sdogruyol> It's official yet, I will also start writing a Crystal book
<Papierkorb> Anyone in here ever used Qt/QML?
<FromGitter> <sdogruyol> What?
<FromGitter> <faustinoaq> Also, I know Ary is very busy, I'm ok with that. But I wish to see him talking about Crystal at least time a time. The creators of a language are people that inspire.
<FromGitter> <faustinoaq> Papierkork, you mean this πŸ‘‰ https://pragprog.com/book/crystal/crystal
<Papierkorb> QML looks a bit like JS - It's not really JS though. It let's you write UIs in a declarative manner: https://doc.qt.io/qt-5/qmlfirststeps.html
<Papierkorb> Have been thinking about writing a PoC of that for Crystal, using DSL stuff. Could be interesting.
<Papierkorb> faustinoaq, nope. I don't read programming books in general...
<FromGitter> <faustinoaq> Me too, just for references, but...
<FromGitter> <faustinoaq> if there is a first crystal book, I would read it from begin to end πŸ˜…
<FromGitter> <faustinoaq> Papierkorb, I use PyQT in Manjaro KDE, the QT designer comes by default
<Papierkorb> QtCreator is still the best C++ IDE I know...
Philpax_ has quit [Ping timeout: 240 seconds]
<Papierkorb> Well, IDE in general.
<FromGitter> <faustinoaq> Yes, is full featured for C++ and QT framework in general. Would be great to interact QT with Crystal in some way
<Papierkorb> Oh if I did that PoC, I'd bind to Qt somehow. I prefer Qt over Gtk in general, so..
<Papierkorb> The look n feel of Qt is just so much better on all platforms
<FromGitter> <faustinoaq> πŸ‘
<w-p> is there a keyword for breaking out of an if block early?
<Papierkorb> No
<w-p> thx
<FromGitter> <straight-shoota> `break` ??
<Papierkorb> breaks out of a block, not an if
<FromGitter> <straight-shoota> oh, I overlooked that "if"
<w-p> so nested if's are it
<Papierkorb> w-p: Deep nesting is a *usually* sign that you actually wanted to write a new method instead
<w-p> yeah, i know. hence the question. i don't like nested anything.
<w-p> i'm parsing something with a lot of 'bail out' conditions.
<w-p> ugly
<Papierkorb> sounds .. fun
<FromGitter> <sdogruyol> Anyone got this error on a fresh Ubuntu 16.04 box with Crystal ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=597cb57b2723db8d5e594d09]
<hightower3> Papierkorb, I used qt extensively
<w-p> how does one differentiate between, for example, a local module struct and Crystal class of the same name imported into the same file? using just the local module name doesn't seem to work.
<w-p> for example, MyModule::JSON vs the Crystal JSON type
<Papierkorb> Leading `::` forces the lookup to start at the top-level, as opposed to the current level. So, `JSON` from inside that MyModule would be `::JSON` w-p
<w-p> Oh, man - excellent. Is that documented anywhere?
<FromGitter> <sdogruyol> that's actually a Ruby-ism :P
<FromGitter> <sdogruyol> should be documented though
<Papierkorb> Can't find an explicit mention of it in the docs. "The Program" uses it for a method, and type grammar uses it casually for Nil
<w-p> I'm finding a few of those so I usually google for 'how to do x in Ruby'.
<Papierkorb> Yeah, erm .. for better or worse, the origin from Ruby is quite apparent
<oprypin> i mean it's noise but he's also not wrong
<Papierkorb> for a moment, I wasn't sure if you intended to write 'nice' or not
<FromGitter> <bararchy> Well, this kind of discussion is not meant for Github
<FromGitter> <bararchy> Maybe google-groups is better for it
<Papierkorb> Most will see it there though
<FromGitter> <bararchy> True
<FromGitter> <sdogruyol> IMHO it's to be somewhere
<FromGitter> <sdogruyol> GH is good for visibility
<w-p> hackernews, reddit, medium ...
<hightower3> sdogruyol: do you have a suggestion for my question from earlier:
<hightower3> sdogruyol: what I am trying to do is have a "before_all" block in which I take a DB connection from the pool, set user on it, and save it in context. But I can't do that since the connection is of type DB::Connection (so I can't save it to context hash)
<FromGitter> <sdogruyol> you can use custom context types for that
<FromGitter> <sdogruyol> hold on
<FromGitter> <sdogruyol> @hightower3 to register a custom type to Context storage use `add_context_storage_type(YourType)`
<FromGitter> <sdogruyol> this needs documentation though
<FromGitter> <sdogruyol> Hope the Github issue doesn't go flame war
<Papierkorb> Time to drink some tea @sdogruyol
<FromGitter> <sdogruyol> Thanks @papierkorb :)
<Papierkorb> Mh how on earth do I now bind to C++. I could write the name mangling into a macro. That's insane. So maybe I do that. Or I write/auto-gen a C wrapper lib and bind to that. Choices >_>
<Papierkorb> not to mention Qt's event loop. that will be fun to integrate into the crystal world.
<FromGitter> <bararchy> Papierkorb, When you get an idea, tell me because there are a few C++ libs I want to bind over also
<Papierkorb> bararchy, well the macro would be kinda fun, but the c glue lib is easier to port. Though completely auto-generating it through libClang isn't fun. Even with Clang, parsing C++ is a clusterfuck. But maybe it could work by auto-generating from a simpler declaration file. Could be interesting as one needs to rewrite some things in any case (E.g., crystals String <-> QString)
<Papierkorb> In any case, as far Qt is concerned, I'm mostly/only interested in the GUI parts. using stuff like QNetworkAccessManager (what a name) from non C++/Qt just doesn't feel right.
<FromGitter> <bararchy> How does Python binds to C++ ? I see that Ruby has issues with it also, but it seems that Python is really ok with it
<Papierkorb> The C-glue way is the usual approach. Though Python is kinda special in that many C++ users really like Python, so it has actually good bindings both ways.
<Papierkorb> Well, it's arguably easier to bind from Py compared to Ruby
<hightower3> A C short is what? Int4?
<Papierkorb> bararchy, even better, memory management. In Qt, QObjects can have a parent. In that case, they're not controlled through GC anymore. So, one major thing to look out for is that the non-GC and GC worlds play nice. The Crystal proxy class may have to take this into account. Bonus points for modern-ish C++11 libs, which mostly use std::unique_ptr or references, which is even worse w.r.t to binding
<Papierkorb> hightower3: `Int4` doesn't exist. on many platforms (most likely, all you care about), a short is 2 bytes.
<hightower3> ah thanks, yeah
<hightower3> What would 'unsigned char' in C map to in Crystal?
<Papierkorb> `LibC::UChar`
<Papierkorb> and all other types analogue to that
<hightower3> awesome, thanks
<hightower3> So am I encouraged to convert e.g. ints to LibC::Int or Int32?
<Papierkorb> the former
<Papierkorb> that'll always be correct
<hightower3> ok great, thanks
<hightower3> How do I specify that something's return value is void*?
<Papierkorb> literally `Void*`
<hightower3> If I have "typedef int Handler(Event *event, void *clientdata);", how do I convert that to Crystal? I see there is 'type', but I'm unsure how to apply it here
<Papierkorb> that typedef looks broken
<Papierkorb> if it were correct, it'd break down to `alias Handler = Event*, Void* -> LibC::Int`
<hightower3> It is found in /usr/include/gpm.h line 154
<Papierkorb> oh they're using a weird notation where they put the * at the use-site
<hightower3> What's the best way to convert #defines to Crystal? Using macros?
<FromGitter> <bew> If it's a C macro, then a Crystal macro or method. If it's a C constant, then a Crystal constant is enough
<hightower3> Right, C macro. Ok great, thanks
<hightower3> Ok so I now have a fun which takes a pointer to C structure as argument. I've converted that structure to Crystal. Now with the function and with the appropriate struct, how do I make use of it from Crystal; specifically, how do I create/allocate the structure to pass it to the function?
<hightower3> And in the common case where the structure is used to return data from the C function, how would I convert func(struct*) into something that would allow me to write x = func() rather than func(x)?
<Papierkorb> the front-end wrapper method allows you to.
<Papierkorb> that you write
<hightower3> Ok, sounds good. And how do I allocate the struct? Or how do I prepare the struct so that I can call a lib method with it as argument?
<oprypin> Papierkorb, if you're serious about making Qt bindings, i'm interested in that
<oprypin> though as i always say it's not c++ that scares me, but that it's not even simply c++
<Papierkorb> I used C++/Qt for .. almost 3 years
<Papierkorb> Has been 3 years since then, but eh, moc isn't that magic really.
<Papierkorb> Except that it's just plain awful at parsing C++ lul
<oprypin> when you say it feels wrong to use Qt's networking, well, so it does in Python, but what can you do, if integration for other stuff may not be doable
<hightower3> Papierkorb, ah, I didn't know I could run #new on custom structs. Did that, used pointerof(), and got it working. Thanks!
<oprypin> hightower3, when you pass a pointer for that function only to write something to it, that's when you use an `out` argument
<Papierkorb> oprypin: the GUI stuff is just displaying. networking etc is completely separate from that. The important part is to correctly integrate Qts event loop for it to work properly.
<hightower3> thanks oprypin
snsei has joined #crystal-lang
hightower3 has quit [Ping timeout: 248 seconds]
snsei_ has joined #crystal-lang
snsei has quit [Ping timeout: 260 seconds]
hightower3 has joined #crystal-lang
<Papierkorb> Ah man, SWIG can't generate C++ -> C bindings :|
<Groogy> It can't? that's kind of suprising
<Papierkorb> indeed
<Groogy> I mean it's super easy? You just have to make a struct containing reference to the object, wrap function calls on object that converts struct to non-obscured struct and then done?
<Groogy> or am I missing something which put it way harder for SWIG to autogenerate?
saadq has quit [Ping timeout: 260 seconds]
<Groogy> "In 2008, there was a GSoC project to write a C backend, but that was apparently never completed/incorporated into SWIG."
<Groogy> maybe that one still works?
<hightower3> I have \u0020 in a regex and it tells me that PCRE does not support \u. What alternative notation could I use?
saadq has joined #crystal-lang
<hightower3> (\u being a match for a character with four hexadecimal digits)
<Papierkorb> Groogy: maintaining swig yourself doesn't sound like a lot of fun
<Papierkorb> Groogy: Well super easy and C++ isn't what I'd use in the same sentence. Beyond method overloading, just think of templates.
<Groogy> Well the CSFML binding isn't that fancy
<Groogy> and you can't bind templates anyway unless they are invoked so
<FromGitter> <crisward> Is there any performance tooling for crystal, ie creating flamegraphs?
<Groogy> well there is the Benchmark module? Though guessing you want more than that?
<FromGitter> <crisward> Groogy, I'm trying to optimise my app. In node it was possible to create flame graphs at runtime, a bit like those in chrome, in fact they are viewable in webkit dev tools. Wasn't sure if LLVM had something similar.
<FromGitter> <crisward> Thanks for mentioning benchmark, could be good for monitoring code speed during tests to check for speed regressions.
cyberarm has quit [Ping timeout: 260 seconds]
cyberarm has joined #crystal-lang
<FromGitter> <crisward> Looks like it used to be possible with Mac Instruments... but not any longer.
snsei_ has quit [Remote host closed the connection]
alibby has joined #crystal-lang
alibby1 has quit [Read error: Connection reset by peer]
<FromGitter> <alex-lairan> hello :) I have to do something like ⏎ ⏎ ```Hash(Char, Hash(Char, Hash(Char, ...))``` ⏎ ⏎ How can I do it? :) ... [https://gitter.im/crystal-lang/crystal?at=597d01821c8697534a6f9a84]
<Papierkorb> alex-lairan, what do you need to store?
<FromGitter> <alex-lairan> I found how, I need to store multiples chars for a gramatical analyser
<FromGitter> <alex-lairan> But I have a weird question, I need a pointer to know where I am ⏎ ⏎ How can I do ⏎ ⏎ ```class Foo ⏎ @foo : Int32 = 0 ⏎ @pfoo : Pointer(typeof(@foo)) = pointerof(@foo) ⏎ end``` ... [https://gitter.im/crystal-lang/crystal?at=597d0944f5b3458e30936e82]
<FromGitter> <alex-lairan> I can't do ⏎ ⏎ ```can't use 'typeof' here ⏎   ⏎   @pfoo : Pointer(typeof(@foo)) = pointerof(@foo)``` [https://gitter.im/crystal-lang/crystal?at=597d09572723db8d5e5a4233]
Dreamer3_ is now known as Dreamer3
<Papierkorb> https://i.imgur.com/2ntGNo7.png cc oprypin
<FromGitter> <alex-lairan> Papierkorb you work for a GUI?
<Papierkorb> It generates the C glue lib using an awful generator I wrote based on a YML specification. That same thing could also write the Crystal binding code
<Papierkorb> alex-lairan, binding to Qt
<FromGitter> <alex-lairan> Oh ok :)
<hightower3> I have \u0020 in a regex and it tells me that PCRE does not support \u. What alternative notation could I use?
<Papierkorb> a space
<hightower3> Yeah I mean in general :)
<hightower3> If I don't want to guess specific chars
<hightower3> Strings do support \u...., so I can define all those chars in a string and then reference them from there
<Papierkorb> Well .. have you tried the totally non-ugly, perfectly readable `/#{"\u0020"}/` ?
<hightower3> hehe yeah, I wanted to have some reuse of the chars :-)
<hightower3> Where do I find Math function floor?
<Papierkorb> Float#floor
bradleyd has joined #crystal-lang
<hightower3> Is there a way to pass 'g' flag to Regex.new?
<FromGitter> <alex-lairan> I get ⏎ ⏎ ```unless @value.is_a?(Nil) ⏎ @value[c]? = nil ⏎ end``` ⏎ ⏎ Why? :) Thanks for the help [https://gitter.im/crystal-lang/crystal?at=597d151876a757f8085a5691]
<hightower3> alex-lairan: before doing if/unless, you need to do something like value= @value, and then to a check/set on value instead of @value
<hightower3> s/to/do/
<FromGitter> <bew> you should use: `if @value`
<FromGitter> <bew> oh true too: `if val = @value`
<hightower3> and what bew says too... if value, or if value.nil?, depending on your case
<FromGitter> <alex-lairan> okay, thank :)
<hightower3> And you don't need []? when assigning. When assigning you need just []=
<FromGitter> <crisward> I've been profiling my app and I've found one bottleneck is a String#sub I'm using on a large string (14kb). Is there a quicker alternative to sub?
<FromGitter> <alex-lairan> I can't `pointerof()` an element in array?
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
<hightower3> alex-lairan: Right, appears not
deep-book-gk_ has joined #crystal-lang
deep-book-gk_ has left #crystal-lang [#crystal-lang]