Skip to content

Commit

Permalink
Implement Hook.Call to make calling hooks easier
Browse files Browse the repository at this point in the history
  • Loading branch information
G3Kappa committed May 16, 2024
1 parent 2a93fa8 commit 0215b73
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Ergo/Interpreter/Libraries/_Shared/HookDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public void SetArg(int i, ITerm arg)
args[i] = arg;
}

public IEnumerable<Solution> Call(ErgoVM vm, params object[] args)
{
for (int i = 0; i < args.Length; i++)
{
if (args[i] is ITerm term)
SetArg(i, term);
else if (args[i] is { } obj)
SetArg(i, TermMarshall.ToTerm(obj, obj.GetType()));
}
vm.Query = Compile();
return vm.RunInteractive();
}

/// <summary>
/// Creates a wrapper that compiles the hook just in time when it is first called.
/// </summary>
Expand Down

0 comments on commit 0215b73

Please sign in to comment.