From 0b2a49edc3eecebbfc15e0672efc06d79735ff91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?johnche=28=E8=BD=A6=E9=9B=84=E7=94=9F=29?= Date: Mon, 19 Mar 2018 14:42:54 +0800 Subject: [PATCH] fix https://github.com/Tencent/xLua/issues/321 --- .../XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt b/Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt index e9c1365e5..1f8c11cfd 100644 --- a/Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt +++ b/Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt @@ -168,8 +168,8 @@ namespace XLua if (type == LuaTypes.LUA_TUSERDATA ) { val = (<%=full_type_name%>)FastGetCSObj(L, index); - }<%if not is_enum then%> - else if (type ==LuaTypes.LUA_TTABLE) + } + else if (type == LuaTypes.LUA_TTABLE) { val = new <%=full_type_name%>(); int top = LuaAPI.lua_gettop(L); @@ -180,10 +180,14 @@ namespace XLua } LuaAPI.lua_pop(L, 1); <%end)%> - }<%end%> + }<%if not type_info.Type.IsValueType then%> + else if (type == LuaTypes.LUA_TNIL || type == LuaTypes.LUA_TNONE) + { + val = null; + }<%end%> else { - val = (<%=full_type_name%>)objectCasters.GetCaster(typeof(<%=full_type_name%>))(L, index, null); + throw new Exception("can not cast " + LuaAPI.lua_type(L, index) + " to " + typeof(<%=full_type_name%>)); } } <%end)%>