jlbun
    Preparing search index...

    Class Julia

    Index

    Constructors

    Properties

    DataType: JuliaDataType
    Float16: JuliaDataType
    Float32: JuliaDataType
    Float64: JuliaDataType
    Function: JuliaDataType
    Nothing: JuliaDataType
    nthreads: number
    version: string

    Accessors

    • get defaultScopeMode(): ScopeMode

      Get the default scope mode for Julia.scope(). Does not affect Julia.scopeAsync() which always uses "safe" mode.

      Returns ScopeMode

    • set defaultScopeMode(mode: ScopeMode): void

      Set the default scope mode for Julia.scope().

      Parameters

      • mode: ScopeMode

        The scope mode to use by default:

        • 'default': Scope-based with concurrent async support (thread-safe)
        • 'safe': All objects use FinalizationRegistry (closure-safe)
        • 'perf': Lock-free stack-based (single-threaded LIFO only)

        Note: Julia.scopeAsync() always uses "safe" mode regardless of this setting.

      Returns void

    Methods

    • Call a Julia function with variable arguments.

      Parameters

      • func: JuliaFunction

        The Julia function to be called.

      • ...args: unknown[]

        The arguments to be passed to the function. Non-JuliaValue objects will be automatically wrapped by Julia.autoWrap. Since the automatic wrapping does not work perfectly all the time, be sure to wrap the objects yourself in order to feed the function with the exact types.

      Returns JuliaValue

    • Call a Julia function with keyword arguments and variable arguments.

      Parameters

      • func: JuliaFunction

        The Julia function to be called.

      • kwargs: JuliaNamedTuple | Record<string, any>

        Keyword arguments to be passed to the function. If a plain object is provided, it will be automatically wrapped as a JuliaNamedTuple. Be sure to wrap it yourself to get exact typing.

      • ...args: any[]

        Variable arguments to be passed to the function. Non-JuliaValue objects will be automatically wrapped by. Be sure to wrap it yourself to get exact typing.

      Returns JuliaValue

    • Close the Julia runtime and also close the dynamic library.

      Parameters

      • status: number = 0

        Status code to be reported.

      Returns void

    • Delete an object from the global scope maintained by jlbun.

      Parameters

      • name: string

        Name of the object to be deleted.

      Returns boolean

      Whether the object was deleted.

    • Evaluate a Julia code fragment and get the result as a JuliaValue.

      Parameters

      • code: string

        Julia code to be evaluated.

      Returns JuliaValue

    • Retrieve an object from the global scope maintained by jlbun.

      Parameters

      • name: string

        Name of the object to be retrieved.

      Returns JuliaValue

    • Get the string representation of a Julia value's type. Uses caching to avoid repeated FFI calls for common types.

      Parameters

      • ptr: JuliaValue | Pointer

        Pointer to a Julia object, or a JuliaValue object.

      Returns string

    • Import a module and get a JuliaModule object referring to that module.

      Parameters

      • name: string

        Name of the module to be imported.

      Returns JuliaModule

    • Initialize the Julia runtime. All other methods need to be called after this.

      Parameters

      • extraOptions: Partial<JuliaOptions> = {}

        Extra options for initialization.

      Returns void

    • Get a string representation of a JuliaValue using Julia's repr() function, with the given MIME.

      Parameters

      • value: JuliaValue

        Object to be represented.

      • mime: MIME = MIME.Default

        The MIME to use. Default to MIME.Default.

      Returns string

    • Execute code within a scoped context where Julia objects are automatically tracked and released when the scope ends.

      Objects created through the scoped julia proxy are automatically tracked and released when the scope ends. This provides automatic memory management without manual setGlobal() or deleteGlobal() calls.

      Type Parameters

      • T

      Parameters

      Returns T

      The return value of the function.

      const result = Julia.scope((julia) => {
      const a = julia.Base.rand(1000, 1000);
      const b = julia.Base.rand(1000, 1000);
      const c = julia.Base["*"](a, b);
      return c.value; // Return JS value, Julia objects are auto-released
      });
      // Return a Julia object that escapes the scope
      const arr = Julia.scope((julia) => {
      const temp = julia.Base.rand(100);
      const sorted = julia.Base.sort(temp);
      return julia.escape(sorted); // Escape from scope
      });
      // arr is still valid here
    • Execute async code within a scoped context where Julia objects are automatically tracked and released when the scope ends.

      Note: Async scopes always use "safe" mode to prevent race conditions with concurrent async operations. The mode option is ignored.

      Type Parameters

      • T

      Parameters

      • fn: (julia: ScopedJulia) => Promise<T>

        An async function that receives a ScopedJulia proxy.

      • Optionaloptions: JuliaScopeOptions

        Options (mode is always forced to "safe")

      Returns Promise<T>

      A promise that resolves to the return value of the function.

      const result = await Julia.scopeAsync(async (julia) => {
      const task = JuliaTask.from(julia.eval("() -> sum(1:1000)"));
      const value = await task.value;
      return value.value;
      });
    • Sava an object to the global scope maintained by jlbun.

      Parameters

      • name: string

        Name to use.

      • obj: JuliaValue

        Object to be saved.

      Returns void

    • Evaluate a Julia code fragment and get the result as a JuliaValue. This method supports value-interpolation, meaning that the tagged values will be automatically wrapped and interpolated into the code.

      Parameters

      • strings: TemplateStringsArray

        Strings separated by tagged values

      • ...values: any[]

        Tagged values to be interpolated

      Returns JuliaValue

    • Wrap a pointer as a JuliaValue object. Uses Map lookup for common types (O(1)) before falling back to string comparison for parametric and special types.

      Parameters

      • ptr: Pointer

        Pointer to the Julia object.

      Returns JuliaValue