Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to compile Cs into Js with JSBinding + SharpKit

Shulou Source: shulou.com Published: 2022-06-01 14:01:04 09月26日 Update

This article will explain in detail how JSBinding + SharpKit compiles Cs into Js. The content of the article is of high quality, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.

The compilation symbols passed to skc5.exe can be found in Compiler.cs. Notice that the symbol contains Unity_Editor, and here's why. First of all, Js distinguishes overloaded functions by adding suffixes to functions, such as having a class

1 class A2 {3 public void f(int i){}4 public void f(string s){}5 }

The generated Js function names are

1 f$$Int322 f$$String

When you run JSB| Generate JS and CS Bindings], the code is executed under the editor, so there must be a definition of UNITY_EDITOR at that time. Let's change the definition of A:

class A{#if UNITY_EDITOR public void f(int i){}#endif public void f(string s){}}

The names of these two functions are still generated.

f$$Int32f$$String

If the Js compiler does not define Unity_EDITOR, when you call a.f(""), it generates Js code that is

a.f("") //No suffix, call failed!

Because he thinks that f is not overloaded, he will not add suffixes to it. The result was that the call failed!

I don't know if this situation exists at present, but there is a certain risk ~!

About JSBinding + SharpKit how to compile Cs into Js to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Functions compilations suffixes generation code content articles more knowledge symbols articles a.f yes names names that is situations ways are for example Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB Xiaomi Shulou Tech Info OPPO Reno