-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteropService.cs
53 lines (45 loc) · 1.75 KB
/
InteropService.cs
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
using System;
using System.Collections.Generic;
namespace Quras.VM
{
public class InteropService
{
private Dictionary<string, Func<ExecutionEngine, bool>> dictionary = new Dictionary<string, Func<ExecutionEngine, bool>>();
public InteropService()
{
Register("System.ExecutionEngine.GetScriptContainer", GetScriptContainer);
Register("System.ExecutionEngine.GetExecutingScriptHash", GetExecutingScriptHash);
Register("System.ExecutionEngine.GetCallingScriptHash", GetCallingScriptHash);
Register("System.ExecutionEngine.GetEntryScriptHash", GetEntryScriptHash);
}
protected void Register(string method, Func<ExecutionEngine, bool> handler)
{
dictionary[method] = handler;
}
internal bool Invoke(string method, ExecutionEngine engine)
{
if (!dictionary.ContainsKey(method)) return false;
return dictionary[method](engine);
}
private static bool GetScriptContainer(ExecutionEngine engine)
{
engine.EvaluationStack.Push(StackItem.FromInterface(engine.ScriptContainer));
return true;
}
private static bool GetExecutingScriptHash(ExecutionEngine engine)
{
engine.EvaluationStack.Push(engine.CurrentContext.ScriptHash);
return true;
}
private static bool GetCallingScriptHash(ExecutionEngine engine)
{
engine.EvaluationStack.Push(engine.CallingContext.ScriptHash);
return true;
}
private static bool GetEntryScriptHash(ExecutionEngine engine)
{
engine.EvaluationStack.Push(engine.EntryContext.ScriptHash);
return true;
}
}
}