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
56ca73db
Commit
56ca73db
authored
May 01, 2015
by
Vinicius Jarina
Browse files
Merge pull request #156 from dpull/master
RegisterOperatorsFunctions support base class
parents
7250e7b6
f6a8c49d
Changes
3
Show whitespace changes
Inline
Side-by-side
Core/NLua/Extensions/GeneralExtensions.cs
View file @
56ca73db
...
...
@@ -62,8 +62,8 @@ namespace NLua.Extensions
{
public
static
bool
HasMethod
(
this
Type
t
,
string
name
)
{
var
op
=
t
.
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
return
op
.
Any
(
m
=>
m
.
Name
==
name
)
;
var
op
=
t
.
GetMethods
(
name
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
|
BindingFlags
.
FlattenHierarchy
);
return
op
!=
null
;
}
public
static
bool
HasAdditionOpertator
(
this
Type
t
)
...
...
Core/NLua/Metatables.cs
View file @
56ca73db
...
...
@@ -1167,7 +1167,7 @@ namespace NLua
}
Type
type
=
target
.
GetType
();
var
operators
=
type
.
GetMethods
(
operation
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
var
operators
=
type
.
GetMethods
(
operation
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
|
BindingFlags
.
FlattenHierarchy
);
foreach
(
var
op
in
operators
)
{
bool
isOk
=
translator
.
MatchParameters
(
luaState
,
op
,
ref
validOperator
);
...
...
Core/NLua/Method/LuaMethodWrapper.cs
View file @
56ca73db
...
...
@@ -141,10 +141,16 @@ namespace NLua.Method
SetPendingException
(
null
);
if
(
methodToCall
==
null
)
{
// Method from name
if
(
isStatic
)
if
(
isStatic
)
{
targetObject
=
null
;
else
}
else
{
targetObject
=
_ExtractTarget
(
luaState
,
1
);
if
(
targetObject
==
null
||
targetObject
.
Equals
(
null
))
{
_Translator
.
ThrowError
(
luaState
,
String
.
Format
(
"instance method '{0}' requires a non null target object"
,
_MethodName
));
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
}
}
if
(
_LastCalledMethod
.
cachedMethod
!=
null
)
{
// Cached?
int
numStackToSkip
=
isStatic
?
0
:
1
;
// If this is an instance invoe we will have an extra arg on the stack for the targetObject
...
...
@@ -207,12 +213,6 @@ namespace NLua.Method
// System.Diagnostics.Debug.WriteLine("cache miss on " + methodName);
// If we are running an instance variable, we can now pop the targetObject from the stack
if
(!
isStatic
)
{
if
(
targetObject
==
null
)
{
_Translator
.
ThrowError
(
luaState
,
String
.
Format
(
"instance method '{0}' requires a non null target object"
,
_MethodName
));
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
}
LuaLib
.
LuaRemove
(
luaState
,
1
);
// Pops the receiver
}
...
...
@@ -264,6 +264,11 @@ namespace NLua.Method
}
else
{
if
(!
methodToCall
.
IsStatic
&&
!
methodToCall
.
IsConstructor
&&
targetObject
==
null
)
{
targetObject
=
_ExtractTarget
(
luaState
,
1
);
if
(
targetObject
==
null
||
targetObject
.
Equals
(
null
))
{
_Translator
.
ThrowError
(
luaState
,
String
.
Format
(
"instance method '{0}' requires a non null target object"
,
_MethodName
));
LuaLib
.
LuaPushNil
(
luaState
);
return
1
;
}
LuaLib
.
LuaRemove
(
luaState
,
1
);
// Pops the receiver
}
...
...
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