MCPcopy Create free account
hub / github.com/Tencent/xLua / ImportGenericType

Function ImportGenericType

Assets/XLua/Src/StaticLuaCallbacks.cs:879–917  ·  view source on GitHub ↗
(RealStatePtr L)

Source from the content-addressed store, hash-verified

877 }
878
879 [MonoPInvokeCallback(typeof(LuaCSFunction))]
880 public static int ImportGenericType(RealStatePtr L)
881 {
882 try
883 {
884 int top = LuaAPI.lua_gettop(L);
885 if (top < 2) return LuaAPI.luaL_error(L, "import generic type need at lease 2 arguments");
886 ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
887 string className = LuaAPI.lua_tostring(L, 1);
888 if (className.EndsWith("<>")) className = className.Substring(0, className.Length - 2);
889 Type genericDef = translator.FindType(className + "`" + (top - 1));
890 if (genericDef == null || !genericDef.IsGenericTypeDefinition())
891 {
892 LuaAPI.lua_pushnil(L);
893 }
894 else
895 {
896 Type[] typeArguments = new Type[top - 1];
897 for(int i = 2; i <= top; i++)
898 {
899
900 typeArguments[i - 2] = getType(L, translator, i);
901 if (typeArguments[i - 2] == null)
902 {
903 return LuaAPI.luaL_error(L, "param need a type");
904 }
905 }
906 Type genericInc = genericDef.MakeGenericType(typeArguments);
907 translator.GetTypeId(L, genericInc);
908 translator.PushAny(L, genericInc);
909 }
910
911 return 1;
912 }
913 catch (System.Exception e)
914 {
915 return LuaAPI.luaL_error(L, "c# exception in xlua.import_type:" + e);
916 }
917 }
918
919 [MonoPInvokeCallback(typeof(LuaCSFunction))]
920 public static int Cast(RealStatePtr L)

Callers

nothing calls this directly

Calls 10

lua_gettopMethod · 0.80
luaL_errorMethod · 0.80
FindMethod · 0.80
lua_tostringMethod · 0.80
FindTypeMethod · 0.80
lua_pushnilMethod · 0.80
GetTypeIdMethod · 0.80
PushAnyMethod · 0.80
getTypeFunction · 0.70

Tested by

no test coverage detected