ソースを参照

chore: add meta tests

akeit0 1 週間 前
コミット
46cbb93b42
1 ファイル変更15 行追加4 行削除
  1. 15 4
      tests/Lua.Tests/LuaObjectTests.cs

+ 15 - 4
tests/Lua.Tests/LuaObjectTests.cs

@@ -47,6 +47,12 @@ public partial class LuaTestObj
         await Task.Delay(1);
         return x + y;
     }
+    
+    [LuaMetamethod(LuaObjectMetamethod.Unm)]
+    public LuaTestObj Unm()
+    {
+        return new LuaTestObj() { x = -x, y = -y };
+    }
 
     [LuaMember]
     public object GetObj() => this;
@@ -246,12 +252,17 @@ public class LuaObjectTests
         state.Environment["TestObj"] = userData;
         var results = await state.DoStringAsync("""
                                                 function testLen(obj)
-                                                    local ret=  #obj
-                                                    return ret
+                                                    return #obj
                                                 end
-                                                return testLen(TestObj.create(1, 2))
+                                                local obj = TestObj.create(1, 2)
+                                                return testLen(TestObj.create(1, 2)),-obj
                                                 """);
-        Assert.That(results, Has.Length.EqualTo(1));
+        Assert.That(results, Has.Length.EqualTo(2));
         Assert.That(results[0].Read<double>(), Is.EqualTo(3));
+        Assert.That(results[1].Read<object>(), Is.TypeOf<LuaTestObj>());
+        var objUnm = results[1].Read<LuaTestObj>();
+        Assert.That(objUnm.X, Is.EqualTo(-1));
+        Assert.That(objUnm.Y, Is.EqualTo(-2));
+        
     }
 }