Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MethodInfoCallInstruction.cs
Go to the documentation of this file.
3
5
7{
8 protected readonly MethodInfo _target;
9
10 protected readonly int _argumentCount;
11
12 public override int ArgumentCount => _argumentCount;
13
14 public override int ProducedStack
15 {
16 get
17 {
18 if (!(_target.ReturnType == typeof(void)))
19 {
20 return 1;
21 }
22 return 0;
23 }
24 }
25
26 internal MethodInfoCallInstruction(MethodInfo target, int argumentCount)
27 {
28 _target = target;
29 _argumentCount = argumentCount;
30 }
31
32 public override int Run(InterpretedFrame frame)
33 {
34 int num = frame.StackIndex - _argumentCount;
35 object obj;
36 if (_target.IsStatic)
37 {
38 object[] args = GetArgs(frame, num, 0);
39 try
40 {
41 obj = _target.Invoke(null, args);
42 }
44 {
47 }
48 }
49 else
50 {
51 object obj2 = frame.Data[num];
53 object[] args2 = GetArgs(frame, num, 1);
54 if (CallInstruction.TryGetLightLambdaTarget(obj2, out var lightLambda))
55 {
56 obj = InterpretLambdaInvoke(lightLambda, args2);
57 }
58 else
59 {
60 try
61 {
62 obj = _target.Invoke(obj2, args2);
63 }
64 catch (TargetInvocationException exception2)
65 {
68 }
69 }
70 }
71 if (_target.ReturnType != typeof(void))
72 {
73 frame.Data[num] = obj;
74 frame.StackIndex = num + 1;
75 }
76 else
77 {
78 frame.StackIndex = num;
79 }
80 return 1;
81 }
82
83 protected object[] GetArgs(InterpretedFrame frame, int first, int skip)
84 {
85 int num = _argumentCount - skip;
86 if (num > 0)
87 {
88 object[] array = new object[num];
89 for (int i = 0; i < array.Length; i++)
90 {
91 array[i] = frame.Data[first + i + skip];
92 }
93 return array;
94 }
95 return Array.Empty<object>();
96 }
97
98 public override string ToString()
99 {
100 return "Call(" + _target?.ToString() + ")";
101 }
102}
object InterpretLambdaInvoke(LightLambda targetLambda, object[] args)
static bool TryGetLightLambdaTarget(object instance, [NotNullWhen(true)] out LightLambda lightLambda)
static void UnwrapAndRethrow(TargetInvocationException exception)
object[] GetArgs(InterpretedFrame frame, int first, int skip)
object? Invoke(object? obj, object?[]? parameters)