<FromGitter>
<Blacksmoke16> thought you could do it with `sprintf` as well but im thinking no
<FromGitter>
<ArtLinkov> well, It's biggy... I'll just make a quick method of my own :)
<FromGitter>
<straight-shoota> You can simply copy `humanize.cr` from master into your codebase and remove it once 0.28.0 is released
<FromGitter>
<ArtLinkov> π
<FromGitter>
<TheOnlyArtz> I'm using UDPSocket API, every time I receive a packet the connection closes ( Well that's expected cause it's a stateless protocol ) β But whole the program stops itself
<FromGitter>
<TheOnlyArtz> How can I prevent that from happening?
<FromGitter>
<TheOnlyArtz> Put a loop around β `message, client_ip = server.receive` ?
<Groogy>
Yo! o/
<FromGitter>
<Blacksmoke16> o/
<FromGitter>
<Naoyo> @TheOnlyArtz Yeah I just put a `loop do .. end` between `server.receive` and it worked.
<FromGitter>
<TheOnlyArtz> I've got an issue with the TCPServer API, I'm binding a new server to port 3000 and for some reason other machines can't access it while when I'm using Kemal, they can.
azuri5 has quit [Quit: azuri5]
<FromGitter>
<TheOnlyArtz> I needed to use `open` instead of `new` issue solved
azuri5 has joined #crystal-lang
<FromGitter>
<TheOnlyArtz> @straight-shoota I'm having issues with `Invalid memory access` β As you can see here I got crystal to the left and C to the right, I'm trying to call the `bufferToHandShakeClient` β and I'm getting this error
<FromGitter>
<straight-shoota> I don't know what your code is doing, but these calls to fwrite, strcopy, cutstr seem to assume a certain string size which might not be true
<FromGitter>
<TheOnlyArtz> Basically we are getting a buffer of bytes and slicing it by a certain offset to extract the data we want
<FromGitter>
<TheOnlyArtz> sweet, but that won't help us resolve the memory issue
<FromGitter>
<straight-shoota> I don't think this is a limitation of Crystal, it's probably just a stupid bug somewhere in your code. Probably related to some memory ownership issues between Crystal and C.
<FromGitter>
<TheOnlyArtz> I mean... it's just a simple function
<FromGitter>
<TheOnlyArtz> What bug can exist there exactly.. the C code works perfectly
<FromGitter>
<straight-shoota> Dunno
<FromGitter>
<straight-shoota> You said, removing `puts tesa` avoids the invalid memory access?
<FromGitter>
<z64> a good place to start would be to validate what you are passing into the C function β is `message` what you expect it to be before passing it?
<FromGitter>
<TheOnlyArtz> No, removing `tesa = Protocol.buffer....`
<FromGitter>
<straight-shoota> Ofc, then it doesn't do anything
<FromGitter>
<TheOnlyArtz> @z64 As I said, the C manipulates the Buffer perfectly
<FromGitter>
<z64> i'm not skeptical of C. i'm asking you to check, i.e. `p message`, before passing it to the C function.
<FromGitter>
<TheOnlyArtz> Well.. if the C function slices the buffer it gets, then yes `message` is a valid thing
<FromGitter>
<straight-shoota> Can you show me the entire code?
<FromGitter>
<z64> it would just take a moment to try a simple sanity check of `p message` :p to me, it looks like you get a message that is parsed just fine. but, `IO#gets` is `String?` - the call to gets on the *next* iteration may return `nil`
<FromGitter>
<TheOnlyArtz> You may be right
<FromGitter>
<TheOnlyArtz> Nope, that's not the issue actually since it crashes without the `loop do ... end`
<FromGitter>
<straight-shoota> Hm, there seems to be a discrepancy between your C and Crystal type definition
<FromGitter>
<straight-shoota> Not sure if that's the issue
<FromGitter>
<TheOnlyArtz> What do you mean?
<FromGitter>
<straight-shoota> The instance variables of `HandShakeClient` are static arrays in C, an pointers in Crystal
<FromGitter>
<TheOnlyArtz> Oh right
<FromGitter>
<TheOnlyArtz> What's the equivalent of Static arrays then?
<FromGitter>
<straight-shoota> `StaticArray(UInt8, 128)` etc.
<FromGitter>
<TheOnlyArtz> OMG
<FromGitter>
<TheOnlyArtz> Thank you very much!
<FromGitter>
<straight-shoota> Or just `UInt8[128]`
<FromGitter>
<TheOnlyArtz> That's fantastic guys! you're the best
<FromGitter>
<straight-shoota> Great that it helped
<FromGitter>
<j8r> what's the main difference between StaticArray and Slice?
<FromGitter>
<bew> basically, a slice is a pointer and a size ; a static array is a bunch of bytes on the stack or embedded in an object (like a struct) and you manipulate these bytes like an array where the size can't change (known at compile time)
<FromGitter>
<kinxer> I copied the wrong thing... Is this your error: https://carc.in/#/r/6jgv ?
<FromGitter>
<kinxer> If so, the whole error is β β ```code paste, see link``` β β That's an error where the method arguments after `serverVersion: StaticArray(UInt8, 16_u8).new 0` are being interpreted as `StaticArray(T,N).new` arguments, which can be fixed by adding parentheses: https://carc.in/#/r/6jgw [https://gitter.im/crystal-lang/crystal?at=5c93e5a79d9cc8114afbbecd]
<FromGitter>
<johnjansen> for consistency, probably add the brackets to both βnewβ
<FromGitter>
<kinxer> Yeah, definitely. I left off the second set of parentheses to emphasize that they're not necessary, though.
<FromGitter>
<johnjansen> totally ;-)
<robacarp>
burn the unnecessary syntax
<FromGitter>
<johnjansen> IMO in this case β β ```code paste, see link``` β β bracketing the 0 on the last line is necessary for consistency β¦ given the previous one is, and the closing bracket has the potential to add confusion [https://gitter.im/crystal-lang/crystal?at=5c93ed125547f774484244b0]
<FromGitter>
<kinxer> Yes, I agree that it's necessary, as much as proper style and readability make something necessary. I specifically left off the parentheses for the second `StaticArray` constructor to emphasize that the parentheses on the first constructor are the *syntactically* necessary addition.
<FromGitter>
<johnjansen> i wasnt aiming the comment at you @kinxer
<FromGitter>
<johnjansen> its was in response to `*<robacarp>* burn the unnecessary syntax`
<FromGitter>
<kinxer> Ah... I assumed that was a joke. :P
<FromGitter>
<johnjansen> hard to know
<robacarp>
there are varying degrees of necessity, some are compiler driven and some are readability driven
<robacarp>
but for example, I know a bunch of javascript devs who insist on using semicolons everywhere just because, yet it's not helpful to the interpreter (most of the time) and it's not really going to help readability
<FromGitter>
<TheOnlyArtz> Guys, I'm using TCPServer, whenever a message is coming from the client, I won't be able to read it until the client connection is getting closed
<Groogy>
I expected that to count as explicitly counting as providing the generic argument
<Groogy>
it works perfectly fine within a method
gangstacat has joined #crystal-lang
<z64>
the metaclass isn't instantiated for generics like that. T can't be inferred by looking at the class definition alone
<Groogy>
Yeah trying to optimize so I don't have to new everytime the method is called
<Groogy>
since value will always be the same but because the generic argument is not available I can't
<Groogy>
anyone got any ideas how I can accomplish that? I.e avoid an allocation there?
<Yxhuvud>
I suppose you actually have more code in there and isn't simply trying to bend the type system into a lookup table by class?
<Groogy>
Well it's for my vectors
<Groogy>
and it's normal to want to fetch out zero and unit(1) vectors
<Groogy>
so it gets called all over the place so instead of having to new each time I might as well just have a copy already defined
<Groogy>
the Vector.zero method appears a lot in the profiling data
<Yxhuvud>
How about a constant instead of a class variable?
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<Yxhuvud>
Hmm. Seems to be the T.new part that doesn't work.
<Yxhuvud>
(for the constant case)
azuri5 has quit [Ping timeout: 252 seconds]
<Yxhuvud>
Do the vectors have more content? it seems very strange that a small *struct* spend a noticable time being allocated considering that they are allocated on the stack and copied by value.
<Groogy>
no it's just used in a lot of places
<Groogy>
@pos = Boleite::Vector2f.zero
<Groogy>
and in algorithms etc.
<Groogy>
it's a bit of micro optimization but would be gone to get gone
<Groogy>
been fixing other hotspots meanwhile
<Groogy>
good to get it gone*
Kixune has joined #crystal-lang
hightower2 has joined #crystal-lang
<hightower2>
Hey is Time#epoch_ms now called Time#to_unix_ms or what?
<FromGitter>
<Blacksmoke16> yes
<hightower2>
alrighty
<hightower2>
thanks
<FromGitter>
<mikeonslow> Hey all, can't say that I've used Crystal but I really the ideas behind it! We're hosting a new conference and are looking for speakers. We'd love to hear from the Crystal community: https://www.papercall.io/dtw, event details here: https://detroittechwatch.org/
Kixune1 has joined #crystal-lang
<hightower2>
mikeonslow: we glad you really the ideas! :)
hightower2 has quit [Quit: Leaving]
Kixune has quit [Ping timeout: 272 seconds]
Kixune1 is now known as Kixune
<FromGitter>
<mikeonslow> Definitely! I think it solves some common pain points for sure. We moved from using PHP to Elixir about a year and a half ago to solve some of those pain points. Wish we had the static type checking in the core of the language though like Crystal does!