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
b2f1afc5
Commit
b2f1afc5
authored
Dec 29, 2014
by
Isaac Brodsky
Browse files
Fix passing a nullable int.
parent
b239449e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Core/NLua/CheckType.cs
View file @
b2f1afc5
...
@@ -102,16 +102,34 @@ namespace NLua
...
@@ -102,16 +102,34 @@ namespace NLua
paramType
=
paramType
.
GetElementType
();
paramType
=
paramType
.
GetElementType
();
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
);
bool
netParamIsNumeric
=
paramType
==
typeof
(
int
)
||
paramType
==
typeof
(
uint
)
||
paramType
==
typeof
(
long
)
||
paramType
==
typeof
(
ulong
)
||
paramType
==
typeof
(
short
)
||
paramType
==
typeof
(
ushort
)
||
paramType
==
typeof
(
float
)
||
paramType
==
typeof
(
double
)
||
paramType
==
typeof
(
decimal
)
||
paramType
==
typeof
(
byte
);
// If it is a nullable
if
(
underlyingType
!=
null
)
{
// null can always be assigned to nullable
if
(
luatype
==
LuaTypes
.
Nil
)
{
// Return the correct extractor anyways
if
(
netParamIsNumeric
)
return
extractValues
[
extractKey
];
return
extractNetObject
;
}
}
if
(
paramType
.
Equals
(
typeof
(
object
)))
if
(
paramType
.
Equals
(
typeof
(
object
)))
return
extractValues
[
extractKey
];
return
extractValues
[
extractKey
];
...
@@ -132,15 +150,6 @@ namespace NLua
...
@@ -132,15 +150,6 @@ namespace NLua
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
double
))];
return
extractValues
[
GetExtractDictionaryKey
(
typeof
(
double
))];
}
}
bool
netParamIsString
=
paramType
==
typeof
(
string
)
||
paramType
==
typeof
(
char
[]);
bool
netParamIsString
=
paramType
==
typeof
(
string
)
||
paramType
==
typeof
(
char
[]);
bool
netParamIsNumeric
=
paramType
==
typeof
(
int
)
||
paramType
==
typeof
(
uint
)
||
paramType
==
typeof
(
long
)
||
paramType
==
typeof
(
ulong
)
||
paramType
==
typeof
(
short
)
||
paramType
==
typeof
(
float
)
||
paramType
==
typeof
(
double
)
||
paramType
==
typeof
(
decimal
)
||
paramType
==
typeof
(
byte
);
if
(
netParamIsNumeric
)
{
if
(
netParamIsNumeric
)
{
if
(
LuaLib
.
LuaIsNumber
(
luaState
,
stackPos
)
&&
!
netParamIsString
)
if
(
LuaLib
.
LuaIsNumber
(
luaState
,
stackPos
)
&&
!
netParamIsString
)
...
...
tests/LuaTests.cs
View file @
b2f1afc5
...
@@ -653,10 +653,14 @@ namespace NLuaTest
...
@@ -653,10 +653,14 @@ namespace NLuaTest
lua
.
DoString
(
"TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"
);
lua
.
DoString
(
"TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"
);
lua
.
DoString
(
"test=TestClass()"
);
lua
.
DoString
(
"test=TestClass()"
);
lua
.
DoString
(
"a = test:NullableMethod(nil)"
);
lua
.
DoString
(
"a = test:NullableMethod(nil)"
);
Assert
.
AreEqual
(
null
,
lua
[
"a"
]);
lua
[
"timeVal"
]
=
TimeSpan
.
FromSeconds
(
5
);
lua
[
"timeVal"
]
=
TimeSpan
.
FromSeconds
(
5
);
lua
.
DoString
(
"b = test:NullableMethod(timeVal)"
);
lua
.
DoString
(
"b = test:NullableMethod(timeVal)"
);
Assert
.
AreEqual
(
null
,
lua
[
"a"
]);
Assert
.
AreEqual
(
TimeSpan
.
FromSeconds
(
5
),
lua
[
"b"
]);
Assert
.
AreEqual
(
TimeSpan
.
FromSeconds
(
5
),
lua
[
"b"
]);
lua
.
DoString
(
"d = test:NullableMethod2(2)"
);
Assert
.
AreEqual
(
2
,
lua
[
"d"
]);
lua
.
DoString
(
"c = test:NullableMethod2(nil)"
);
Assert
.
AreEqual
(
null
,
lua
[
"c"
]);
}
}
}
}
...
...
tests/TestLua.cs
View file @
b2f1afc5
...
@@ -379,6 +379,11 @@ namespace NLuaTest.Mock
...
@@ -379,6 +379,11 @@ namespace NLuaTest.Mock
return
input
;
return
input
;
}
}
public
int
?
NullableMethod2
(
int
?
input
)
{
return
input
;
}
public
object
[]
TestLuaFunction
(
LuaFunction
func
)
public
object
[]
TestLuaFunction
(
LuaFunction
func
)
{
{
if
(
func
!=
null
)
{
if
(
func
!=
null
)
{
...
...
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