Unity3d hot update book-script (iii) C # lightedevil syntax and debugging

Source: Internet
Author: User
Tags float double

Debugging, Which is unavoidable

C # light has three scenarios: lexical explanation, syntax explanation, and runtime.

So there are similar problems with C #.

 

Errors can be roughly divided into compilation errors and runtime errors.

An error will be reported during the compilation phase due to an inexplicable spelling or incorrect syntax. This error is well checked because

C # Light syntax is a strict subset of C #. All C # Light scripts can use C # standard for syntax check.

This is also the reason why C # light basically uses Visual Studio as an editor. It can be compiled directly as C # code to eliminate most Syntax problems.

Then some of the remaining code can be compiled as C # code, but C # light cannot be compiled because C # light is a subset of C # And does not implement all C # syntaxes in 100%.

Lexical error C # The tokenparser of light will throw an exception. If you observe this exception, you will be notified of the problem.

Syntax Error C # Light compiler will throw an exception. Similarly, we can see the exception.

However, you still need to know which syntaxes will cause exceptions.

Let's first list unsupported syntaxes:

Project Supported Not Supported

Note

Supported // Not Supported /**/
Basic Type Int uint bool string float double supported Does not support byte char short, but can be extended
Variables and definitions The same as C # defines the variable mode, which can be defined first and then used. You can assign values at the same time.

Example

Int I;
Int J = 0;
Int K = I + 1;
Bool B1;
Bool b2 = true;
Bool B3 = false;

 
Mathematical computing

Same as C #

Supported

+-*/%

Five mathematical calculations

Supported

+ =-=/= * = % =

Five self-operations

Supported

++ --

Two auto-increment operations: Only variables on the left

++ I does not support I ++.

Supported

>>=<=! ===& & |

Eight logical operations

Yes! Invert

Support for three-object operations? :

Bit operations not supported
Loop SupportedFor foreach, SupportedContinue,Break, return

SupportedIf, YesIf elseNesting

Example

If (I = 1)
{
}
Else if (I = 2)
{
}
Else if (I = 3)
{
}
Else
{
}

Not SupportedWhile dowhile GOTO
Namespace Writable
Debug. Log ();
Not writable
Unityenging. Debug. Log ();
C # You can write using in the edevil header.
Not Supported
Object call After the type is registered
New support
Supported as and forced type conversion
Member variable access support
Support for member function calls
Register event Proxy Support with Type
Support [] index access of Objects
Static support
C # You can write the class in the script.
The class written in the script cannot be inherited.
Array Supported as type
For example, you can set list <int>
Dictionary <int, string> is used to register a class.
The Int [] abc = new int [3] syntax is not supported.
The input parameters include int [] and can be registered as types.
Because the array is the overall registration of a keyword
Therefore, if the registered list <int> is registered with the keyword "list <int>", the list <ini> cannot be written without spaces. Otherwise, the keyword cannot match.
Delegate Allows you to write scripts to delegate functions to a program.
A. Test + = func1;
A. settest (func1 );
Two Forms
 
Anonymous Functions   Not Supported
Exception Handling   Trycatch is not supported.

C # The type that light can call must be registered in advance.

Env. regtype (New CSLE. reghelper_type (typeof (unityengine. Debug )));

Env. regtype (New CSLE. reghelper_type (typeof (list <string>), "list <string> "));
Env. regtype (New CSLE. reghelper_type (typeof (list <int>), "list <int> "));
Env. regtype (New CSLE. reghelper_type (typeof (list <int>), "list <int> "));

Delegated registration is slightly different

Env. regdeletype (New CSLE. reghelper_deleaction ("action "));
Env. regdeletype (New CSLE. reghelper_deleaction <int> ("Action <int> "));
Env. regdeletype (New CSLE. reghelper_deleaction <int, string> ("Action <int, string> "));


The second parameter keyword is not required for a simple type.

 

Although the column does not support a lot of looks, it will not actually affect you.How to troubleshoot running errors

 

 

There are usually errors during runtime:

1. Log in for judgment

2. breakpoint debugging

2. Error Context Analysis (stack analysis and nearby variable analysis)

C # light does not provide the breakpoint debugging function. You can call Debug. Log directly for logging.

Error context C # light has good support

You only need to try it when running the script. After an error occurs, you can use content. dumpvalue to dump the variable values on the script stack.

Content. dumpstack can dump the script execution stack

In addition, the exception itself feedback

This is a deliberate error.

Dumpvalue is the variable on each layer of script Functions

Dumpstack is the script stack. The top line tells us the 31st rows of test03.cs where the bug is located.

Systemerror is part of the exception throw.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.