engine, lang: Allow resources with a field of type interface

This lets us add a resource that has an implementation with a field
whose type is determined at compile time. This let's us write more
flexible resources.

What's missing is additional type checking so that we guarantee that a
specific resource doesn't change types during run-time.
This commit is contained in:
James Shubin
2023-11-12 16:16:47 -05:00
parent 9a1a81925e
commit b048b2684b
7 changed files with 62 additions and 1 deletions

View File

@@ -93,6 +93,13 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
value2 := obj2.FieldByName(key2)
kind2 := value2.Kind()
// For situations where we send a variant to the resource!
// TODO: should this be a for loop to un-nest multiple times?
if kind1 == reflect.Interface {
value1 = value1.Elem() // un-nest one interface
kind1 = value1.Kind()
}
if obj.Debug {
obj.Logf("Send(%s) has %v: %v", type1, kind1, value1)
obj.Logf("Recv(%s) has %v: %v", type2, kind2, value2)