<BlaXpirit>
/usr/bin/ld: warning: libsfml-window.so.2.3, needed by ../../../repos/CSFML/lib/libcsfml-window.so, not found (try using -rpath or -rpath-link)
<BlaXpirit>
now what?
<BlaXpirit>
copied all libs into current folder and LD_LIBRARY_PATH=. crystal build --link-flags "-L." simple.cr
<jhass>
that seems double
<jhass>
mh, try an absolute path for -L
<jhass>
maybe the linker is executed in .crystal/foo/bar/baz/simple.cr
<BlaXpirit>
i even tried LD_LIBRARY_PATH=../../../repos/CSFML/lib:../../../projects/repos/SFML/lib crystal build --link-flags "-L../../../repos/CSFML/lib -L../../../projects/repos/SFML/lib" simple.cr
<BlaXpirit>
but it says /usr/bin/ld: warning: libsfml-window.so.2.3, needed by ../../../repos/CSFML/lib/libcsfml-window.so, not found (try using -rpath or -rpath-link)
<BlaXpirit>
don't know where to put -rpath. and it doesn't work in --link-flags
<BlaXpirit>
but whatever, this is fine. LD_LIBRARY_PATH=lib crystal run --link-flags "-Llib" simple.cr
vegai has left #crystal-lang [#crystal-lang]
JBat has quit [Quit: Computer has gone to sleep.]
<jhass>
mh
<jhass>
I'd still be curios if it works with LD_LIBRARY_PATH="$(realpath ../../../repos/CSFML/lib):$(realpath ../../../repos/SFML/lib)" or --link-flags "-L$(realpath ../../../repos/CSFML/lib) -L$(realpath ../../../repos/SFML/lib)"
<BlaXpirit>
bet not
<BlaXpirit>
hm it works
DerisiveLogic has joined #crystal-lang
<BlaXpirit>
so I have Size_t = ifdef x86_64 UInt64 / UInt32
<BlaXpirit>
how to convert to Size_t?
<BlaXpirit>
should i make another function to convert?
<jhass>
Size_t.cast(x)
<jhass>
btw there's already LibC::SizeT
<BlaXpirit>
riiight
<jhass>
>> LibC::SizeT.cast(123).class
<DeBot>
jhass: Sorry, that took too long.
<jhass>
>> LibC::SizeT.cast(123).class
<DeBot>
jhass: UInt32
<BlaXpirit>
thanks
sardaukar has joined #crystal-lang
<sardaukar>
hello
<sardaukar>
anyone up?
<BlaXpirit>
.
<jhass>
sardaukar: hey
<sardaukar>
hello!
<sardaukar>
I'm trying to do a DSL
<sardaukar>
how can I get a line like this to parse?
<sardaukar>
get "/ab" => "ab#index"
<sardaukar>
I get a token error on =>
<jhass>
yes, you need explicit { } in crystal
<sardaukar>
oh ok
<jhass>
so get "/ab"/, to: "ab#index" might be nicer API :)
<jhass>
er, sans the stray / there
<sardaukar>
yeah, just curious about how it would work
<sardaukar>
I got get({ "products/:id" => "products#show" }) to work
<sardaukar>
doesnt without ()
<jhass>
mh
<jhass>
>> def foo(a); p a; end; foo {"a" => "b"}
<DeBot>
jhass: Syntax error in eval:3: unexpected token: =>
<jhass>
could be considered a bug I'd say
<sfcgeorge>
Ruby has the same behavious
<sfcgeorge>
It is treating the wiggly brackets as a block rather than a last hash parameter
<jhass>
yeah, but it makes the {} optional
<sfcgeorge>
Which is why Crystal's syntax should ideally do what Ruby does and allow the last parameter to be a hash without wiggly brackets
<jhass>
asterite said recently it was a design decision not to, let me find it
<sfcgeorge>
I would definitely be interested to see the reasoning. Cases like this make it seem like optional is nice. I ran across a similar case in my own app.
<sardaukar>
so, to conclude: get "products/:id", { to: "products#show" } is the only way
<sardaukar>
since the hash must be explicit, right?
<jhass>
mh, can't find it
<jhass>
sardaukar: no, you can make to a keyword arg, not a required one yet unfortunately
<sardaukar>
ok
<jhass>
>> def get(matcher, to=nil); p {matcher, to}; end; get "/ab", to: "a#b"
<DeBot>
jhass: Syntax error in eval:3: unexpected token: }
<jhass>
>> def get(matcher, to=nil); p({matcher, to}); end; get "/ab", to: "a#b"
<DeBot>
jhass: {"/ab", "a#b"}
<sardaukar>
so, I don't need to specify types here
<sardaukar>
def get (regex : String, hash : {} of String -> String) ?
<jhass>
that's a syntax error :P
<sardaukar>
yes, trying to understand how hashes can be specified
<jhass>
def get(regex, hash : String => String) would be one
<jhass>
run into all kinds of type interference issues too
<jhass>
*ran
<sardaukar>
I'm building a "Rails-like" router
<sardaukar>
and would like to store which action in a Controller to call
<sardaukar>
how can I do that in Crystal?
<sardaukar>
(other than having the actions being blocks)
<sardaukar>
so, my routes are defined with get "/products/:id", { to: "products#show" } with creates a Route object with GET as @method, the path as @regex, products as @controllers, and show as @action
<sardaukar>
how can I call the method on the controller programmatically?
<sardaukar>
is it even possible?
<jhass>
no it isn't
<jhass>
I threw up a PoC for some other guy doing the same thing as you, but doesn't look like he uploaded anything to github yet, at least I can't find it
<jhass>
let me see if I still have the concept
<sardaukar>
thanks!
<sardaukar>
I guess I could write a macro to just write out every possible route?
<sardaukar>
like a huge switch statement
<jhass>
sort of, but a bit smarter :)
<jhass>
gotta clean up the spammer from my pastebin first though
<jhass>
Request, Hash(String, String) -> String is the type
<sardaukar>
aaaah
<sardaukar>
sorry, getting used to reading it :D
<jhass>
like A => B is syntax sugar for Hash(A, B), A -> B is syntax sugar for Proc(A, B), basically
<jhass>
no worries ;)
<sardaukar>
cool
<sardaukar>
I have a ton more questions, hope I'm not boring you :D
<jhass>
not at all
<sardaukar>
ok, brb for now!
<jhass>
so Request, Hash(String, String) -> String is a Proc with two parameters, a Request and a Hash(String, String) and that returns a String
<jeromegn>
jhass: why would a ECR.process_file return a blank string? I created a file with <p>hello</p>. I’m doing String.build {|__str__| ECR.process_file(file_path) }
<jhass>
jeromegn: String.build ignores the return value of the block iirc, .build do |io| io << ECR... should do
<jeromegn>
that returns __str__ << "hello"
<jhass>
(though I'm not sure why you do the String.build, doesn't process_file return a string?)
<jeromegn>
process_file tries to use a buffer to append to
<jeromegn>
you need to provide it the name of the buffer as a string… by default it’s __str__
<jeromegn>
pretty confusing
<jhass>
oh, I see what it does
<jhass>
(never used ecr yet)
<jeromegn>
:)
<jeromegn>
seems like I might have to run/eval the result...
<jhass>
can't you use the embed_ecr macro?
<jeromegn>
I’m trying to do stuff dynamically a little bit
<jhass>
the idea is that process_file is run at compile time with the run macro and the resulting string is inserted
<jhass>
I think you want a macro def there then
<jhass>
mh, no that won't work either
<jeromegn>
is templating doomed in Crystal?
<jhass>
so basically your issue is that ECR is designed to be called compile time and you want to feed it runtime data
<jeromegn>
indeed
<jeromegn>
I could use run
<jhass>
run is executed compile time, still
<jeromegn>
ah
<jeromegn>
no fun!
<jeromegn>
I wanted to make a macro that defined a new Class view
<jeromegn>
but that’s not allowed anymore
<jeromegn>
macros can’t define classes
<jhass>
I guess an approach to make runtime decision work with ECR is to add stuff to the macro language that allows to do a path glob and build a hash literal using that
<jhass>
of filename => rendered template
<jhass>
mh, no, that still lacks context
<jeromegn>
yea
<jeromegn>
compile to a proc?
<jeromegn>
I might go back to that bson project quickly enough :)
<sardaukar>
jhass: so if double quotes would not work, what would the solution be?
<jhass>
nah, they should work, I was missing something else
<jhass>
waj: mind opping me shortly so I can fix something in the topic?
DerisiveLogic has quit [Ping timeout: 256 seconds]
willlll has joined #crystal-lang
DerisiveLogic has joined #crystal-lang
<fowl>
Iok
<jhass>
?
strcmp1 has quit [Quit: Leaving]
strcmp1 has joined #crystal-lang
<sardaukar>
jhass: finished my route DSL parser, thanks for all the help
<jhass>
yw
<sardaukar>
one issue, though: all of the routes get called once after parsing
<jhass>
well, my code calls them directly, yours should just store the blocks
<sardaukar>
should I make the matcher method store the procs?
<sardaukar>
yes, ok
wanderer_ has joined #crystal-lang
HakanD_ has quit [Quit: Be back later ...]
<sardaukar>
how do I go about that anyway? store the return of yield on #matcher?
<jhass>
no, route
<sardaukar>
oh right
<sardaukar>
and then yield the stored routes with the new requests and params
<jhass>
in the matcher? no, just store
<jhass>
call the stored proc in the request parser
blaix has joined #crystal-lang
strcmp1 has quit [Ping timeout: 255 seconds]
HakanD_ has joined #crystal-lang
<jeromegn>
waj: what did you want to know about the BSON project? :)
<jeromegn>
it’s not shared anywhere yet. I will push soon. I’ve written the tests I wanted to write. I just need to push some Time extensions to Crystal itself and maybe reorganize the code a little bit
ismaelga has quit [Remote host closed the connection]
ismaelga has joined #crystal-lang
vikaton has quit []
ismaelga has quit [Client Quit]
<waj>
jeromegn: you said it works except for an issue
<jeromegn>
I said that often :) the one I was talking about is fixed (one of the bindings didn’t declare the correct type)
<jhass>
for the alignment issue just adding a bunch of padding worked?
<jeromegn>
seems like it
<jeromegn>
it works well now
<jeromegn>
whatever operations I do
<jeromegn>
so I think it’s all good
HakanD__ has joined #crystal-lang
sfcgeorg_ has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
HakanD_ has quit [Ping timeout: 272 seconds]
<crystal-gh>
[crystal] jeromegn opened pull request #642: Implement Time.from_ms and Time#to_ms (master...time-ms) http://git.io/vUIBy
DerisiveLogic has quit [Ping timeout: 264 seconds]
<jeromegn>
I thought it would figure out which type of Int to use
<jeromegn>
that number seems off
<jeromegn>
should look more like 1414703893000
<jhass>
ticks isn't milliseconds
<jhass>
oh, TimeSpan takes ticks, nvm
<jeromegn>
I gave it ticks and I asked for milliseconds
<jeromegn>
:)
strcmp1 has joined #crystal-lang
<jhass>
anyway, as said I don't think it makes sense for Epoch
<jeromegn>
I have no hard CS background, I’m self-taught in all the things :)
<jeromegn>
so these concepts are elusive at the moment
<jeromegn>
need to learn more
<jeromegn>
for now I’ll just extend them in my project.
leafybasil has quit [Ping timeout: 256 seconds]
<jhass>
I'm not sure if my CS studies added that much background to what I had previously :P
<jhass>
the concurrency course was nice
shama has joined #crystal-lang
zz_Cidan is now known as Cidan
<sardaukar>
I can't manage to require my dep code by path
<sardaukar>
is there a trick?
<sardaukar>
it only works with require "../crails/**"
<sardaukar>
(on my project's root folder, the Crails code is in the folder up)
<sardaukar>
my Projectfile has deps do ; path "../crails" ; end
<sardaukar>
and I see a crails file on my project's "libs" folder
<sardaukar>
but I get Error in ./app.cr:1: while requiring "crails": can't find file 'crails' relative to '/Users/bruno/Code/OWN/crails-hello-world' if I just do require "crails"
<sardaukar>
other than that, it seems to be working :D got 200s and 404s working, gonna take the rest of the weekend to polish it up and maybe add a view layer
<jhass>
it should be src/crails/crails.cr
<jhass>
deps will make it libs/crails/crails.cr
<jhass>
and require with expand search for crails.cr and if that's missing crails/crails.cr
<sardaukar>
ah ok
<sardaukar>
lemme try
<jeromegn>
jhass: so whatever I name my repo on github, what’s important is the name of the file?
<jeromegn>
I’m about to push the BSON stuff
<sardaukar>
yes! thanks
<sardaukar>
jhass: couldn't have done this today without your help! thanks a bunch
<sardaukar>
I'll be around
<sardaukar>
c ya
<jhass>
jeromegn: I'm not sure tbh
<jeromegn>
hmm
<jhass>
I know it does something with dropping crystal- from repo names...
<jeromegn>
and the spec library needs a lot more stuff!
<jeromegn>
I don’t know how much is possible without meta programming
<jhass>
I found a concept where let and before each hooks work, but it creates many classes -> slow
<jeromegn>
ah
<jeromegn>
well, can’t be slower than Ruby
<jeromegn>
also, the tests are fast as hell at the moment :)
<jhass>
well, slow to compile that is mainly
<jeromegn>
hmm, how do I pass those sweet options to “crystal spec”? h/crystal/blob/0df531ede12efc4417519f8baf355a9d0e649f03/src/spec/spec.cr#L145-L163
<jeromegn>
Error: '-v' is not a file
<jeromegn>
Error: unknown command: -v
Tetsumi has joined #crystal-lang
DerisiveLogic has quit [Remote host closed the connection]
<jeromegn>
hmm, I need to install libbson on travis