private void push_map(SDataBuff data, NParam o, IntPtr L) { SMapReader pmap = data.mapReader; LuaAPI.lua_newtable(L); if (pmap != null && o.DType == ParamType.ptype_object) { NStruct ps = NStructManager.GetInstance().Find(o.TypeName); if (ps != null) { SDataBuff k = new SDataBuff(); SDataBuff v = new SDataBuff(); while (pmap.Next(k, v)) { NParam p = ps.Get(k.intValue); if (p != null) { LuaAPI.lua_pushstring(L, p.Name); push_data(v, L, p); LuaAPI.xlua_psettable(L, -3); } } } } }
private Sio.SData format_map(IntPtr L, int index, NParam o) { Sio.SMapWriter pmap = new Sio.SMapWriter(); Sio.SData data = new Sio.SData(pmap); if (LuaAPI.lua_istable(L, index) && o.DType == ParamType.ptype_object) { NStruct ps = NStructManager.GetInstance().Find(o.TypeName); if (ps != null) { LuaAPI.lua_pushnil(L); while (LuaAPI.lua_next(L, index) != 0) { if (LuaAPI.lua_isstring(L, -2)) { NParam findparam = ps.Get(LuaAPI.lua_tostring(L, -2)); if (findparam != null) { pmap.write(findparam.Id, format_data(findparam, L, LuaAPI.lua_gettop(L), true)); } } LuaAPI.lua_pop(L, 1); } } } return(data); }
public void TestStruct1() { NStruct builder = NStruct.RandomDomain(); var script = builder .CustomUsing() .HiddenNamespace() .Attribute("[StructLayout(LayoutKind.Explicit)]") .Access(Natasha.Reverser.Model.AccessTypes.Public) .Name("EnumUT1") .Field(item => { item.Attribute <FieldOffsetAttribute>("0").Public().Name("Apple").Type <int>(); }) .Field(item => { item.Attribute <FieldOffsetAttribute>("0").Public().Name("Orange").Type <int>(); }) .Script; Assert.Equal($"using System.Runtime.InteropServices;{Environment.NewLine}using System;{Environment.NewLine}[StructLayout(LayoutKind.Explicit)]{Environment.NewLine}public struct EnumUT1{{{Environment.NewLine}[System.Runtime.InteropServices.FieldOffsetAttribute(0)]{Environment.NewLine}public System.Int32 Apple;{Environment.NewLine}[System.Runtime.InteropServices.FieldOffsetAttribute(0)]{Environment.NewLine}public System.Int32 Orange;{Environment.NewLine}}}", script); Assert.NotNull(builder.GetType()); }
public void TestStruct() { NStruct builder = NStruct.RandomDomain(); var script = builder .CustomUsing() .HiddenNamespace() .Access(Natasha.Reverser.Model.AccessTypes.Public) .Name("EnumUT1") .Field(item => { item.Public().Name("Apple").Type <int>(); }) .Field(item => { item.Public().Name("Orange").Type <string>(); }) .Property(item => { item.Public().Name("Banana").Type <NClass>(); }) .Script; Assert.Equal($"using System;{Environment.NewLine}using Natasha.CSharp;{Environment.NewLine}public struct EnumUT1{{{Environment.NewLine}public System.Int32 Apple;{Environment.NewLine}public System.String Orange;{Environment.NewLine}public Natasha.CSharp.NClass Banana{{{Environment.NewLine}get;{Environment.NewLine}set;{Environment.NewLine}}}{Environment.NewLine}}}", script); Assert.NotNull(builder.GetType()); }
public static void Show() { //默认共享域 NStruct nStruct = new NStruct(); //nStruct // .Namespace("Core30") // .OopName("Test") // .Ctor(builder => builder // .MemberAccess(AccessTypes.Public) // .Param<string>("name") // .Body("Name=name;")) // .PublicField<string>("Name"); //var type = nStruct.GetType(); var domain1 = DomainManagment.Create("TempDomain"); // nStruct = new NStruct(); // nStruct // .Namespace("Core30") // .OopName("Test1") // .Ctor(builder => builder // .MemberAccess(AccessTypes.Public) // .Param<string>("name") // .Body(@"Name=name+""1"";")) // .PublicField<string>("Name"); //var type1 = nStruct.GetType(); // domain1.RemoveType(type1); // nStruct = new NStruct(); // nStruct // .Namespace("Core30") // .OopName("Test") // .Ctor(builder => builder // .MemberAccess(AccessTypes.Public) // .Param<string>("name") // .Body(@"Name=name+""2"";")) // .PublicField<string>("Name"); // var type3 = nStruct.GetType(); // domain1.RemoveType(type3); nStruct = new NStruct(); nStruct.Complier.Domain = domain1; nStruct .Namespace("Core30") .OopName("Test") .Ctor(builder => builder .MemberAccess(AccessTypes.Public) .Param <string>("name") .Body(@"Name=name+""3"";")) .PublicField <string>("Name"); var type4 = nStruct.GetType(); //nStruct = new NStruct(); //nStruct // .InDomain(domain1) // .Namespace("Core30") // .OopName("Test") // .Ctor(builder => builder // .MemberAccess(AccessTypes.Public) // .Param<string>("name") // .Body(@"Name=name+""1"";")) // .PublicField<string>("Name"); //var type2 = nStruct.GetType(); var temp = FastMethodOperator.New; temp.Complier.Domain = domain1; temp //.Using<Test>() //.Using(type) .Using(type4) //.MethodAttribute<MethodImplAttribute>("MethodImplOptions.NoInlining") .MethodBody(@" Test obj = new Test(""Hello World!""); Console.WriteLine(obj.Name);" ); action = temp.Complie <Action>(); action(); DomainManagment.Get("TempDomain").Dispose(); }