@@ -75,3 +75,50 @@ The `script` can be any of the following types:
7575- [`Napi::String`](string.md)
7676- `const char *`
7777- `const std::string &`
78+
79+ ### SetInstanceData
80+
81+ ```cpp
82+ template <typename T> using Finalizer = void (*)(Env, T*);
83+ template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
84+ void SetInstanceData(T* data);
85+ ```
86+
87+ - ` [template] fini ` : A function to call when the instance data is to be deleted.
88+ Accepts a function of the form ` void CleanupData(Napi::Env env, T* data) ` . If
89+ not given, the default finalizer will be used, which simply uses the ` delete `
90+ operator to destroy ` T* ` when the addon instance is unloaded.
91+ - ` [in] data ` : A pointer to data that will be associated with the instance of
92+ the addon for the duration of its lifecycle.
93+
94+ Associates a data item stored at ` T* data ` with the current instance of the
95+ addon. The item will be passed to the function ` fini ` which gets called when an
96+ instance of the addon is unloaded.
97+
98+ ### SetInstanceData
99+
100+ ``` cpp
101+ template <typename DataType, typename HintType>
102+ using FinalizerWithHint = void (*)(Env, DataType*, HintType*);
103+ template <typename DataType,
104+ typename HintType,
105+ FinalizerWithHint<DataType, HintType> fini =
106+ Env::DefaultFiniWithHint<DataType, HintType>>
107+ void SetInstanceData (DataType* data, HintType* hint);
108+ ```
109+
110+ - `[template] fini`: A function to call when the instance data is to be deleted.
111+ Accepts a function of the form
112+ `void CleanupData(Napi::Env env, DataType* data, HintType* hint)`. If not given,
113+ the default finalizer will be used, which simply uses the `delete` operator to
114+ destroy `T*` when the addon instance is unloaded.
115+ - `[in] data`: A pointer to data that will be associated with the instance of
116+ the addon for the duration of its lifecycle.
117+ - `[in] hint`: A pointer to data that will be associated with the instance of
118+ the addon for the duration of its lifecycle and will be passed as a hint to
119+ `fini` when the addon instance is unloaded.
120+
121+ Associates a data item stored at `T* data` with the current instance of the
122+ addon. The item will be passed to the function `fini` which gets called when an
123+ instance of the addon is unloaded. This overload accepts an additional hint to
124+ be passed to `fini`.
0 commit comments