RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
Kixune has quit [Ping timeout: 272 seconds]
Kixune has joined #crystal-lang
lucasb has quit [Quit: Connection closed for inactivity]
Kixune has quit [Quit: Kixune]
<FromGitter> <dscottboggs_gitlab> @bew the issue we were talking about the other night, I did my best to describe it #7573
Raimondi has quit [Read error: Connection reset by peer]
Raimondi has joined #crystal-lang
<FromGitter> <codenoid> json parse in crystal is hard
crystal-lang564 has quit [Ping timeout: 258 seconds]
<FromGitter> <girng> @codenoid I think there should be a JSON.parse but works without JSON::Any, but actually parses objects statically. Would be amazing
chemist69 has quit [Ping timeout: 252 seconds]
chemist69 has joined #crystal-lang
beepdog has quit [Ping timeout: 250 seconds]
mntmn has quit [Ping timeout: 240 seconds]
mntmn has joined #crystal-lang
beepdog has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <ditsara> let me jump on the bandwagon a bit here -- we're hosting a Ruby conference in Bangkok, Thailand on Sept 6-7. if you're going to be in the neighborhood (or want to make plans to visit), we'd be really happy to have Crystal talks. More info on our website (https://rubyconfth.com/) and papercall (https://www.papercall.io/rubyconfth)
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <codenoid> @girng aggreeee
<FromGitter> <codenoid> or just like json unmarshal from struct
<FromGitter> <TheOnlyArtz> Many articles suggest Crystal as possible game development language, what dependencies are there for that?
<FromGitter> <wontruefree> @mikeonslow I have been giving a few talks on Crystal in Chicago and would be interested in checking out your con
<FromGitter> <girng> @TheOnlyArtz Depends on what you mean by dependencies I think. For client side, there is https://github.com/ysbaddaden/sdl.cr and https://github.com/oprypin/crsfml. There is also the Godot engine, which uses GDScript (python like syntax), and intertwines perfectly with crystal on the server, example: https://forum.crystal-lang.org/t/simple-godot-crystal-tcp-script/45/7
<FromGitter> <TheOnlyArtz> How scalable is Crystal for the backend tho?
<FromGitter> <TheOnlyArtz> Like.. can you scale it?
<FromGitter> <TheOnlyArtz> Woah!
<FromGitter> <TheOnlyArtz> I will def look further with GD + Crystal
<FromGitter> <TheOnlyArtz> My main issue is the development it self, I'm pretty sure GD works way better on Windows than on Linux, and Crystal is available on Linux..
<FromGitter> <bew> @Groogy hi! I think your compile error is due to the fact that there's one `@@bar` for all `Foo` types
<FromGitter> <bew> So for exemple `Foo(Int32).weird` is the same result as `Foo(UInt8).weird`, but the types aren't the same..
<FromGitter> <bew> I think you could have a workaround using some *heavy* macros if you really need this, but I don't think it's worth it..
<FromGitter> <bew> Maybe Generics specialization would allow to have something like this, you can try to raise your voice in the issue talking about that (to have a `@@bar` for each type instance of the generic `Foo`
<FromGitter> <bew> #3298
ashirase has quit [Ping timeout: 255 seconds]
ashirase has joined #crystal-lang
<FromGitter> <cserb> Is it intentional, that shell commands can't be spawned or a bug? https://play.crystal-lang.org/#/r/6jp4
<FromGitter> <cserb> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c94af5349fdaa0d81f7cecd]
<FromGitter> <straight-shoota> That looks like a bug with the macro generation. Please open an issue at https://github.com/crystal-lang/crystal/issues/new Thanks!
hightower2 has joined #crystal-lang
<FromGitter> <j8r> How can I iterate over ivars of a given Class, passed as an argument of a macro: https://carc.in/#/r/6jpo
<FromGitter> <vladfaust> @j8r you can't. Instance vars are unknown at this point of time
<FromGitter> <j8r> that's exactly this, upvote added
<FromGitter> <TheOnlyArtz> Hm for what `@@` is being used?
<FromGitter> <j8r> class_vars
<FromGitter> <TheOnlyArtz> But that's `@` no?
<FromGitter> <j8r> that's instance var
<FromGitter> <TheOnlyArtz> Oh ok ty
<FromGitter> <j8r> class vars are shared for all objects, instance var only for one
<FromGitter> <j8r> @vladfaust thanks for the answer, I'm trying the other way around: https://carc.in/#/r/6jq2
<FromGitter> <j8r> I would like to iterate over the Point's ivars
<FromGitter> <vladfaust> Only class and instance methods have access to ivars
<FromGitter> <vladfaust> `def cast_to`
<FromGitter> <vladfaust> There is also a dirty hack with getters https://github.com/onyxframework/sql/blob/master/src/onyx-sql/model/enums.cr
<FromGitter> <j8r> right, it works
<FromGitter> <j8r> strange to be able to use `{{}}` directly inside methods
<FromGitter> <j8r> without `{% begin %}`
<FromGitter> <vladfaust> Well, `for` somewhat acts as `begin`
<FromGitter> <j8r> `{% verbatim %}` is used to avoid the backslashes?
<FromGitter> <j8r> I can directly `p {{@type.instance_vars.stringify}}` inside the def
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <vladfaust> Not a bug though :)
<FromGitter> <vladfaust> The hack mentioned above allows to get instance var names outside instance methods
<FromGitter> <vladfaust> But it only works when an object has raw getters
<FromGitter> <vladfaust> You shouldn't use it probably if you're OK with methods :)
<FromGitter> <dscottboggs_gitlab> > I think there should be a JSON.parse but without JSON::Any, but actually parses objects statically. Would be amazing ⏎ ⏎ @girng ⏎ It *would* be amazing, but it's not possible. Data structures must be known at compile-time, and the JSON isn't fed to the compiler, but the program you're writing. I.E., the actual data isn't presented until run-time, but it's needed at compile time. ⏎ ...
mntmn has quit [Ping timeout: 252 seconds]
mntmn has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron- has joined #crystal-lang
<FromGitter> <Blacksmoke16> How can I iterate over ivars of a given Class ⏎ My dream atm
<FromGitter> <j8r> the main problem with dynamic/bytecode interpreted language is memory, it takes a lot more. And memory is expensive, more than CPUs
hightower2 has quit [Ping timeout: 245 seconds]
lucasb has joined #crystal-lang
Jenz has joined #crystal-lang
Jenz has left #crystal-lang [#crystal-lang]
Jenz has joined #crystal-lang
ma_ has joined #crystal-lang
ma_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sz0 has joined #crystal-lang
<FromGitter> <TheOnlyArtz> @girng In your TCP example you said rate limiting should be implemented, how can you rate limit movement of players?
<FromGitter> <TheOnlyArtz> Like, obviously you can but it's nonsense, movement can't be rate limited, it's unplayable
ma_ has joined #crystal-lang
ma_ has quit [Client Quit]
ma_ has joined #crystal-lang
Jenz has quit [Ping timeout: 272 seconds]
<z64> controlling data throughput / system backpressure is important in building scalable systems. as for application in something like a game, this can be done in lots of ways; many solve this problem by implementing things like client side prediction and means for the client & server to sync with each other seamlessly, in addition to being tolerant to things like packet loss etc
<FromGitter> <TheOnlyArtz> This makes sense I guess
Kixune has joined #crystal-lang
<FromGitter> <TheOnlyArtz> How would I error handle a TCPSocket, I'm using fibers for each thread and I'm getting errors sometimes like "Broken pipe" and whenever the client closes
<z64> like you handle any other error in crystal; by handling them with `rescue`, `ensure`, etc.
<FromGitter> <TheOnlyArtz> So like ⏎ ⏎ ```begin ⏎ spawn handle_connection(socket, clients_arr) ⏎ rescue e : Errno ⏎ ... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c95028b52c7a91455da2738]
<FromGitter> <TheOnlyArtz> Or being more specific and putting one for every "dangerous" method?
<FromGitter> <TheOnlyArtz> Like the send operation
<z64> well, you don't want to capture `spawn`. if you want to capture general errors with a specific connection, that should likely go in your `handle_connection` method
<FromGitter> <TheOnlyArtz> I'm doing that like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9503c981b15c5e4b6b9fa7]
<FromGitter> <TheOnlyArtz> But It's an infinite loop
<FromGitter> <TheOnlyArtz> it hurts
<FromGitter> <TheOnlyArtz> Maybe I'm implementing the handle_connection wrong?
<FromGitter> <TheOnlyArtz> I'm aiming to be able to read more than a single packet in a connection
<FromGitter> <TheOnlyArtz> (It's for a game server)
<FromGitter> <z64> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c95048ed0133e21e5f94b87]
<FromGitter> <TheOnlyArtz> But is there a possibility that my implementation is wron in general?
<FromGitter> <TheOnlyArtz> It seems to infinite loop
<FromGitter> <z64> it will read until the socket closes, whether you close it or the client does
<FromGitter> <z64> if thats what you want.. then that's fine
<FromGitter> <z64> if you decide the session is invalid or over, then you ideally send some message to the peer saying you're going to go away, then call `socket.close`, etc..
Kixune has quit [Ping timeout: 255 seconds]
<FromGitter> <z64> you could make some higher level API that more rigidly defines your protocol between server/client if you wanted with classes to represent sessions, etc.. tons of possibilities
<FromGitter> <TheOnlyArtz> That's what I'm doing with decide_operation
<FromGitter> <TheOnlyArtz> I think
<FromGitter> <z64> yep, pretty much. there's tons of ways you could go from there
<FromGitter> <TheOnlyArtz> So far the C bindings are working really great :)
<FromGitter> <TheOnlyArtz> I'm working with someone who writes the client in Rust and he had a really rough time lmao
<FromGitter> <z64> so i heard :p
<FromGitter> <TheOnlyArtz> Can Crystal run on embedded devices since it compiles to byte code?
Kixune has joined #crystal-lang
<FromGitter> <straight-shoota> Sure, as long as the target architecture is supported
<FromGitter> <TheOnlyArtz> Any documentation on that?
<FromGitter> <z64> probably best to start here and determine if the platform you want to use is well supported, etc: ⏎ https://github.com/crystal-lang/crystal/wiki/Platform-Support ⏎ as well as https://crystal-lang.org/reference/syntax_and_semantics/cross-compilation.html for instructions on cross compilation if you need to
<FromGitter> <TheOnlyArtz> Amazing , ty
Kixune has quit [Remote host closed the connection]
DTZUZO has joined #crystal-lang
fanta7531 has joined #crystal-lang
ma_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
laaron has joined #crystal-lang
laaron- has quit [Remote host closed the connection]
Kixune has joined #crystal-lang
Kixune has quit [Quit: Kixune]
<FromGitter> <tenebrousedge> So, I'm not actually getting the sense that procs are very well supported ⏎ ⏎ $ crystal eval 'a = 15; b = ->a.divisible_by?(Int32);' ⏎ Module validation failed: Invalid bitcast ⏎ Error: you've found a bug in the Crystal compiler. [https://gitter.im/crystal-lang/crystal?at=5c9539d12fb6800d80641e82]
<FromGitter> <Blacksmoke16> nice, thats a new one. I'd file an issue for it
<FromGitter> <tenebrousedge> what's the most useful things to include in that?
<FromGitter> <tenebrousedge> (I assume there's a template?)
<FromGitter> <Blacksmoke16> the code, playground link and the error is fine
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6jvf
<FromGitter> <tenebrousedge> thank you very much
<FromGitter> <Blacksmoke16> np
sz0 has quit [Quit: Connection closed for inactivity]
fanta7531 has quit [Quit: fanta7531]
Kixune has joined #crystal-lang
blassin has quit [Quit: The Lounge - https://thelounge.chat]
blassin has joined #crystal-lang
Kixune has quit [Quit: Kixune]
<FromGitter> <TheOnlyArtz> Can you scale TCP Servers using https://github.com/stefanwille/crystal-redis?
<FromGitter> <TheOnlyArtz> How does it work?
<FromGitter> <Blacksmoke16> well redis is a popular choice for cacheing
<FromGitter> <Blacksmoke16> a simple example being after a request you throw the response in redis, then on other requests can check if its there and still fresh and return that vs hitting up your db again or whatever
<FromGitter> <Blacksmoke16> easiest to think about it in a JSON api idea, where the data might be a bit expensive so could cache it for a given period of time
<FromGitter> <TheOnlyArtz> Well
<FromGitter> <TheOnlyArtz> It doesn't make sense to use Redis for a game server then
<FromGitter> <Blacksmoke16> im sure there could be a use case
<FromGitter> <Blacksmoke16> but ofc would be up to you to know what could be cached
<FromGitter> <Blacksmoke16> depending on how your game works, and what the api is doing?
<FromGitter> <TheOnlyArtz> I've built a protocol in C dedicated for the game
<FromGitter> <TheOnlyArtz> It uses the TCPServer API
<FromGitter> <TheOnlyArtz> The C protocol handles the packets
<FromGitter> <girng> @dscottboggs_gitlab Could't it be done with macros though? ⏎ @TheOnlyArtz Keep track of the player's current_position and old_position. Each time a movement cmd is received, get the difference. If it's greater than XXX, that user is teleporting. If that user has a `increased_movement_speed` valuable, make sure you account for that. For rate limiting requests, I have a `last_message_received`, and a
<FromGitter> ... `last_message_received2` property for the `Client`. `last_message_received` is for a global flood check (to check against all incoming messages message), and `last_message_received2` is for specific commands (updating inventory, logging in, deleting char, creating char, sending a pm, buying from auction house, etc, etc). Example (ht ... [https://gitter.im/crystal-lang/crystal?at=5c954d87a21ce51a20a50b17]
<FromGitter> <TheOnlyArtz> Every time the player moves we send a packet to the server, then the server uses the C API to extract the `MovementPacket` struct from the buffer ⏎ The `MovementPacket` struct contains properties like `direction (which uses an enum to indicate the direction) and the entity's ID)`
<FromGitter> <TheOnlyArtz> It sounds like you don't let players to move continuously without the need to stop (so the client will stop sending movement packets)
<FromGitter> <TheOnlyArtz> @girng
<FromGitter> <TheOnlyArtz> I'm talking in a `network-programming` related place right now and people suggesting to design a netcode strong enough so you won't have to rate limit
<FromGitter> <girng> You always will have to rate limit, even Path of Exile does
<FromGitter> <TheOnlyArtz> Again, players in your games won't be able to move continuously because of the rate limits?
<FromGitter> <TheOnlyArtz> @girng
<FromGitter> <girng> Nope they can, the client sends the movement messages at 20 times/second. If it goes faster than that, the server will eventually kick them (dependent on `client.flood_attempts`)
<FromGitter> <TheOnlyArtz> Kick them?
<FromGitter> <girng> disconnect them, close their connection*
<FromGitter> <TheOnlyArtz> In what way are you sending movement packets ? If I will hold down the `w` button to move, it won't pass the 20 per second?
<FromGitter> <TheOnlyArtz> more than*
<FromGitter> <girng> @TheOnlyArtz In Godot, I just have a timer running at 20 times/s. Whenever the player's old and new position is different, that means they are moving. Then it sends their pos.x, and pos.y values to server
<FromGitter> <TheOnlyArtz> Well yea same here (the send part) but what do you mean with the `timer running at 20 times/s`
<FromGitter> <girng> @TheOnlyArtz A method basically executing 20 times a second, which sends the positional data
Jenz has joined #crystal-lang
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <dscottboggs_gitlab> @girng no, macros can only generate code to be compiled, not change it after it's been written. Have you ever used a templating language to build HTML? ECR, ERB, Jinja, etc?
Jenz has quit [Quit: Lost terminal]
<FromGitter> <girng> @dscottboggs_gitlab To your question, nope.
<FromGitter> <Blacksmoke16> fun fact, can use ECR to build anything not just HTML
<FromGitter> <Blacksmoke16> i.e. i use it in my yaml config file to allow it to pull in ENV vars
<FromGitter> <straight-shoota> @Blacksmoke16 Using ECR in YAML in makes it depend on compilation. That's somewhat counterproductive. YAML etc. files are usually used for configuration at runtime.
<FromGitter> <johnjansen> very handy for interpolating in ENV vars in the right situation though
<FromGitter> <johnjansen> actually very common for that purpose
<FromGitter> <dscottboggs_gitlab> My point was that using Crystal macros is no different than generating a `.py`, `.cr`, `.rb`, etc file from a Jinja/ERB/ECR/other template. The template doesn't have any access to the runtime logic, and vice versa. For example, if you were to use a jinja template to write a python file, you might write `jinja some-file.jinja.py | python` into your terminal. The jinja template would generate a .py
<FromGitter> ... file, which would then be read and interpreted by the python interpreter. The Jinja template wouldn't be able to call out to a python function, because the python interpreter hasn't been involved yet. The python can't update the template because the jinja parser has already finished running. ⏎ ⏎ The advantage of crystal macr ... [https://gitter.im/crystal-lang/crystal?at=5c9573ee81b15c5e4b6e9f95]
<FromGitter> <dscottboggs_gitlab> But you haven't used a templating langauge so that won't help you understand :/