<_jaitaiwan>
BlaXpirit: Thanks for the pointer with the innheritance issue. Looks like I can't push an un-init class onto the Array
pawnbox has joined #crystal-lang
vrand has joined #crystal-lang
<azrad>
Hi, noob here. I noticed something that seemed odd in crystal, with a program spread across two files (where file 1 requires file 2). It seems that some libraries used by file 2, must be "required" by file 2, and other libraries used by file 2 can be "required" by file 1. example: https://gist.github.com/anonymous/6ee2e8ebb2512adfc3dd14c1abf40edb not sure if this is a bug, or just unexpected behavior, or working as intented. Any
pawnbox has quit [Ping timeout: 276 seconds]
Philpax has quit [Ping timeout: 252 seconds]
<FromGitter>
<drosehn> Hmm. Isn't `test2.cr` compiled when it is included? And I assume that the compiler expects to compile it before proceeding to the next line (the `require "http/client"` in this case). What happens if you put the `require "json"` before the `require "./test2.cr"` ?
<FromGitter>
<drosehn> Note that I have only a little experience with crystal, so I'm just guessing here.
vrand has quit [Remote host closed the connection]
<azrad>
I'll give it a try!
vrand has joined #crystal-lang
<azrad>
ah ha! you are right, if you "require" it in main.cr before the require for test2.cr it works.... thanks
<azrad>
and now it makes sense to me, thanks agin
<FromGitter>
<drosehn> sure. glad that it was a good guess. :)
vrand has quit [Remote host closed the connection]
<wmoxam>
Is there a way to alias a method in a c binding? IE: a function in a c lib is named different in one OS vs another but I want to present an identical interface
<crystal-gh>
[crystal] Sija opened pull request #3194: Use Exception#message getter instead of @ivar to allow overloading (master...patch-1) https://git.io/v6dQ4
<jeromegn>
I’ve attempted giving a minimal example in that gist ^
<jeromegn>
basically, getting a value returns all the right things as I inspect them within the method, but there’s a memory access error between when it returns the value and my example program consuming it (just to print it)
Oliphaunte has joined #crystal-lang
<jeromegn>
I tried a lot of variations, I used the `out` keyword before and it made things worse. With `out`, I was not getting the full node value, it was cut from the beginning. When I stopped using `out`, at least I could inspect the full value
<jeromegn>
in my experience memory problems with bindings is usually a problem with badly defined bindings, that don’t match the C definitions. In this case, they seem to match, no?
<jeromegn>
this may be too long a question for IRC :)
perks has joined #crystal-lang
<BlaXpirit>
jeromegn, wat
<BlaXpirit>
i think you're telling it to write a string but you point it to a single byte
<BlaXpirit>
referring to 'buffer' variable
<jeromegn>
mmm
<BlaXpirit>
so it kinda seems to work right afterwards
<BlaXpirit>
but the stack is totally busted
mkl0502 has left #crystal-lang [#crystal-lang]
<jeromegn>
isn’t that what it wants though? from the function signature: `char *buffer`
<BlaXpirit>
jeromegn, does this thing have any good documentation?
<jeromegn>
it has docs inline
<jeromegn>
I can add them to the gist
<jeromegn>
but no real usage docs
<BlaXpirit>
oh good, it has source cod
<BlaXpirit>
i don't know how you're supposed to choose the buffer size, but this should work:
<BlaXpirit>
oh, that's quite nice. i was going to suggest buffer.to_unsafe.to_slice(buffer_len) works
<jeromegn>
"The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperExecption to be thrown."
Oliphaunte has joined #crystal-lang
<jeromegn>
ah
soveran has quit [Remote host closed the connection]
Oliphaunte has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
<jeromegn>
BlaXpirit: any tip on how I should decide what value to use for that static array? UInt8[1024]. How do I determine what’s a good limit here?
ome has quit [Quit: Connection closed for inactivity]
<FromGitter>
<deepj> Is there any chance to use Crystal on AWS Lambda? Any luck or experiences?
<FromGitter>
<kofno> You can launch native code on lambda w/ a small node js wrapper. After that, it kind of depends on what your native dependencies are.
perks has quit [Quit: perks]
<BlaXpirit>
jeromegn, i have no idea. C is full of such arbitrary limits
<jeromegn>
according to the zookeeper docs, a znode’s data can be up to 1 MB
<jeromegn>
but I don’t know if that matters or even translate to a size of StaticArray
<BlaXpirit>
jeromegn, well translating is easy, it's 1024*1024
<BlaXpirit>
but i dont know
<jeromegn>
that seems huge though :)
<RX14>
allocating a StaticArray of 1024*1024?
Oliphaunte has joined #crystal-lang
<jeromegn>
yea...
soveran has quit [Remote host closed the connection]
<RX14>
why not a Slice?
<RX14>
StaticArray is on the stack
<RX14>
1MB seems a little big for the stack
<jeromegn>
yea
<jeromegn>
hmm
<RX14>
i'm not 100% sure what you're doing
<jeromegn>
using a slice with no specified size seems to work… weird
<BlaXpirit>
"gets the data associated with a node synchronously."
<BlaXpirit>
jeromegn pls
<jeromegn>
hehe, I explained above, but it’s a long explanation
<RX14>
jeromegn, you can't have a slice with no size...
<jeromegn>
BlaXpirit: I went the simplest route for now, I still need to figure out how to do that async
<jeromegn>
uninitialized Slice(UInt8)
<BlaXpirit>
jeromegn, it's a slice of random size in random memory location
<jeromegn>
ah
<BlaXpirit>
not literally random but i think u get the idea
<jeromegn>
ok, I initialized it instead with the limit size
<jeromegn>
yea
<RX14>
you want Slice.new
<RX14>
uninitialized slice will just create a Slice struct without the pointer
<jeromegn>
BlaXpirit: about that sync vs async thing… I’m not sure how to handle it really… fibers? kinda want to return the value from that call as if it was synchronous
<RX14>
well how does the async call work?
<BlaXpirit>
when two worlds with different async paradigms clash, that usually involves a busy loop
<RX14>
you can call that, pause the current fiber, then resume in the callback
<RX14>
like the IO does
<BlaXpirit>
but how can a callback work in one thread? is this explicitly threaded?
<RX14>
actually i really don't know how libevent works
<RX14>
is the libevent loop in a different thread?
<jeromegn>
multi threaded yes
<jeromegn>
^ not an answer to the last question
<jeromegn>
BlaXpirit: zookeeper provides 2 implementations, single and multi threaded. I’m using the multi threaded one
<BlaXpirit>
RX14, who knows. well libevent doesnt need a thread, i can guess that it's an event loop based on context switching, which is done based on 'select'
Oliphaunte has quit [Read error: Connection reset by peer]
<RX14>
oh i see how it works
<RX14>
there's a fiber that ruuns the libevent event loop
<RX14>
and because the callbacks happen on the event loop fiber
<RX14>
the scheduler works properly
<BlaXpirit>
callbacks don't directly execute code, that's the secret
<RX14>
what do you mean?
<BlaXpirit>
a function in a fiber does something, and tells the event loop it's finished, and the event loop resumes a different fiber
<BlaXpirit>
that is nice stuff
<RX14>
yes
<BlaXpirit>
while multithreaded stuff starts a new thread and does the callback in that thread. that is not nice
<RX14>
yes
Oliphaunte has joined #crystal-lang
<RX14>
it would be nicer if the scheduler was threadsafe
<RX14>
then we could have a reschedule_later that could be called from different threads
<RX14>
so you could just tell the scheduler to resume fiber x next at some time in the future
<BlaXpirit>
thread safety is always one lock away xD
<RX14>
well if you want to patch the scheduler...
Oliphaunte has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
xmgx has joined #crystal-lang
Philpax has quit [Read error: Network is unreachable]
Philpax has joined #crystal-lang
mgarciaisaia has joined #crystal-lang
Oliphaunte has joined #crystal-lang
mgarciaisaia1 has joined #crystal-lang
mgarciaisaia has quit [Read error: Connection reset by peer]
azrad has joined #crystal-lang
mgarciaisaia has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
mgarciaisaia1 has quit [Ping timeout: 252 seconds]
mgarciaisaia has left #crystal-lang [#crystal-lang]
<BlaXpirit>
ok, must have been some anomaly, new results do make sense. yeah it's linear scaling, if not sub-linear
matp has joined #crystal-lang
<BlaXpirit>
another fun thing is it acts as a .not_nil!
vikaton has joined #crystal-lang
<BlaXpirit>
I wonder whether it's better to see the outputs like power_assert does it hierarchically, or simply right to left. this way it is indeed easier to see but it can be hard to find the root expression
Oliphaunte has quit [Remote host closed the connection]
Oliphaunte has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
tomchapin has joined #crystal-lang
Oliphaunte has quit [Read error: Connection reset by peer]
matp has quit [Ping timeout: 250 seconds]
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Read error: Connection reset by peer]