CSLua


CSLua is a pure C# library for interfacing to the Lua 5.1 Windows DLL. It supports the core Lua API and includes a C# class wrapper for using C# objects from Lua script. I built this for fun to learn more about Lua and C# and thought I would share it.

CSLua 1.0 Download

Lua Binaries Download

Lua Reference Manual

lib/CSLua/LuaDLL.cs contains the marshalling definitions to the standard Lua API.

lib/CSLua/LuaState.cs is a class wrapper for a lua state and an API for registering C# objects and functions with Lua.

test/Window1.xaml.cs contains an basic interactive Lua interface with a test suite of C# classes and methods.

test/data/test.lua contains a Lua script that is designed to stress test the test objects in Window1.xaml.cs.

Features:

  • Mostly complete standard Lua C API exposed to C#
  • Some additional features for supporting C# features, such as variable arguments
  • C# class wrapper of lua state
  • Support for registration of C# methods as global Lua functions
  • Support for registration of C# objects, either as global objects or returned from methods
  • Automatic registration of class when objects are registered or returned

Future features:

  • Make Lua tables available to use as native C# objects