You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Massimiliano had some good suggestions; quoting his email.
In glycerine/luar/luar.go the func goToLuaFunction() contains:
t := v.Type()
nIn := t.NumIn()
argsT := make([]reflect.Type, nIn)
for i := range argsT {
argsT[i] = t.In(i)
}
// NB (jea): we wish their was a more efficient way to distinguish
// methods (with a receiver argument) from functions (no receiver)
// with reflect. However this is what I could come up with.
// Better methods welcome, but this appears to work for now.
//
fname := getFunctionName(v)
isMethod := fname == "reflect.methodValueCall"
I think the question whether the reflect.Value 'v' (which contains a
function or method) already includes the receiver or not can be answered
as follows:
it depends on how 'v' was obtained, see my example at
if the method was obtained directly from receiver's reflect.Value
with reflect.Value.Method(int) or reflect.Value.MethodByName(string)
then the receiver will be already bound
if the method was obtained from from receiver's reflect.Value.Type()
with reflect.Type.Method(int) or reflect.Value.MethodByName(string)
(they both return reflect.Method)
and then extracting the field reflect.Method.Func,
then the receiver will not be bound
Attempts to distinguish the two cases purely by inspecting the
reflect.Value that contains the method are possible, as you have shown,
but I believe they are both non-portable and fragile.
Regards,
Massimiliano Ghilardi
(cosmos72)
The text was updated successfully, but these errors were encountered:
Massimiliano had some good suggestions; quoting his email.
In glycerine/luar/luar.go the func goToLuaFunction() contains:
I think the question whether the reflect.Value 'v' (which contains a
function or method) already includes the receiver or not can be answered
as follows:
it depends on how 'v' was obtained, see my example at
https://play.golang.org/p/QJ-33HOBR3p
if the method was obtained directly from receiver's reflect.Value
with reflect.Value.Method(int) or reflect.Value.MethodByName(string)
then the receiver will be already bound
if the method was obtained from from receiver's reflect.Value.Type()
with reflect.Type.Method(int) or reflect.Value.MethodByName(string)
(they both return reflect.Method)
and then extracting the field reflect.Method.Func,
then the receiver will not be bound
Attempts to distinguish the two cases purely by inspecting the
reflect.Value that contains the method are possible, as you have shown,
but I believe they are both non-portable and fragile.
Regards,
Massimiliano Ghilardi
(cosmos72)
The text was updated successfully, but these errors were encountered: