<watzon>
Haha that's awesome. Now you should try taking a Crystal project, building it using `--cross-compile --target "x86_64-unknown-linux-gnu"` and then try using zig to do the linking
ur5us has quit [Ping timeout: 246 seconds]
ur5us has joined #crystal-lang
_whitelogger has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
_whitelogger has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<watzon>
Holy fuck. Zig actually make work to cross compile Crystal for other platforms.
<watzon>
* Holy fuck. Zig actually may work to cross compile Crystal for other platforms.
<watzon>
*may work
_ht has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter>
<confact> does it exist a way to extend an enum? I want to be able to add module or similar to it to handle DB stuff.
<FromGitter>
<eddloschi> @watzon cross compiling crystal with zig didn’t work on my machine
<oprypin>
stronny, uhh in some sense, probably. i'd be happy to figure out a solution if something currently doesnt work with dbus
<FromGitter>
<j8r> I don't think those are a solution, because it won't work if it is variable
<oprypin>
`a = "0.0000584674565152"; puts a`
<oprypin>
the other ones yes
<FromGitter>
<j8r> oprypin, @fenicks probably has a variable which is a `Float64`
<FromGitter>
<stronny> @oprypin dbus lib totally needs some love, currently it's not very usable at all at Crystal level. I mean `DBus` API, not `LibDBus`. But even the lib could use some improvements, for example shouldn't `connection_read_write_dispatch` have a `@[Raises]` anno?
<oprypin>
stronny, yea looks appropriate to have that
<oprypin>
tbh connection_read_write_dispatch is not usable because it's blocking
<FromGitter>
<stronny> It's fine for my usecase
<FromGitter>
<stronny> basically I need a custom dbus-monitor
<FromGitter>
<stronny> what I miss the most is a way to deal with messages. You have some code in `Pending#reply` but it's not easy to use that generally
<oprypin>
fenicks, anyhow, the number gets converted as soon as you write it out because it's stored in hexadecimal. then one needs to convert it back to decimal when printing
<Stephie>
crystal seems to "just work" on LLVM 10 for once
<oprypin>
fenicks, you can use this `printf("%.14f\n", 0.0000584674565152)` but it hardcodes the number of decimal places
<FromGitter>
<stronny> would BigDecimal help?
<oprypin>
and if u don't hardcode it, then it reaaaally dumps things `puts sprintf("%.50f", 0.0000584674565152).rstrip('0') #=> 0.00005846745651519999931351734279161291851778514683`
<oprypin>
stronny, hm probably
<oprypin>
very good idea. this works exactly. `require "big"; puts BigDecimal.new("0.0000584674565152")`
<oprypin>
stronny, i think you want server functionality? i never got around to that :(
<oprypin>
some of that functionality could indeed be logically derived from what's there currently
<oprypin>
what this really needs is event loop integration and never using blocking calls
<oprypin>
or hope for crystal threading support and hack with blocking calls anyway
<FromGitter>
<stronny> would it be possible to convert dbus messages to/from Crystal classes like JSON/YAML?
<oprypin>
stronny, i think so. but again, my thought process stopped just short of figuring that out
<oprypin>
really wish i had finished that one ;p
<FromGitter>
<stronny> yeah, I've figured that much
<FromGitter>
<j8r> oprypin or `printf "%.50f", 0.0000584674565152`?
<oprypin>
stronny, one could generate a class (with a technique similar to json) that accepts only exactly these types and then is able to be converted to 1) an array like that and 2) a signature like that
<FromGitter>
<confact> Say I have a module in a struct, like Type::Namespace. And I want to use a macro to run new on Type. but {{@type}} is returning Type::Namespace. Is it any way to solve that?
<FromGitter>
<Blacksmoke16> do you need a macro?
<FromGitter>
<Blacksmoke16> `new "foo"`?
<FromGitter>
<Blacksmoke16> or really is that a problem? `{{@type}}.new`?
<FromGitter>
<Blacksmoke16> oh, you want to have `@type` based on the type the module gets included in?
<FromGitter>
<Blacksmoke16> but im pretty sure initializers would just work, assuming you're not doing anything custosm?
<FromGitter>
<confact> and how do I get the type? Or will it be `@type` then?
<FromGitter>
<confact> I am doing highly custom. trying to extend enum to be able to use it in a ORM :)
<FromGitter>
<Blacksmoke16> `@type` would represent the included type in that case
<FromGitter>
<confact> nice, thanks. Got another issue now that it thinks the module is not defined. I guess as it is a struct and not initialized (as it is enum)
<FromGitter>
<Blacksmoke16> which would prob cause the methods to be added to the actual enum versus the parent type
<FromGitter>
<stronny> I guess I'm missing something here, but my first guess would be to just patch `Enum` with no macros
<FromGitter>
<confact> oh, cool! I don't get that error anymore. But I got the error that it can't access ColumnType constant in the module now. Am I doing something wrong you can see there?
<FromGitter>
<Blacksmoke16> mm yea now we're into the lucky internals which im not familiar enough with
<FromGitter>
<confact> I think if i just make it possible for it to get ColumnType from the module it should work fine. It seems it can't get into the module's constant in the actual Enum here.
<FromGitter>
<confact> can it be because it is an `alias`?
<FromGitter>
<Blacksmoke16> im not sure
<FromGitter>
<confact> I think I know the issue. It is a bit of moment 22. I have to use inherited to get the actual enum to cast it correctly from DB. But for setting up the module, constant and such, it needs to be in Enum, as that is the "type".
<FromGitter>
<confact> so both you @Blacksmoke16 and @stronny are right here.
<FromGitter>
<confact> how would you do @stronny to cast the actual enum inside the enum?
<FromGitter>
<Blacksmoke16> i think he means just do like
<FromGitter>
<confact> I am pretty sure this won't work. As I looked in the code. They want the methods to be self. Then the enum will be Enum and not the actual enum right?
<FromGitter>
<confact> @asterite I am trying to instead of having a wrapper around enum, using the actual enum for the Lucky type you helped with yesterday i think. It would look much nicer that way. ⏎ ⏎ I came this far: https://gist.github.com/confact/9f2e9048935ce33196697f3393223910
<FromGitter>
<confact> Problem with that gist is it can't access the constant ColumnType as it is only added on inherited.
<FromGitter>
<confact> and `Avram::Type` in Lucky module is also doing an `macro included do extend self` which is used for Lucky to parse and stuff. So my code will probably not work.
<FromGitter>
<confact> Tell me to re-explain if my babel make no sense :D
<FromGitter>
<stronny> > They want the methods to be self. Then the enum will be Enum and not the actual enum right? ⏎ I'm unclear what you mean by that
<FromGitter>
<stronny> I'm unclear what you mean by that
<FromGitter>
<confact> sure, i will try to make it more clear. I am not hundred percent sure how macro with self/initialize work. But lucky want to call `.parse` on class, and not on instance of it. Not sure how Enum handle that. Will it call on the actual enum (say `enum Status`, will it call it on Status?) or will it call it on Enum, the struct?
<FromGitter>
<confact> I notice that `ColumnType` can only be accessed if it is moved to Enum struct directly, and not with macro. I guess it is because it has to be in the class? Then maybe my theory is correct. I don't know how I can cast an actual enum in the enum class though. Extended would not work as it is a struct.
<FromGitter>
<confact> oh, okay. I think I understand. I will see what I can do.
<FromGitter>
<stronny> `s/self.class/self/` and it works as expected
<FromGitter>
<naqvis> is it possible to define a new *primitive* type in crystal? `alias`ing is just a simple alias and any extension mades are applied to aliased built-in primitives.
<FromGitter>
<fenicks> @j8r Nice, works well with `printf`et `sprintf`.
cyberarm has quit [Ping timeout: 240 seconds]
<oprypin>
naqvis, i think it would basically be `struct`
<FromGitter>
<naqvis> yeah, but how can we use it without instantiation? like those primitives works
<FromGitter>
<naqvis> I understand behind the scenes primitives are struct, but for them compiler do the magic of instantiation as one needn't invoke `initialization`
<FromGitter>
<naqvis> I hope someday crystal can allow types re-definitions (not just simple aliasing) like other languages. I don't know Ruby, but wish it was there in Ruby as every reference for new feature is looked at how things works in Ruby 😆
<oprypin>
naqvis, no, structs actually are how it should be done. the inaccessible thing is just creating through literals
<FromGitter>
<naqvis> as @Blacksmoke16 said above, use `is_a?`
<FromGitter>
<drum445> Legend, god bless
Human_G33k has joined #crystal-lang
<FromGitter>
<asterite> @confact sorry, can you provide full code? That gist compiles file. If I add `Role::Lucky.parse` that doesn't work but that's okay because such method doesn't exist
<FromGitter>
<asterite> Also maybe explain what are you trying to achieve. Including a module in all enums is a very bad smell
<FromGitter>
<confact> I want that method to exists. ^^ ⏎ ⏎ I'm trying to make enum support to Avram without need to wrap it inside a class. So instead of status: enumwrapper.new(:opened) i would like to just do status: :opened. ⏎ ⏎ Types in avram add a lucky module to types structs to handle database type like to and from and parse it. [https://gitter.im/crystal-lang/crystal?at=5e7bacf0fb1252280f49bd42]
<FromGitter>
<confact> @asterite ^
<FromGitter>
<confact> I will add the model to the gist to understand the context. But it will be a bit avram in it.
<FromGitter>
<confact> @asterite now you got everything except for avram shard and all that. the enum file i want to work to be able to get ColumnType and parse method.
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
<FromGitter>
<asterite> @confact There's no way to do what you can do. You can't `include` stuff into Enum, it's a current limitation. Also `macro inherited` won't trigger for Enum subclasses.
<FromGitter>
<asterite> Please open feature request for at least doing `include` and `extend` for Enum, they should be pretty easy to implement
<FromGitter>
<confact> Okay, thanks for checking @asterite. And sorry for bombing this chat. I'll open an issue for that!
renich has joined #crystal-lang
<FromGitter>
<asterite> No problem! I'm actually implementing it already :-)
<FromGitter>
<asterite> But only for `include` and `extend`. I think you had an `avram_enum` macro, so you could include the module there, no need to use `inherited` (which will not work anyway)
<FromGitter>
<stronny> idk, extend works for me
<FromGitter>
<asterite> You mean, `enum Foo; A; extend B; end` compiles fine for you? I get a syntax error
<FromGitter>
<stronny> ah, no, I mean `struct Enum; extend A end`
<FromGitter>
<asterite> Oh, yeah, that works. But I wouldn't do that, I wouldn't touch all enums
<FromGitter>
<andrewc910> The idea is users have many apps but apps have many users. I used a join table. I just need to find a way to query between apps & users in an efficient manner.
<FromGitter>
<Blacksmoke16> wouldnt it just be select from mapping_table where user_id = user.id?
<FromGitter>
<andrewc910> What do you mean?
<FromGitter>
<Blacksmoke16> er nvm
<FromGitter>
<Blacksmoke16> you could do this in one query i think, would be like has_many through?
<FromGitter>
<andrewc910> through would solve my problem but idk if jennifer supports it :/
<FromGitter>
<andrewc910> No it doesn't. That's why i am stuck
<FromGitter>
<Blacksmoke16> it has `has_and_belongs_to_many` tho
<FromGitter>
<Blacksmoke16> isnt that what you want?
<FromGitter>
<andrewc910> I couldn't get it working :( Then i did some reading on rails (since there is more documentation & guides) and this method was recommended to avoid `has_and_belongs_to_many`. ⏎ ⏎ I will give `has_and_belongs_to_many` another go.
<FromGitter>
<Blacksmoke16> oh really? welp
<FromGitter>
<Blacksmoke16> either way seems you need has_many_through
<FromGitter>
<andrewc910> Okay, i will play around some more! Thanks :)
<FromGitter>
<Blacksmoke16> could always just lookup how that is done and do some raw SQL thing?
<FromGitter>
<andrewc910> @Blacksmoke16 i actually got the `has_and_belongs_to_many` relation working & it's working how i needed. Was pretty this time around. Don't why i couldn't get it working a few hours ago. I thought about the sql route as i just spent the last 2 weeks studying it. Wanted to try the relations of the orm before i went down that route.