-
-
Notifications
You must be signed in to change notification settings - Fork 437
[Request/Question] Support proxies for expr.Env
#777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think we can add those features. What about this case:
|
@antonmedv good question! Please check updated proposal. |
What about something like this: type Proxy struct {
Get(path []string) (any, error)
} And on an expression: let x = 100;
foo.bar[42 + x].baz Proxy will be called with
|
@antonmedv as far as I know, expr supports variables. It might be complex to handle such cases: let y = foo.bar
y[42 + x].baz // Path chain has to be preserved when passed to Proxy imho it might be easier to support nested Also user might want to have a proxy only for specific fields (e.g. only for |
@antonmedv if you're interested, I can try to make a PR after the proposal will be finalized. |
I think implementation should be done via patcher which will replace property access with function cause. |
@antonmedv if patched code will throw an error, would error position point to an original (pre-patched) code? Let's imagine a code like this: foo.bar.baz and patched version would look like this: foo.bar().baz() // bar returns nil Ideally returned
Imho native object proxy support will make implementation much more simple. |
Expr patcher designed to point to original code location! Actually a lot of optimizations is done via patcher. But errors always return original code allocation. |
Greetings.
I've a question - does
expr
support having proxies asexpr.Env
(something similar toProxy
feature in JS)?I have a situation where I've to deal with a chain of objects as env that have prototype inheritance (also like in JS).
As env itself is dynamic (might depend on context, environment vars, etc), in order to build
expr.Env
each time I need to run an expression - it's necessary to traverse a whole prototype chain and create a new map.Feature Benefits
This feature will allow to handle complex cases such as:
Proposed solutions
Global & Nested Proxy
Ideally, to handle such cases,
expr.Env
could consume aProxyEnv
interface that will be called to get a variable:If returned value implements
ProxyEnv
, it also should be treated as proxy:Pros
Cons
Alternative Solutions
Please feel free to provide a better more efficient solution.
The text was updated successfully, but these errors were encountered: