private static void GenerateConstructorMethod(ClassDescription cd, ConstructorDescription c, Lua4NetSerializer serializer) { serializer.NewLine(); string ctordef = string.Format("private static int {0}({1} Instance,IntPtr l)",c.NickName,cd.ClassName); GeneratorHelper.GenerateCSFunction(ctordef, serializer, s => { int nParameterIndex = 3; foreach (MethodFieldDescription mfd in c.InputArgs) { switch (mfd.Type) { case MessageFieldType.NumberType: { switch (mfd.GetNumberType()) { case NumberType.Boolean: { serializer.NewLine(string.Format("{0} {1} = LuaApi.lua_tonumber(l,{2})!=0;", mfd.TypeName, mfd.Name, nParameterIndex)); break; } case NumberType.Enum: case NumberType.Numeric: { serializer.NewLine(string.Format("{0} {1} = ({0})LuaApi.lua_tonumber(l,{2});", mfd.TypeName, mfd.Name, nParameterIndex)); break; } } break; } case MessageFieldType.StringType: { serializer.NewLine(string.Format("string {0} = LuaApi.lua_tostring(l,{1});", mfd.Name, nParameterIndex)); break; } default: { serializer.NewLine(string.Format("int {0}id = (int)LuaApi.lua_tonumber(l,{1});", mfd.Name, nParameterIndex)); serializer.NewLine(string.Format("{0} {1} = LuaManager.Instance.GetObjectT<{0}>({1}id);", mfd.TypeName, mfd.Name)); break; } } ++nParameterIndex; } serializer.NewLine(string.Format("Instance = new {0}({1});", cd.ClassName, GeneratorHelper.GenerateParameter(c.Ci.GetParameters().ToList()))); serializer.NewLine("int id = LuaManager.Instance.PushStackObject(Instance);"); serializer.NewLine("LuaApi.lua_pushnumber(l,id);"); serializer.NewLine("return 1;"); }); }
private static void GetConstructor(Assembly a, ClassDescription result, ScriptableClass sc) { result.Constructors = new List<ConstructorDescription>(); foreach (ScriptableMethod ctor in sc.Constructor) { ConstructorInfo info = result.Class.GetConstructor(ctor.GetArgs(result)); if (null != info) { ConstructorDescription ctordesc = new ConstructorDescription(); ctordesc.Ci = info; ctordesc.Default = ctor.DefaultConstructor; GetMethod(ctordesc, info, string.IsNullOrEmpty(ctor.NickName)?ctor.Name:ctor.NickName,string.Empty); result.Constructors.Add(ctordesc); } else { Console.WriteLine(string.Format("constructor {0} not found,In = {1}", ctor.Name, ctor.In)); } } }
private static void GetConstructor(Assembly a, ClassDescription result, Type type) { result.Constructors = new List<ConstructorDescription>(); foreach (ConstructorInfo ci in type.GetConstructors()) { ScriptableAttribute attr = GetAttribute(ci); if (null != attr) { ConstructorDescription ctordesc = new ConstructorDescription(); ctordesc.Ci = ci; GetMethod(ctordesc, ci, attr.Name, string.Empty); result.Constructors.Add(ctordesc); } } }