-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExample5.cs
More file actions
62 lines (56 loc) · 1.43 KB
/
Example5.cs
File metadata and controls
62 lines (56 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Puerts;
using XLua;
/// <summary>
/// 静态方法调用
/// 逻辑: 参数求和并返回
/// 参数: 三个值类型参数
/// 返回值: 值类型
/// </summary>
[Test]
public class Example5 : IExecute
{
public bool Static => true;
public string Method => "float Payload(int, int, float);";
public CallTarget Target => CallTarget.ScriptCallCSharp;
public object RunCS(int count)
{
float result = 0f;
for (var i = 0; i < count; i++)
{
result += Example5.Payload(i, i + 1, i + 2f);
}
return result;
}
public object RunJS(JsEnv env, int count)
{
float result = env.Eval<float>(string.Format(
@"(function() {{
var Example = require('csharp').Example5;
var result = 0;
for(let i = 0; i < {0}; i++){{
result += Example.Payload(i, i + 1, i + 2);
}}
return result;
}})()", count));
return result;
}
public object RunLua(LuaEnv env, int count)
{
object[] result = env.DoString(string.Format(
@"
return (function()
local Example = CS.Example5;
local result = 0;
for i = 0,{0} do
result = result + Example.Payload(i, i + 1, i + 2);
end
return result;
end)()
", count - 1));
return result != null && result.Length > 0 ? result[0] : null;
}
public static float Payload(int param1, int param2, float param3)
{
return param1 + param2 + param3;
}
}