Scripts2026年7月25日·1 分钟阅读

Luau — Fast Embeddable Scripting Language Based on Lua

Luau is a small, fast scripting language derived from Lua 5.1, extended with a gradual type system, type inference, and performance optimizations developed by Roblox.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Luau
直接安装命令
npx -y tokrepo@latest install 533e17d4-8847-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Luau (pronounced "Lu-ow") started as an internal fork of Lua 5.1 at Roblox to support millions of developers building games on the platform. It adds a gradual type system, better performance, and modern language features while maintaining backward compatibility with standard Lua.

What Luau Does

  • Provides a Lua-compatible scripting language with gradual typing
  • Performs type inference to catch errors without requiring annotations
  • Compiles to a custom bytecode with a fast interpreter and JIT compiler
  • Embeds easily into C/C++ host applications via a simple API
  • Supports sandboxing for safe execution of untrusted scripts

Architecture Overview

Luau consists of a compiler that produces bytecode, a bytecode interpreter, and a native code generator for x64 and ARM64. The type checker runs as a separate analysis pass and supports both strict and nonstrict modes. The runtime is designed for low-latency environments, with incremental garbage collection tuned for interactive applications.

Self-Hosting & Configuration

  • Build from source using CMake on Linux, macOS, or Windows
  • Embed by linking the Luau library and initializing a Lua state
  • Use luau_compile() to compile source to bytecode ahead of time
  • Enable the type checker with --!strict or --!nonstrict directives
  • Configure sandboxing by restricting available standard library functions

Key Features

  • Gradual type system with inference eliminates common runtime errors
  • Native code generation (JIT) for x64 and ARM64 platforms
  • Backward compatible with Lua 5.1 syntax and semantics
  • Incremental garbage collector tuned for real-time applications
  • String interpolation, compound assignment, and other syntax improvements over Lua

Comparison with Similar Tools

  • Lua 5.4 — Standard Lua lacks a type system and JIT; Luau adds both while staying compatible
  • LuaJIT — Faster JIT for Lua 5.1 but no type system; Luau trades peak throughput for type safety
  • Teal — Typed Lua that transpiles to Lua; Luau is a native implementation with its own runtime
  • MoonScript — CoffeeScript-like syntax for Lua; Luau extends Lua syntax without changing its feel

FAQ

Q: Is Luau only for Roblox development? A: No. Luau is open source and can be embedded in any C/C++ application. It is used outside Roblox in game engines and other projects.

Q: Can I run existing Lua 5.1 scripts in Luau? A: Most Lua 5.1 code runs without changes. Some differences exist in string patterns and coroutine behavior.

Q: Does Luau support LuaRocks packages? A: Not directly. LuaRocks packages targeting the C Lua API need adaptation for the Luau API differences.

Q: How does the gradual type system work? A: Type annotations are optional. Luau infers types where possible and only reports errors where it can prove a type mismatch. Strict mode requires all types to be resolvable.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产