This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Lua-CSharp is a high-performance Lua interpreter implemented in C# for .NET and Unity. It provides a Lua 5.2 interpreter with async/await integration, Source Generator support for easy C#-Lua interop, and Unity support.
# Build entire solution
dotnet build
# Build in Release mode
dotnet build -c Release
# Build specific project
dotnet build src/Lua/Lua.csproj
Write lua to sandbox/ConsoleApp1/test.lua, then:
# Run simple tests
dotnet run --project sandbox/ConsoleApp1/ConsoleApp1.csproj
# For pattern matching testing, you can run specific Lua scripts like:
# echo 'print(string.gsub("hello", "()l", function(pos) return "[" .. pos .. "]" end))' > sandbox/ConsoleApp1/test.lua
# echo 'print(string.gsub("abc", "", "."))' > sandbox/ConsoleApp1/test.lua
# echo 'print(string.gsub("(hello) and (world)", "%b()", function(s) return s:upper() end))' > sandbox/ConsoleApp1/test.lua
# Run all tests
dotnet test
# Run tests with detailed output
dotnet test --logger "console;verbosity=detailed"
# Run specific test project
dotnet test tests/Lua.Tests/Lua.Tests.csproj
# Run performance benchmarks
dotnet run -c Release --project sandbox/Benchmark/Benchmark.csproj
# Create NuGet package
dotnet pack -c Release
Lua Runtime (src/Lua/)
LuaState.cs: Main entry point for Lua executionLuaValue.cs: Represents values in Lua (nil, boolean, number, string, table, function, userdata, thread)Runtime/LuaVirtualMachine.cs: Core VM implementation that executes Lua bytecodeRuntime/OpCode.cs, Runtime/Instruction.cs: VM instruction definitionsCodeAnalysis/: Lexer, parser, and compiler that converts Lua source to bytecodeSource Generator (src/Lua.SourceGenerator/)
[LuaObject] attributeLuaObjectGenerator.csStandard Libraries (src/Lua/Standard/)
OpenLibsExtensions.csAsync/Await Integration
DoStringAsync, DoFileAsync)Value Representation
LuaValue is a discriminated union struct3Memory Management
Pool.cs, PooledArray.cs, PooledList.cs)src/Lua.Unity/).lua filestests/Lua.Tests/tests/Lua.Tests/tests-lua/sandbox/Benchmark/IsOpen property to track stream stateReadNumberAsync() for reading numeric values (supports formats like "6.0", "-3.23", "15e12", hex numbers)ReadLineAsync() to accept a keepEol parameter for controlling line ending behaviorReadStringAsync() to ReadAsync()CloseAsync() method for async stream closingReadNumberAsync() in all implementationskeepEol parameter in ReadLineAsync() for TextLuaStream