Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NewInstruction.cs
Go to the documentation of this file.
3
5
6internal class NewInstruction : Instruction
7{
8 protected readonly ConstructorInfo _constructor;
9
10 protected readonly int _argumentCount;
11
12 public override int ConsumedStack => _argumentCount;
13
14 public override int ProducedStack => 1;
15
16 public override string InstructionName => "New";
17
18 public NewInstruction(ConstructorInfo constructor, int argumentCount)
19 {
20 _constructor = constructor;
21 _argumentCount = argumentCount;
22 }
23
24 public override int Run(InterpretedFrame frame)
25 {
26 int num = frame.StackIndex - _argumentCount;
27 object[] args = GetArgs(frame, num);
28 object obj;
29 try
30 {
31 obj = _constructor.Invoke(args);
32 }
34 {
37 }
38 frame.Data[num] = obj;
39 frame.StackIndex = num + 1;
40 return 1;
41 }
42
43 protected object[] GetArgs(InterpretedFrame frame, int first)
44 {
45 if (_argumentCount > 0)
46 {
47 object[] array = new object[_argumentCount];
48 for (int i = 0; i < array.Length; i++)
49 {
50 array[i] = frame.Data[first + i];
51 }
52 return array;
53 }
54 return Array.Empty<object>();
55 }
56
57 public override string ToString()
58 {
59 return "New " + _constructor.DeclaringType.Name + "(" + _constructor?.ToString() + ")";
60 }
61}
static void UnwrapAndRethrow(TargetInvocationException exception)
NewInstruction(ConstructorInfo constructor, int argumentCount)
object[] GetArgs(InterpretedFrame frame, int first)
override int Run(InterpretedFrame frame)
object Invoke(object?[]? parameters)