Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix require #149

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NeoLua.Dbg/NeoLua.Dbg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Neo.Lua.Dbg</AssemblyName>
<RootNamespace>Neo.IronLua</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFrameworks>net45;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp3.1</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>NeoLua.snk</AssemblyOriginatorKeyFile>
<PackageId>NeoLuaDebug</PackageId>
Expand Down
4 changes: 2 additions & 2 deletions NeoLua.NuGet/common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<RepositoryType>git</RepositoryType>

<AssemblyVersion>5.3.0.0</AssemblyVersion>
<FileVersion>1.3.14.0</FileVersion>
<FileVersion>1.4.0.0</FileVersion>

<!--<VersionAdd>beta.0</VersionAdd>-->
<VersionAdd>beta.0</VersionAdd>
<SimpleVersionPattern>^(\d+)\.(\d+)\.(\d+)</SimpleVersionPattern>
<SimpleVersion>$([System.Text.RegularExpressions.Regex]::Match($(FileVersion), $(SimpleVersionPattern)))</SimpleVersion>

Expand Down
6 changes: 6 additions & 0 deletions NeoLua.Test/ControlStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ public void Control19()
TestCode(GetLines("Lua.Control19.lua"), 4);
}

[TestMethod]
public void Control20()
{
TestCode(GetLines("Lua.Control20.lua"), 500000500000, 500000500001);
}

[TestMethod]
public void TestVariableAssign01()
{
Expand Down
8 changes: 8 additions & 0 deletions NeoLua.Test/Lua/Control20.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local t = {};
local j = 1;
for i = 500000500000, 500000500001 do
print(tostring(i));
t[j] = i;
j = j + 1;
end;
return t[1], t[2];
117 changes: 109 additions & 8 deletions NeoLua.Test/LuaTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IronLua;

Expand All @@ -13,6 +11,45 @@ namespace LuaDLR.Test
[TestClass]
public class LuaTableTests : TestHelper
{
#region -- class ObjectInit ---------------------------------------------------

public const string ObjectInitLua = "";

public class ObjectInit
{
private readonly object[] values = new object[10];

public void TestEvent()
{
Assert.IsNotNull(Event);
}

public object this[int idx] { get => values[idx]; set => values[idx] = value; }

public int fieldValue;

public int Value { get; set; } = 100;
public Func<int> Action { get; set; }

public event EventHandler Event;
}

#endregion

#region -- class ObjectInitS --------------------------------------------------

public class ObjectInitS
{
public ObjectInitS(LuaTable t)
{
Value = (int)t.GetMemberValue(nameof(Value));
}

public int Value { get; }
}

#endregion

#region -- TestMember -------------------------------------------------------------

[TestMethod]
Expand Down Expand Up @@ -393,19 +430,83 @@ public void TestMetaTable11()
#region -- TestConvert ------------------------------------------------------------

[TestMethod]
public void TestConvert01()
public void TestConvert01a()
=> TestCode("return cast(LuaDLR.Test.LuaTypeTests.SubStruct, { Value = 2 }).Value", 2);

[TestMethod]
public void TestConvert01b()
{
using (Lua l = new Lua())
using (var l = new Lua())
{
l.PrintExpressionTree = Console.Out;
var g = l.CreateEnvironment();
var r = g.DoChunk("return cast(System.Diagnostics.ProcessStartInfo, { FileName = 'Test.exe', Arguments = 'aaa' });", "dummy");
ProcessStartInfo psi = (ProcessStartInfo)r[0];
Assert.IsTrue(psi.FileName == "Test.exe");
Assert.IsTrue(psi.Arguments == "aaa");
var r = g.DoChunk("return cast(LuaDLR.Test.LuaTableTests.ObjectInit, { Value = 42, 1, 2, 3 });", "dummy");
var o = (ObjectInit)r[0];
Assert.AreEqual(o.Value, 42);
Assert.AreEqual(o[0], 1);
Assert.AreEqual(o[1], 2);
Assert.AreEqual(o[2], 3);
}
} // func TestConvert01

[TestMethod]
public void TestConvert02a()
{
using (var l = new Lua())
{
var g = l.CreateEnvironment();
var t = (LuaTable)g.DoChunk("return { fieldValue = 42, Value = 23, Action = function() : int return 44 end, Event = function(s, e) : void print('test') end, 1, 2, 3 };", "dummy")[0];

var o = t.InitObject<ObjectInit>(true);
Assert.AreEqual(o.Value, 23);
Assert.AreEqual(o.fieldValue, 42);
Assert.AreEqual(o.Action(), 44);
o.TestEvent();
Assert.AreEqual(o[0], 1);
Assert.AreEqual(o[1], 2);
Assert.AreEqual(o[2], 3);
}
}

[TestMethod]
public void TestConvert02b()
{
using (var l = new Lua())
{
var g = l.CreateEnvironment();
var t = (LuaTable)g.DoChunk("return { fieldValue = 42, err = 23, Value = 23, Action = function() : int return 44 end, Event = function(s, e) : void print('test') end, 1, 2, 3 };", "dummy")[0];

var o = t.InitObject<ObjectInit>(false);
Assert.AreEqual(o.Value, 23);
Assert.AreEqual(o.fieldValue, 42);
Assert.AreEqual(o.Action(), 44);
o.TestEvent();
Assert.AreEqual(o[0], 1);
Assert.AreEqual(o[1], 2);
Assert.AreEqual(o[2], 3);
}
}

[TestMethod]
public void TestConvert02c()
{
using (var l = new Lua())
{
var g = l.CreateEnvironment();
var t = (LuaTable)g.DoChunk("return { err = 23 };", "dummy")[0];

try
{
var o = t.InitObject<ObjectInit>(true);
Assert.Fail();
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}
}
}

#endregion

#region -- Length -----------------------------------------------------------------
Expand Down
37 changes: 31 additions & 6 deletions NeoLua.Test/LuaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IronLua;
using static LuaDLR.Test.LuaTableTests;

namespace LuaDLR.Test
{
Expand Down Expand Up @@ -35,6 +34,9 @@ public override int Foo()
public class DataTypeTest
{
public Type DataType;

public static explicit operator DataTypeTest(LuaTable t)
=> t.SetObjectMember(new DataTypeTest());
}

public class Graph
Expand Down Expand Up @@ -308,14 +310,14 @@ public void TypeTest07()
public void TypeTest08()
{
TestCode(Lines("local t : System.Type = clr.System.Text.StringBuilder;",
"return t"), typeof(System.Text.StringBuilder));
"return t"), typeof(StringBuilder));
}

[TestMethod]
public void TypeTest09()
{
TestCode(Lines("local t : LuaDLR.Test.LuaTypeTests.DataTypeTest = { DataType = clr.System.Text.StringBuilder };",
"return t.DataType"), typeof(System.Text.StringBuilder));
"return t.DataType"), typeof(StringBuilder));
}

[TestMethod]
Expand Down Expand Up @@ -497,9 +499,32 @@ public void CtorTest02()
}

[TestMethod]
public void CtorTest03()
public void CtorTest10()
{
TestCode("return cast(LuaDLR.Test.LuaTypeTests.SubStruct, { Value = 2 }).Value", 2);
using (var l = new Lua())
{
l.PrintExpressionTree = Console.Out;
var g = l.CreateEnvironment();
var r = g.DoChunk("return clr.LuaDLR.Test.LuaTableTests.ObjectInit(){ Value = 42, 1, 2, 3 };", "dummy");
var o = (ObjectInit)r[0];
Assert.AreEqual(o.Value, 42);
Assert.AreEqual(o[0], 1);
Assert.AreEqual(o[1], 2);
Assert.AreEqual(o[2], 3);
}
}

[TestMethod]
public void CtorTest11()
{
using (var l = new Lua())
{
l.PrintExpressionTree = Console.Out;
var g = l.CreateEnvironment();
var r = g.DoChunk("return clr.LuaDLR.Test.LuaTableTests.ObjectInitS{ Value = 42, 1, 2, 3 };", "dummy");
var o = (ObjectInitS)r[0];
Assert.AreEqual(o.Value, 42);
}
}

[TestMethod]
Expand Down
2 changes: 2 additions & 0 deletions NeoLua.Test/NeoLua.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<None Remove="Lua\Control11.lua" />
<None Remove="Lua\Control12.lua" />
<None Remove="Lua\Control19.lua" />
<None Remove="Lua\Control20.lua" />
<None Remove="Lua\Coroutines01.lua" />
<None Remove="Lua\EnvDynamicCall01.lua" />
<None Remove="Lua\Function08.lua" />
Expand All @@ -51,6 +52,7 @@
<EmbeddedResource Include="Lua\Control11.lua" />
<EmbeddedResource Include="Lua\Control12.lua" />
<EmbeddedResource Include="Lua\Control19.lua" />
<EmbeddedResource Include="Lua\Control20.lua" />
<EmbeddedResource Include="Lua\Coroutines01.lua" />
<EmbeddedResource Include="Lua\EnvDynamicCall01.lua" />
<EmbeddedResource Include="Lua\Function08.lua" />
Expand Down
3 changes: 0 additions & 3 deletions NeoLua.Test/RunLuaTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IronLua;

Expand Down
Loading