topiary 0.7.0
dotnet add package topiary --version 0.7.0
NuGet\Install-Package topiary -Version 0.7.0
<PackageReference Include="topiary" Version="0.7.0" />
<PackageVersion Include="topiary" Version="0.7.0" />
<PackageReference Include="topiary" />
paket add topiary --version 0.7.0
#r "nuget: topiary, 0.7.0"
#:package topiary@0.7.0
#addin nuget:?package=topiary&version=0.7.0
#tool nuget:?package=topiary&version=0.7.0
Topiary C# Bindings
This package provides a wrapper for topiary functions.
Current topiary v0.8.0
Setup
- Add Topiary to your project with nuget or cloning this repo.
- Compile your .topi file with
Story.Compile(string)(always good to serialize the returnsbyte[]and store for runtime) - Create your OnDialogue and OnChoices Callbacks
public delegate void OnDialogueCallback(Story story, Dialogue dialogue);public delegate void OnChoicesCallback(Story story, Choice[] choices);
- Create a new Story with
var story = new Story(bytes, onDialogue, onChoices, logSeverity) - Run your story until the end, calling
story.SelectContinue()after everyonDialogueandstory.SelectChoice(int)after everyonChoicesthat's invoked.-
try { story.Start(); // this example assumes onDialogue calls story.SelectContinue() itself while (story.CanContinue) story.Run(); } catch (Exception e) { Console.WriteLine(e); }
-
Examples
Check out the Test/UnitTest.cs for a very simple setup, as well as the Topiary.Unity.
Functions
Topiary provides a TopiAttribute, simply add [Topi(name)] where "name" matches the extern variable name in your .topi file.
Any function with 0-4 TopiValue parameters and return type void or TopiValue is valid.
// .topi: extern const strPrint = |str| {}
// will be overriden with the C# function
[Topi("strPrint")]
private static void StrPrint(TopiValue value)
{
var str = value.String;
Console.WriteLine($"StrPrint:: {str}");
}
// .topi: extern const sqr = |x| print("sqr: {x}")
// will be overriden with the C# function
[Topi("sqr")]
private static TopiValue Sqr(TopiValue value)
{
var i = value.Int;
return new TopiValue(i * i);
}
Then you can bind all the functions with the attribute in the assembly with story.BindFunctions(Assemblies[])
Values
Currently only the following value types are valid in the C# bindings (*Experiemental and requires deallocating memory):
- Null
- Bool
- Float
- String
- List*
- Map*
- Set*
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.1
- Microsoft.CSharp (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.