charly icon indicating copy to clipboard operation
charly copied to clipboard

Charly lang embeded inside Crystal

Open faustinoaq opened this issue 8 years ago • 4 comments

Hi @KCreate

Would be possible to use Charly inside Crystal?

I mean:

require "charly"

puts Charly.run("2 + 2") # => 4

code = <<-CHARLY
print("hello world")
CHARLY

Charly.run(code) # => hello world

faustinoaq avatar Mar 28 '17 01:03 faustinoaq

Should be possible, but I'm not sure how it should behave. Charly loads a prelude file on startup, so it would need to be run every time to make sure you always run off a blank slate.

Another option would be to instantiate a dedicated Charly object that would handle these things.

What I mean:

require "charly"

vm = Charly.new

vm.run "2 + 2" # => 4

code = <<-CODE
print("hello world")
CODE

vm.run code # => hello world

Something similar to this is also included inside Issue #154.

Thanks for the suggestion!

KCreate avatar Mar 28 '17 16:03 KCreate

Hi, nice shard here: https://github.com/veelenga/lua.cr

It works very similar to you comment sample:

lua = Lua.load
sum = lua.run %q{
  function sum(x, y)
    return x + y
  end

  return sum
}
p sum.as(Lua::Function).call(3.2, 1) # => 4.2
lua.close

faustinoaq avatar Mar 28 '18 01:03 faustinoaq

Hey, that looks really nice, something like that was exactly what I had in mind. I'm currently devoting most of my development to a new c++ virtual machine for the Charly programming language and will mostly likely deprecate the Crystal version once the VM is finished.

If you're interested in that, please take a look at the new project: KCreate/charly-vm

KCreate avatar Apr 02 '18 22:04 KCreate

Oh, @KCreate really nice! Thank you for sharing! :tada:

faustinoaq avatar Apr 02 '18 22:04 faustinoaq