# ruin
**Repository Path**: naichabaobao/ruin
## Basic Information
- **Project Name**: ruin
- **Description**: ruin 语言
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-10-08
- **Last Updated**: 2025-10-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 🚀 Ruin 语言
[](https://github.com/naichabaobao/ruin)
[](LICENSE)
[](https://github.com/naichabaobao/ruin)
**现代、强类型、支持 GPU/CV/AI 的脚本语言**
[快速开始](#-快速开始) • [文档](docs/html/index.html) • [示例代码](#-示例代码) • [特性](#-核心特性)
---
## 📖 简介
**Ruin** 是一个专为自动化、游戏开发和AI应用设计的现代脚本语言。提供强类型系统、完整的输入控制、计算机视觉、GPU加速和AI集成能力。
### 为什么选择 Ruin?
- 🎯 **强类型系统** - 11种类型,泛型支持,编译时类型检查
- ⌨️ **全局输入控制** - 实时轮询 + 模拟输入,支持自动化操作
- 🔍 **计算机视觉** - 集成 OpenCV,100+ CV函数(图像处理、DNN、人脸检测)
- 🤖 **AI 集成** - Llama.cpp 支持,本地 LLM 推理
- 🎮 **游戏开发** - GUI系统、输入系统、Canvas绘图
- 🚀 **GPU 加速** - 34个 GPU 函数,支持矩阵运算
- ⚡ **异步编程** - ruin function 关键字,await 语法,future 类型
- 🌐 **网络功能** - HTTP/HTTPS 客户端,JSON 支持
- 📸 **屏幕捕获** - 跨平台截图(DXGI/X11)
- 📦 **28个内置模块** - 开箱即用的标准库
---
## ✨ 核心特性
### 🎯 强类型系统
```ruin
// 必须显式声明类型
let number age = 25;
let string name = "Alice";
let boolean isActive = true;
let array scores = [90, 85, 88];
let map ages = {"Alice": 25, "Bob": 30};
```
### ⌨️ 全局输入控制
```ruin
import input from "input";
// 实时查询键盘鼠标状态(不需要事件监听)
if (input.isKeyDown("A")) {
console.log("A 键被按下");
}
let object mousePos = input.getMousePos();
console.log("鼠标位置: ", mousePos.x.toString(), ", ", mousePos.y.toString());
// 模拟键盘鼠标输入(自动化操作)
input.moveMouse(500, 300); // 移动鼠标
input.mouseClick(); // 左键单击
input.typeText("Hello World!"); // 输入文本(支持中文)
input.pressKey(input.KEY_ENTER); // 按回车
// 反作弊随机延迟(避免被检测为脚本)
input.setDelayRange(50, 150); // 设置随机延迟范围
input.pressKey("E"); // 使用随机延迟
// 组合键
input.pressKeyCombination(input.KEY_CTRL, 65); // Ctrl+A
```
### 🎨 GUI 系统
```ruin
import gui from "gui";
import director from "director";
// 创建窗口
let window win = gui.createWindow({
width: 800,
height: 600,
title: "我的应用"
});
// 创建组件
let label title = gui.createLabel("欢迎使用 Ruin", {
fontSize: 32
});
let button btn = gui.createButton("点击我", {
width: 150,
height: 50
});
// 添加事件
btn.on("click", () => {
console.log("按钮被点击!");
});
// 添加到场景
director.getScene().canvas.addChild(title);
director.getScene().canvas.addChild(btn);
win.show();
```
### 🤖 AI 大语言模型集成
```ruin
import llama from "llama";
import console from "console";
// 加载模型
let object model = llama.loadModel("models/TinyLlama-1.1B-Chat-v1.0.Q8_0.gguf", {
nGpuLayers: 0 // 0=CPU, 33=GPU
});
let object ctx = llama.createContext(model, {
nCtx: 2048
});
let object sampler = llama.createSampler({
temperature: 0.7,
topK: 40,
topP: 0.9
});
// 启动聊天会话
llama.startChatSession(model, ctx, {
templateType: 4,
systemPrompt: "You are a helpful AI assistant.",
maxHistoryMessages: 10
});
// 多轮对话
console.log("User: Hello! What can you help me with?");
let string reply1 = llama.chatWithHistory(model, ctx, sampler, "Hello! What can you help me with?", {
maxTokens: 80
});
console.log("AI: " + reply1);
console.log("User: Tell me about programming");
let string reply2 = llama.chatWithHistory(model, ctx, sampler, "Tell me about programming", {
maxTokens: 100
});
console.log("AI: " + reply2);
// 查看历史
let object history = llama.getChatHistory(model);
console.log("Total messages: " + history.count().toString());
// 清理资源
llama.freeSampler(sampler);
llama.freeContext(ctx);
llama.freeModel(model);
```
完整示例见: [docs/examples/llama/chat-system-direct-api.ruin](docs/examples/llama/chat-system-direct-api.ruin)
### 🚀 GPU 加速
```ruin
import gpu from "gpu";
// 检查 GPU 是否可用
if (gpu.isAvailable()) {
// 矩阵乘法
let array matrixA = [1.0, 2.0, 3.0, 4.0];
let array matrixB = [5.0, 6.0, 7.0, 8.0];
let array result = gpu.matrixMultiply(matrixA, matrixB, 2, 2, 2);
// 向量运算
let array vec1 = [1.0, 2.0, 3.0];
let array vec2 = [4.0, 5.0, 6.0];
let array sum = gpu.vectorAdd(vec1, vec2);
}
```
### ⚡ 异步编程
```ruin
import http from "http";
import json from "json";
ruin function fetchUserData = (string userId) => future