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
e25a411a
"vscode:/vscode.git/clone" did not exist on "7dbad8a05841e50710d6f6a770d5dcdbcddd273e"
Commit
e25a411a
authored
Dec 13, 2019
by
Vinicius Jarina
Browse files
Fix #337 Array access on an object that doesn't implement array access does not throw an error
parent
805a5e33
Changes
2
Show whitespace changes
Inline
Side-by-side
src/Metatables.cs
View file @
e25a411a
...
@@ -355,8 +355,11 @@ namespace NLua
...
@@ -355,8 +355,11 @@ namespace NLua
if
(
fallback
!=
0
)
if
(
fallback
!=
0
)
return
fallback
;
return
fallback
;
if
(!
string
.
IsNullOrEmpty
(
methodName
))
if
(!
string
.
IsNullOrEmpty
(
methodName
)
||
index
!=
null
)
{
{
if
(
string
.
IsNullOrEmpty
(
methodName
))
methodName
=
index
.
ToString
();
return
PushInvalidMethodCall
(
luaState
,
objType
,
methodName
);
return
PushInvalidMethodCall
(
luaState
,
objType
,
methodName
);
}
}
...
@@ -1197,7 +1200,7 @@ namespace NLua
...
@@ -1197,7 +1200,7 @@ namespace NLua
{
{
var
luaState
=
LuaState
.
FromIntPtr
(
state
);
var
luaState
=
LuaState
.
FromIntPtr
(
state
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
translator
.
ThrowError
(
luaState
,
"Trying to invoke invalid method"
);
translator
.
ThrowError
(
luaState
,
"Trying to invoke invalid method
or an access an invalid index
"
);
luaState
.
PushNil
();
luaState
.
PushNil
();
return
1
;
return
1
;
}
}
...
...
tests/src/LuaTests.cs
View file @
e25a411a
...
@@ -2700,6 +2700,17 @@ namespace NLuaTest
...
@@ -2700,6 +2700,17 @@ namespace NLuaTest
Assert
.
AreEqual
(
Enumeration
.
First
,
result
,
"#1"
);
Assert
.
AreEqual
(
Enumeration
.
First
,
result
,
"#1"
);
}
}
[
Test
]
public
void
InvalidArrayIndex
()
{
var
lua
=
new
Lua
();
lua
[
"main"
]
=
new
Person
();
object
result
=
lua
.
DoString
(
"return main[15]"
)[
0
];
Assert
.
AreNotEqual
(
15
,
result
,
"#1"
);
}
static
Lua
m_lua
;
static
Lua
m_lua
;
}
}
...
...
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