Skip to content

Commit

Permalink
把常用的(RawObject)转换器给加上
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Apr 12, 2018
1 parent 790f08f commit dbe33ba
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 19 deletions.
20 changes: 1 addition & 19 deletions Assets/XLua/Examples/11_RawObject/RawObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@

namespace XLuaTest
{
public class IntObject : RawObject
{
int mTarget;

public IntObject(int i)
{
mTarget = i;
}

public object Target
{
get
{
return mTarget;
}
}
}

public class RawObjectTest : MonoBehaviour
{
public static void PrintType(object o)
Expand All @@ -35,7 +17,7 @@ void Start()
//直接传1234到一个object参数,xLua将选择能保留最大精度的long来传递
luaenv.DoString("CS.XLuaTest.RawObjectTest.PrintType(1234)");
//通过一个继承RawObject的类,能实现指明以一个int来传递
luaenv.DoString("CS.XLuaTest.RawObjectTest.PrintType(CS.XLuaTest.IntObject(1234))");
luaenv.DoString("CS.XLuaTest.RawObjectTest.PrintType(CS.XLua.Cast.Int32(1234))");
luaenv.Dispose();
}

Expand Down
84 changes: 84 additions & 0 deletions Assets/XLua/Src/RawObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,87 @@ public interface RawObject
object Target { get; }
}
}

namespace XLua.Cast
{
public class Any<T> : RawObject
{
T mTarget;

public Any(T i)
{
mTarget = i;
}

public object Target
{
get
{
return mTarget;
}
}
}

public class Byte : Any<byte>
{
public Byte(byte i) : base(i)
{
}
}

public class SByte : Any<sbyte>
{
public SByte(sbyte i) : base(i)
{
}
}

public class Char : Any<char>
{
public Char(char i) : base(i)
{
}
}

public class Int16 : Any<short>
{
public Int16(short i) : base(i)
{
}
}

public class UInt16 : Any<ushort>
{
public UInt16(ushort i) : base(i)
{
}
}

public class Int32 : Any<int>
{
public Int32(int i) : base(i)
{
}
}

public class UInt32 : Any<uint>
{
public UInt32(uint i) : base(i)
{
}
}

public class UInt64 : Any<ulong>
{
public UInt64(ulong i) : base(i)
{
}
}

public class Float : Any<float>
{
public Float(float i) : base(i)
{
}
}
}

0 comments on commit dbe33ba

Please sign in to comment.