Show HN: Burrito: An embeddable QuickJS wrapper written in Nim

4 months ago 2

What is Burrito?

Burrito is a comprehensive wrapper around the QuickJS JavaScript engine for Nim. It lets you embed JavaScript execution directly into your Nim applications with minimal overhead.

🎯

The Killer Feature

Drop a complete JavaScript REPL with syntax highlighting, command history, and custom Nim function exposure into your application with just a few lines of code!

Embedded REPL Example

cat > burrito_repl.nim <<EOF import burrito var js = newQuickJS(configWithBothLibs()) proc greet(ctx: ptr JSContext, name: JSValue): JSValue = let nameStr = toNimString(ctx, name) result = nimStringToJS(ctx, "Hello from Nim, " & nameStr & "!") js.registerFunction("greet", greet) let replCode = readFile("quickjs/repl.js") discard js.evalModule(replCode, "<repl>") js.runPendingJobs() js.processStdLoop() js.close() EOF nim r burrito_repl.nim

Basic Usage

cat > burrito_example.nim <<EOF import burrito var js = newQuickJS() echo js.eval("3 + 4") echo js.eval("'Hello ' + 'World!'") proc greet(ctx: ptr JSContext, name: JSValue): JSValue = let nameStr = toNimString(ctx, name) result = nimStringToJS(ctx, "Hello from Nim, " & nameStr & "!") js.registerFunction("greet", greet) echo js.eval("greet('Burrito')") js.close() EOF nim r burrito_example.nim

Installation

git clone https://github.com/tapsterbot/burrito.git cd burrito nimble get_quickjs nimble build_quickjs nimble example

Perfect for:

scripting Nim applications, configuration with JavaScript, plugin systems, dynamic code execution, user-defined functions, testing and mocking, template engines, automation workflows, live code editing, interactive debugging, game scripting, bot programming, creative coding, procrastination tools, ordering lunch, making coffee, finding socks, training cats, flying drones, driving cars, talking to robots, and prototyping and experimentation.

Key Features

🎨

Embeddable REPL

Full-featured JavaScript REPL with syntax highlighting and command history

🔗

Two-way Binding

Seamlessly call Nim from JavaScript and JavaScript from Nim

🚀

Native Performance

Zero-overhead C function bridging for maximum speed

🧠

Smart Types

Automatic type marshaling between Nim and JavaScript

📦

Easy Integration

Simple API that gets you up and running in minutes

📚

Full QuickJS Support

Access to std and os modules for complete functionality

Read Entire Article