Commit 8a89f183 authored by Bradley Faskowitz's avatar Bradley Faskowitz Committed by Vinicius Jarina
Browse files

For a function on a net object with string parameters, the 'extractor' for a...

For a function on a net object with string parameters, the 'extractor' for a null string would return an object type.  This extractor is cached, and on the next invocation, a non-null string parameter would try to be extracted as an object type, which would cause a failure.
parent f16398f8
...@@ -128,10 +128,8 @@ namespace NLua ...@@ -128,10 +128,8 @@ namespace NLua
} }
else if (netParamIsString) else if (netParamIsString)
{ {
if (luaState.IsString(stackPos)) if (luaState.IsString(stackPos) || luatype == LuaType.Nil)
return _extractValues[paramType]; return _extractValues[paramType];
if (luatype == LuaType.Nil)
return _extractNetObject; // kevinh - silently convert nil to a null string pointer
} }
else if (paramType == typeof(LuaTable)) else if (paramType == typeof(LuaTable))
{ {
......
...@@ -1100,6 +1100,26 @@ namespace NLuaTest ...@@ -1100,6 +1100,26 @@ namespace NLuaTest
Assert.AreEqual("str", t1.getStrVal()); Assert.AreEqual("str", t1.getStrVal());
} }
} }
/*
* Tests calling of an object's method with a nil string param value,
* then a non-null string value. This test ensures that after a method
* is cached, a string parameter can be retrieved appropriately.
*/
[Test]
public void CallObjectMethodNilStringParam()
{
using (Lua lua = new Lua())
{
TestTypes.TestClass t1 = new TestTypes.TestClass();
lua["netobj"] = t1;
string inputParam = "foo";
lua.DoString($"val=netobj:getParamStrVal(nil)");
lua.DoString($"val=netobj:getParamStrVal('{inputParam}')");
string val = (string)lua.GetString("val");
Assert.AreEqual(inputParam, val);
}
}
/* /*
* Tests calling of an object's method with no overloading * Tests calling of an object's method with no overloading
* and out parameters * and out parameters
......
...@@ -115,6 +115,11 @@ namespace NLuaTest.TestTypes ...@@ -115,6 +115,11 @@ namespace NLuaTest.TestTypes
return strVal; return strVal;
} }
public string getParamStrVal(string str)
{
return str;
}
public int outVal(out int val) public int outVal(out int val)
{ {
val = 5; val = 5;
......
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