Skip to content
The C# to Lua compiler
C# Lua Other
Branch: master
Clone or download

Latest commit

Latest commit daf7160 Apr 1, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Update build.yml Oct 25, 2019
CSharp.lua.Launcher fix #288 Apr 1, 2020
CSharp.lua fix #288 Apr 1, 2020
download fix input is files list Dec 23, 2019
test fix github action run fail Feb 12, 2020
.editorconfig add export ctor, field, property meta data Jan 18, 2019
.gitattributes fix #100 Jan 7, 2019
.gitignore remvoe BridgeNet Test Case no used code & fix some errors May 20, 2019
CSharp.lua.sln fix #35 Feb 3, 2018
Dockerfile Add Dockerfile Jan 21, 2019
LICENSE Update LICENSE Feb 9, 2018
README.md fix PropertyPatternClause Nov 20, 2019

README.md

CSharp.lua

The C# to Lua compiler.

Introduction

CSharp.lua is a C# to Lua compiler. Write C# then run on lua VM.

  • Build on Microsoft Roslyn. Support for C# 7.0.

  • Highly readable code generation. C# AST ---> Lua AST ---> Lua Code.

  • Allowing almost all of the C# language features.

  • Provides CoreSystem.lua library, can run away of CLR.

  • Self-Compiling, run "./test/self-compiling/self.bat".

  • Used by dotnet Standard 2.1, Ability to use across platforms.

Sample

C# code

using System;

namespace HelloLua {
  public static class Program {
    public static void Main() {
      Console.WriteLine("hello lua!");
    }
  }
}

To Lua

-- Generated by CSharp.lua Compiler
local System = System
System.namespace("HelloLua", function (namespace) 
  namespace.class("Program", function (namespace) 
    local Main
    Main = function () 
      System.Console.WriteLine("hello lua!")
    end
    return {
      Main = Main
    }
  end)
end)

Try Live

https://yanghuan.github.io/external/bridgelua-editor/index.html

How to Use

Command Line Parameters

D:\>dotnet CSharp.Lua.Launcher.dll -h
Usage: CSharp.lua [-s srcfolder] [-d dstfolder]
Arguments
-s              : can be a directory where all cs files will be compiled, or a list of files, using ';' or ',' to separate
-d              : destination directory, will put the out lua files

Options
-h              : show the help message and exit
-l              : libraries referenced, use ';' to separate
                  if the librarie is a module, whitch is compield by CSharp.lua with -module arguemnt, the last character needs to be '!' in order to mark  

-m              : meta files, like System.xml, use ';' to separate
-csc            : csc.exe command argumnets, use ' ' or '\t' to separate

-c              : support classic lua version(5.1), default support 5.3
-a              : attributes need to export, use ';' to separate, if ""-a"" only, all attributes whill be exported
-e              : enums need to export, use ';' to separate, if ""-e"" only, all enums will be exported
-p              : do not use debug.setmetatable, in some Addon/Plugin environment debug object cannot be used
-metadata       : export all metadata, use @CSharpLua.Metadata annotations for precise control
-module         : the currently compiled assembly needs to be referenced, it's useful for multiple module compiled

Make sure that the. NET core 3.0+ is installed. https://dotnet.microsoft.com/download

Download

https://github.com/yanghuan/CSharp.lua/releases

CoreSystem.lua

CoreSystem.lua library that implements most of the .NET Framework core classes, including support for basic type, delegate, generic collection classes & linq. The Converted lua code, need to reference it

Example

  • fibonacci, a console program code, print Fibonacci number.

Documentation

https://github.com/yanghuan/CSharp.lua/wiki

License

Apache 2.0 license.

Acknowledgements

Communication

You can’t perform that action at this time.