(RealStatePtr L, Type type, out bool is_first)
| 1007 | |
| 1008 | |
| 1009 | public int getTypeId(RealStatePtr L, Type type, out bool is_first) |
| 1010 | { |
| 1011 | int type_id; |
| 1012 | is_first = false; |
| 1013 | if (!typeIdMap.TryGetValue(type, out type_id)) // no reference |
| 1014 | { |
| 1015 | if (type.IsArray) |
| 1016 | { |
| 1017 | if (common_array_meta == -1) throw new Exception("Fatal Exception! Array Metatable not inited!"); |
| 1018 | return common_array_meta; |
| 1019 | } |
| 1020 | if (typeof(MulticastDelegate).IsAssignableFrom(type)) |
| 1021 | { |
| 1022 | if (common_delegate_meta == -1) throw new Exception("Fatal Exception! Delegate Metatable not inited!"); |
| 1023 | TryDelayWrapLoader(L, type); |
| 1024 | return common_delegate_meta; |
| 1025 | } |
| 1026 | |
| 1027 | is_first = true; |
| 1028 | Type alias_type = null; |
| 1029 | aliasCfg.TryGetValue(type, out alias_type); |
| 1030 | LuaAPI.luaL_getmetatable(L, alias_type == null ? type.FullName : alias_type.FullName); |
| 1031 | |
| 1032 | if (LuaAPI.lua_isnil(L, -1)) //no meta yet, try to use reflection meta |
| 1033 | { |
| 1034 | LuaAPI.lua_pop(L, 1); |
| 1035 | |
| 1036 | if (TryDelayWrapLoader(L, alias_type == null ? type : alias_type)) |
| 1037 | { |
| 1038 | LuaAPI.luaL_getmetatable(L, alias_type == null ? type.FullName : alias_type.FullName); |
| 1039 | } |
| 1040 | else |
| 1041 | { |
| 1042 | throw new Exception("Fatal: can not load metatable of type:" + type); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | //循环依赖,自身依赖自己的class,比如有个自身类型的静态readonly对象。 |
| 1047 | if (typeIdMap.TryGetValue(type, out type_id)) |
| 1048 | { |
| 1049 | LuaAPI.lua_pop(L, 1); |
| 1050 | } |
| 1051 | else |
| 1052 | { |
| 1053 | if (type.IsEnum()) |
| 1054 | { |
| 1055 | LuaAPI.xlua_pushasciistring(L, "__band"); |
| 1056 | LuaAPI.lua_pushstdcallcfunction(L, metaFunctions.EnumAndMeta); |
| 1057 | LuaAPI.lua_rawset(L, -3); |
| 1058 | LuaAPI.xlua_pushasciistring(L, "__bor"); |
| 1059 | LuaAPI.lua_pushstdcallcfunction(L, metaFunctions.EnumOrMeta); |
| 1060 | LuaAPI.lua_rawset(L, -3); |
| 1061 | } |
| 1062 | if (typeof(IEnumerable).IsAssignableFrom(type)) |
| 1063 | { |
| 1064 | LuaAPI.xlua_pushasciistring(L, "__pairs"); |
| 1065 | LuaAPI.lua_getref(L, enumerable_pairs_func); |
| 1066 | LuaAPI.lua_rawset(L, -3); |
no test coverage detected