|
@@ -1,59 +1,59 @@
|
|
|
using Lua.Standard;
|
|
using Lua.Standard;
|
|
|
|
|
|
|
|
namespace Lua.Tests;
|
|
namespace Lua.Tests;
|
|
|
|
|
+
|
|
|
[LuaObject]
|
|
[LuaObject]
|
|
|
-public partial class LuaTestObj {
|
|
|
|
|
|
|
+public partial class LuaTestObj
|
|
|
|
|
+{
|
|
|
int x;
|
|
int x;
|
|
|
int y;
|
|
int y;
|
|
|
|
|
|
|
|
[LuaMember("x")]
|
|
[LuaMember("x")]
|
|
|
- public int X {
|
|
|
|
|
|
|
+ public int X
|
|
|
|
|
+ {
|
|
|
get => x;
|
|
get => x;
|
|
|
set => x = value;
|
|
set => x = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[LuaMember("y")]
|
|
[LuaMember("y")]
|
|
|
- public int Y {
|
|
|
|
|
|
|
+ public int Y
|
|
|
|
|
+ {
|
|
|
get => y;
|
|
get => y;
|
|
|
set => y = value;
|
|
set => y = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[LuaMember("create")]
|
|
[LuaMember("create")]
|
|
|
- public static LuaTestObj Create(int x, int y) {
|
|
|
|
|
- return new LuaTestObj() {
|
|
|
|
|
- x = x,
|
|
|
|
|
- y = y
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ public static LuaTestObj Create(int x, int y)
|
|
|
|
|
+ {
|
|
|
|
|
+ return new LuaTestObj() { x = x, y = y };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[LuaMetamethod(LuaObjectMetamethod.Add)]
|
|
[LuaMetamethod(LuaObjectMetamethod.Add)]
|
|
|
- public static LuaTestObj Add(LuaTestObj a, LuaTestObj b) {
|
|
|
|
|
- return new LuaTestObj() {
|
|
|
|
|
- x = a.x + b.x,
|
|
|
|
|
- y = a.y + b.y
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ public static LuaTestObj Add(LuaTestObj a, LuaTestObj b)
|
|
|
|
|
+ {
|
|
|
|
|
+ return new LuaTestObj() { x = a.x + b.x, y = a.y + b.y };
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
[LuaMetamethod(LuaObjectMetamethod.Sub)]
|
|
[LuaMetamethod(LuaObjectMetamethod.Sub)]
|
|
|
- public static async Task<LuaTestObj> Sub(LuaTestObj a, LuaTestObj b) {
|
|
|
|
|
|
|
+ public static async Task<LuaTestObj> Sub(LuaTestObj a, LuaTestObj b)
|
|
|
|
|
+ {
|
|
|
await Task.Delay(1);
|
|
await Task.Delay(1);
|
|
|
- return new LuaTestObj() {
|
|
|
|
|
- x = a.x - b.x,
|
|
|
|
|
- y = a.y - b.y
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ return new LuaTestObj() { x = a.x - b.x, y = a.y - b.y };
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
[LuaObject]
|
|
[LuaObject]
|
|
|
public partial class TestUserData
|
|
public partial class TestUserData
|
|
|
{
|
|
{
|
|
|
- [LuaMember]
|
|
|
|
|
- public int Property { get; set; }
|
|
|
|
|
|
|
+ [LuaMember] public int Property { get; init; }
|
|
|
|
|
|
|
|
- [LuaMember]
|
|
|
|
|
- public LuaValue LuaValueProperty { get; set; }
|
|
|
|
|
|
|
+ [LuaMember] public int ReadOnlyProperty { get; }
|
|
|
|
|
|
|
|
- [LuaMember("p2")]
|
|
|
|
|
- public string PropertyWithName { get; set; } = "";
|
|
|
|
|
|
|
+ [LuaMember] public int SetOnlyProperty { set { } }
|
|
|
|
|
+
|
|
|
|
|
+ [LuaMember] public LuaValue LuaValueProperty { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ [LuaMember("p2")] public string PropertyWithName { get; set; } = "";
|
|
|
|
|
|
|
|
[LuaMember]
|
|
[LuaMember]
|
|
|
public static void MethodVoid()
|
|
public static void MethodVoid()
|
|
@@ -201,7 +201,7 @@ public class LuaObjectTests
|
|
|
Assert.That(results, Has.Length.EqualTo(1));
|
|
Assert.That(results, Has.Length.EqualTo(1));
|
|
|
Assert.That(results[0], Is.EqualTo(new LuaValue("Called!")));
|
|
Assert.That(results[0], Is.EqualTo(new LuaValue("Called!")));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
[Test]
|
|
[Test]
|
|
|
public async Task Test_ArithMetamethod()
|
|
public async Task Test_ArithMetamethod()
|
|
|
{
|
|
{
|
|
@@ -209,7 +209,7 @@ public class LuaObjectTests
|
|
|
|
|
|
|
|
var state = LuaState.Create();
|
|
var state = LuaState.Create();
|
|
|
state.OpenBasicLibrary();
|
|
state.OpenBasicLibrary();
|
|
|
- state.Environment["TestObj"]=userData;
|
|
|
|
|
|
|
+ state.Environment["TestObj"] = userData;
|
|
|
var results = await state.DoStringAsync("""
|
|
var results = await state.DoStringAsync("""
|
|
|
local a = TestObj.create(1, 2)
|
|
local a = TestObj.create(1, 2)
|
|
|
local b = TestObj.create(3, 4)
|
|
local b = TestObj.create(3, 4)
|