Skip to content

Commit a0cbf46

Browse files
committed
Merge branch 'master' of https://github.com/pangweiwei/slua
2 parents c79c990 + 51ec548 commit a0cbf46

File tree

10 files changed

+119
-124
lines changed

10 files changed

+119
-124
lines changed

Diff for: Assets/Plugins/Slua_Managed/Logger.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ namespace SLua
1010
/// </summary>
1111
internal class Logger
1212
{
13+
private static UnityEngine.Object FindScriptByMsg(string msg)
14+
{
15+
#if UNITY_EDITOR
16+
int idx = msg.IndexOf(":");
17+
if (idx < 0) return null;
18+
string filename = msg.Substring(0, idx);
19+
idx = filename.LastIndexOf("/");
20+
if (idx >= 0) filename = filename.Substring(idx + 1);
21+
string[] guids = UnityEditor.AssetDatabase.FindAssets(filename);
22+
filename = filename + ".txt";
23+
for (int i = 0; i < guids.Length; i++)
24+
{
25+
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);
26+
if(System.IO.Path.GetFileName(path).Equals(filename))
27+
{
28+
return UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path);
29+
}
30+
}
31+
#endif
32+
return null;
33+
}
34+
1335
public static void Log(string msg)
1436
{
1537
#if !SLUA_STANDALONE
@@ -18,10 +40,19 @@ public static void Log(string msg)
1840
Console.WriteLine(msg);
1941
#endif
2042
}
21-
public static void LogError(string msg)
43+
public static void LogError(string msg, bool hasStacktrace = false)
2244
{
2345
#if !SLUA_STANDALONE
24-
UnityEngine.Debug.LogError(msg);
46+
if(hasStacktrace)
47+
{
48+
// Disable Stacktrace so we can jump
49+
var Type = UnityEngine.Application.GetStackTraceLogType(UnityEngine.LogType.Error);
50+
UnityEngine.Application.SetStackTraceLogType(UnityEngine.LogType.Error, UnityEngine.StackTraceLogType.None);
51+
UnityEngine.Debug.LogError(msg, FindScriptByMsg(msg));
52+
UnityEngine.Application.SetStackTraceLogType(UnityEngine.LogType.Error, Type);
53+
}
54+
else
55+
UnityEngine.Debug.LogError(msg);
2556
#else
2657
Console.WriteLine(msg);
2758
#endif

Diff for: Assets/Plugins/Slua_Managed/Lua3rdMeta.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static Lua3rdMeta Instance{
6161
#if UNITY_EDITOR
6262
if(_instance == null){
6363
_instance = ScriptableObject.CreateInstance<Lua3rdMeta>();
64-
string path = "Assets/Slua/Meta/Resources";
64+
string path = "Assets/Slua/Resources";
6565
if(!Directory.Exists(path)){
6666
Directory.CreateDirectory(path);
6767
}

Diff for: Assets/Plugins/Slua_Managed/LuaState.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,16 @@ public static int errorReport(IntPtr L)
688688
LuaDLL.lua_pushnumber(L, 2);
689689
LuaDLL.lua_call(L, 2, 1);
690690
LuaDLL.lua_remove(L, -2);
691-
Logger.LogError(LuaDLL.lua_tostring(L, -1));
692-
if (errorDelegate != null)
693-
{
694-
errorDelegate(LuaDLL.lua_tostring(L, -1));
695-
}
691+
string error = LuaDLL.lua_tostring(L, -1);
696692
LuaDLL.lua_pop(L, 1);
697-
return 0;
693+
694+
Logger.LogError(error, true);
695+
if (errorDelegate != null)
696+
{
697+
errorDelegate(error);
698+
}
699+
700+
return 0;
698701
}
699702

700703
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]

Diff for: Assets/Slua/Editor/LuaCodeGen.cs

+60-97
Original file line numberDiff line numberDiff line change
@@ -109,72 +109,14 @@ static public void GenerateAll()
109109
{
110110
autoRefresh = false;
111111
Generate();
112-
GenerateUI();
112+
GenerateUI();
113+
GenerateAds();
113114
Custom();
114115
Generate3rdDll();
115116
autoRefresh = true;
116117
AssetDatabase.Refresh();
117118
}
118119

119-
[MenuItem("SLua/Unity/Make UnityEngine")]
120-
static public void Generate()
121-
{
122-
if (IsCompiling) {
123-
return;
124-
}
125-
126-
Assembly assembly = Assembly.Load("UnityEngine");
127-
Type[] types = assembly.GetExportedTypes();
128-
129-
List<string> uselist;
130-
List<string> noUseList;
131-
132-
CustomExport.OnGetNoUseList(out noUseList);
133-
CustomExport.OnGetUseList(out uselist);
134-
135-
// Get use and nouse list from custom export.
136-
object[] aCustomExport = new object[1];
137-
InvokeEditorMethod<ICustomExportPost>("OnGetUseList", ref aCustomExport);
138-
if (null != aCustomExport[0])
139-
{
140-
if (null != uselist)
141-
{
142-
uselist.AddRange((List<string>)aCustomExport[0]);
143-
}
144-
else
145-
{
146-
uselist = (List<string>)aCustomExport[0];
147-
}
148-
}
149-
150-
aCustomExport[0] = null;
151-
InvokeEditorMethod<ICustomExportPost>("OnGetNoUseList", ref aCustomExport);
152-
if (null != aCustomExport[0])
153-
{
154-
if ((null != noUseList))
155-
{
156-
noUseList.AddRange((List<string>)aCustomExport[0]);
157-
}
158-
else
159-
{
160-
noUseList = (List<string>)aCustomExport[0];
161-
}
162-
}
163-
164-
List<Type> exports = new List<Type>();
165-
string path = GenPath + "Unity/";
166-
foreach (Type t in types)
167-
{
168-
if (filterType(t, noUseList, uselist) && Generate(t, path))
169-
exports.Add(t);
170-
}
171-
172-
GenerateBind(exports, "BindUnity", 0, path);
173-
if(autoRefresh)
174-
AssetDatabase.Refresh();
175-
Debug.Log("Generate engine interface finished");
176-
}
177-
178120
static bool filterType(Type t, List<string> noUseList, List<string> uselist)
179121
{
180122
// check type in uselist
@@ -195,22 +137,46 @@ static bool filterType(Type t, List<string> noUseList, List<string> uselist)
195137
}
196138
return true;
197139
}
198-
}
199-
200-
[MenuItem("SLua/Unity/Make UI (for Unity4.6+)")]
201-
static public void GenerateUI()
202-
{
203-
if (IsCompiling) {
204-
return;
205-
}
206-
207-
List<string> uselist;
208-
List<string> noUseList;
209-
210-
CustomExport.OnGetNoUseList(out noUseList);
211-
CustomExport.OnGetUseList(out uselist);
212-
213-
// Get use and nouse list from custom export.
140+
}
141+
142+
[MenuItem("SLua/Unity/Make UnityEngine")]
143+
static public void Generate()
144+
{
145+
GenerateFor("UnityEngine", "Unity/", 0, "BindUnity");
146+
}
147+
148+
[MenuItem("SLua/Unity/Make UnityEngine.UI")]
149+
static public void GenerateUI()
150+
{
151+
GenerateFor("UnityEngine.UI", "Unity/", 1, "BindUnityUI");
152+
}
153+
154+
[MenuItem("SLua/Unity/Make UnityEngine.Advertisements")]
155+
static public void GenerateAds()
156+
{
157+
GenerateFor("UnityEngine.Advertisements", "Unity/", 2, "BindUnityAds");
158+
}
159+
160+
static public void GenerateFor(string asemblyName, string genAtPath, int genOrder, string bindMethod)
161+
{
162+
if (IsCompiling)
163+
{
164+
return;
165+
}
166+
167+
Assembly assembly;
168+
try { assembly = Assembly.Load(asemblyName); }
169+
catch (Exception) { return; }
170+
171+
Type[] types = assembly.GetExportedTypes();
172+
173+
List<string> uselist;
174+
List<string> noUseList;
175+
176+
CustomExport.OnGetNoUseList(out noUseList);
177+
CustomExport.OnGetUseList(out uselist);
178+
179+
// Get use and nouse list from custom export.
214180
object[] aCustomExport = new object[1];
215181
InvokeEditorMethod<ICustomExportPost>("OnGetUseList", ref aCustomExport);
216182
if (null != aCustomExport[0])
@@ -239,24 +205,19 @@ static public void GenerateUI()
239205
}
240206
}
241207

242-
Assembly assembly = Assembly.Load("UnityEngine.UI");
243-
Type[] types = assembly.GetExportedTypes();
244-
245-
List<Type> exports = new List<Type>();
246-
string path = GenPath + "Unity/";
247-
foreach (Type t in types)
248-
{
249-
if (filterType(t,noUseList,uselist) && Generate(t,path))
250-
{
251-
exports.Add(t);
252-
}
253-
}
254-
255-
GenerateBind(exports, "BindUnityUI", 1, path);
256-
if(autoRefresh)
257-
AssetDatabase.Refresh();
258-
Debug.Log("Generate UI interface finished");
259-
}
208+
List<Type> exports = new List<Type>();
209+
string path = GenPath + genAtPath;
210+
foreach (Type t in types)
211+
{
212+
if (filterType(t, noUseList, uselist) && Generate(t, path))
213+
exports.Add(t);
214+
}
215+
216+
GenerateBind(exports, bindMethod, genOrder, path);
217+
if (autoRefresh)
218+
AssetDatabase.Refresh();
219+
Debug.Log("Generate interface finished: " + asemblyName);
220+
}
260221

261222
static String FixPathName(string path) {
262223
if(path.EndsWith("\\") || path.EndsWith("/")) {
@@ -490,7 +451,9 @@ static public void CompileDLL()
490451
UriBuilder uri = new UriBuilder(assem.CodeBase);
491452
string path = Uri.UnescapeDataString(uri.Path).Replace("\\", "/");
492453
string name = Path.GetFileNameWithoutExtension(path);
493-
if (path.StartsWith(projectPath) || referenced.Contains(name))
454+
// ignore dll for Editor
455+
if ((path.StartsWith(projectPath) && !path.Contains("/Editor/") && !path.Contains("CSharp-Editor"))
456+
|| referenced.Contains(name))
494457
{
495458
libraries.Add(path);
496459
}
@@ -591,12 +554,12 @@ static public void CompileDLL()
591554
Directory.CreateDirectory(GenPath);
592555
File.Move (WrapperName, GenPath + WrapperName);
593556
AssetDatabase.Refresh();
557+
File.Delete(ArgumentFile);
594558
}
595559
else
596560
{
597561
Debug.LogError(error.ToString());
598-
}
599-
File.Delete(ArgumentFile);
562+
}
600563
}
601564

602565
static void clear(string[] paths)

Diff for: Assets/Slua/Meta.meta

-9
This file was deleted.

Diff for: Assets/Slua/Meta/Resources.meta

-9
This file was deleted.

Diff for: Assets/Slua/Resources/lua3rdmeta.asset

4.08 KB
Binary file not shown.

Diff for: Assets/Slua/Resources/lua3rdmeta.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Slua/Resources/setting.asset

4.11 KB
Binary file not shown.

Diff for: Assets/Slua/Resources/setting.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)