charly-lang / charly

🐈 The Charly Programming Language | Written by @KCreate
https://charly-lang.github.io/charly/
MIT License
199 stars 10 forks source link

Charly lang embeded inside Crystal #167

Open faustinoaq opened 7 years ago

faustinoaq commented 7 years ago

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
KCreate commented 7 years ago

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!

faustinoaq commented 6 years ago

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
KCreate commented 6 years ago

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

faustinoaq commented 6 years ago

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