<postmodern>
could i add my own ASCII lookup table that the macro uses to map CharLiteral to Int?
<FromGitter>
<Blacksmoke16> you could do something like that
<FromGitter>
<Blacksmoke16> define a hash with the key as the char and the value the int value
<FromGitter>
<Blacksmoke16> essentially replicate what `.ord` does
<FromGitter>
<Blacksmoke16> would be the hacky workaround
<oprypin>
postmodern, i dont get it. `p {{ 'a'.stringify }}`
<oprypin>
oh but it's a string then
<FromGitter>
<Blacksmoke16> right
<postmodern>
also stringify returns a StringLiteral, i believe
<FromGitter>
<Blacksmoke16> right
<postmodern>
oprypin, here's a simplified example of what i'm trying to do: https://carc.in/#/r/8mnh
<oprypin>
postmodern, one pragmatic option would be to just write out the integer
<oprypin>
actually in hexadecimal would be nice
<oprypin>
and then do an assert that the value equals to your computation but at runtime
<oprypin>
(could be in specs)
<oprypin>
i think doing computations inside `lib` is bound to get you into more trouble than just the macro itself
<oprypin>
the available syntax in them is limited, right? but what you want should still be supported, yeah
* FromGitter
* Blacksmoke16 wants the PR
<postmodern>
oprypin, but then you lose the four character code (fourcc) information. You'd have to move that into a comment or something, because that's how pixel formats are historically represented
<postmodern>
Blacksmoke16, where would i put the CharLiteral#ord method?
<FromGitter>
<Blacksmoke16> sec i have that branch checked out, i can try it
<oprypin>
postmodern, in the context of #8836 or without it?
<postmodern>
depends if 8836 will be accepted before the next release?
<postmodern>
might be more pragmatic to just add CharLiteral#ord directly
<FromGitter>
<Blacksmoke16> could add it either way
<oprypin>
postmodern, yea lol do the lookup table. write out a HashLiteral 😬
<FromGitter>
<andrewc910> In a config class for my shard I have an option for setting the mailer class. How can I do something like `property mailer_class : Mochi::Mailer = Mochi::Mailer`. I need to set a default but I get an error like 'mailer_class cannot be Mochi::Mailer.class'. May I ask for proper syntax?
<FromGitter>
<Blacksmoke16> actually cant seem to get it to work
<FromGitter>
<Blacksmoke16> add a `.new`
<FromGitter>
<Blacksmoke16> otherwise you're trying to assign the class `MochI::Mailer` to something typed as an instance of it
<FromGitter>
<Blacksmoke16> postmodern: sorry that method is inherently missing so it would have to be added even with that PR :/
<postmodern>
ok i created an ascii table, and it appears to be generating number literals, but now i get this error when it's called from within the enum
<postmodern>
Error: unexpected token: 826427218
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<Blacksmoke16> Called how?
<postmodern>
it appears that macros cannot be used within enums at all?
<FromGitter>
<Blacksmoke16> Can you share the error and trace
<FromGitter>
<christopherzimmerman> @ArtLinkov @bararchy I just merged in a PR to add opencl integration to num.cr (https://github.com/crystal-data/num.cr), it would be awesome to have GPU support in shainet! If you have specific ways you'd like to integrate it that I would be able to take care of, just let me know.
<FromGitter>
<andrewc910> @Blacksmoke16 Thank you very much. I have that feeling when you're four characters away from fixing a problem that's been bugging you for a week. :facepalm:
<postmodern>
Blacksmoke16, begin/end around the macro or around it's body?
<FromGitter>
<watzon> @postmodern it appears as though you've found a bug
<FromGitter>
<watzon> I don't think that's intended
<FromGitter>
<watzon> Just something that doesn't happen much
<postmodern>
a bug? in software? surely you jest
<FromGitter>
<watzon> Lmao
<postmodern>
watzon, which example should i submit in my bug report, and am i correct that it appears macros cannot be called from within enum bodies?
<FromGitter>
<watzon> It defintely looks that way. I'd submit both, one as a simple example and the other as a more complete example.
<FromGitter>
<watzon> I tried everything I could think of to make it work
<FromGitter>
<Blacksmoke16> Around where you set the enum value
<postmodern>
tried putting begin/end around the enum element assignment, and the whole enum it self
<postmodern>
Error: expecting token 'EOF', not 'end'
<FromGitter>
<Blacksmoke16> should it exist in a `lib`?
<FromGitter>
<Blacksmoke16> works when its not
<FromGitter>
<Blacksmoke16> `enum Linux::V4L2PixFmt` would do the same job
<postmodern>
Blacksmoke16, it probably should because it comes from C and is used in other C structs
<postmodern>
that also seems like a bug, is it some scope difference issue?
<FromGitter>
<Blacksmoke16> idk much about the c binding stuff, but essentially `lib` is a macro too i think?
<FromGitter>
<watzon> I tried taking the enum out of `lib` and it still didn't work
<FromGitter>
<Blacksmoke16> ofc have to remove the `Linux::` namespace from the type too
<postmodern>
enum LibName::EnumName did work for me with the simplified example
<postmodern>
er i had to edit the source code a bit so the line numbers don't match with the error
<postmodern>
ah ha, compiling the file separately works. It's something else in my source code...
<FromGitter>
<Blacksmoke16> 👍
<postmodern>
hmm or maybe it's being optimized out in my single file example
<postmodern>
the backtrace is wrong
<postmodern>
print debugging found it, a ' ' char that i was missing
<postmodern>
but coming from line 137, not 89
<FromGitter>
<Blacksmoke16> 😬
<postmodern>
hmm can't repro outside of my code
<postmodern>
far too many hacks and bugs here. hope that macros and enums get some work
<FromGitter>
<andrewc910> Is it possible to determine a parent class from a variable? `MyController < Mochi.config.parent_controller`
<FromGitter>
<andrewc910> Can't find anything in docs.
<FromGitter>
<andrewc910> I thought about a macro but then that requires me to require files and invoke methods in a very particular order that I am not fond of.
<FromGitter>
<watzon> Not like that, but I'm pretty sure you can with a macro
<FromGitter>
<watzon> You also can't extend a non-constant
<postmodern>
do variadic function declarations require an argument?
<postmodern>
can i call foo(a,b,...) as foo(a,b)?
<FromGitter>
<andrewc910> May I ask what you mean by 'you can't extend a non-constant'? I don't truly understand extend.
<FromGitter>
<andrewc910> I'll try with macros. Just need to think about implementation. 😭
<FromGitter>
<tenebrousedge> postmodern, if you have `foo(a, *b)` then yes
<postmodern>
ah forgot to splat the args
<FromGitter>
<Blacksmoke16> @andrewc910 thats not possible
<FromGitter>
<Blacksmoke16> unless you define some method within the parent that would expose it as a class method
<postmodern>
is it possible to define macros local to a class or namespace? or are all macros global?
<FromGitter>
<Blacksmoke16> they would work just like class methods
<FromGitter>
<andrewc910> @Blacksmoke16 best to use a macro?
<FromGitter>
<Blacksmoke16> What are trying to do exactly?
<FromGitter>
<Blacksmoke16> got auto service resolution implemented
<FromGitter>
<Blacksmoke16> if no arguments are provided to `Register`, it'll fallback to the initializer arguments, attempting to resolve arguments automatically based on type restriction
<FromGitter>
<Blacksmoke16> if multiple services are registered with that type, will fall back on the arg's name
<FromGitter>
<andrewc910> @Blacksmoke16 In my shard, i have controllers already made for people. I made an `ApplicationController` which inherits from `Amber::Controller::Base`. All my controllers parent class is this `Mochi::ApplicationController`. I would like for people to be able to change it.
<FromGitter>
<Blacksmoke16> change the base class?
<FromGitter>
<Blacksmoke16> @andrewc910 yea thats not possible
<FromGitter>
<andrewc910> If i use a macro, then you have to require the app controller, invoke the macro then require the rest of the files. I don't like that things need to be in such a specific order :/
<FromGitter>
<andrewc910> Macro it is!
<FromGitter>
<Blacksmoke16> can you not make it a module or something?
<FromGitter>
<Blacksmoke16> then they can just include it whereever they want?
<FromGitter>
<andrewc910> I can with a different implementation. Currently, a user would inherit from my controller then their controllers look like: ⏎ ⏎ ```def confrm ⏎ super ⏎ end``` ⏎ ⏎ It seems like modules would be best. My controllers are full modules instead of classes, the controller i generate for you already have the mixin and the same final effect is done. [https://gi
<FromGitter>
<andrewc910> obvious the params method wouldn't be empty but you get the point
<FromGitter>
<andrewc910> I think that would work too. Just sucks you can't see the methods directly in your controller. You can still do some before/after code which is nice.
<FromGitter>
<Blacksmoke16> prob would show up in generated api docs
darkstardevx has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter>
<andrewc910> That's true. I have to sit and think of some other implementations. I think pure modules is the way to go but I'm not really liking it.
darkstardevx has joined #crystal-lang
<FromGitter>
<Blacksmoke16> sounds like a plan
<FromGitter>
<WintonMc_twitter> Hi
<FromGitter>
<WintonMc_twitter> I'm new, someone tells me why I can't post anything on forum
<FromGitter>
<tenebrousedge> do you get some sort of error message?
<FromGitter>
<WintonMc_twitter> I registered yesterday, they gave me a badge and well I still don't know
<FromGitter>
<tenebrousedge> and do you get an error if you try to create a new topic?
<FromGitter>
<WintonMc_twitter> I do not go out to create a new
<FromGitter>
<WintonMc_twitter> It does not give me the option
<FromGitter>
<WintonMc_twitter> I still have 2 weeks learning this language, works well backed
<FromGitter>
<WintonMc_twitter> ?
<FromGitter>
<tenebrousedge> yes, it's a very nice backend language. It's very surprising to me that you're having trouble with the forums. I've never had any problems, but perhaps it's because I used github to sign up
<FromGitter>
<grkek> @sorcus Yeah I saw that made me really happy
<FromGitter>
<grkek> @watzon Sup, I had to work on a backend project for one of my buddies and was so busy that crystal progressed with 2 versions, haha. very nice very nice
ur5us has joined #crystal-lang
_ht has joined #crystal-lang
<sorcus>
grkek: :-)
ur5us has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
sz0 has joined #crystal-lang
<FromGitter>
<wout> Given the following json string: `%({"value":"3.14","currency":"EUR"})`. What would be to convert the `value` to `BigDecimal` when the struct includes `JSON::Serializable`? Should I use a `JSON::Field` annotation with a converter, or is there a more convenient way?
<FromGitter>
<Blacksmoke16> converter
<FromGitter>
<wout> @Blacksmoke16 Thanks!
<FromGitter>
<asterite> Doesn't BigDecimal already know how to de serialize from JSON?
<FromGitter>
<wout> @asterite It does not so it seems. I have tried a few things but I keep getting `Error: can't cast (String | Nil) to BigDecimal`.
<FromGitter>
<wout> Probably because it is `String | Nil` instead of `String`?
<FromGitter>
<wout> Using `@[JSON::Field(nilable: false)]` results in:
<FromGitter>
<j8r> `405 Method Not Allowed`... this means the router has to store the route, then the methods available for each one.
<FromGitter>
<j8r> I have done the other way around :/
<FromGitter>
<Blacksmoke16> 😐
<FromGitter>
<j8r> I was taking example in Kemal, that stores the HTTP method first - need to store it last. ⏎ What does Athena?
<FromGitter>
<Blacksmoke16> athena does like `"/" + method + prefix + path`
<FromGitter>
<Blacksmoke16> so like `"/" + "GET" + "" + "/foo/bar"`
<FromGitter>
<j8r> so 405 can't be supported easily
<FromGitter>
<Blacksmoke16> i use 405 for CORs, but otherwise it would be 404
<FromGitter>
<j8r> On my side I will first resolve the path, then return available actions
<FromGitter>
<j8r> It would also simplify doc generation :D
<FromGitter>
<j8r> I was planning to release today, but I need to fix this first
<FromGitter>
<Blacksmoke16> > On my side I will first resolve the path, then return available actions ⏎ ⏎ how does this work? wouldnt the path map 1:1 to an action?
<FromGitter>
<j8r> now it is the case
<FromGitter>
<j8r> in the future the path can map to one Object, which holds 0 to several actions
<FromGitter>
<j8r> this will allow to send a 405 is there are actions available
FromGitter has quit [Ping timeout: 245 seconds]
postmodern has quit [Quit: Leaving]
dwdv has joined #crystal-lang
_whitelogger has joined #crystal-lang
MasterdonX has quit [Ping timeout: 272 seconds]
masterdonx2 has joined #crystal-lang
Nekka has quit [Read error: Connection reset by peer]