Questions tagged [crystal-lang]

Crystal is a programming language with a Ruby inspired syntax but statically type checked and compiled to native and efficient code.

Links

Projects

660 questions
0
votes
1 answer

Crystal array of Strings declaration

How do I declare an array of Strings in a getter / method declaration ? Ex ( none of these exemples works ) : class Test getter var1 : String[] getter var2 : String* getter var3 : Array(String) end
0
votes
1 answer

Type Mismatch Crystal when creating an Array of NamedTuples

Seem to be having issues with a type mismatch, but I can't wrap my head around it, need a second pair of eyes, I find the Crystal type mismatch errors to be almost unreadable when dealing with databases. Aliases (accounts.cr) alias CampaignDetail =…
Conner Stephen McCabe
  • 581
  • 4
  • 10
  • 20
0
votes
1 answer

Trying to use Crystal's Bycrypt library - "invalid salt size"

I'm trying to hash + salt user passwords with the Bcrypt library that ships with Crystal. The following code produces an "Invalid salt size" error, when run in a playground. require "crypto/bcrypt" user = "Jones" pass = "password" temp =…
Jones
  • 1,154
  • 1
  • 10
  • 35
0
votes
1 answer

Crystal Unhandled exception in spawn/fork: Cannot allocate memory

I keep running into this crystal compiler bug and I currently see no workaround other than rebooting my box. I filed an issue here. crystal$ crystal build main.cr Unhandled exception in spawn: fork: Cannot allocate memory (Errno) 0x55b5be: ??? at…
Tyler
  • 19,113
  • 19
  • 94
  • 151
0
votes
2 answers

Crystal handle json file of known format but dynamic keys

So I have a JSON file of a somewhat known format { String => JSON::Type, ... }. So it is basically of type Hash(String, JSON::Type). But when I try and read it from file to memory like so: JSON.parse(File.read(@cache_file)).as(Hash(String,…
tpei
  • 671
  • 9
  • 26
0
votes
2 answers

Crystal get raised Exception's class

I was expecting that typeof(...) would give me the exact class, but when rescuing an Exception typeof(MyCustomException) just returns Exception class A < Exception; end class B < A; end begin raise B.new rescue e puts typeof(e) # =>…
tpei
  • 671
  • 9
  • 26
0
votes
0 answers

Crystal App Initialized in $GOPATH Directory

I have both Go and Crystal installed on macOS. GOPATH Directory: export PATH=$PATH:/usr/local/go/bin Crystal Location: /usr/local/bin/crystal When I initialize a crystal app with crystal init app fizzbuzz (example) in the terminal, the fizzbuzz.cr…
Redy
  • 21
  • 2
0
votes
1 answer

How to call functions from a dylib using Crystal?

I wish to call the various functions defined in a Rust dylib using Crystal. I've gone through the manual, but I was not able to understand it. How do I properly include and call this dylib? Am I using the CLI flags wrong? Here's the Crystal…
0
votes
1 answer

Use Bootstrap in kemal app

I'm creating app in crystal-lang with kemal the web framework. How can I use style.css or Bootstrap files in the app template in kemal? myapp.cr location = src/myapp.cr bootstrap located = src/public/css/bootstrap.css layout file =…
user6691484
0
votes
1 answer

Binding C to Crystal: preprocessor directives

I'm working with the crt.cr Crystal shard, which binds ncurses. It's lacking some things I want, like mvhline(). So I'm adding the things I want. One thing I want is is ncurses alternative character sheet, so I can make nice boxes. As far as I can…
Jones
  • 1,154
  • 1
  • 10
  • 35
0
votes
1 answer

can't use instance variables at the top level

I'm trying to get an audio player working with Crystal. The internet indicated that portaudio was the best C library for playing audio, and seeing as there are no native Crystal libraries, it seems like the best option. Someone already put in most…
Jones
  • 1,154
  • 1
  • 10
  • 35
0
votes
1 answer

Runtime error with Crystal - "Error opening file"

So I've got the following code causing issues: if File.file?(indexPath) puts "Have to move index" File.rename(indexPath, "#{indexPath}.old") end File.new(indexPath) File.write(indexPath, "test" )#handler.getDoc) sleep 60.second I would…
Jones
  • 1,154
  • 1
  • 10
  • 35
0
votes
2 answers

How does one serve a file?

I'm trying to learn Crystal. As an exercise, I'm making a simple web application, which needs to serve a file (called index.html). Unfortunately, I can only figure out how to serve the directory the file resides in. This is hat you get if you load…
Jones
  • 1,154
  • 1
  • 10
  • 35
0
votes
1 answer

What is the right way to work with DB and DB connection pool?

In my code I open DB at start of program and pass db variable to other methods. I think it's stupid and not right. But what should I do? Should I open db connection in each method? But this way also doesn't look right... And I have a lot of errors:…
nobilik
  • 736
  • 9
  • 29
0
votes
1 answer

How to save console output to string in crystal?

On ruby I can do require "stringio" def with_captured_stdout begin old_stdout = $stdout $stdout = StringIO.new('','w') yield $stdout.string ensure $stdout = old_stdout end end and later call it like str =…
Ruslan López
  • 4,433
  • 2
  • 26
  • 37