Skip to content

Commit a81b6a4

Browse files
committedJan 11, 2017
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

+1-1
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

+1-1
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

+2-2
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

+8-2
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

+4-1
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);

‎Assets/XLua/Src/StaticLuaCallbacks.cs

+345-225
Large diffs are not rendered by default.

‎Assets/XLua/Src/TemplateEngine/TemplateEngine.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ public static void OpenLib(RealStatePtr L)
244244
LuaAPI.xlua_pushasciistring(L, "execute");
245245
LuaAPI.lua_pushstdcallcfunction(L, templateExecuteFunction);
246246
LuaAPI.lua_rawset(L, -3);
247-
LuaAPI.lua_setglobal(L, "template");
247+
if (0 != LuaAPI.xlua_setglobal(L, "template"))
248+
{
249+
throw new Exception("call xlua_setglobal fail!");
250+
}
248251
}
249252
}
250253
}

‎Assets/XLua/Src/Utils.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,10 @@ static List<string> getPathOfType(Type type)
10921092
public static void LoadCSTable(RealStatePtr L, Type type)
10931093
{
10941094
int oldTop = LuaAPI.lua_gettop(L);
1095-
LuaAPI.lua_getglobal(L, "CS");
1095+
if (0 != LuaAPI.xlua_getglobal(L, "CS"))
1096+
{
1097+
throw new Exception("call xlua_getglobal fail!");
1098+
}
10961099

10971100
List<string> path = getPathOfType(type);
10981101

@@ -1119,7 +1122,10 @@ public static void SetCSTable(RealStatePtr L, Type type, int cls_table)
11191122
{
11201123
int oldTop = LuaAPI.lua_gettop(L);
11211124
cls_table = abs_idx(oldTop, cls_table);
1122-
LuaAPI.lua_getglobal(L, "CS");
1125+
if (0 != LuaAPI.xlua_getglobal(L, "CS"))
1126+
{
1127+
throw new Exception("call xlua_getglobal fail!");
1128+
}
11231129

11241130
List<string> path = getPathOfType(type);
11251131

‎build/make_android_lua53.sh

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mkdir -p build_v7a && cd build_v7a
44
cmake -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=../cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.6 -DANDROID_NATIVE_API_LEVEL=android-9 ../
55
cd ..
66
cmake --build build_v7a --config Release
7+
mkdir -p plugin_lua53/Plugins/Android/libs/armeabi-v7a/
78
cp build_v7a/libxlua.so plugin_lua53/Plugins/Android/libs/armeabi-v7a/libxlua.so
89

910
mkdir -p build_x86 && cd build_x86

‎build/make_android_luajit.sh

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mkdir -p build_lj_v7a && cd build_lj_v7a
1818
cmake -DUSING_LUAJIT=ON -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=../cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.6 -DANDROID_NATIVE_API_LEVEL=android-9 ../
1919
cd "$DIR"
2020
cmake --build build_lj_v7a --config Release
21+
mkdir -p plugin_luajit/Plugins/Android/libs/armeabi-v7a/
2122
cp build_lj_v7a/libxlua.so plugin_luajit/Plugins/Android/libs/armeabi-v7a/libxlua.so
2223

2324

‎build/xlua.c

+23
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,29 @@ LUA_API int xlua_psettable_bypath(lua_State* L, int idx, const char *path) {
285285
return lua_pcall(L, 3, 0, 0);
286286
}
287287

288+
static int c_lua_getglobal(lua_State* L) {
289+
lua_getglobal(L, lua_tostring(L, 1));
290+
return 1;
291+
}
292+
293+
LUA_API int xlua_getglobal (lua_State *L, const char *name) {
294+
lua_pushcfunction(L, c_lua_getglobal);
295+
lua_pushstring(L, name);
296+
return lua_pcall(L, 1, 1, 0);
297+
}
298+
299+
static int c_lua_setglobal(lua_State* L) {
300+
lua_setglobal(L, lua_tostring(L, 1));
301+
return 0;
302+
}
303+
304+
LUA_API int xlua_setglobal (lua_State *L, const char *name) {
305+
lua_pushcfunction(L, c_lua_setglobal);
306+
lua_pushstring(L, name);
307+
lua_pushvalue(L, -3);
308+
return lua_pcall(L, 2, 0, 0);
309+
}
310+
288311
LUA_API int xlua_tryget_cachedud(lua_State *L, int key, int cache_ref) {
289312
lua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);
290313
lua_rawgeti(L, -1, key);

0 commit comments

Comments
 (0)
Please sign in to comment.