Skip to content

Sydney680928/MOGWAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

309 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MOGWAI

MOGWAI - An embeddable RPN scripting engine for .NET

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

Embeddable. Extensible. NativeAOT-friendly. A small stack-based RPN runtime you can drop into any .NET app — desktop, mobile, or IoT.

▶ 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). Under the hood it's a stack-based, concatenative language in the tradition of the legendary HP calculators (HP 28S, HP 48) — which gives it clean, unambiguous semantics with no operator precedence to reason about.

The stack, in 30 seconds

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.

Key Features

  • Stack-Based RPN Syntax - Clean, unambiguous, no operator precedence
  • 304 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)

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
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. The scripting language surface — syntax, primitives, and MW.x error codes — aims to remain stable within the 8.x line: scripts written today keep working. The C# embedding API is still maturing and may see occasional breaking changes, always documented in the CHANGELOG (for example, the error-identifier renames in 8.9.1).

MOGWAI CLI (Open Source)

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

  • License: Apache 2.0
  • Repository: MOGWAI CLI
  • Status: Functional

Build from source — requires the .NET SDK:

git clone https://github.com/Sydney680928/mogwai.git
cd mogwai/examples/Console/ConsoleExample
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 (in development)

MOGWAI STUDIO v2 — a cross-platform visual IDE for MOGWAI 8 (debugging, breakpoints, stack inspection, code editing) — is in early private development. More details will follow on mogwai.eu.com.

  • License: Proprietary (freemium)
  • Status: Early private development — not yet publicly available

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 *
}

5 square ?                  # → 25
# 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.9.1"] -> 'info'
info ?                      # → [name: "MOGWAI" version: "8.9.1"]
# 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, useDefaultFolders: false);

// 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 zero operator precedence ambiguity — the stack is the single source of truth
  • You're embedding a scripting runtime in a .NET application, including NativeAOT builds
  • You appreciate the concatenative programming model in the tradition of Forth, Factor, PostScript and HP RPL
  • 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

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
│   └── 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 (304 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
└── README.md                       # This file

Documentation

Complete Guides

Examples

Examples are available:

Changelog

See CHANGELOG.md for a detailed history of changes.

Latest Release: v8.9.1


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
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)
"AA:BB:CC:DD:EE:FF" ble.connect -> 'device'
device "temperature" ble.read -> 'temp'

# Control based on value
if (temp 25 >) then
{
    "fan" gpio.on
}

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

Version 8.0 (Released)

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

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)

Version 8.7

  • Sorted identifiers
  • OOP introspection
  • External processes support

Version 8.8

  • Skill system — scripts can verify at startup that they run in the right host environment (skills, hasSkill, mogwai.assertSkill)
  • IDelegate default implementations — MOGWAI is now embeddable with zero delegate code for simple use cases
  • console.width / console.height primitives
  • post primitive — deferred block execution after pending events and timers
  • path.home / path.setHome primitives and HomeDirectory property on MogwaiEngine
  • mogwai.info now includes a skills: key

Version 8.9.1 (Latest)

  • task.start primitive — launch a parameterless task cleanly, without passing and discarding a dummy value
  • Corrected public error identifiers (host-side naming fixes; scripts are unaffected, they identify errors by MW.x code)
  • Auto-evaluation ! flag now cleared after evaluation of records and lists — avoids needless re-evaluation on every access
  • Corrected English wording in several built-in error messages

Future Plans

  • MOGWAI STUDIO v2 public release
  • Community plugins marketplace
  • Additional language integrations
  • Extended function library

Contributing

Contributions are welcome! Here's how you can help:

Reporting Issues

Found a bug or have a feature request? Please open an issue on GitHub:

  • Bug Reports: Use the bug report template
  • Feature Requests: Describe the use case and expected behavior
  • Questions: Use GitHub Discussions

Contributing Code

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Commit with clear messages (git commit -m 'Add amazing feature')
  5. Push to your fork (git push origin feature/amazing-feature)
  6. Open a Pull Request

Code Style

  • Follow existing code conventions
  • Add XML documentation comments for public APIs
  • Keep functions focused and well-named

Why MOGWAI?

Born from Real Needs

Created in 2015 to simulate Bluetooth Low Energy devices for IoT testing. Over 10 years, MOGWAI evolved into a full-featured scripting language used in industrial automation.

Battle-Tested

HP Calculator Heritage

Inspired by the legendary HP 28S and HP 48 calculators, MOGWAI brings RPN elegance to modern software:

  • Clear semantics - No operator precedence confusion
  • Stack-based - Natural for complex calculations
  • Composable - Build complex operations from simple parts

License

MOGWAI Runtime & CLI

Apache License 2.0

Copyright 2015-2026 Stéphane Sibué

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

See LICENSE and NOTICE for details.

MOGWAI STUDIO

Proprietary License - Freemium model (Free + Pro versions)

MOGWAI STUDIO is not open source and will be distributed under a proprietary license. More details will be announced upon release.


Links


Community & Support

  • GitHub Issues: For bug reports and feature requests
  • GitHub Discussions: For questions and community support
  • Email: Contact via coding4phone.com

Acknowledgments

  • HP Calculators - For inspiring the RPN approach
  • Open Source Community - For .NET and supporting tools
  • Early Adopters - For feedback and real-world testing

Have Questions or Feedback?

We'd love to hear from you!

  • Found a bug? Open an issue
  • Have an idea? Start a discussion
  • Like MOGWAI? Star the repo to show your support!
  • Using MOGWAI in production? We'd love to hear your story!

Even a simple "I tried it and it works!" is valuable feedback!


Made with ❤️ by Stéphane Sibué

MOGWAI - Where stack-based elegance meets modern .NET power