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
7dbad8a0
Commit
7dbad8a0
authored
Apr 19, 2020
by
Vinicius Jarina
Browse files
Fixed #328 Non-existent member access always returns "invalid method" function
parent
7ff6e7c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Lua.cs
View file @
7dbad8a0
...
...
@@ -216,7 +216,7 @@ namespace NLua
/// <summary>
/// The maximum number of recursive steps to take when adding global reference variables. Defaults to 2.
/// </summary>
public
int
MaximumRecursion
{
get
;
set
;}
=
2
;
public
int
MaximumRecursion
{
get
;
set
;
}
=
2
;
#
region
Globals
auto
-
complete
/// <summary>
...
...
src/Metatables.cs
View file @
7dbad8a0
...
...
@@ -33,7 +33,6 @@ namespace NLua
public
static
readonly
LuaNativeFunction
CallConstructorFunction
=
CallConstructor
;
public
static
readonly
LuaNativeFunction
ToStringFunction
=
ToStringLua
;
public
static
readonly
LuaNativeFunction
CallDelegateFunction
=
CallDelegate
;
public
static
readonly
LuaNativeFunction
CallInvalidFunction
=
CallInvalidMethod
;
public
static
readonly
LuaNativeFunction
AddFunction
=
AddLua
;
public
static
readonly
LuaNativeFunction
SubtractFunction
=
SubtractLua
;
...
...
@@ -372,11 +371,9 @@ namespace NLua
private
int
PushInvalidMethodCall
(
LuaState
luaState
,
Type
type
,
string
name
)
{
var
invokeDelegate
=
CallInvalidFunction
;
SetMemberCache
(
type
,
name
,
null
)
;
SetMemberCache
(
type
,
name
,
invokeDelegate
);
_translator
.
PushFunction
(
luaState
,
invokeDelegate
);
_translator
.
Push
(
luaState
,
null
);
_translator
.
Push
(
luaState
,
false
);
return
2
;
}
...
...
@@ -1192,21 +1189,6 @@ namespace NLua
return
result
;
}
/*
* LuaNativeFunction called when the method wasn't found
*/
#if __IOS__ || __TVOS__ || __WATCHOS__
[
MonoPInvokeCallback
(
typeof
(
LuaNativeFunction
))]
#endif
static
int
CallInvalidMethod
(
IntPtr
state
)
{
var
luaState
=
LuaState
.
FromIntPtr
(
state
);
var
translator
=
ObjectTranslatorPool
.
Instance
.
Find
(
luaState
);
translator
.
ThrowError
(
luaState
,
"Trying to invoke invalid method or an access an invalid index"
);
luaState
.
Error
();
return
1
;
}
int
CallDelegateInternal
(
LuaState
luaState
)
{
var
del
=
_translator
.
GetRawNetObject
(
luaState
,
1
)
as
Delegate
;
...
...
tests/src/LuaTests.cs
View file @
7dbad8a0
...
...
@@ -2708,7 +2708,23 @@ namespace NLuaTest
lua
[
"main"
]
=
new
Person
();
object
result
=
lua
.
DoString
(
"return main[15]"
)[
0
];
object
result2
=
lua
.
DoString
(
@"
function bar()
if main.foo ~= nil then
return 42
end
return 10
end
return bar()
"
)[
0
];
Assert
.
AreNotEqual
(
15
,
result
,
"#1"
);
Assert
.
AreEqual
(
10
,
result2
,
"#2"
);
Assert
.
IsNull
(
result
,
"#3"
);
}
[
Test
]
...
...
@@ -2812,13 +2828,13 @@ namespace NLuaTest
lua
[
"myTc"
]
=
tc
;
if
(
maxRecursion
==
0
)
Assert
.
AreEqual
(
1
,
lua
.
Globals
.
Count
());
//register only the root reference
Assert
.
AreEqual
(
1
,
lua
.
Globals
.
Count
()
,
"#1"
);
//register only the root reference
else
Assert
.
IsTrue
(
lua
.
Globals
.
Count
()
>
1
);
//many globals registered (all sub properties)
Assert
.
IsTrue
(
lua
.
Globals
.
Count
()
>
1
,
"#1"
);
//many globals registered (all sub properties)
// ensure even with 0 recursion we can still call properties
object
o
=
lua
.
DoString
(
@"return myTc.LongValue"
)[
0
];
Assert
.
AreEqual
(
5
,
o
);
Assert
.
AreEqual
(
5
,
o
,
"#2"
);
}
}
...
...
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