Description
Feature request
An earlier version of this issue included references to comparators. I am looking into it, and think that the issue may have been caused by a bug internally. I still think that silent getter/setters would be valuable.
Please include the following information:
Is your feature request related to a problem? Please describe.
I am using Polyglot to define data models. The host process will then create instances to perform business logic. I want the fields to be properties of the class, rather than a ProxyObject
passed as a parameter. Currently, as far as I can tell, there is no clean way to expose a single typed variable with a getter, setter, equal, and comparator.
class User:
username = field.string({
"primary_key": True
})
lifecycle = field.fsm({
"options": {
"UNKNOWN": {
"value": 1,
},
"AWAITING_VERIFICATION": {
"value": 2,
},
"VERIFIED": {
"value": 3
}
}
})
def onVerify(self):
if(self.status == 2)
self.status.set("VERIFIED")
# field.fsm() exposes a get() and set() method that will automatically convert Strings to values
Describe the solution you'd like.
I should be able to say that a class implements ProxyValue
(or similar) and write getter/setter/comparator methods that will be exposed in a more "language-native" way. For the above code, I want the guest language code to be
def onVerify(self):
if(self.status == "AWAITING_VERIFICATION"):
self.status = "VERIFIED"
where self.status is a class FSMValue
that contains
public boolean equals(Object o){}
public int compareTo(Object o){}
public Object get(){}
public void set(Object o){}
Describe who do you think will benefit the most.
This will most benefit users who write Polyglot scripts (especially those who aren't maintaining the host application). It will lower the barrier of entry for people who have not written scripts for polyglot before.
Describe alternatives you've considered.
I have considered exposing a proxy object as a parameter to a method, but I prefer to offer a more traditional object syntax. I am currently bridging this with explicit getter/setter calls. This approach while sufficient, is not ideal.
Additional context.
This may cause some ambiguity with the =
operation, whether that should be a set operation or a replacement operation. I think it is reasonable to assume that if a member/variable implements this type, then the =
syntax should be equal to .set(Object o)
. There may need to be a separate method to indicate an uncontrolled replacement.
Express whether you'd like to help contributing this feature
I don't think I have the skillset to contribute to this feature.