Commit 3da6e77c authored by Isaac Brodsky's avatar Isaac Brodsky
Browse files

Structs initialized via the default constructor

parent f9c5a807
......@@ -1096,7 +1096,7 @@ namespace NLua
LuaLib.LuaRemove (luaState, 1);
var constructors = klass.UnderlyingSystemType.GetConstructors ();
foreach (var constructor in constructors) {
bool isConstructor = MatchParameters (luaState, constructor, ref validConstructor);
......@@ -1113,6 +1113,16 @@ namespace NLua
return 1;
}
}
if (klass.UnderlyingSystemType.IsValueType)
{
int numLuaParams = LuaLib.LuaGetTop (luaState);
if (numLuaParams == 0)
{
translator.Push (luaState, Activator.CreateInstance (klass.UnderlyingSystemType));
return 1;
}
}
string constructorName = (constructors.Length == 0) ? "unknown" : constructors [0].Name;
translator.ThrowError (luaState, String.Format ("{0} does not contain constructor({1}) argument match",
......
......@@ -196,7 +196,6 @@ namespace NLuaTest
}
}
/*
* Tests structure assignment
*/
......@@ -211,10 +210,24 @@ namespace NLuaTest
lua.DoString ("struct=TestStruct(2)");
lua.DoString ("test.Struct = struct");
lua.DoString ("val=test.Struct.val");
Assert.AreEqual (2.0d, (double)lua ["val"]);
Assert.AreEqual (2.0d, (double)lua ["val"]);
}
}
/*
* Tests structure creation via the default constructor
*/
[Test]
public void TestStructDefaultConstructor()
{
using (Lua lua = new Lua())
{
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestStruct=luanet.import_type('NLuaTest.Mock.TestStruct')");
lua.DoString ("struct=TestStruct()");
}
}
[Test]
public void TestStructHashesEqual()
{
......
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