<FromGitter>
<Blacksmoke16> and in your mapping you have it as not null
<FromGitter>
<Blacksmoke16> but is just empty string i imagine...
<FromGitter>
<kandayo> it's a empty string ("")
<FromGitter>
<Blacksmoke16> hm
kandayo has quit [Quit: Lost terminal]
_whitelogger has joined #crystal-lang
<FromGitter>
<kandayo> funny if I set the fields as nilable (guild_id: UInt64?, ... so on)
<FromGitter>
<kandayo> it gives "PG::ResultSet#read returned a Int64. A (UInt64 | Nil) was expected"
<FromGitter>
<kandayo> wew got it
<FromGitter>
<kandayo> pg doesn't support unsigned ints
<FromGitter>
<dscottboggs_gitlab> nifty!
<FromGitter>
<Qard> @bararchy What I'm trying to do is make an API to add functions to a lua stack. The current design requires procs like `->(stack : Lua::Stack) {}` and then you get the arguments by indexing stack like an array `stack[1]`. I tried implementing range indexing so I could just get all the elements and pass them into `proc.call(*args)`, but splat only accepts tuples, so I need to convert it to a tuple somehow, I guess?
<FromGitter>
<dscottboggs_gitlab> why not just pass it as an array?
<FromGitter>
<Qard> I'm trying to have a signature like `->(first : String, second : Int32) {}` when the first and second items in the stack are a string and number.
<FromGitter>
<Qard> I basically already have it as an array with the stack, with some extra benefits. I was just hoping I could make something a little more user-friendly than needing to navigate an array to get their function arguments.
<FromGitter>
<dscottboggs_gitlab> so the thing about the Array type in crystal is that it doesn't have a set length so there isn't (*yet*) a way to splat arrays or do multiple assignment from an array.
<FromGitter>
<dscottboggs_gitlab> you could do proc.call(args[0], args[1]) or restrict args to being a Tuple to make anyone using it use that.
<FromGitter>
<dscottboggs_gitlab> I feel like StaticArray (which has a fixed size) might help you but I don't know from experience, maybe someone else does
<FromGitter>
<Blacksmoke16> got a playground link?
<FromGitter>
<m-o-e> that's crecto
<FromGitter>
<Blacksmoke16> ah, :shrug:
<FromGitter>
<dscottboggs_gitlab> ouch
<FromGitter>
<m-o-e> a bit difficult to extract. but in a nutshell: no matter the column data type (int32 here), from_json interprets numbers as int16
<FromGitter>
<Qard> The problem is I don't want a fully static size. I want to make a generic method of accepting a proc accepting an arbitrary number and type of parameters and matching that to basically an array that *should* contain that same number of arguments of the same types. I would do some type unwrapping to ensure they match, or raise an exception.
<FromGitter>
<m-o-e> looking at the crecto source, i can't find where that even happens, sigh
<FromGitter>
<Blacksmoke16> :/
<FromGitter>
<dscottboggs_gitlab> @Qard what about something like `->(T) forall T`?
<FromGitter>
<dscottboggs_gitlab> good to know, thanks!
<FromGitter>
<m-o-e> phew, just glad it wasn't always broken. ripping crecto out of this project would've been painful
<FromGitter>
<dscottboggs_gitlab> you could always fix crecto ;) that's a big part of why I switched to Crystal, it's approachable the whole way down
<FromGitter>
<m-o-e> no time atm unfortunately. also this json stuff looks really hairy.
DTZUZO has joined #crystal-lang
sp3ncer has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter>
<Qard> Hmm...maybe? I'll have to do some experimenting with `forall T` to see if I can figure out a way to make that work.
sp3ncer has quit [Read error: Connection reset by peer]
rohitpaulk has quit [Ping timeout: 272 seconds]
jemc has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> @j8r I found this digging around in the compiler today, makes our earlier example a bit more generic for variables: https://carc.in/#/r/5mj8
<FromGitter>
<dscottboggs_gitlab> I wonder if there's something similar for methods
jemc has quit [Ping timeout: 268 seconds]
<FromGitter>
<j8r> @dscottboggs_gitlab yes i know this, but i takes all ivars. It's used in JSON::Serializable
<FromGitter>
<j8r> Depends of the use case
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<FromGitter>
<bew> @Qard are you aware of the existing Lua for Crystal binding?
<jokke>
i fixed it by definining multiple methods for the different types
<FromGitter>
<vladfaust> What?
<FromGitter>
<drum445> Where is the best place to store go/crystal release binaries on a server?
<FromGitter>
<drum445> atm they just sit in home/ed/, should they be in /var/www...
<FromGitter>
<vladfaust> IDK, I always use Docker
<FromGitter>
<straight-shoota> @drum445 There is no "best place"
<FromGitter>
<straight-shoota> It depends
<FromGitter>
<straight-shoota> you should put them where it fits for your setup
<FromGitter>
<straight-shoota> for example in project-specific bin directories, or global in /usr/local/bin
<FromGitter>
<j8r> how do I pass temp vars to another macro? I have `%var{somevar}`, and I want that in another macro that `%var{somevar}`has the same reference
<FromGitter>
<greenbigfrog> I guess I didn't ask my question clear enough 😄 ⏎ I want to parse stuff like `10 days` `1 month` etc ⏎ Should I regex it and simply call a Time::Span then, or is there a better way?
<FromGitter>
<j8r> from 10, you want make a 10-days time span?
<FromGitter>
<greenbigfrog> if user gives `10 days` I basically want the result of `10.days`
<jokke>
j8r i think he want's the "days" part to be user inputtable as well
<FromGitter>
<greenbigfrog> yep
<jokke>
you make a case
<jokke>
and yeah, you can parse via regex
<FromGitter>
<j8r> yes, `case/when`
<jokke>
but maybe splitting is easier
<FromGitter>
<j8r> yes, better to avoid regex for this parsing
<jokke>
so something like `input = gets(chomp: true); raise ... if input.nil?; split_input = input.split(/\s+/); raise ... unles input.size == 2; amount, unit = split_input; case unit.downcase; when "days" then amount.to_i.days; ...`
<FromGitter>
<j8r> the `limit` isn't mandatory - more efficient to define it
<FromGitter>
<kinxer> Yeah, then I'm out of my depth to help... Sorry.
<jokke>
thanks though :)
<jokke>
hm seems like i'll have to write my own oauth provider then
akaiiro has quit [Ping timeout: 252 seconds]
<FromGitter>
<kinxer> How does `JSON.mapping` interact with inheritance? Can a mapping safely be added to by a subclass?
<FromGitter>
<j8r> For this you can use `JSON::Serializable`
<FromGitter>
<kinxer> Thank you.
Vexatos has quit [Quit: ZNC Quit]
akaiiro has joined #crystal-lang
jemc has quit [Ping timeout: 252 seconds]
non-aristotelian has joined #crystal-lang
pbodev1 has joined #crystal-lang
<FromGitter>
<omidathari> Hello ⏎ I am hoping to get some help with returning an array from a C library into a Crystal program. ⏎ Is there a way to convert a "C" array to a proper Crystal Array? ⏎ Thanks in advance. ⏎ Example code: ... [https://gitter.im/crystal-lang/crystal?at=5bfc4c81a115c91ef798bdc8]
<FromGitter>
<bew> In crystal do you know the size of the array? Or do you have the read the C array until some value that marks the end?
WA9ACE has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
<FromGitter>
<omidathari> @bew No. The C allocates an unknown size and returns it. I was hoping to not have to return the size of the array from C and instead have Crystal handle determining the size. Is that possible?
<FromGitter>
<bew> Well, possible, yes but how will you determine the size? Is there some kind of null value at the end?
<FromGitter>
<bew> Or 0, or -1 as we're talking about int32w
<FromGitter>
<bew> -w
<FromGitter>
<bew> Also do you need an Array or a Slice is enough in Crystal world? (do you need to later extend it? Or do you simply want to read from it?)
<oprypin>
omidathari, it's really not possible, you have to provide the size as well
<FromGitter>
<omidathari> @bew No there is array end indicator. I simply need to read it in Crystal. I have seen that if a C function returns a char* which is actually an array of (Uint8)s indicating a string, In crystal we can use the returned char pointer to create a proper String with "String.new( Uint8*). I was hoping to do the same sort of a thing with array of other types. Thanks for all your help
<FromGitter>
<omidathari> @bew No there is no array end indicator of any sort.
<FromGitter>
<omidathari> @FromIRC Thanks I'll check it out
<oprypin>
omidathari, here's an example with array end indicator, and don't be confused by `Char` - this is actually UInt32 - though the end result is still a string ....
<FromGitter>
<bew> @omidathari a string in C is terminated by a NUL char (value 0), that's how `String.new(c_string)` does its thing, if you don't have a way to find the end and you don't have the size, there is no hope ^^
<FromGitter>
<omidathari> @bew Thanks very much. So if we are passed the size of the array, what is the syntax to convert the int32* form C to Array(Uint32) in Crystal or do we have to just create and populate ( copy the data passed from C) a new Array in Crystal. Thanks again for all your help
<FromGitter>
<bew> If you have the size, the first example from @oprypin can help you
<FromGitter>
<bew> You create an array of the specified size, then initialize each slot with a value from the C array
<FromGitter>
<bew> This will do a copy of the C array into Crystal world
<FromGitter>
<omidathari> @bew got you. Thanks very much.
rohitpaulk has quit [Ping timeout: 250 seconds]
jemc has joined #crystal-lang
jemc has quit [Quit: WeeChat 2.2]
druonysus has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]