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
mps has joined #crystal-lang
<FromGitter> <parruda> Hey guys, is it possible to use JSON.mapping and leave one of the keys unparsed? For example: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ This will throw an error when trying to parse the json string: `Unhandled exception: Expected string but was begin_object` [https://gitter.im/crystal-lang/crystal?at=5c9ebf496a9761361b254ffd]
<FromGitter> <Blacksmoke16> would have to use a converter to tell it you want that as a string
<FromGitter> <Blacksmoke16> sec
<FromGitter> <parruda> would String::RawConverter work?
<FromGitter> <Blacksmoke16> :0
<FromGitter> <Blacksmoke16> TIL thats a thint
<FromGitter> <Blacksmoke16> but yea thats what you would want
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6m3q
<FromGitter> <Blacksmoke16> good call
<FromGitter> <parruda> Well you helped me when you mentioned converted. It helped me to find String::RawConverter, so thanks a lot!
<FromGitter> <Blacksmoke16> wasnt expecting it to be under String module
<FromGitter> <Blacksmoke16> should be one for YAML too imo
<FromGitter> <Blacksmoke16> or same module should work for both
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron- has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
boughtly has joined #crystal-lang
<boughtly> is it possible to define a macro which allows variable shadowing in a block (or even do this without a macro)
<boughtly> block scoping and no explicit variable definition syntax seems to make shadowing impossible
_whitelogger has joined #crystal-lang
<FromGitter> <ryanstout> is there a way to ```Fiber.yield``` and pass it a file descriptor to have the scheduler ```select``` on? (or the epoll/kqueue equivalent) Using libusb and want to do something when the usb device responds.
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
boughtly has quit [Ping timeout: 256 seconds]
_whitelogger has joined #crystal-lang
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <TheOnlyArtz> Hi. I'm trying to use the CLI tools and it doesn't seem to work ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f2b5a1f6e900d5eaa99fe]
<FromGitter> <TheOnlyArtz> How can I run a CLI I make with crystal CLI? the Crystal CLI tries to pick the options
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
<FromGitter> <TheOnlyArtz> ```code paste, see link``` ⏎ ⏎ But when I remove the `require` at the top it suddenly works? [https://gitter.im/crystal-lang/crystal?at=5c9f3cb9a84e0c501aa85457]
ua has quit [*.net *.split]
johndescs has quit [*.net *.split]
snapcase has quit [*.net *.split]
snapcase has joined #crystal-lang
johndescs has joined #crystal-lang
laaron- has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> uhh
<FromGitter> <Blacksmoke16> @TheOnlyArtz I'm pretty sure thats not it. I tried it in the playground and that doesnt work either way
<FromGitter> <TheOnlyArtz> Well add another parameter so it will work @Blacksmoke16
<FromGitter> <Blacksmoke16> still doesnt work either way
<FromGitter> <Blacksmoke16> because nothing references `value`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6m8w works fine with or w/o the `require "colorize"`
<FromGitter> <Blacksmoke16> also prob dont need that to be a macro if thats all its doing. class method would be sufficient
<FromGitter> <TheOnlyArtz> Ok
<FromGitter> <TheOnlyArtz> Thank you
<FromGitter> <TheOnlyArtz> I have another question
<FromGitter> <TheOnlyArtz> I can use macro syntax without using an actual macro being defined, right..?
<FromGitter> <TheOnlyArtz> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f7683f851ee043d31bd41]
<FromGitter> <TheOnlyArtz> yes?
<FromGitter> <TheOnlyArtz> Actually it doesn't work
<FromGitter> <r00ster91> you can't use runtime variables in macros. Macros are evaluated at compile-time
<FromGitter> <r00ster91> also there's no `each` in macros. There are `for`s: `{% for i in A %}`
<FromGitter> <TheOnlyArtz> Can I get the documentation for that specific macros special stuff?
<FromGitter> <Blacksmoke16> you have access to constants at compile time tho
<FromGitter> <TheOnlyArtz> I'm reading this right now, so everything I need about macros syntax is there, right?
<FromGitter> <Blacksmoke16> ehhh kinda/not really? :P
<FromGitter> <r00ster91> there are other pages too. Just search for "macro"
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.27.2/Crystal/Macros.html api docs helped me too
<FromGitter> <Blacksmoke16> esp `TypeNode`
<FromGitter> <TheOnlyArtz> Can't I create macro variables?
<FromGitter> <TheOnlyArtz> Oh wait, you said I can access constants using macros. right?
<FromGitter> <TheOnlyArtz> I can use that
<FromGitter> <Blacksmoke16> or can do like `{% my_var = "foo" %}`
<FromGitter> <Blacksmoke16> within a `{% begin %} ... {% end %}` block would allow you to reuse the `my_var` within your macro
<FromGitter> <TheOnlyArtz> I need all of my macro code to be inside that begin..end right?
<FromGitter> <r00ster91> no not all
<FromGitter> <r00ster91> a for macro will work without it
<FromGitter> <TheOnlyArtz> I mean when using a macro variable
<FromGitter> <r00ster91> yes: https://carc.in/#/r/6m9m
<FromGitter> <TheOnlyArtz> 👌
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6m9n
<FromGitter> <TheOnlyArtz> So, I can't really generate class functions using macros unless I declare the specific class within the macro, right?
<FromGitter> <TheOnlyArtz> Since `self` would be undefined.
<FromGitter> <TheOnlyArtz> Or just expressed wrong
<FromGitter> <TheOnlyArtz> What I mean is let's say I got the rest: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f79d093fb4a7dc2a5d5eb]
<FromGitter> <r00ster91> put `self.` before `{{i}}`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6ma3
<FromGitter> <TheOnlyArtz> Oh! I went `self.def` when testing it... sorry guys, thank you once again!
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/CrSerializer/releases/tag/v0.6.1 new CrSerializer version. Fixed a bug that was preventing deserializing structs
<FromGitter> <TheOnlyArtz> lovely !
<FromGitter> <TheOnlyArtz> Guys?
<FromGitter> <Blacksmoke16> you know there is already a built in `Logger` clas
<FromGitter> <TheOnlyArtz> I don't want it
<FromGitter> <TheOnlyArtz> I want class functions not instance once
<FromGitter> <vladfaust> You could patch standard `Logger` class and add a static methods to it which would proxy to a singleton instance
<FromGitter> <TheOnlyArtz> I think fetch_time is infinite looping
<FromGitter> <Blacksmoke16> could you make that into a playground link?
<FromGitter> <vladfaust> Well, that what you're doing
<FromGitter> <TheOnlyArtz> https://play.crystal-lang.org/#/r/6man
<FromGitter> <TheOnlyArtz> It should loop 4 times, should it? @vladfaust
<FromGitter> <TheOnlyArtz> iterate*
<FromGitter> <TheOnlyArtz> There are 4 values in CASES
<FromGitter> <Blacksmoke16> i see the issue
<FromGitter> <vladfaust> I do not, though. Becoming old
<FromGitter> <TheOnlyArtz> Yes? @Blacksmoke16
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6mb0
<FromGitter> <Blacksmoke16> `#{{{log_case.stringify.upcase}}}`
<FromGitter> <Blacksmoke16> it was trying to call `log` again within the log method
<FromGitter> <TheOnlyArtz> oh shoot
<FromGitter> <vladfaust> Nice one
<FromGitter> <TheOnlyArtz> Thank you, and yea, nice call
<FromGitter> <Blacksmoke16> np
hoffentlichja has left #crystal-lang [#crystal-lang]
<FromGitter> <TheOnlyArtz> https://play.crystal-lang.org/#/r/6mb1
<FromGitter> <TheOnlyArtz> I just love the macros here
<FromGitter> <TheOnlyArtz> So powerful
<FromGitter> <TheOnlyArtz> https://github.com/TheOnlyArtz/artzlogger/blob/master/src/functions/methods.js#L21 ⏎ This is something I wrote in JS, comparing that to crystal with no boilerplate code, this is just a dream coming true!
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <TheOnlyArtz> And it's working incredibly good :)
<FromGitter> <Blacksmoke16> nice one
<FromGitter> <TheOnlyArtz> The reason I've wrote a "custom" logger class is because I don't want to have an instance of Logger hopping around in my code, it's just a big mess
<FromGitter> <Blacksmoke16> most people just do like `LOGGER = Logger.new STDOUT, Logger::Debug`
<FromGitter> <Blacksmoke16> then just do `LOGGER.warn xxx`
<FromGitter> <Blacksmoke16> or make it a class property on a like `Config` class
<FromGitter> <Blacksmoke16> then can do `MyApp.settings.logger = xxx`
<FromGitter> <TheOnlyArtz> I thought about it but it's just unnecessary
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <TheOnlyArtz> Btw, is it true that compiling with `--release` will cause better performance?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <TheOnlyArtz> I do see that the file's size gets 20% less in size
<FromGitter> <Blacksmoke16> like prob for sure
<FromGitter> <TheOnlyArtz> 50% in size even
<FromGitter> <TheOnlyArtz> So when I will have a production ready app I will call `--release --no-debug` for max performance
<FromGitter> <TheOnlyArtz> Tbh it's a gameserver
<FromGitter> <TheOnlyArtz> Performance matter
<FromGitter> <Blacksmoke16> well `--no-debug` is arguable. If size of the binary isnt super impt then prob better to include debug info so it would be easier to debug if something happens
<FromGitter> <TheOnlyArtz> debug in what means? like, debug flags are being written in compile time?
<FromGitter> <Blacksmoke16> im not super sure tbh, but id prob be like things that allow backtraces to work, vs getting a bunch of `?`. Someone else can prob fact check me :p
<FromGitter> <TheOnlyArtz> I need some help writing test units
<FromGitter> <TheOnlyArtz> How would I describe something like that ⏎ ⏎ https://github.com/amit-gguurr-gamedev/Server/blob/master/src/server.cr#L17
<FromGitter> <j8r> you can create a server to test it's methods
<FromGitter> <Blacksmoke16> i do like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f8ff9a0790b29c93272f8]
<FromGitter> <Blacksmoke16> then like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f90110aad635019fd3ffe]
<FromGitter> <Blacksmoke16> imo context should be removed
<FromGitter> <Blacksmoke16> literally the same as `describe`
<FromGitter> <j8r> agree 💯 @Blacksmoke16
<FromGitter> <TheOnlyArtz> So like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f91193ebbdc55b332010c]
<FromGitter> <TheOnlyArtz> Like that?
<FromGitter> <j8r> hum, IIRC there `describe` and `context` doesn't report the same text
<FromGitter> <Blacksmoke16> pretty sure they do
<FromGitter> <TheOnlyArtz> "undefined method describe"
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6mbb
<FromGitter> <Blacksmoke16> you spelled the 2nd one wrong
<FromGitter> <j8r> right
<FromGitter> <TheOnlyArtz> Oh
<FromGitter> <TheOnlyArtz> Thanks :)
<FromGitter> <TheOnlyArtz> Why does it start the app
<FromGitter> <TheOnlyArtz> lmao ?
<FromGitter> <Blacksmoke16> are prob requiring some file in spec_helper that is starting the app
<FromGitter> <TheOnlyArtz> Oh yea good one
<FromGitter> <j8r> so I don't see why having both
<FromGitter> <j8r> may be worth having an issue to figure this out
<FromGitter> <Blacksmoke16> i get the idea behind them, but it just adds confusion as im wondering which i should use when it doesnt really matter
<FromGitter> <Blacksmoke16> would be diff if they formatted the failure message differently
<FromGitter> <TheOnlyArtz> For some reason my test fails
<FromGitter> <TheOnlyArtz> I don't know why
<FromGitter> <TheOnlyArtz> It says it's getting `nil`
<FromGitter> <TheOnlyArtz> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f936c7ecbdc29cacfc7d0]
<FromGitter> <Blacksmoke16> well there's your problem
<FromGitter> <TheOnlyArtz> Oh wait...
<FromGitter> <TheOnlyArtz> Logger.debug doesn't return a string
<FromGitter> <TheOnlyArtz> it logs it
<FromGitter> <TheOnlyArtz> How can I write a test for such a thing?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9f93a4759abc043c39e70e]
<FromGitter> <Blacksmoke16> something like that prob would do it
<FromGitter> <Blacksmoke16> using an IO
<FromGitter> <Blacksmoke16> then read off the IO
<FromGitter> <TheOnlyArtz> sweet
<FromGitter> <TheOnlyArtz> My test is hanging for some reason
<FromGitter> <TheOnlyArtz> https://hastebin.com/uhibobixaj.rb
<FromGitter> <TheOnlyArtz> It doesn't stop
<FromGitter> <TheOnlyArtz> and `r.gets` is an empty string for some reason
DmitryBochkarev has joined #crystal-lang
<FromGitter> <Blacksmoke16> :shrug: prob something to do with you using `puts` and class methods
<FromGitter> <Blacksmoke16> since you cant override what IO gets outputted to
<FromGitter> <TheOnlyArtz> What do you want me to use instead of `puts`?
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
<FromGitter> <Blacksmoke16> well im just saying its going to be harder to test, is there a way to create an IO to read from STDOUT to read the output from puts?
<FromGitter> <TheOnlyArtz> Guessing you are not asking me so I will just wait for someone knows the answer to that
DmitryBochkarev has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> yea im not super familiar with IO stuff
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <kingsleyh> If anyone knows about OpenSSL I could use a hand implementing ecies for SushiChain Blockchain - another pair of eyes would be helpful to spot any stupid mistakes also
lucasb has joined #crystal-lang
<FromGitter> <Sija> Anyone here familiar with ndb?
<FromGitter> <j8r> @TheOnlyArtz don't use puts, always have a way to define the IO
<FromGitter> <j8r> for loggers
<FromGitter> <j8r> it can be as simple as having `class_property output : IO = STDOUT, error : IO = STDERR`
<FromGitter> <j8r> then having `output.puts`
<FromGitter> <j8r> then on your tests ⏎ ⏎ ```Log.output = File.open File::DEVNULL, "w" ⏎ Log.error = File.open File::DEVNULL, "w"``` [https://gitter.im/crystal-lang/crystal?at=5c9fad6d3ebbdc55b332c52f]
<FromGitter> <TheOnlyArtz> Alright I will look into it
<FromGitter> <TheOnlyArtz> I have sent a Crystal compiled executable through Discord, then downloaded it on my Linux subsystem on Windows and didn't manage to run it
<FromGitter> <TheOnlyArtz> But then I've `git pull`ed the code I've committed, built the app again and this time it did run
<FromGitter> <TheOnlyArtz> Any reason for that?
<FromGitter> <j8r> it's more this https://en.wikipedia.org/wiki/Static_build
<FromGitter> <j8r> `crystal build --static`. only truly supported on Alpine Linux
<FromGitter> <TheOnlyArtz> Oh gotcha
<FromGitter> <TheOnlyArtz> Btw, does the machine have to have Crystal installed on it?
<FromGitter> <j8r> no
<FromGitter> <TheOnlyArtz> Sweet
<FromGitter> <j8r> everything is bundled inside the binary. It must runs on a compatible architecture and kernel, though
<FromGitter> <TheOnlyArtz> Yea sure
<FromGitter> <TheOnlyArtz> It's debian
<FromGitter> <TheOnlyArtz> Btw, can I run `--release` along with `--static`?
<FromGitter> <elorest> In the case of shared objects and dylib they must exist on the system though.
<FromGitter> <j8r> for instance you probably can't run a Debian 10 binary on Debian 4 - lol
<FromGitter> <j8r> yes you can combine flags
<FromGitter> <elorest> Would be nice if there was a way to compile in libs as well.
<FromGitter> <j8r> https://hub.docker.com/r/jrei/crystal-alpine may help you @TheOnlyArtz
<FromGitter> <TheOnlyArtz> Oh yea it's nice
<FromGitter> <TheOnlyArtz> I've managed to compile it statically and run it
<FromGitter> <TheOnlyArtz> But it's still weird since I don't have to compile it statically to run it
<FromGitter> <TheOnlyArtz> But when I download the one I've put on Discord and try to run it, it doesn't work
<FromGitter> <TheOnlyArtz> It says `./server command not found`
<FromGitter> <TheOnlyArtz> something like that
<mps> TheOnlyArtz: 'chmod u+x server' maybe could help
<FromGitter> <TheOnlyArtz> `libevent`
<FromGitter> <TheOnlyArtz> :)
<mps> and maybe you downloaded on 'noexec' filesystem
<FromGitter> <TheOnlyArtz> I think livevent is missing
<FromGitter> <j8r> then you haven't statically linked your app
<FromGitter> <j8r> that's the whole purpose of `--static`
<FromGitter> <TheOnlyArtz> But when I compile it on the same machine from the code on git without the static flag it works as expected and runs.
<mps> no, command not found means that you are not allowed to execute it
<mps> if 'server' is there, ofc
<FromGitter> <TheOnlyArtz> Won't `static` compiled programs affect performance for the worse?
<FromGitter> <j8r> @TheOnlyArtz because you have the dynamic libraries with the right versions, try `ldd my_crystal_binary`
<mps> not really, just will use more memory
<FromGitter> <TheOnlyArtz> On the one that has been compiled on the other OS or the one from git? @j8r
<FromGitter> <j8r> actually it will be a bit faster, using a bit more memory
<FromGitter> <j8r> usually
<FromGitter> <j8r> @TheOnlyArtz just do, you'll see what libraries are required to run any binary
<FromGitter> <TheOnlyArtz> So libevent is the issue
<mps> if it is fully static it will run on debian without problem, I do this, i.e. build on Alpine and run on debian
<FromGitter> <j8r> 👍 mps
<mps> j8r: :)
<FromGitter> <TheOnlyArtz> Installed libevent successfuly
<FromGitter> <TheOnlyArtz> Let's see if it works
<FromGitter> <TheOnlyArtz> Woah!!!
<FromGitter> <TheOnlyArtz> That's an old version of the project but at least I know it works now
<FromGitter> <TheOnlyArtz> A couple of days ago I ask about Crystal and embedded device, what functionalities Crystal can have on embedded devices?
<FromGitter> <r00ster91> you could host something on a raspberry pi with Crystal
<FromGitter> <TheOnlyArtz> I mean.. Raspberry pi is just another Linux machine in the size of a palm, isn't it?
<FromGitter> <r00ster91> yes
<FromGitter> <parruda> Heys guys, if I wanted to manipulate process capabilities (CAP_EFFECTIVE, CAP_INHERITABLE, etc), how would you recommend me to go about it? I've looked through the docs and couldn’t find anything, so I am guessing I have to import functions from `sys/capability.h`?
<FromGitter> <TheOnlyArtz> Do you have another embedded device for an example (Except of Arduino)
<FromGitter> <TheOnlyArtz> You can always link it if you want @parruda
<FromGitter> <parruda> Not very experienced with C programming here =/ ⏎ can you recommend something I could read? ⏎ ⏎ I’ve used `lib LibC` and `fun` to be able to use `setuid`. But to use something like `cap_set_flag`, it expects some types (like `cap_t`) and I have no idea how to create them [https://gitter.im/crystal-lang/crystal?at=5c9fba7f8148e555b21ef181]
<FromGitter> <parruda> I understand what needs to be done, I just don’t know how to do it.
<FromGitter> <TheOnlyArtz> `typedef struct *cap*struct *cap_t;`
<FromGitter> <TheOnlyArtz> ```struct cap_t ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c9fbb2d016a930a453546ec]
<FromGitter> <TheOnlyArtz> I guess
<FromGitter> <TheOnlyArtz> https://github.com/amit-gguurr-gamedev/Server/blob/master/src/server/c_bindings/bindings.cr ⏎ These are some bindings example evolving custom types if you want
<FromGitter> <parruda> thanks a lot!
<FromGitter> <TheOnlyArtz> No problem :)
<FromGitter> <TheOnlyArtz> I should change my GitHub pfp :facepalm:
<FromGitter> <parruda> @TheOnlyArtz your examples really helped. Now I think I have to improve my C syntax knowledge haha
<FromGitter> <parruda> I was doing well on the simple stuff, then I stumbled upon this https://github.com/mhiramat/libcap/blob/8c67abc3f5cfa8310dae21e5db464fd990cb71a2/libcap/libcap.h#L115
<FromGitter> <parruda> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9fc4aa3ebbdc55b3336515]
<FromGitter> <ryanstout> ok, simple question I'm having trouble finding the answer to. What's the best way to get a slice to a struct? (doing some c bindings)
<FromGitter> <ryanstout> anything better than ```Slice.new(my_struct.to_unsafe, sizeof(my_struct))```
ua has joined #crystal-lang
<FromGitter> <TheOnlyArtz> @parruda I'm super glad to see!
<FromGitter> <parruda> I think I got it working but the process ID doesn’t seem right
<FromGitter> <parruda> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9fcc35a0790b29c9340ded]
<FromGitter> <TheOnlyArtz> It looks like `cap_t` exists just for the sake of being a type, it doesn't hold any values
<FromGitter> <TheOnlyArtz> @ryanstout Can you be a little bit more descriptive than that?
<FromGitter> <TheOnlyArtz> Oh
<FromGitter> <TheOnlyArtz> Sorry Paulo didn't see the source you've put above
<FromGitter> <TheOnlyArtz> A union is a special data type available in C that allows to store different data types in the same memory location.
<FromGitter> <ryanstout> sure, thanks for the help. I'm working with a C library wrapper (libusb) that takes a Slice for a few places where the C function takes a pointer and size. I'm wanting to get a slice to a crystal struct (the struct that the C function takes) I'm assuming the memory layout on crystal structs mirrors what you would get in C.
<FromGitter> <ryanstout> I ended up doing this: ```req_slice = Bytes.new(pointer: pointerof(req).as(Pointer(UInt8)), size: sizeof(PTPOperationRequest))```
<FromGitter> <TheOnlyArtz> Union types in Crystal for example: `Int32 | String`
<FromGitter> <ryanstout> where ```req``` is an instance of my PTPOperationRequest struct
<FromGitter> <TheOnlyArtz> I can't manage to figure this out too, interesting.
<FromGitter> <TheOnlyArtz> I will probably be able to figure this out once I will understand what's that `u` before `[_LINUX_CAPABILITY_U32S_1]`
DTZUZO has joined #crystal-lang
<FromGitter> <r00ster91> it stands for unsigned 32 bit integer
<FromGitter> <TheOnlyArtz> Well.. `_LINUX_CAPABILITY_U32S_1` is `1`
<FromGitter> <TheOnlyArtz> So it's an array with the length of... `1`?
<FromGitter> <ryanstout> ok, looks like Struct's have two extra bytes when doing sizeof(MyStruct)
<FromGitter> <ryanstout> so I'm guessing I can't pass a pointer to a crystal struct directly to C?
<FromGitter> <TheOnlyArtz> Of course you can!
<FromGitter> <TheOnlyArtz> I'm returning Pointers and receiving them on Crystal's end
<FromGitter> <TheOnlyArtz> And doing otherwise look at `bufferToX` functions
<FromGitter> <TheOnlyArtz> @parruda I will ask about your issue in a dedicated place, it's really hard to figure out what's going on in there
<FromGitter> <ryanstout> @TheOnlyArtz thanks, checking it out
<FromGitter> <ryanstout> @TheOnlyArtz is there an example of converting a crystal struct to a pointer or slice and passing that to C? (sorry, maybe I'm missing it) The examples I see are using structs defined on the C side.
<FromGitter> <ryanstout> @TheOnlyArtz also, thanks for the help. Always fun to be a n00b again
<FromGitter> <TheOnlyArtz> Why would you want to parse a struct to any of the things you've pointed out
<FromGitter> <TheOnlyArtz> How about passing the struct directly?
<FromGitter> <TheOnlyArtz> Wouldn't it be easier and way more efficient?
<FromGitter> <ryanstout> the C library wrapper takes a ```buffer : UInt8*, length : Int``` (int is ```LibC::Int```)
<FromGitter> <ryanstout> so I am trying to pass my crystal struct to it, but sizeof(MyStruct) adds 2 bytes
<FromGitter> <TheOnlyArtz> Very nice bindings you have there !
<FromGitter> <ryanstout> @TheOnlyArtz those are someone elses, I'm just trying to use them :-)
<FromGitter> <TheOnlyArtz> oh :)
<FromGitter> <ryanstout> thanks to @alexbatalov for those
<FromGitter> <TheOnlyArtz> What's your struct?
<FromGitter> <TheOnlyArtz> How does it look like
<FromGitter> <TheOnlyArtz> And as what parameter would you like to pass it? `buffer`?
<FromGitter> <ryanstout> ```code paste, see link``` ⏎ ⏎ sizeof(PTPOperationRequest) == 32 [https://gitter.im/crystal-lang/crystal?at=5c9fd4561f6e900d5eaf2920]
<FromGitter> <ryanstout> yea, buffer
<FromGitter> <ryanstout> (talking to a usb camera over PTP)
<FromGitter> <TheOnlyArtz> You can stringify any struct and convert it to a slice of bytes
<FromGitter> <TheOnlyArtz> But I don't think that's what you want?
<FromGitter> <ryanstout> yea, ideally I would just pass a pointer to it without doing a copy
<FromGitter> <TheOnlyArtz> That's what you're looking for?
<FromGitter> <ryanstout> let me see if that works
<FromGitter> <ryanstout> still 32 bytes
<FromGitter> <ryanstout> not sure where the extra 2 are coming from
<FromGitter> <TheOnlyArtz> What's the issue with 32 bytes?
<FromGitter> <ryanstout> it should be 30 bytes right?
<FromGitter> <TheOnlyArtz> You are clearly using `UInt32`
<FromGitter> <TheOnlyArtz> `32` stands for `32` bytes
<FromGitter> <ryanstout> actually, to_s.to_slice is 168 bytes (utf conversion?)
<FromGitter> <TheOnlyArtz> Let's do some math
<FromGitter> <ryanstout> the first one is UInt16, maybe a word alignment issue?
<FromGitter> <ryanstout> 32 is bits right?
<FromGitter> <TheOnlyArtz> Yes
<FromGitter> <TheOnlyArtz> Don't know why I said `bytes`, wasn't sure
<FromGitter> <ryanstout> ok, so 2+4+4+4+4+4+4+4 = 30
<FromGitter> <ryanstout> ```sizeof(PTPOperationRequest) == 32```
<FromGitter> <ryanstout> so crystal is adding 2 bytes
<FromGitter> <TheOnlyArtz> Maybe the struct weighs a bit
<FromGitter> <ryanstout> maybe aligning the first UInt16 to a word boundry
<FromGitter> <ryanstout> yea
<FromGitter> <ryanstout> that too, maybe some internal crystal data?
<FromGitter> <TheOnlyArtz> Idk tbh, I don't really know how much memory Crystal allocates for each type
<FromGitter> <j8r> @TheOnlyArtz what's the purpose of taking a screenshot of carc.in/play.crystal.org? That's the whole purpose of the site 😆
<FromGitter> <TheOnlyArtz> Yea sorry about that :)
<FromGitter> <j8r> sending a link to show the code & result
<FromGitter> <TheOnlyArtz> It looks like a struct takes only 1 byte
<FromGitter> <ryanstout> ok, yea, setting that first UInt16 to UInt32 keeps it at sizeof == 32. So I'm guessing Crystal (or LLVM) is aligning fields to word boundries.
<FromGitter> <ryanstout> @TheOnlyArtz where do you see that?
<FromGitter> <TheOnlyArtz> https://play.crystal-lang.org/#/r/6me8
<FromGitter> <TheOnlyArtz> It's known that structs are light and more memory efficient so it makes sense
<FromGitter> <TheOnlyArtz> But now we got another byte left
<FromGitter> <ryanstout> the 2nd one I don't understand :-)
<FromGitter> <TheOnlyArtz> Well they don't really hold data so I don't think Crystal allocates any memory for them at that point
<FromGitter> <TheOnlyArtz> Just checks for type references on compile time
<FromGitter> <TheOnlyArtz> https://play.crystal-lang.org/#/r/6mer @ryanstout
<FromGitter> <Blacksmoke16> what would you guys rather have, a config file that gets rendered via ECR to set env vars, or be able to set the config file at runtime, which you could just use ENV vars to pass in that path
<FromGitter> <Blacksmoke16> im thinking the latter would be more helpful...and easier for me to test :P
<FromGitter> <TheOnlyArtz> Idk, I tend to avoid runtime stuff since it just calls for error
<FromGitter> <Blacksmoke16> well it would be when you go to start your server, so any errors would be quickly caught and error out
<FromGitter> <TheOnlyArtz> And another question, how do you use the `property` macro without having a constructor in your struct @ryanstout
<FromGitter> <ryanstout> I took out the constructor for clarity
<FromGitter> <TheOnlyArtz> Gotcha
<FromGitter> <ryanstout> sorry for the confusion
<FromGitter> <TheOnlyArtz> Can you send the whole struct in playground link?
<FromGitter> <TheOnlyArtz> https://play.crystal-lang.org/#/cr
<FromGitter> <ryanstout> its all assigned externally right now
<FromGitter> <ryanstout> actually, sorry, I had a session_id initializer in there also
<FromGitter> <vladfaust> What is the most efficient (and maybe hacky) way to turn `MessagePack::Any` to `JSON::Any`? Currently doing `JSON.parse(MessagePack.unpack(payload).to_json)`
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <ryanstout> instance_sizeof is 32 for my struct also :-()
<FromGitter> <TheOnlyArtz> https://play.crystal-lang.org/#/r/6mex
<FromGitter> <TheOnlyArtz> Yea I got this too
<FromGitter> <TheOnlyArtz> Well it's 12:05 AM now and I really want to go to sleep
<FromGitter> <TheOnlyArtz> I sorry I couldn't help you
<FromGitter> <ryanstout> @TheOnlyArtz I appreciate the time, thanks
jokke has quit [Quit: WeeChat 2.4]
DTZUZO has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> so im having some issues with my specs, prob messin something up with fibers
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ca0007c8148e555b220c21f]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ca0008a93fb4a7dc2a964fc]
<FromGitter> <Blacksmoke16> where i have that method that starts a server, runs the specs, then closes for each spec file
<FromGitter> <Blacksmoke16> however 2 specs are failing when running all specs, but pass when i run them on their own
<FromGitter> <Blacksmoke16> which is prob due to some fiber leaking or something?
<FromGitter> <Blacksmoke16> any better ideas on how to set this up?