Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
joethephish committed Apr 12, 2016
2 parents 8e66757 + 486fef8 commit 12f04d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ink-engine-runtime/Story.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ internal void CallExternalFunction(string funcName, int numberOfArguments)
arguments.Add (valueObj);
}

// Reverse arguments from the order they were popped,
// so they're the right way round again.
arguments.Reverse ();

// Run the function!
object funcResult = func (arguments.ToArray());

Expand Down
16 changes: 14 additions & 2 deletions tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,21 +1676,33 @@ public void TestExternalBinding()
var story = CompileString (@"
EXTERNAL message(x)
EXTERNAL multiply(x,y)
EXTERNAL times(i,str)
~ message(""hello world"")
{multiply(5.0, 3)}
{times(3, ""knock "")}
");
string message = null;

story.BindExternalFunction ("message", (string arg) => {
message = "MESSAGE: "+arg;
});

story.BindExternalFunction ("multiply", (int arg1, float arg2) => {
story.BindExternalFunction ("multiply", (float arg1, int arg2) => {
return arg1 * arg2;
});

story.BindExternalFunction ("times", (int numberOfTimes, string str) => {
string result = "";
for(int i=0; i<numberOfTimes; i++) {
result += str;
}
return result;
});


Assert.AreEqual ("15\n", story.ContinueMaximally());
Assert.AreEqual ("15\n", story.Continue());

Assert.AreEqual ("knock knock knock \n", story.Continue());

Assert.AreEqual ("MESSAGE: hello world", message);
}
Expand Down

0 comments on commit 12f04d3

Please sign in to comment.