File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -199,10 +199,30 @@ class ScriptContext
199199 *reinterpret_cast <uint64_t *>(&functionData[0 ]) = 0 ;
200200 }
201201
202- *reinterpret_cast <T*>(&functionData[0 ]) = value;
203-
204202 m_numResults = 1 ;
205203 m_numArguments = 0 ;
204+
205+ if constexpr (std::is_same_v<T, const char *> || std::is_same_v<T, std::string>)
206+ {
207+ if constexpr (std::is_same_v<T, const char *>)
208+ {
209+ if (!value)
210+ {
211+ *reinterpret_cast <const char **>(&functionData[0 ]) = nullptr ;
212+ return ;
213+ }
214+ }
215+
216+ static thread_local std::string lastResult;
217+ lastResult = value;
218+ const char * persistentPtr = lastResult.c_str ();
219+
220+ *reinterpret_cast <const char **>(&functionData[0 ]) = persistentPtr;
221+ }
222+ else
223+ {
224+ *reinterpret_cast <T*>(&functionData[0 ]) = value;
225+ }
206226 }
207227
208228 template <typename T> inline T GetResult ()
You can’t perform that action at this time.
0 commit comments