Skip to content

Commit a81b6a4

Browse files
committed
1、封装getglobal,setglobal的lua异常;
2、c#的callback,统一把异常给catch,转成lua异常;
1 parent b3331e0 commit a81b6a4

File tree

15 files changed

+398
-235
lines changed

15 files changed

+398
-235
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ UnityVS
1515
/Assets/UnityVS.meta
1616
.DS_Store
1717
*.o
18-
*.a
18+
/build/*/*.a
1919
luajit
2020
buildvm
2121
minilua
Binary file not shown.
173 KB
Binary file not shown.

Assets/Plugins/x86/xlua.dll

512 Bytes
Binary file not shown.

Assets/Plugins/x86_64/xlua.dll

0 Bytes
Binary file not shown.

Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ namespace CSObjectWrap
265265
<%end)%>
266266
return LuaAPI.luaL_error(L, "invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!");
267267
<%else%>
268-
<%=GetCasterStatement(type, 1, "rightside", true)%>;
269268
try {
269+
<%=GetCasterStatement(type, 1, "rightside", true)%>;
270270
<%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. " rightside")%>;
271271
} catch(System.Exception __gen_e) {
272272
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);

Assets/XLua/Src/LuaDLL.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public static void lua_newtable(IntPtr L)//[-0, +0, m]
9696
}
9797

9898
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
99-
public static extern int lua_getglobal(IntPtr L, string name);//[-1, +0, m]
99+
public static extern int xlua_getglobal(IntPtr L, string name);//[-1, +0, m]
100100

101101
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
102-
public static extern void lua_setglobal(IntPtr L, string name);//[-1, +0, m]
102+
public static extern int xlua_setglobal(IntPtr L, string name);//[-1, +0, m]
103103

104104
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
105105
public static extern void xlua_getloaders(IntPtr L);

Assets/XLua/Src/LuaEnv.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public LuaEnv()
5959
LuaAPI.lua_atpanic(L, StaticLuaCallbacks.Panic);
6060

6161
LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.Print);
62-
LuaAPI.lua_setglobal(L, "print");
62+
if (0 != LuaAPI.xlua_setglobal(L, "print"))
63+
{
64+
throw new Exception("call xlua_setglobal fail!");
65+
}
6366

6467
//template engine lib register
6568
TemplateEngine.LuaTemplate.OpenLib(L);
@@ -111,7 +114,10 @@ public LuaEnv()
111114

112115
translator.Alias(typeof(Type), "System.MonoType");
113116

114-
LuaAPI.lua_getglobal(L, "_G");
117+
if (0 != LuaAPI.xlua_getglobal(L, "_G"))
118+
{
119+
throw new Exception("call xlua_getglobal fail!");
120+
}
115121
translator.Get(L, -1, out _G);
116122
LuaAPI.lua_pop(L, 1);
117123

Assets/XLua/Src/ObjectTranslator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ public void CreateDelegateMetatable(RealStatePtr L)
469469

470470
public void OpenLib(RealStatePtr L)
471471
{
472-
LuaAPI.lua_getglobal(L, "xlua");
472+
if (0 != LuaAPI.xlua_getglobal(L, "xlua"))
473+
{
474+
throw new Exception("call xlua_getglobal fail!" + LuaAPI.lua_tostring(L, -1));
475+
}
473476
LuaAPI.xlua_pushasciistring(L, "import_type");
474477
LuaAPI.lua_pushstdcallcfunction(L,importTypeFunction);
475478
LuaAPI.lua_rawset(L, -3);

0 commit comments

Comments
 (0)