-
Notifications
You must be signed in to change notification settings - Fork 202
FAQ_en
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.
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.
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.
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
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.
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.
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.
- 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.
- 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.
The run environment is .NET Core, which can be used across platforms.
-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