Skip to content

Sydney680928/MOGWAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

376 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MOGWAI

MOGWAI - Embeddable Scripting for .NET

GitHub Stars Build License .NET NuGet NuGet Downloads VS Code Extension

Give your .NET app a scripting engine in 4 lines of code. Embeddable, extensible, NativeAOT-friendly — small enough to drop into desktop, mobile, or IoT apps, to script workflows or expose safe, hot-swappable logic to your users.

▶ Try it now — run MOGWAI in your browser — no install, no signup, runs entirely client-side.

If MOGWAI looks useful to you, a ⭐ helps others discover it — thank you!


What is MOGWAI?

MOGWAI is a lightweight scripting engine you embed in your .NET applications — to script complex workflows, expose safe user-customizable logic, or design your own DSL, all without leaving the .NET runtime (NativeAOT included).

Looks familiar? It should.

foo(45 "TOTO" 17)      # classic-style call — reads like foo(45, "TOTO", 17)
foo[x: 10 y: 20]        # named parameters, C#-style
45 "TOTO" 17 foo        # the exact same call, written in MOGWAI's native RPN form

Note the spaces, not commas. MOGWAI parameters are space-separated — foo(45 "TOTO" 17), not foo(45, "TOTO", 17). It reads like a familiar function call, but there's no comma operator in the language.

Under the hood, MOGWAI is a stack-based, concatenative engine — which is what gives it clean, unambiguous semantics with no operator precedence to reason about. But day to day, you can write and read code in the classic-style syntax above; the stack form is always there when you want it (better performance, more composable), never a requirement.

The stack, in 30 seconds

For the curious — here's what's actually happening under the hood.

MOGWAI reads left to right. Values are pushed onto a stack; operators consume values from it and push the result back. There's no operator precedence and no parentheses — the order on the stack is the program.

3            →  [ 3 ]
4            →  [ 3 4 ]
+            →  [ 7 ]
2            →  [ 7 2 ]
*            →  [ 14 ]

The same calculation on a single line — 3 4 + 2 * — also leaves [ 14 ] on the stack. That's the whole idea: small pieces compose, and what you see is exactly what happens.

Not ready for RPN yet? Use calc

New to stack-based thinking? You don't have to convert every formula by hand. The calc primitive accepts a regular infix expression as a string — parentheses, operator precedence and all — converts it to RPN under the hood (Dijkstra's Shunting-yard algorithm), and runs it immediately.

"5 * X + (7 + sin(Y))" calc

Write formulas the way you already know them, and grow into RPN at your own pace.

Key Features

  • Classic-Style Syntax - Write foo(45 "TOTO" 17) or foo[x: 10 y: 20] — reads like C#/Java, no RPN required to get started
  • 354 Built-in Functions - Math, strings, lists, files, HTTP, and more
  • Async/Await Support - Modern asynchronous execution
  • Plugin System - Clean plugin contract via MOGWAI.IPlugin — official plugins in development
  • Battle-Tested - 10+ years of real-world usage
  • Extensible - Easy integration with .NET applications
  • NativeAOT-Ready - Embed in ahead-of-time compiled .NET apps
  • Cross-Platform - Windows, Linux, macOS, Android, iOS
  • VS Code Extension - Syntax highlighting, autocompletion, run & debug directly from VS Code (install)
  • Stack-Based RPN Core - Clean, unambiguous engine underneath, with calc for classic infix math formulas when you want them ("5 * X + 2", via Shunting-yard)

Get Started in Seconds

Download a prebuilt CLI

The quickest way to try MOGWAI — no .NET SDK required. Grab a ready-to-run CLI for your platform from the Releases page. Each release ships self-contained binaries for Windows (x64), Linux (x64 / arm64) and macOS (x64 / arm64): download the archive, extract it, and run the MOGWAI_CLI executable.

First run on Windows or macOS. The binaries are not code-signed, so the system will warn about an “unrecognized” app the first time — this is expected, not a problem with the build:

  • Windows (SmartScreen): click More infoRun anyway, or right-click the downloaded file → PropertiesUnblock before extracting.
  • macOS (Gatekeeper): right-click the binary → Open → confirm, or run xattr -d com.apple.quarantine MOGWAI_CLI in Terminal.

Build MOGWAI CLI from source

Clone the repository and build the CLI for your platform using the .NET SDK:

git clone https://github.com/Sydney680928/mogwai.git
cd mogwai/examples/Console/ConsoleExample/MOGWAI_CLI
dotnet run

Or publish a self-contained binary:

# Windows x64
dotnet publish -c Release -r win-x64 --self-contained

# macOS x64
dotnet publish -c Release -r osx-x64 --self-contained

# macOS arm64
dotnet publish -c Release -r osx-arm64 --self-contained

# Linux x64
dotnet publish -c Release -r linux-x64 --self-contained

# Linux arm64
dotnet publish -c Release -r linux-arm64 --self-contained

VS Code Extension

Write, run, and debug MOGWAI scripts directly from Visual Studio Code with full language support:

  • Syntax highlighting — static keywords + dynamic primitives from the connected runtime
  • Autocompletion — all runtime primitives, color-coded by category
  • Run & Debug — execute scripts and step through code without leaving VS Code
  • Runtime panel — live view of the stack, local and global variables
  • Error navigation — jump directly to the failing instruction

Install MOGWAI Language Support from the VS Code Marketplace

How to connect VS Code to the runtime: see MOGWAI_VSCODE.md for the step-by-step connection guide.


The MOGWAI Ecosystem

MOGWAI Runtime (Open Source)

The core scripting engine, available as a NuGet package. Embed MOGWAI in your .NET applications.

API stability. MOGWAI follows Semantic Versioning. Scripts written today keep working — the language surface (syntax, primitives, MW.x error codes) stays stable within the 8.x line. The C# embedding API is still maturing; occasional breaking changes there are documented in the CHANGELOG.

MOGWAI CLI (Open Source)

Command-line interface for running MOGWAI scripts and interactive REPL sessions.

  • License: Apache 2.0
  • Source: built from the examples/Console example, in this same repository
  • Status: Functional

Build from source — requires the .NET SDK:

git clone https://github.com/Sydney680928/mogwai.git
cd mogwai/examples/Console/ConsoleExample/MOGWAI_CLI
dotnet run

MOGWAI VS Code Extension

Syntax highlighting, autocompletion, runtime execution, step-by-step debugging, and live variable inspection — all directly inside VS Code.

MOGWAI STUDIO

A visual IDE for MOGWAI 8 (debugging, breakpoints, stack inspection, code editing), currently built with WinForms (Windows only). Details will follow on mogwai.eu.com when available.

  • License: Proprietary (freemium)

Built with MOGWAI

Open source projects powered by the MOGWAI scripting engine:

Project Description
GIZMO Build Terminal User Interface (TUI) applications with MOGWAI scripting — cross-platform, self-contained, Apache 2.0

Blog Articles

New to MOGWAI? Start with these three:

All articles on coding4phone.com

Quick Start

Installation

Install the MOGWAI runtime via NuGet:

dotnet add package MOGWAI

Hello World

using MOGWAI.Engine;
using MOGWAI.Interfaces;

var engine = new MogwaiEngine("MyApp");
engine.Delegate = this; // Your class implementing IDelegate

var result = await engine.RunAsync(@"
    ""Hello from MOGWAI!"" ?
    2 3 + ?
", debugMode: false);

MOGWAI

MOGWAI Language Example

# 1 — Print to output with ?
"Hello from MOGWAI!" ?      # → Hello from MOGWAI!
2 3 + ?                     # → 5
# 2 — Store and recall  ( value -> 'name' )
42 -> '$answer'             # the $ prefix marks a global variable
$answer ?                   # → 42
# 3 — Define and use a function
to 'square' with [n: .number] do
{
    n n *
}

square(5) ?                  # → 25   (classic-style call)
5 square ?                  # → 25   (same call, native RPN form)
# 4 — Transform a list
(1 2 3 4 5) foreach 'n' transform { n square } -> '$result'
$result ?                   # → (1 4 9 16 25)
# 5 — Structured data with records  (space-delimited — no commas)
[name: "MOGWAI" version: "8.14.0"] -> 'info'
info ?                      # → [name: "MOGWAI" version: "8.14.0"]
# 6 — Conditionals
if ($answer 40 >) then
{
    "The answer is greater than 40" ?
}

Note on variables: Variables prefixed with $ are global. When the engine is instantiated with keepAlive: true, global variables persist across multiple script executions — making them the natural choice for interactive sessions like the REPL or the Blazor playground. Local variables (without $) are scoped to a single execution and are the recommended approach for one-shot embedding scenarios.

// Global variables persist across executions
var engine = new MogwaiEngine("MyApp", keepAlive: true);

// Global variables are reset on each execution (default)
var engine = new MogwaiEngine("MyApp");

Is MOGWAI a Good Fit for You?

MOGWAI is a focused tool, not a general-purpose language. It shines when:

  • You want 354 built-in functions (math, strings, lists, files, HTTP, and more) without pulling in a heavier language runtime
  • You're embedding a scripting runtime in a .NET application, including NativeAOT builds
  • You need a lightweight, extensible runtime with a clean plugin contract
  • You want to offer safe, hot-swappable scripting to your users — update logic without recompiling or redeploying your app
  • You appreciate the concatenative programming model in the tradition of Forth, Factor, PostScript and HP RPL
  • You want zero operator precedence ambiguity — the stack is the single source of truth

Build from Source

Prerequisites

Clone and Build

# Clone repository
git clone https://github.com/Sydney680928/mogwai.git
cd mogwai

# Restore dependencies
dotnet restore src/MOGWAI/MOGWAI.sln

# Build
dotnet build src/MOGWAI/MOGWAI.sln --configuration Release

# Pack (optional)
dotnet pack src/MOGWAI/MOGWAI.sln --configuration Release

The compiled assembly will be in src/MOGWAI/MOGWAI/bin/Release/net9.0/.

Project Structure

mogwai/
├── .github/
│   └── workflows/                  # GitHub Actions (CI, GitHub Pages deployment)
├── docs/
│   ├── EN/
│   │   ├── use-cases/              # Use case articles
│   │   ├── MOGWAI_EN.md            # Language reference
│   │   ├── MOGWAI_FUNCTIONS_EN.md  # Function reference
│   │   └── MOGWAI_INTEGRATION_GUIDE_EN.md  # Integration guide
│   └── FR/
│       ├── cas d'usage/            # Use case articles in french
│       ├── MOGWAI_FR.md            # Language reference in french
│       ├── MOGWAI_FUNCTIONS_FR.md  # Function reference in french
│       └── MOGWAI_INTEGRATION_GUIDE_FR.md  # Integration guide in french
├── examples/
│   ├── Avalonia/
│   │   └── MogwaiRepl/             # Cross-platform REPL with Avalonia UI
│   ├── Blazor/
│   │   └── MogwaiPlayground/       # Blazor WASM interactive playground
│   ├── Console/
│   │   └── ConsoleExample/
│   │       └── MOGWAI_CLI/         # Command-line interface and REPL
│   ├── MAUI/
│   │   └── MauiExample/            # Cross-platform mobile app
│   ├── Scripts/                    # Standalone .mog example scripts (games, tasks, web)
│   └── WinForms/
│       └── WinFormsExample/        # Turtle graphics demo
├── images/                         # Screenshots and media
├── src/
│   └── MOGWAI/
│       ├── MOGWAI.sln              # Main solution
│       ├── MOGWAI/
│       │   ├── Engine/             # Core runtime engine
│       │   ├── Objects/            # MOGWAI object types
│       │   ├── Primitives/         # Built-in functions (354 primitives)
│       │   ├── Interfaces/         # Public interfaces (IDelegate, IPlugin)
│       │   └── Exceptions/         # Exception types
│       ├── MOGWAI.Tests/           # Unit tests
│       └── MOGWAI_TEST/            # Lightweight CLI runner for in-solution testing
├── LICENSE                         # Apache 2.0 license
├── NOTICE                          # Copyright notice
├── CONTRIBUTING.md                 # Contribution guidelines
└── README.md                       # This file

Documentation

Complete Guides

Examples

Examples are available:

Changelog

See CHANGELOG.md for a detailed history of changes.

Latest Release: v8.14.0


Use Cases

Blazor WASM Applications

MOGWAI

You can test it live on Blazor REPL

Avalonia Cross-Platform REPL

MOGWAI

A full-featured REPL and script editor running natively on Windows, Linux and macOS — with Studio mode for live VS Code debugging.

Avalonia REPL Example →

Embedded Applications

# WinForms turtle graphics — classic-style
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
"Square complete!" ?
# same script, native RPN form
100 turtle.forward
90 turtle.right
100 turtle.forward
"Square complete!" ?

MOGWAI

Industrial IoT Automation

Illustrative example — how MOGWAI orchestrates hardware through plugins:

# Read sensor via BLE (requires MOGWAI_BLE plugin — coming soon) — classic-style calls
ble.connect("AA:BB:CC:DD:EE:FF") -> 'device'
ble.read(device "temperature") -> 'temp'

# Control based on value — comparisons stay in RPN, they read best that way
if (temp 25 >) then
{
    gpio.on("fan")
}

Note: Official MOGWAI plugins (BLE, Serial...) are currently in development and not yet publicly available. Third-party plugins can already be built today by implementing the MOGWAI.IPlugin interface.

MOGWAI

Use Case #1 — Electronic Board Test Bench


Roadmap

Full version history lives in CHANGELOG.md. Highlights of the latest release, v8.14.0:

  • Full HTTP verb coverage (http.head/put/patch/delete) and UDP primitives (udp.send/receive/sendReceive)
  • Hardened HTTP internals (shared HttpClient, consistent error reporting)
  • sum on an empty list () now returns 0 instead of raising an error

Next up: a community plugins marketplace, additional language integrations, and an extended function library.

Older milestones (8.0 → 8.6)

Version 8.0

  • Complete rewrite with namespace organization
  • 240+ primitives
  • Apache 2.0 open source license
  • Published on NuGet
  • .NET 9.0 support
  • Complete documentation

Version 8.1

  • +/- primitive to negate a number
  • New error code: OperationNotSupportedError (MW.7)
  • Convenience typed-object helpers on MOGBaseItems (AddString, AddNumber, AddBoolean, …) and MOGRecord (SetString, SetNumber, SetBoolean, …) — no explicit Engine reference required
  • foreach ... transform — transform items while iterating a list

Version 8.2

  • Classic-style call syntax as alternatives to RPN: foo[x: 50 y: 20] (named parameters) and foo(2 3 4) (parameter list)
  • Parser now reports the source position on error (used by MOGWAI STUDIO)
  • Fixed UI freezes and timer/event issues in the Blazor WebAssembly playground under long-running scripts

Version 8.3

  • Variable references with &varname — mutate variable content in place instead of pushing a copy (+, set, get, butfirst, butlast, last, first, sub, size)
  • Explicit variable access with the @ sigil — significant performance gain on frequent variable access
  • char-> primitive — ASCII code from a single character
  • foreach loop over string characters
  • Performance work: host function detection at parse time, faster dictionary lookups, removed systematic primitive cloning during execution

Version 8.4

  • Plugin contract via MOGWAI.IPlugin interface
  • AOT compatibility (IsAotCompatible)
  • Major performance optimizations (O(1) primitive lookup, LINQ removal in hot paths)
  • bag primitive
  • !A auto-eval sigil
  • --> in-place pipeline operator
  • Binary data primitives (DATA/BIN families)

Version 8.5

  • Enhanced debugging protocol
  • 280+ built-in primitives
  • Additional examples and documentation

Version 8.6

  • OOP support (classes, instances, properties, methods, lifecycle hooks)
  • MOGWAI STUDIO v2 (early private development — rebuilt from scratch for MOGWAI 8)

(8.7 through 8.14 — skill system, OOP introspection, math/string primitive families, calc, HTTP/UDP support — see CHANGELOG.md for full detail.)


Contributing

Contributions are welcome! Bug reports, feature requests, and pull requests all start the same way — see CONTRIBUTING.md for the full guide (issue templates, branch/PR workflow, code style).


Why MOGWAI?

Created in 2015 to simulate Bluetooth Low Energy devices for IoT testing, MOGWAI evolved over 10+ years into a full-featured scripting language now used in industrial automation — see how it drives an electronic board test bench in production (read the story).

If you grew up on an HP 28S or HP 48, the stack engine underneath will feel like home — that's the lineage MOGWAI's RPN core comes from. Everyone else can just use the classic-style syntax shown above and never think about it.


License

  • MOGWAI Runtime & CLI: Apache License 2.0 — see LICENSE and NOTICE
  • MOGWAI STUDIO: Proprietary, freemium (Free + Pro) — not open source; details to follow on mogwai.eu.com

Links & Community


Made with ❤️ by Stéphane Sibué

About

MOGWAI –Embeddable scripting engine for .NET. Embed it in any app, script complex workflows, design your own DSL — classic-style syntax or native RPN, your choice.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages