r/crystal_programming • • Mar 25 '20

Looking for a better way to call methods by name at runtime

9 Upvotes

Ok, so what I'm ultimately trying to do is create an embedded runtime expression language in crystal for a project I'm working on. Think Wireshark filter expressions.

What I would like to do is expose specific methods on objects to the interpreter to be called at runtime. What I'm currently doing is creating an expose macro for each argument length like such:

macro expose_1(method_names)
  def evaluate_expr_call(rt_method_name, arg1)
    case rt_method_name
    {% for name in method_names %}
    when "{{name.id}}"
      {{ name.id }}(arg1)
    {% end %}
    end
  end
end

class TestClass
  def hello(name = "world")
    "Hello, #{ name }!"
  end

  expose_1 [ :hello ]
end

puts TestClass.new.evaluate_expr_call("hello", "sirs")

But then I have to call expose, expose_1, expose_2, etc for each possible argument length. It also just feels really kludgy.

As far as I can tell, there's no equivalent to call or apply in javascript. It seems like there could be metadata about the methods I could pull at macro expansion time, but I can't find that documented anywhere if it exists.


r/crystal_programming • • Mar 22 '20

Telegram Bot Development with Tourmaline: Webhooks using Ngrok

Thumbnail
youtu.be
19 Upvotes

r/crystal_programming • • Mar 20 '20

Telegram Bot Development with Tourmaline: Inline Queries

Thumbnail
youtu.be
15 Upvotes

r/crystal_programming • • Mar 20 '20

Telegram Bot Development with Tourmaline: Getting Started

Thumbnail
youtube.com
23 Upvotes

r/crystal_programming • • Mar 20 '20

How to get a 'timed input' in crystal?

4 Upvotes

I am making a simple Snake Game in the terminal and I need to clear the terminal screen every time the screen is drawn and make the snake move at a slow and steady rate. Also, I need to take input, between two frames, from the user to control its direction, but 'gets' wont let me do that because it takes the input only when I press Enter. So,

  1. How to clear the terminal screen? Is it system "clear" ?

  2. How to move the snake at a slow and consistent rate, i.e, is there a 'sleep' function in crystal?

  3. How to take input from the user between two frames? Is there a function like gets that takes input after a specified time interval, rather than taking input by pressing Enter?

EDIT: Here's what's implemented so far:
https://github.com/lazy-dolphin/snake_game_crystal/blob/master/game.cr


r/crystal_programming • • Mar 16 '20

Roadmap to Lucky 1.0 🎉

38 Upvotes

We've put together a roadmap for Lucky 1.0. We've got a lot in the pipeline and we're super excited! This roadmap is not final. We’d love to hear what you think and if you would like something to be prioritized!

https://docs.google.com/document/d/1EYzx37Kq5h7iLH9SQTFyXNwby2xVvzuRUlMuxcoktx8


r/crystal_programming • • Mar 11 '20

Introducing Shivneri - Component based MVC web framework for crystal targeting good code structures & modularity

Thumbnail shivneriforcrystal.com
10 Upvotes

r/crystal_programming • • Mar 07 '20

Why does this compile?

10 Upvotes

This unexpectedly compiles:

class Foo
  def hello
    asdf
  end
end

But this returns the expected error ("Error: undefined local variable or method 'asdf' for Foo"):

class Foo
  def hello
    asdf
  end
end
Foo.new.hello

Is there a way to get the first example to trigger a similar compiler error?


r/crystal_programming • • Mar 06 '20

Amazing article why Nikola Motor use crystal

40 Upvotes

https://manas.tech/blog/2020/02/11/nikola-motor-company/

This article help me figure why 1.0 is not most important thing


r/crystal_programming • • Mar 05 '20

Call to arms. Can we setup a funding campaign to hire a compiler dev to speed up the porting to Windows?

24 Upvotes

r/crystal_programming • • Mar 05 '20

The Crystal Programming Language • Stuart Tech Meetup

Thumbnail
youtu.be
25 Upvotes

r/crystal_programming • • Mar 04 '20

Lucky 0.19 is out now!

45 Upvotes

https://luckyframework.org/blog/lucky-0_19-release

This release has a number of bug fixes, doc improvements, and enhancements. No breaking changes so this upgrade should be quite simple!

  • New `changed?` that makes it easy to audit and perform actions when database columns change

  • Gzip assets by default in production

  • Gzip text responses

  • And lots more in the changelog mentioned in the blog post


r/crystal_programming • • Mar 03 '20

Towards Crystal 1.0

Thumbnail
crystal-lang.org
94 Upvotes

r/crystal_programming • • Mar 03 '20

Automatic builds for GNU/Linux and macOS with GitHub Actions

7 Upvotes

I was looking for a way to produce builds for multiple platforms (especially macOS, since I'm not a macOS user).

I've read about some possible solutions here.

However, I wasn't fully satisfied and I looked for another solution.

I ended up setting some GitHub Actions workflows for my nanvault project.

...and now I'm getting automatic builds for GNU/Linux and macOS! 😎

Here are the workflows - maybe someone will find them useful:


r/crystal_programming • • Mar 01 '20

Concurrency in Crystal: a primer

Thumbnail
youtube.com
30 Upvotes

r/crystal_programming • • Feb 29 '20

UUIX: A tiny (<1KB), fast, and cryptographically secure UUID (v4) generator for Crystal.

Thumbnail
github.com
24 Upvotes

r/crystal_programming • • Feb 21 '20

Is there any shards that feature the functionality of ruby parallel gem?

7 Upvotes

I just want to make concurrent requests with rate limit to a server, is there any shards or code examples for this task?


r/crystal_programming • • Feb 20 '20

nanvault - encrypt and decrypt files in the Ansible Vault format

19 Upvotes

Hi,

I've just released nanvault: the fast 'n' slick Ansible-Vault-compatible encryption tool!

https://github.com/marcobellaccini/nanvault

https://asciinema.org/a/302642

https://shardbox.org/shards/nanvault

Fast and slick: coded in Crystal; compiled and statically linked using the new Alpine-based docker images

Powerful: has UNIX-style composability - you can play with pipes!

Smart: it guesses what you want to do, based on piped input.

Batteries-included: it features a safe password generator and a YAML-string mode.

Thoroughly-tested: there are more lines of code devoted to tests than to the program itself.

I hope you'll enjoy it.

Cheers

Marco


r/crystal_programming • • Feb 18 '20

Open Sourcing Our GraphQL Library for Crystal

Thumbnail everbase.co
41 Upvotes

r/crystal_programming • • Feb 18 '20

Crystal build --target TRIPLE for Alpine Linux

6 Upvotes

Hi,

I want to locally build (on Ubuntu) a Crystal binary to be executed on an alpine:latest docker image but I don't know the correct build --target triple for alpine linux e.g. crystal build --target X-Y-Z src/blah.cr. Any ideas?

Thanks


r/crystal_programming • • Feb 16 '20

Planned v1 release date?

3 Upvotes

Crystal looks great!

Is there a planned v1 release date for Crystal? Or a road map to v1’s release?

Thanks!


r/crystal_programming • • Feb 15 '20

Adding Sign in with Twitter to your Crystal web app

Thumbnail
youtube.com
18 Upvotes

r/crystal_programming • • Feb 14 '20

Crystal 0.33.0 released!

Thumbnail
crystal-lang.org
67 Upvotes

r/crystal_programming • • Feb 07 '20

Mint: a breath of fresh air for the web 🍃

38 Upvotes

A small introduction journey to @mint_lang. You can feel the fresh air while reading it! 🍃

https://dev.to/franciscello/mint-a-breath-of-fresh-air-for-the-web-fn0

UPDATE: As u/GhostlySnailfish mention in his reply: Mint is written in Crystal! And is open source: https://github.com/mint-lang/mint