Skip to content

Commit 6de0f28

Browse files
committed
Remove string free for logging
1 parent 8bd98a6 commit 6de0f28

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

Runtime/Code/Luau/LuauCoreCallbacks.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ private static int LuauError(IntPtr thread, string err) {
124124
}
125125

126126
#if UNITY_EDITOR
127+
private static readonly Regex AnchorLinkPattern = new Regex(@"(\S+\.lua):(\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
127128
private static string InjectAnchorLinkToLuaScript(string logMessage) {
128129
// e.g. "path/to/my/script.lua:10: an error occurred"
129-
var rx = new Regex(@"(\S+\.lua):(\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
130-
131-
return rx.Replace(logMessage, (m) => {
130+
return AnchorLinkPattern.Replace(logMessage, (m) => {
132131
var scriptPath = m.Groups[1].Value;
133132
var line = m.Groups[2].Value;
134133

@@ -140,14 +139,10 @@ private static string InjectAnchorLinkToLuaScript(string logMessage) {
140139

141140
//when a lua thread prints something to console
142141
[AOT.MonoPInvokeCallback(typeof(LuauPlugin.PrintCallback))]
143-
static void printf(LuauContext context, IntPtr thread, int style, int gameObjectId, IntPtr buffer, int length, IntPtr ptr) {
142+
static void printf(LuauContext context, IntPtr thread, int style, int gameObjectId, IntPtr buffer, int length) {
144143
CurrentContext = context;
145144

146-
string res = LuauCore.PtrToStringUTF8(buffer, length);
147-
if (res == null) {
148-
LuauPlugin.LuauFreeString(ptr);
149-
return;
150-
}
145+
var res = LuauCore.PtrToStringUTF8(buffer, length);
151146

152147
#if UNITY_EDITOR
153148
if (style == 1 || style == 2) {
@@ -169,14 +164,11 @@ static void printf(LuauContext context, IntPtr thread, int style, int gameObject
169164
Debug.LogWarning(res, logContext);
170165
} else if (style == 2) {
171166
Debug.LogError(res, logContext);
172-
//If its an error, the thread is suspended
167+
//If it's an error, the thread is suspended
173168
ThreadDataManager.Error(thread);
174-
//GetLuauDebugTrace(thread);
175169
} else {
176170
Debug.Log(res, logContext);
177171
}
178-
179-
LuauPlugin.LuauFreeString(ptr);
180172
}
181173

182174
[AOT.MonoPInvokeCallback(typeof(LuauPlugin.ToStringCallback))]

Runtime/Code/Luau/LuauPlugin.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Debug = UnityEngine.Debug;
1111

1212
public static class LuauPlugin {
13-
public delegate void PrintCallback(LuauContext context, IntPtr thread, int style, int gameObjectId, IntPtr buffer, int length, IntPtr ptr);
13+
public delegate void PrintCallback(LuauContext context, IntPtr thread, int style, int gameObjectId, IntPtr buffer, int length);
1414
public delegate int GetPropertyCallback(LuauContext context, IntPtr thread, int instanceId, IntPtr classNamePtr, int classNameSize, IntPtr propertyName, int propertyNameSize);
1515
public delegate int SetPropertyCallback(LuauContext context, IntPtr thread, int instanceId, IntPtr classNamePtr, int classNameSize, IntPtr propertyName, int propertyNameSize, LuauCore.PODTYPE type, IntPtr propertyData, int propertySize);
1616
public delegate int CallMethodCallback(LuauContext context, IntPtr thread, int instanceId, IntPtr className, int classNameSize, IntPtr methodName, int methodNameSize, int numParameters, IntPtr firstParameterType, IntPtr firstParameterData, IntPtr firstParameterSize, IntPtr shouldYield);
@@ -661,17 +661,6 @@ public static LuauContext LuauGetContextFromThread(IntPtr thread) {
661661
ThreadSafetyCheck();
662662
return GetContextFromThread(thread);
663663
}
664-
665-
#if UNITY_IPHONE
666-
[DllImport("__Internal")]
667-
#else
668-
[DllImport("LuauPlugin")]
669-
#endif
670-
private static extern void FreeString(IntPtr cStringPtr);
671-
public static void LuauFreeString(IntPtr cStringPtr) {
672-
ThreadSafetyCheck();
673-
FreeString(cStringPtr);
674-
}
675664

676665
#if UNITY_IPHONE
677666
[DllImport("__Internal")]

0 commit comments

Comments
 (0)