Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yanghuan/CSharp.lua
The C# to Lua compiler
https://github.com/yanghuan/CSharp.lua
compiler cs2lua csharp csharp-to-lua csharp2lua lua lua-compiler
Last synced: 3 months ago
JSON representation
The C# to Lua compiler
- Host: GitHub
- URL: https://github.com/yanghuan/CSharp.lua
- Owner: yanghuan
- License: other
- Created: 2017-01-09T08:58:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-03T11:43:25.000Z (5 months ago)
- Last Synced: 2024-06-21T04:38:08.405Z (5 months ago)
- Topics: compiler, cs2lua, csharp, csharp-to-lua, csharp2lua, lua, lua-compiler
- Language: C#
- Homepage:
- Size: 27.5 MB
- Stars: 1,189
- Watchers: 44
- Forks: 197
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/dotnet/roslyn). Support for C# 10.
* Highly readable code generation. C# AST ---> Lua AST ---> Lua Code.
* Provides [CoreSystem.lua](https://github.com/yanghuan/CSharp.lua/tree/master/CSharp.lua/CoreSystem.Lua/CoreSystem) library, can run away of CLR.
* Build by .NET Core, Ability to across platforms.## Sample
C# code
```csharp
using System;namespace HelloLua {
public static class Program {
public static void Main() {
Console.WriteLine("hello lua!");
}
}
}
```
To Lua
```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/CSharpLuaWeb/index.html## How to Use
### Command Line Parameters
```cmd
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 filesOptions
-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
-ei : enums is represented by a variable reference rather than a constant value, need to be used with -e
-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
-inline-property: inline some single-line properties
-include : the root directory of the CoreSystem library, adds all the dependencies to a single file named out.lua
-noconcurrent : close concurrent compile
```
Make sure that .NET 7.0 is installed.
https://dotnet.microsoft.com/download/dotnet/7.0### Download
https://github.com/yanghuan/CSharp.lua/releases## CoreSystem.lua
[CoreSystem.lua library](https://github.com/yanghuan/CSharp.lua/tree/master/CSharp.lua/CoreSystem.Lua/CoreSystem) that implements most of the [.NET Framework core classes](http://referencesource.microsoft.com/), including support for basic type, delegate, generic collection classes & linq. The Converted lua code, need to reference it## Example
- [fibonacci](https://github.com/yanghuan/CSharp.lua/tree/master/test/fibonacci), a console program code, print Fibonacci number.## Documentation
https://github.com/yanghuan/CSharp.lua/wiki## *License*
[Apache 2.0 license](https://raw.githubusercontent.com/yanghuan/CSharp.lua/master/LICENSE).## *Acknowledgements*
- [Bridge.NET](http://bridge.net/)
- [WootzJs](https://github.com/kswoll/WootzJs)
- [.NET referencesource](http://referencesource.microsoft.com/)
- [Resharper](https://www.jetbrains.com/resharper/)## Communication
- [Issues](https://github.com/yanghuan/CSharp.lua/issues)
- Mail:[email protected]
- QQ Group: 715350749 (Chinese Only)