manifold-3d
    Preparing search index...

    Class Evaluator

    An object that will evaluate ManifoldCAD scripts on demand.

    It inserts the Manifold instance (module) into the evaluation context, as well as a selection of available methods. Additional properties can be inserted through addContext, addContextMethodWithCleanup or can be directly added to the context property.

    This class provides some simple garbage collection. It does this by intercepting calls to a white-list of functions, tracking new instances of Manifold and CrossSection. This way, users don't have to care about calling delete manually. Note that this only fixes memory leak across different runs: the memory will only be freed when cleanup() is called.

    Index

    Constructors

    Properties

    afterScript: string = 'return typeof result === "undefined" ? undefined : result;'

    Boilerplate code run after the supplied code.

    beforeScript: string = 'resetToCircularDefaults();'

    Boilerplate script run before the supplied code.

    context: any = {}

    Additional objects inserted into the evaluation context.

    memoryRegistry: (Manifold | CrossSection)[]
    module: ManifoldToplevel = manifoldwasm

    Methods

    • Add objects to the evaluation context.

      Parameters

      • moreContext: Record<string, any>

        An object containing properties or methods.

      Returns void

    • Add a method to the evaluation context, with cleanup.

      Calls to the method will be intercepted, and their results added to the cleanup list. If your function does not generate new Manifold or CrossSection objects, you can add it to the context directly.

      Parameters

      • name: string

        The name for the method in the context.

      • originalFn: any

        The function to intercept and include.

      Returns void

    • Intercept calls and add their results to our garbage collection list.

      Parameters

      • className: string

        The class to intercept.

      • methodNames: string[]

        An array of methods to intercept.

      • areStatic: boolean

        Are these static methods? If so, intercept them at the prototype level.

      Returns void

    • Delete any objects tagged for garbage collection.

      Returns void

    • Evaluate a string as javascript code creating a Manifold model.

      This function assembles the final execution context. It then runs beforeScript, code and afterScript in order. Finally, it returns the end result.

      Parameters

      • code: string

        The input string.

      Returns any

      any By default, this script will return either undefined or a Manifold object. Changing afterScript will affect this behaviour.

    • Get the instantiated manifold WASM instance owned by this module.

      Note that function calls that have been intercepted for garbage collection will continue to be intercepted, even outside of the evaluator.

      Returns ManifoldToplevel