Unverified Commit 7ff6e7c5 authored by Thomas Nind's avatar Thomas Nind Committed by GitHub
Browse files

Use configurable MaximumRecursion (#368)

* Made RegisterGlobal maximum recursion level user configurable

* Added test for MaximumRecursion field

* Added reference to System.Data

* Revert "Added test for MaximumRecursion field"

This reverts commit d04299638765cdb73111a61288b7654ef51781ec.

* Re added test (after fixing accidental whitespace changes)

* Revert "Added reference to System.Data"

This reverts commit 3e8838383a8d4f3e883bd3209614060fc1c755d1.

* Changed TestMaximumRecursion to use NLuaTest.TestTypes.TestClass

* Fix for NUnitLite not having `Greater` assertion
parent cd740aa3
......@@ -213,6 +213,11 @@ namespace NLua
//";
public bool UseTraceback { get; set; } = false;
/// <summary>
/// The maximum number of recursive steps to take when adding global reference variables. Defaults to 2.
/// </summary>
public int MaximumRecursion { get; set;} = 2;
#region Globals auto-complete
/// <summary>
/// An alphabetically sorted list of all globals (objects, methods, etc.) externally added to this Lua instance
......@@ -631,7 +636,7 @@ namespace NLua
_globals.Add(path + "(");
}
// If the type is a class or an interface and recursion hasn't been running too long, list the members
else if ((type.IsClass || type.IsInterface) && type != typeof(string) && recursionCounter < 2)
else if ((type.IsClass || type.IsInterface) && type != typeof(string) && recursionCounter < MaximumRecursion)
{
#region Methods
foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
......
......@@ -2796,6 +2796,32 @@ namespace NLuaTest
}
}
[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
[TestCase(3)]
public void TestMaximumRecursion(int maxRecursion)
{
var tc = new TestClass();
tc.LongValue = 5;
using (Lua lua = new Lua())
{
lua.MaximumRecursion = maxRecursion;
lua.LoadCLRPackage();
lua["myTc"] = tc;
if(maxRecursion == 0)
Assert.AreEqual(1,lua.Globals.Count()); //register only the root reference
else
Assert.IsTrue(lua.Globals.Count() > 1); //many globals registered (all sub properties)
// ensure even with 0 recursion we can still call properties
object o = lua.DoString(@"return myTc.LongValue")[0];
Assert.AreEqual(5, o);
}
}
static Lua m_lua;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment