krgamestudios/Toy 封面
好玩项目
compilerembedded-scripting-languageinterpreter

krgamestudios/Toy

The Toy Scripting Language. Mirrored nightly.

263语言:C来源:GitHub收录于 2026年10月27日

站内导读

中文 Toy v2-beta 是用 C 写的可嵌入脚本语言参考实现,以字节码解释执行,作为宿主程序的一部分运行,通过外部脚本暴露程序逻辑。它采用类 C 语法,带中间 AST 与字节码表示、可选强类型、一等函数与闭包,并支持 C 原生绑定和重定向输出与错误信息。适合需要在自有程序中加入可定制脚本层的开发者。

README · 详细文档

来源 · 查看原文

<p align="center"> <image src="toylogo.png" alt="The Toy Logo" /> </p>

Toy v2-beta

The Toy Scripting Language is an imperative, bytecode-interpreted, embeddable scripting language. Rather than functioning independently, it serves as part of another program, the "host". This design allows for straightforward customization by both the host's developers and end users, achieved by exposing program logic through external scripts.

This repository holds the reference implementation for Toy version 2, written in C - open beta is currently underway.

Nifty Features

  • Simple C-like syntax
  • Intermediate AST and bytecode representations
  • Strong, but optional type system
  • First-class functions and closures
  • Extensible with native C-bindings
  • Can re-direct output, error and assertion messages
  • Open-Source under the zlib license

Syntax

fn makeCounter() {
	var counter: Int = 0;

	fn increment() {
		return ++counter;
	}

	return increment;
}

//'tally' holds internal state
var tally = makeCounter();

for (var result = 0; result < 10; result = tally()) {
	print result;
}

Building

This project requires gcc and make by default, but should also work in other environments. Officially supported platforms include linux, windows and macOS, see source/toy_common.h for implementation details.

Run make in the root directory to build the shared library named libToy.so and a useable REPL named repl.out.

Documentation

The contents of docs/ is also available on the official website toylang.com.

License

This source code is covered by the zlib license (see LICENSE for details).

Contributors and Special Thanks

<p align="center"> <image src="noai.png" alt="No AI" width="200px" /> </p>

Contributions via the GitHub mirror are welcome, but absolutely no AI contributions will be accepted.

@Jenny-hso - Syntax highlighting for multiple text editors Suyash Dwivedi - "No AI" logo via wikimedia, CC BY-SA 4.0 @NishiOwO - Unofficial NetBSD support @Gipson62 - v1 docs spell checking @8051Enthusiast - fixAlignment() trick @hiperiondev - v1 Disassembler, v1 porting support and feedback @add00 - v1 Library support @gruelingpine185 - Unofficial v1 MacOS support @solar-mist - v1 Minor bugfixes Various Anons - Feedback @munificent - For writing the book that sparked my interest in langdev

Financial Supporters

You can show your support and be listed here by joining my Patreon, or buying me a coffee at ko-fi.

同类项目 · 好玩项目