Heya.
Ever wanted a JavaScript interpreter in Nim that you can just whimsically add into your Nim program with ease? (I'm guessing you didn't :P)
Bali is a JavaScript engine written from scratch in Nim. It has a fast-ish bytecode VM, a fairly large standard library (BigInt, Set, String, Date, Math, etc.) Bali 0.6.5 is out, and it's relatively quite stable at this point. Here's the repository.
Here's a basic example of using Bali with the easy module. It makes things very simple whilst still letting you use 100% of Bali's flexibility and power:
import pkg/bali/easy, pkg/bali/internal/sugar
proc main() =
var runtime = createRuntimeForSource(
"""
console.log("Hello Bali!")
console.log("This is cool, isn't it? :D")
eat_cake();
eat_cake("this is a test");
"""
)
runtime.defineFn(
"eat_cake",
proc =
echo "The cake is a lie. You gave me " & $runtime.argumentCount & " arguments."
)
runtime.run()
when isMainModule:
main()
For a more comprehensive guide, check out the Bali Manual.
Using Bali, you can implement:
and a lot more :^)
The best part? It's all Nim, so it'll feel much more natural to the point which bindings over something like V8, Duktape, GJS or JavaScriptCore can only dream of.
Happy JavaScript'ing! :D
Wow, that's awesome!
so a java script execution engine in Nim!
I will finally be able to figure out how to extract youtube's audio or video urls ;-)
(they tried to make it quite hard in recent times)