@Chris_Lattner3 and @dan-zheng, in the proposed solution:
We propose introducing a new
@dynamicCallable
attribute to the Swift language which may be applied to structs, classes, enums, and protocols. This follows the precedent of SE-0195.
But the @dynamicMemberLookup
attribute cannot be applied to protocols, AFAIK.
import Foundation
import JavaScriptCore
@dynamicMemberLookup
public protocol JSDynamicMemberLookup {
subscript(dynamicMember name: String) -> JSValue { get set }
}
// error: @dynamicMemberLookup attribute requires 'JSDynamicMemberLookup'
// to have a 'subscript(dynamicMember:)' member with a string index
(I was trying to add this to existing Objective-C classes, such as JSContext
and JSValue
).