topiary 0.7.0

dotnet add package topiary --version 0.7.0
                    
NuGet\Install-Package topiary -Version 0.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="topiary" Version="0.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="topiary" Version="0.7.0" />
                    
Directory.Packages.props
<PackageReference Include="topiary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add topiary --version 0.7.0
                    
#r "nuget: topiary, 0.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package topiary@0.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=topiary&version=0.7.0
                    
Install as a Cake Addin
#tool nuget:?package=topiary&version=0.7.0
                    
Install as a Cake Tool

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 returns byte[] 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 every onDialogue and story.SelectChoice(int) after every onChoices that'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 Compatible and additional computed target framework versions.
.NET Framework net471 is compatible.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.0 218 2/21/2024
0.5.1 236 12/26/2023
0.5.0 203 12/26/2023
0.3.0 235 11/19/2023
0.2.1 207 10/1/2023
0.2.0 190 10/1/2023
0.1.0 195 9/30/2023