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
The basic idea is that type functions don't directly compile as they look like, the first argument is always the pointer or value to the type that implements it. For example:
typeMyTypestruct{}
func (mt*MyType) SayHello(arg1int) {}
// Will compile to something like...funcMyType_SayHello(mt*MyType, arg1int) {}
Having this in consideration, the solution will need some kind of callback since the current implementation only has Value assignment mapping to Plasma Objects, a conceptual workaround could be:
// This is passed to the VM as plasma.ToValue(objVirtualTable, newMemberCaller(self, function))typememberCallerfunc(arguments...any) []anyfuncnewMemberCaller(self, function reflect.Value) memberCaller {
returnfunc(arguments...any) []any {
callArguments:=make([]reflect.Value, 0, function.Type().NumIn())
callArguments=append(callArguments, self) // Add selfforindex:=0; index<function.Type().NumIn(); index++ {
in:=function.Type().In(index)
asValue:=reflect.ValueOf(arguments[index])
asValue=asValue.Convert(in)
callArguments=append(callArguments, asValue)
}
// Some corrections need to be made to also support Variadic function callsasValuesResults:=function.Call(callArguments)
result:=make([]any, 0, len(asValueResults))
for_, v:=rangeasValuesResults {
result=append(result, v.Interface())
}
returnresult
}
}
Is your feature request related to a problem? Please describe.
Map Struct function to Plasma Objects
Describe the solution you'd like
Using reflection, also scan for the functions of an struct an map them to the plasma object
The text was updated successfully, but these errors were encountered: