LogicEmu for LiaScript: ASCII Logic Circuits That Actually Run

LogicEmu for LiaScript: ASCII Logic Circuits That Actually Run

Most circuit simulation tools require a graphical schematic editor. LogicEmu takes a different approach: logic circuits are written as ASCII art — and they simulate. The LogicEmu template integrates this engine into LiaScript, letting instructors embed runnable circuits directly in course content as plain text.


Quick Start

<!--
import: https://raw.githubusercontent.com/liaTemplates/logicemu/master/README.md
-->

Macro 1: @LogicEmu.run — Static Simulation (in fence header)

Place @LogicEmu.run in the header of a code block. The ASCII circuit renders in an iframe and runs automatically. The code is not shown to the student — only the simulation.

```   @LogicEmu.run
   s s s s s s s s   (input byte)
   * * * * * * * *
   e e e e e e e e   (XOR with carry)
   * * * * * * * *
   l l l l l l l l   (output byte)
```

Try it live — click the s switches and watch the lamp turn on/off:


Macro 2: @LogicEmu.eval — Editable Circuit (end-of-block)

Attach @LogicEmu.eval at the end of a code block to keep the ASCII source visible and editable. Students can modify the circuit and re-run it.

```
   s***>a****>l
```
@LogicEmu.eval

ASCII Circuit Notation

LogicEmu uses a compact ASCII language for circuits. Each character has a specific meaning:

Components

CharMeaning
sSwitch (input, toggle with click)
lLamp/LED (output)
aAND gate
oOR gate
eXOR gate
ANAND gate
ONOR gate
EXNOR gate
nNOT gate

Wires

CharMeaning
-Horizontal wire
``
>Right-facing connection
^Upward connection
vDownward connection
<Left-facing connection
*Junction / crossing
+Wire cross (no connection)

Example: Switch → AND → Lamp

s****>a***>l
      *
s*****

Two switches feed an AND gate; the output drives a lamp.


Example: Half Adder

s**>a**>l   (sum bit)
s*>e
   *
   *>l       (carry bit)

Example: SR Latch

s*>o*>l
   * *
   * v
   *>o*>l

Try it live — click the switches to Set and Reset the latch; also edit the ASCII circuit and re-run:


Full Template Demo


Use Cases

Computer science fundamentals — Teach combinational logic with tactile, clickable ASCII circuits. No diagram editor, no PNG exports — just code and simulation.

Digital systems textbooks — Embed half-adders, full-adders, multiplexers, and flip-flops directly as running examples, not static images.

Interactive lectures — Use @LogicEmu.eval so students can modify a circuit and observe how the output changes.

Hobbyists and self-learners — Write circuits in the same plain-text style as logicemu.com without leaving LiaScript.


Technical Facts

Runs in browserYes — iframe via base64/LZ77 URL
Server requiredNo
Circuit formatASCII art
InteractiveYes — clickable switches
EditableYes — via @LogicEmu.eval
Based onlogicemu by Lode Vandevenne (lodev.org)
LicenseMIT
MaintainedVersion 0.0.4

Try It

Try in LiaScript Open in LiveEditor View on GitHub
  • DigiSim — JSON/DSL-based digital logic simulation with full DigitalJS backend
  • ExplainGit — animated git repository visualization
  • AVR8js — AVR/Arduino simulation for embedded courses

Related Posts

JSCAD for LiaScript: Parametric 3D CAD Modeling in the Browser

Use the JSCAD template to create and display parametric 3D CAD models in your LiaScript courses — powered by JSCAD.app, with a fullscreen interactive 3D viewer.

Read More

mec2 for LiaScript: 2D Mechanism and Physics Simulation

Simulate 2D mechanical linkages, constraint-based mechanisms, and chaos systems in LiaScript using mec2 — define nodes, constraints, and views in JSON and watch them run.

Read More

BiwaScheme for LiaScript: Functional Programming with Scheme in the Browser

Use the BiwaScheme template to run Scheme programs in your LiaScript courses — a complete Scheme interpreter in the browser, with an optional interactive REPL terminal.

Read More