asterite changed the topic of #crystal-lang to: #crystal-lang The Crystal programming language | http://crystal-lang.org | Crystal 0.6.1 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ - API: http://crystal-lang.org/api/ - Logs: http://irclog.whitequark.org/crystal-lang
riceandbeans has quit [Ping timeout: 252 seconds]
riceandbeans has joined #crystal-lang
riceandbeans has joined #crystal-lang
Ven has joined #crystal-lang
Ven has quit [Ping timeout: 250 seconds]
Ven has joined #crystal-lang
Ven has quit [Ping timeout: 272 seconds]
Ven has joined #crystal-lang
ddv has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
leafybasil has quit [Remote host closed the connection]
havenwood has quit [Remote host closed the connection]
ponga has joined #crystal-lang
ponga has quit [Client Quit]
ponga has joined #crystal-lang
panga has joined #crystal-lang
ponga has quit [Client Quit]
leafybasil has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
shadeslayer has quit [Ping timeout: 250 seconds]
shadeslayer has joined #crystal-lang
panga is now known as ponga
asterite has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
wanderer has joined #crystal-lang
<wanderer> hi
<wanderer> asterite: hey, when I define functions with `def` or `fun` are they actually objects, too? also how can I take their address?
<asterite> They are not objects, but you can do this
<asterite> >> def foo; 1; end; proc = ->foo; proc.call
<DeBot> asterite: 1
<asterite> Or:
<asterite> >> def foo(x); x + 1; end; proc = ->foo(Int32); proc.call 41
<DeBot> asterite: 42
<wanderer> ah. what about getting a `fun`s address instead of calling it?
<asterite> >> fun foo : Int32; 1; end; proc = ->foo; proc.pointer.address
<DeBot> asterite: 134519040
<wanderer> so it's possible with a `proc`-workaround?
<wanderer> I tried using `pointerof` which doesn't seem to work
<asterite> Possible what?
<asterite> Oh, you mean you tried pointerof(foo)?
<wanderer> I tried e.g. `pointerof(LibC.memset)`
<asterite> Oooh... I see what you mean. Now, that's not possible, but I think you should be able to do ->LibC.memset without specifying the types, because it's a C function... but right now you have to specify the types :(
<asterite> I'll add this to my todo list and later implement it :)
kostya has joined #crystal-lang
<asterite> But pointerof will never be used for that, because in the general case you need to specify the types of the arguments
<asterite> kostya: thanks again for those benchmarks! :-)
waj has joined #crystal-lang
<asterite> It seems we are on the front page of reddit/programming: http://www.reddit.com/r/programming :)
havenwood has joined #crystal-lang
<jhass> \o/
<asterite> I looked at google analytics because it was weird that suddenly people are commenting on the website :-P
<asterite> If you want to upvote, go ahead :)
<jhass> I don't even have a reddit account :P
<wanderer> me neither
<wanderer> ehm, how does pointerof actually work and when does it have to be used?
<asterite> Short answer: neve
<asterite> Longer answer: never, ever
<asterite> (kind of what Matz said about macros for Ruby :-P)
<asterite> Mmm... you use pointerof if you are doing low-level stuff, like dealing with pointers, or trying not to allocate unnecessary memory
<wanderer> so what exactly does it return?
<jhass> a Pointer :P
<wanderer> a = 0; pointerof(a); inside a function would return like `ESP + xx`, the address of the variable in the stack?
<wanderer> `esp - xx`, + would be the function's args
<asterite> Just some days ago I wrote a bit about it in Pointer's doc: https://github.com/manastech/crystal/blob/master/src/pointer.cr#L12
<wanderer> so does it only work for variables?
<asterite> Variables and instance variabels... for now
<asterite> I think it should also work for global variables, not sure that it does though
<wanderer> libgc exports GC_set_warn_proc and GC_ignore_warn_proc, and I'm trying to do `LibGC.set_warn_proc(pointerof(LibGC.ignore_warn_proc))`
<asterite> I think you need to do: LibGC.set_warn_proc(LibGC.ignore_warn_proc)
<asterite> Of course you need to define funs for set_warn_proc and ignore_warn_proc...
<wanderer> wouldn't just `LibGC.ignore_warn_proc` call the function?
<asterite> According to the GC docs, it returns a function
<asterite> So it's a function that returns a function :)
<wanderer> it's the function itself, it doesn't return one
ponga has quit [Quit: Leaving...]
kostya has quit [Quit: Leaving]
wanderer is now known as Guest69717
Guest69717 has quit [Killed (hitchcock.freenode.net (Nickname regained by services))]
wanderer has joined #crystal-lang
wanderer is now known as Guest45086
<Guest45086> `fun ignore_warn_proc = GC_ignore_warn_proc` is the function I want to pass to `GC_set_warn_proc`, so I need to get its address
<asterite> You don't need its address, if you set the return type of `fun ignore_warn_proc` to a function, you can use that
<asterite> Wait, I'll show you
<asterite> Ah, mmm.. I don't understand what this means: GC_API void GC_CALLBACK GC_ignore_warn_proc(char *, GC_word);
<asterite> Is it a function pointer, or a function?
<asterite> C is cryptic
<Guest45086> ignore_warn_proc doesn't return a function
shadeslayer has quit [Ping timeout: 252 seconds]
<Guest45086> GC_API is a define for extern and GC_CALLBACK doesn't do anything
<Guest45086> GC_ignore_warn_proc returns void
<Guest45086> I want to declare it as a `fun` so that it gets imported, but it shouldn't be called, I just want its address
<Guest45086> or like: `$ignore_warn_proc = GC_ignore_warn_proc : Void*; LibGC.set_warn_proc(pointerof(LibGC.ignore_warn_proc))`
<asterite> Try this: ->LibGC.ignore_warn_proc(UInt8*, UInt64)
shadeslayer has joined #crystal-lang
<asterite> or whatever the types of that function are... if you need the pointer, add ".pointer" to that
havenwood has quit []
<Guest45086> do the types matter? I just need the function's address so I should be able to handle it as a function returning void, no?
<Guest45086> `fun ignore_warn_proc = GC_ignore_warn_proc; proc = ->LibGC.ignore_warn_proc` crashes LLVM
<asterite> In this case the types don't matter, because there can be only one C function named like that. But the compiler doesn't know that yet... so for now you'll have to specify the types
<Guest45086> >> lib LibGC; fun ignore_warn_proc = GC_ignore_warn_proc; end; proc = ->LibGC.ignore_warn_proc; proc.pointer
<DeBot> Guest45086: Pointer(Void)@B7647F40
<Guest45086> hm, I get `llvm-3.5.1.src/lib/IR/Constants. , Line 1497 Expression: CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"`
<asterite> It's true, it's a bug
<asterite> If I compile that program with VERIFY=1 in the env var, it crashes
<asterite> I'll add it as a bug
<asterite> Maybe you can't get a pointer to a lib fun... I'm not sure
<Guest45086> doesn't it just work with >> , though?
<jhass> haha, you gotta love reddit
<jhass> already in a meta fight
<asterite> The thing about Vala? :)
leafybas_ has joined #crystal-lang
<asterite> Guest45086: https://github.com/manastech/crystal/issues/504 , I'll fix it soon
leafybas_ has quit [Remote host closed the connection]
<Guest45086> asterite: ok, but isn't `<DeBot> Guest45086: Pointer(Void)@B7647F40` correct?
<asterite> I think so, yes... it's strange that it's not working for you
leafybasil has quit [Ping timeout: 272 seconds]
<Guest45086> asterite: is it maybe because I'm using LLVM 3.5.1?
<Guest45086> like when trying LLVM 3.6.0 I had struct padding issues with `--release`
<asterite> Maybe, I'm using llvm 3.5.0
<Guest45086> I'll compile 3.5.0 later and test that
asterite has quit [Ping timeout: 246 seconds]
Guest45086 has quit [Quit: Page closed]
bcardiff has joined #crystal-lang
leafybasil has joined #crystal-lang
havenwood has joined #crystal-lang
a5i has joined #crystal-lang
<a5i> Hi :D
<jhass> hey
<a5i> jhass :O
<a5i> Anyhow, What's the deal with Crystal and ruby gems? are they compatible? if not, whats the outlook for crystal 3rd party libs
<jhass> no they're not compatible, Crystal has Ruby inspired syntax but is a new language
<jhass> The package/library manager is still rather basic, it works by cloning repos at github and putting them into the right place
<a5i> Kinda like Rust
<jhass> you can find a list of crystal based projects at http://crystalshards.herokuapp.com/
<a5i> Thanks
leafybasil has quit [Remote host closed the connection]
waj1 has joined #crystal-lang
waj has quit [Ping timeout: 256 seconds]
<a5i> jhass, so how can I use your bot framework? as In a sample irc bot script
<jhass> Mmh, it's not really structured in a way yet that you easily can
<jhass> you can clone the repo and copy the bot directory
<jhass> and then remove the plugins
<jhass> and write a new one ;)
<a5i> hmm
<jhass> the basic structure is so I can extract it into separate repos later easily, but it's just not complete or definitive enough yet to do so :)
<a5i> btw, is Windows support coming soon?
<jhass> maybe, somebody is working on it
<a5i> Thats good, anyway so I cloned your repo
<jhass> there's an experimental branch https://github.com/manastech/crystal/tree/windows
<a5i> and Im about to del the src folder of bot
<a5i> and now which file should I be running ?
<jhass> well, you deleted the bot, so you need to write a new one first
<a5i> o
<a5i> Well there's where Im at
<a5i> I'm dumb -.-
<a5i> Cannot find "framework/bot"
<jhass> to run it you need to be in the bot directory
<jhass> and no, you aren't
<jhass> you're about the third person to run this thing :P
<jhass> I had to push a simple fix, please pull
<jhass> I also pushed a more self-contained example: https://github.com/jhass/DeBot/blob/master/bot/src/simple.cr
wanderer has joined #crystal-lang
wanderer is now known as Guest74837
<a5i> jhass, so I should add that file to the bot dir? (simple.cr)
leafybasil has joined #crystal-lang
<jhass> for example
<jhass> where it resides is actually not so important, that your working directory is the right one is ;P
<a5i> sigh
<a5i> jhass ^
<jhass> did you pull? :)
bcardiff has quit [Quit: Leaving.]
<a5i> Thanks, now it worked :P
<jhass> \o/
<jhass> note that this is literally just what I needed to support DeBot, nothing extra ;)
<jhass> but you can make feature requests or even pull requests of course!
<a5i> Okay
bcardiff has joined #crystal-lang
waj1 has quit [Quit: Leaving.]
bcardiff has quit [Quit: Leaving.]
havenwood has quit [Remote host closed the connection]
Guest74837 has quit [Quit: Page closed]
sadin has joined #crystal-lang
shama has joined #crystal-lang
<a5i> jhass, you available?
<jhass> yup
<a5i> I'm trying to figure out how to use this: https://github.com/sferik/twitter-crystal
<a5i> jhass, any idea how to?
<jhass> a5i: create a Projectfile with: deps do; github "sferik/twitter-crystal"; end; then run crystal deps
<a5i> Everyone's been talking about Crystal ever since I posted that reddit thread today :o
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
havenwood has joined #crystal-lang
<a5i> jhass ^
<a5i> Hey havenwood
<jhass> a5i: oh, sounds like ancient git version
<jhass> it has that since 1.9 I think?
<a5i> Ima try to update my git then
<jhass> 1.8.5 even
<havenwood> a5i: hey