Skip to content
YANG Huan edited this page Nov 26, 2019 · 11 revisions

1.Which C# syntax is not supported?

In principle all C# syntax will be supported, currently implemented to C# 7.0, only the following features are temporarily not implemented.

  • Most pointer operations
  • ref returns(C# 7.0)

If you find an error when you use it, you are welcome to pass Issues feedback.

2.Support which. NET class library?

The concrete has been realized see Coresystem.lua, it may be possible to add some commonly used, but not to increase the number of, these are basically enough, already contains the common collection classes and LINQ, The Coresystem.lua library is implemented against the source code of the. NET class library, ensuring consistency with the. NET class Library interface.

3.What if you use it in addition to the base Class library?

When compiled by default, all assemblies in the underlying class library are automatically referenced, except for DLLs that need to be joined through command-line argument 'l', using the full path. The compilation passes, but it is necessary to import these libraries into the lua environment and ensure interface invocation and naming rules.

4.Do you support reflection?

Only the core metadata information is saved at the time of conversion, because lua is a dynamic language that supports many dynamic operations, so it is possible to create classes through strings, invoke methods, and so on. In order to ensure the interface requirements of C#, partial reflection interfaces have been implemented, but it is not supported to rely on complex metadata information, such as obtaining the MethodInfo object with the specified name and parameter type.You can use the C# dynamic keyword to simplify related code.

C#

public void TestDynamic(object obj) {
    dynamic a = obj;
    int name = a.Name;
    int age = a.Age;
    int money = a.Got();
}

lua

local testDynamic
testDynamic = function (this, obj) 
    local a = obj
    local name = a.Name
    local age = a.Age
    local money = a:Got()
end

5.Attribute support

Because of the principle of preserving only the core metadata information, the default compile-time metadata information that is attached to the attribute is not stored. You can use the command line argument "-a" to open.

6.Enum not exported?

Enum is used to convert directly to constant numeric processing, and by default there is no need to save information about its literal amount, and when character information is required, it is exported, such as using typeOf, ToString, Enum.trypase, and so on.

7.How do you call or insert lua code in your code?

 public static void Main(string[] args) {
#if __CSharpLua__
      /*
      [[
      local i = "hello, word"
      print(i)
      ]]*/  
#else
      Console.WriteLine("hello, word");
#endif
      //insert lua code
      /*
      [[
      print('insert lua code')
      ]] 
      */
    }

output

local Main
Main = function (args) 
  local i = "hello, word"
  print(i)

  --insert lua code
  print('insert lua code')
end

the symbol CSharpLua is defined.

9.How to change some of the generated behavior?

  1. The metadata configuration file (xml format) can be provided via the command line parameter "-m" to control some export behavior. It can be written with reference to System.xml, which controls some code generation rules of the standard library.
  2. Refer to https://github.com/yanghuan/CSharp.lua/wiki/attributes_en and currently support writing a small number of properties in the annotations document.

10.Why not use Bridge.lua?

The Bridge.lua is modified on the basis of bridge.net, bridge.net using nrefactory to parse the syntax tree, this library is no longer maintained, has been replaced by Roslyn, With Roslyn, you can better support C# 6.0 and Future Syntax standards (Bridge.net may change to Roslyn in version 17), and Bridge.net use string concatenation to generate code, and CSharp.lua is to output the lua AST first, then output lua source, the difference in this way of implementation lead to CSharp.lua in the following points have great advantages, code simplicity and readability, compile speed, bug fixes and maintenance, support for new syntax standards, and so on, this is essential to implement an industrial-level compiler.

11. Can I run it in a non-Windows environment?

The run environment is .NET Core, which can be used across platforms.

12.How do I pass a define symbol?

-csc parameters can be passed in to the compiler parameters (https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/index). For example, define the DEBUG symbol -csc /define:DEBUG