代码拉取完成,页面将自动刷新
package Scorpio;
public class HelloWorld {
public static class Test {
private int a = 100;
public Test(int a) {
this.a = a;
}
public void Func() {
System.out.println("Func " + a);
}
public static void StaticFunc() {
System.out.println("StaticFunc");
}
}
public static void main(String[] args) {
Script script = new Script(); //new一个Script对象
script.LoadLibrary(); //加载所有Scorpio的库,源码在Library目录下
script.SetObject("CTest", script.CreateObject(new Test(300))); //SetObject可以设置一个c#对象到脚本里
//LoadString 解析一段字符串,LoadString传入的参数就是热更新的文本文件内容
try {
script.LoadString("test", "print(\"hello world\")");
String str = "MyTest = import_type(\"Scorpio.HelloWorld$Test\") //import_type 要写入类的全路径 要加上命名空间 否则找不到此类,然后赋值给 MyTest 对象\n" +
"MyTest.StaticFunc() //调用类的静态函数\n" +
"var t = MyTest(200) //new 一个Test对象, 括号里面是构造函数的参数\n" +
"t.Func() //调用类的内部函数\n" +
"CTest.Func() //调用类的内部函数 CTest是通过 script.SetObject 函数设置\n";
//Scorpio脚本调用c#函数
script.LoadString("test", str);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型