Module: Musa::REPL

Included in:
All
Defined in:
lib/musa-dsl/repl/repl.rb

Overview

REPL (Read-Eval-Print Loop) infrastructure for live coding.

The REPL module provides a TCP-based server that enables live coding by accepting Ruby code over the network, executing it in the DSL context, and returning results or errors to the client.

Architecture

The REPL acts as a bridge between code editors (via MusaLCE clients) and the running Musa DSL environment:

Editor 

Protocol Details

The REPL uses a line-based protocol over TCP:

Client to Server

  • #path: Start path block (optional)
  • file path: Path to the user's file being edited
  • #begin: Start code block
  • code lines: Ruby code to execute (literal #begin/#end must be escaped as ##begin/##end)
  • #end: Execute accumulated code block

Server to Client

  • //echo: Start echo block (code about to be executed)
  • //error: Start error block
  • //backtrace: Start backtrace section within error block
  • //end: End current block
  • regular lines: Output from code execution (puts, etc.)
  • //*text*: Escaped lines starting with // (clients remove one //)

Example Session

Client 

Integration with MusaLCE

The REPL is designed to work seamlessly with MusaLCE (Musa Live Coding Environment) clients for various editors:

  • MusaLCEClientForVSCode: Visual Studio Code extension
  • MusaLCEClientForAtom: Atom editor plugin
  • musalce-server: Server integrating with DAWs (Bitwig, Ableton Live)

File Path Injection

When a client sends a file path via the #path command, the REPL injects it as @user_pathname (Pathname object) into the execution context. This allows the DSL to implement relative require_relative calls based on the editor's current file location.

Use Cases

  • Live coding performances with real-time code evaluation
  • Interactive composition development with DAW synchronization
  • Remote control of running compositions
  • Educational demonstrations and workshops

Defined Under Namespace

Modules: CustomizableDSLContext Classes: REPL