Crystal: Enable `File.join` in Macro

Created on 19 Sep 2018  路  5Comments  路  Source: crystal-lang/crystal

Macro may require to safely join the paths to generate shell commands or others, when the path may be determined by variables. Like this:

macro mark_down(what)
{{ run("cat res/#{what}.md").stringify }} # not cross-platform safe!
# cross-platform safe:
{{ run("cat " + join_path("res", "#{what}.md")).stringify }}
end

puts mark_down book

Most helpful comment

Well, nobody liked my idea of the read_file macro method. If you want it now, go for it :-)

All 5 comments

Just do:

{% if flag?(:windows) %}
...
{% else %}
{% end %}

because I think you will have problems with cat working on Windows to start with...

Once there was #2791, which would solve this issue.

Okay, but the case of executing a program locates in a specific path? In this case, path join may be required.

@asterite that doesn't work when cross-compiling, since the macros are executed on the host triple and the flags are for the target triple.

Well, nobody liked my idea of the read_file macro method. If you want it now, go for it :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhass picture jhass  路  3Comments

lgphp picture lgphp  路  3Comments

costajob picture costajob  路  3Comments

Papierkorb picture Papierkorb  路  3Comments

lbguilherme picture lbguilherme  路  3Comments