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
f3367518
Commit
f3367518
authored
Oct 17, 2020
by
Vinicius Jarina
Browse files
Fixed potential NRE
parent
c396ccd7
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/Lua.cs
View file @
f3367518
...
...
@@ -737,12 +737,20 @@ namespace NLua
public
int
GetInteger
(
string
fullPath
)
{
return
(
int
)(
long
)
GetObjectFromPath
(
fullPath
);
object
result
=
GetObjectFromPath
(
fullPath
);
if
(
result
==
null
)
return
0
;
return
(
int
)(
long
)
result
;
}
public
long
GetLong
(
string
fullPath
)
{
return
(
long
)
GetObjectFromPath
(
fullPath
);
object
result
=
GetObjectFromPath
(
fullPath
);
if
(
result
==
null
)
return
0L
;
return
(
long
)
result
;
}
/*
...
...
@@ -751,6 +759,9 @@ namespace NLua
public
string
GetString
(
string
fullPath
)
{
object
obj
=
GetObjectFromPath
(
fullPath
);
if
(
obj
==
null
)
return
null
;
return
obj
.
ToString
();
}
...
...
src/LuaTable.cs
View file @
f3367518
...
...
@@ -84,7 +84,7 @@ namespace NLua
{
Lua
lua
;
if
(!
TryGet
(
out
lua
))
return
n
ull
;
return
n
ew
object
[
0
]
;
return
lua
.
GetTableDict
(
this
).
Values
;
}
...
...
@@ -117,4 +117,4 @@ namespace NLua
return
"table"
;
}
}
}
\ No newline at end of file
}
src/Metatables.cs
View file @
f3367518
...
...
@@ -83,6 +83,9 @@ namespace NLua
var
state
=
LuaState
.
FromIntPtr
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
state
);
var
func
=
(
LuaNativeFunction
)
translator
.
GetRawNetObject
(
state
,
1
);
if
(
func
==
null
)
return
state
.
Error
();
state
.
Remove
(
1
);
int
result
=
func
(
luaState
);
var
exception
=
translator
.
GetObject
(
state
,
-
1
)
as
LuaScriptException
;
...
...
@@ -249,7 +252,7 @@ namespace NLua
return
result
;
}
static
int
UnaryNegationLua
(
LuaState
luaState
,
ObjectTranslator
translator
)
static
int
UnaryNegationLua
(
LuaState
luaState
,
ObjectTranslator
translator
)
//-V3009
{
object
obj1
=
translator
.
GetRawNetObject
(
luaState
,
1
);
...
...
@@ -347,7 +350,8 @@ namespace NLua
if
(
type
==
LuaType
.
UserData
)
{
object
obj
=
translator
.
GetRawNetObject
(
luaState
,
i
);
strrep
=
obj
.
ToString
();
strrep
=
obj
==
null
?
"(null)"
:
obj
.
ToString
();
}
Debug
.
WriteLine
(
"{0}: ({1}) {2}"
,
i
,
typestr
,
strrep
);
...
...
@@ -403,7 +407,7 @@ namespace NLua
if
(
TryAccessByArray
(
luaState
,
objType
,
obj
,
index
))
return
1
;
int
fallback
=
GetMethodFallback
(
luaState
,
objType
,
obj
,
index
,
methodName
);
int
fallback
=
GetMethodFallback
(
luaState
,
objType
,
obj
,
methodName
);
if
(
fallback
!=
0
)
return
fallback
;
...
...
@@ -518,7 +522,6 @@ namespace NLua
(
LuaState
luaState
,
Type
objType
,
object
obj
,
object
index
,
string
methodName
)
{
object
method
;
...
...
@@ -529,18 +532,18 @@ namespace NLua
// Try to use get_Item to index into this .net object
MethodInfo
[]
methods
=
objType
.
GetMethods
();
int
res
=
TryIndexMethods
(
luaState
,
methods
,
obj
,
index
);
int
res
=
TryIndexMethods
(
luaState
,
methods
,
obj
);
if
(
res
!=
0
)
return
res
;
// Fallback to GetRuntimeMethods
methods
=
objType
.
GetRuntimeMethods
().
ToArray
();
res
=
TryIndexMethods
(
luaState
,
methods
,
obj
,
index
);
res
=
TryIndexMethods
(
luaState
,
methods
,
obj
);
if
(
res
!=
0
)
return
res
;
res
=
TryGetValueForKeyMethods
(
luaState
,
methods
,
obj
,
index
);
res
=
TryGetValueForKeyMethods
(
luaState
,
methods
,
obj
);
if
(
res
!=
0
)
return
res
;
...
...
@@ -564,7 +567,7 @@ namespace NLua
return
0
;
}
private
int
TryGetValueForKeyMethods
(
LuaState
luaState
,
MethodInfo
[]
methods
,
object
obj
,
object
index
)
private
int
TryGetValueForKeyMethods
(
LuaState
luaState
,
MethodInfo
[]
methods
,
object
obj
)
{
foreach
(
MethodInfo
methodInfo
in
methods
)
{
...
...
@@ -578,7 +581,7 @@ namespace NLua
ParameterInfo
[]
actualParams
=
methodInfo
.
GetParameters
();
// Get the index in a form acceptable to the getter
index
=
_translator
.
GetAsType
(
luaState
,
2
,
actualParams
[
0
].
ParameterType
);
object
index
=
_translator
.
GetAsType
(
luaState
,
2
,
actualParams
[
0
].
ParameterType
);
// If the index type and the parameter doesn't match, just skip it
if
(
index
==
null
)
...
...
@@ -617,7 +620,7 @@ namespace NLua
}
private
int
TryIndexMethods
(
LuaState
luaState
,
MethodInfo
[]
methods
,
object
obj
,
object
index
)
private
int
TryIndexMethods
(
LuaState
luaState
,
MethodInfo
[]
methods
,
object
obj
)
{
foreach
(
MethodInfo
methodInfo
in
methods
)
{
...
...
@@ -631,7 +634,7 @@ namespace NLua
ParameterInfo
[]
actualParams
=
methodInfo
.
GetParameters
();
// Get the index in a form acceptable to the getter
index
=
_translator
.
GetAsType
(
luaState
,
2
,
actualParams
[
0
].
ParameterType
);
object
index
=
_translator
.
GetAsType
(
luaState
,
2
,
actualParams
[
0
].
ParameterType
);
// If the index type and the parameter doesn't match, just skip it
if
(
index
==
null
)
...
...
src/Method/LuaClassHelper.cs
View file @
f3367518
using
System
;
using
System
;
namespace
NLua.Method
{
...
...
@@ -32,6 +32,9 @@ namespace NLua.Method
int
iRefArgs
;
object
[]
returnValues
=
function
.
Call
(
inArgs
,
returnTypes
);
if
(
returnValues
==
null
||
returnTypes
.
Length
==
0
)
return
null
;
if
(
returnTypes
[
0
]
==
typeof
(
void
))
{
returnValue
=
null
;
...
...
@@ -52,4 +55,4 @@ namespace NLua.Method
return
returnValue
;
}
}
}
\ No newline at end of file
}
src/ObjectTranslator.cs
View file @
f3367518
...
...
@@ -516,7 +516,7 @@ namespace NLua
return
result
;
}
private
int
GetMethodSignatureInternal
(
LuaState
luaState
)
private
int
GetMethodSignatureInternal
(
LuaState
luaState
)
//-V3009
{
ProxyType
klass
;
object
target
;
...
...
@@ -581,7 +581,7 @@ namespace NLua
return
result
;
}
private
int
GetConstructorSignatureInternal
(
LuaState
luaState
)
private
int
GetConstructorSignatureInternal
(
LuaState
luaState
)
//-V3009
{
ProxyType
klass
=
null
;
int
udata
=
luaState
.
CheckUObject
(
1
,
"luaNet_class"
);
...
...
@@ -955,7 +955,7 @@ namespace NLua
int
newTop
=
luaState
.
GetTop
();
if
(
oldTop
==
newTop
)
return
n
ull
;
return
n
ew
object
[
0
]
;
var
returnValues
=
new
List
<
object
>();
for
(
int
i
=
oldTop
+
1
;
i
<=
newTop
;
i
++)
...
...
@@ -975,7 +975,7 @@ namespace NLua
int
newTop
=
luaState
.
GetTop
();
if
(
oldTop
==
newTop
)
return
n
ull
;
return
n
ew
object
[
0
]
;
int
iTypes
;
var
returnValues
=
new
List
<
object
>();
...
...
src/ObjectTranslatorPool.cs
View file @
f3367518
using
System
;
using
System
;
using
System.Collections.Concurrent
;
using
NLua.Exceptions
;
using
LuaState
=
KeraLua
.
Lua
;
namespace
NLua
...
...
@@ -29,7 +29,7 @@ namespace NLua
LuaState
main
=
luaState
.
MainThread
;
if
(!
translators
.
TryGetValue
(
main
,
out
translator
))
return
null
;
throw
new
Exception
(
"Invalid luaState, couldn't find ObjectTranslator"
)
;
}
return
translator
;
}
...
...
tests/build/net45/NLuaTest.csproj
View file @
f3367518
...
...
@@ -57,7 +57,7 @@
<Version>
3.12.0
</Version>
</PackageReference>
<PackageReference
Include=
"NUnit3TestAdapter"
>
<Version>
3.1
6.1
</Version>
<Version>
3.1
7.0
</Version>
<IncludeAssets>
runtime; build; native; contentfiles; analyzers; buildtransitive
</IncludeAssets>
<PrivateAssets>
all
</PrivateAssets>
</PackageReference>
...
...
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