Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
c1b3a950
Commit
c1b3a950
authored
Dec 29, 2014
by
Isaac Brodsky
Browse files
Fix calling methods with nullable parameters (null could not be passed)
parent
fb177cdf
Changes
3
Show whitespace changes
Inline
Side-by-side
Core/NLua/CheckType.cs
View file @
c1b3a950
...
@@ -103,8 +103,13 @@ namespace NLua
...
@@ -103,8 +103,13 @@ namespace NLua
var
underlyingType
=
Nullable
.
GetUnderlyingType
(
paramType
);
var
underlyingType
=
Nullable
.
GetUnderlyingType
(
paramType
);
if
(
underlyingType
!=
null
)
if
(
underlyingType
!=
null
)
{
// null can always be assigned to nullable
if
(
luatype
==
LuaTypes
.
Nil
)
return
extractNetObject
;
paramType
=
underlyingType
;
// Silently convert nullable types to their non null requics
paramType
=
underlyingType
;
// Silently convert nullable types to their non null requics
}
var
extractKey
=
GetExtractDictionaryKey
(
paramType
);
var
extractKey
=
GetExtractDictionaryKey
(
paramType
);
...
...
tests/LuaTests.cs
View file @
c1b3a950
...
@@ -621,6 +621,25 @@ namespace NLuaTest
...
@@ -621,6 +621,25 @@ namespace NLuaTest
}
}
}
}
/*
* Tests passing a null object as a parameter to a
* method that accepts a nullable.
*/
[
Test
]
public
void
TestNullableParameter
()
{
using
(
Lua
lua
=
new
Lua
())
{
lua
.
DoString
(
"luanet.load_assembly('NLuaTest')"
);
lua
.
DoString
(
"TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"
);
lua
.
DoString
(
"test=TestClass()"
);
lua
.
DoString
(
"a = test:NullableMethod(nil)"
);
lua
[
"timeVal"
]
=
TimeSpan
.
FromSeconds
(
5
);
lua
.
DoString
(
"b = test:NullableMethod(timeVal)"
);
Assert
.
AreEqual
(
null
,
lua
[
"a"
]);
Assert
.
AreEqual
(
TimeSpan
.
FromSeconds
(
5
),
lua
[
"b"
]);
}
}
/*
/*
* Tests if DoString is correctly returning values
* Tests if DoString is correctly returning values
*/
*/
...
...
tests/TestLua.cs
View file @
c1b3a950
...
@@ -374,6 +374,11 @@ namespace NLuaTest.Mock
...
@@ -374,6 +374,11 @@ namespace NLuaTest.Mock
set
{
}
set
{
}
}
}
public
TimeSpan
?
NullableMethod
(
TimeSpan
?
input
)
{
return
input
;
}
public
int
sum
(
int
x
,
int
y
)
public
int
sum
(
int
x
,
int
y
)
{
{
return
x
+
y
;
return
x
+
y
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment