CSLua 0.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSLua --version 0.0.3
                    
NuGet\Install-Package CSLua -Version 0.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CSLua" Version="0.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSLua" Version="0.0.3" />
                    
Directory.Packages.props
<PackageReference Include="CSLua" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSLua --version 0.0.3
                    
#r "nuget: CSLua, 0.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CSLua@0.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSLua&version=0.0.3
                    
Install as a Cake Addin
#tool nuget:?package=CSLua&version=0.0.3
                    
Install as a Cake Tool

Lua 5.2 implemented in pure C#. Hard forked from UniLua. For more examples, see the Test folder.

public void Test()
{
    var L = Lua.New();
    L.OpenLibs(); // or L.OpenSafeLibs();
    L.SetGlobal("AddFromCS", AddFromCs);
    
    L.DoString(
        """
        local a, b = 1, 2
        return AddFromCS(a, b);
        """);

    var r = L.PopInteger();
    Assert.Equal(3, r);
}

private static int AddFromCs(LuaState L)
{
    var a = L.ToInteger(1);
    var b = L.ToInteger(2);
    L.PushInteger(a + b);
    return 1;
}

CSLua is fork of UniLua. I needed a Lua interpreter compatible with AoT C# and as efficient as possible. Unfortunately most libraries don't make the cut due to being focused on unity or allocating too much garbage. This project is a big refactoring of the original code. @Xebecnan's UniLua targets version 5.2 but it also includes some 5.3 features such as utf8 support and integers.

In specific, the differences between my fork and the original are:

  • Code refactoring: Remove references to unity, create new folders.
  • Performance improvements: Converted code to use structs and spans where it makes sense. For example, StkId is no longer a class but a ref to TValue.
  • Added Tests: Including some of the basic Lua 5.2 test suite.
  • Implement some functions of the standard library that were missing: This is still incomplete.
  • Added some power patches: Compound assignments (+=, -=, ..= and friends), continue, != alias for ~=, digit separators (1_000), implicit pairs (for i, v in {1, 2, 3} do ...).
  • First class citizen support for lists:
local list = require 'list'
local list1 = list.new(1, 2, 3)
list1[0] = 2
assert(list1[0] == 2)
assert(#list1 == 3)
list.add(list1, 4)
assert(#list1 == 4)
  • bool concatenation:
local concat = 'foo' .. true -- footrue
  • string concatenation with the + operator:
local concat = 'foo' + true -- footrue
  • C-style comments:
local foo=1 // Call the police
local bar=2 /* Now */

While this library is functional, expect some bugs. Some of lua's tests were disabled due to differences in the implementation or incomplete standard library. You can find them by grepping CSLUA_FAIL in the test/suite folder. Don't expect a stable API.

Contributions are welcome.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.8 120 7/30/2026
0.0.7 101 7/29/2026
0.0.6 93 7/29/2026
0.0.5 99 7/29/2026
0.0.4 102 7/27/2026
0.0.3 99 7/23/2026
0.0.2 99 7/23/2026
0.0.1-alpha-0002 92 7/22/2026
0.0.1-alpha-0001 92 7/22/2026