@@ -102,7 +102,7 @@ private void Awake() {
102102 context = LuauContext . Protected ;
103103 }
104104
105- thread = LoadAndExecuteScript ( gameObject , context , LuauScriptCacheMode . NotCached , script , false ) ;
105+ thread = LoadAndExecuteScript ( gameObject , context , LuauScriptCacheMode . NotCached , script , out var status ) ;
106106 }
107107
108108 /// <summary>
@@ -137,18 +137,20 @@ public static IntPtr LoadScript(GameObject obj, LuauContext context, LuauScriptC
137137 /// <summary>
138138 /// Execute a thread. The thread must first be created with the LoadScript function.
139139 /// </summary>
140- public static void ExecuteScript ( IntPtr thread ) {
140+ public static int ExecuteScript ( IntPtr thread ) {
141141 // Execute the new thread. We don't need to do anything after this. If the thread errors, the error will be
142142 // outputted. If the thread yields, whoever yielded it owns responsibility for resuming it (e.g. the task
143143 // scheduler):
144- LuauPlugin . LuauRunThread ( thread ) ;
144+ return LuauPlugin . LuauRunThread ( thread ) ;
145145 }
146146
147147 /// <summary>
148148 /// Loads and executes the given script. The executed Luau thread is returned. If the thread is a nullptr, then
149149 /// that indicates that Luau failed to load the script.
150150 /// </summary>
151- public static IntPtr LoadAndExecuteScript ( GameObject obj , LuauContext context , LuauScriptCacheMode cacheMode , AirshipScript script , bool pinThread ) {
151+ public static IntPtr LoadAndExecuteScript ( GameObject obj , LuauContext context , LuauScriptCacheMode cacheMode , AirshipScript script , out int status ) {
152+ status = - 1 ;
153+
152154 var thread = LoadScript ( obj , context , cacheMode , script ) ;
153155
154156 var shouldCacheValue = thread == IntPtr . Zero && cacheMode == LuauScriptCacheMode . Cached ;
@@ -163,16 +165,16 @@ public static IntPtr LoadAndExecuteScript(GameObject obj, LuauContext context, L
163165 return thread ;
164166 }
165167
166- if ( shouldCacheValue ) {
167- var requirePath = LuauCore . GetRequirePath ( script . m_path , CleanupFilePath ( script . m_path ) ) ;
168- LuauPlugin . LuauCacheModuleOnThread ( thread , requirePath ) ;
168+ if ( ! shouldCacheValue ) {
169+ status = 0 ;
170+ } else {
171+ status = ExecuteScript ( thread ) ;
169172 }
170173
171- if ( pinThread ) {
172- LuauPlugin . LuauPinThread ( thread ) ;
174+ if ( shouldCacheValue && status == 0 ) {
175+ var requirePath = LuauCore . GetRequirePath ( script . m_path , CleanupFilePath ( script . m_path ) ) ;
176+ LuauPlugin . LuauCacheModuleOnThread ( thread , requirePath ) ;
173177 }
174-
175- ExecuteScript ( thread ) ;
176178
177179 return thread ;
178180 }
0 commit comments