Skip to content

Embed external values into PlatformScript#20

Merged
cowboyd merged 1 commit intomainfrom
cl/external-references
Nov 20, 2022
Merged

Embed external values into PlatformScript#20
cowboyd merged 1 commit intomainfrom
cl/external-references

Conversation

@cowboyd
Copy link
Copy Markdown
Member

@cowboyd cowboyd commented Nov 20, 2022

Motivation

The entire point of PlatformScript is to compose pieces of the platform. In order to do that, we have to be able to represent those pieces as PlatformScript values that can be passed around.

Approach

This introduces a new type PSExternal which can appear anywhere a PSValue can. It supports de-referencing via an optional view property which is a function receiving a path that should produce a new PSValue

To help creating values for embedders, there is a set of top-level constructors for creating PlatformScript values from JavaScript values. e.g.

import * as ps from 'platformscript';

let scope = ps.map({
  num: ps.number(10),
  bool: ps.boolean(true),
  extern: ps.external({ weather: "sunny"}, (path, obj) => ps.string(lodash.get(obj, path))),
})

let platformscript = ps.createPlatformScript(scope);

let prog = platformscript.parse("Hello %($num). That is %($bool). Weather is %($extern.weather)");

await platformscript.eval(prog);

@cowboyd cowboyd requested a review from a team November 20, 2022 17:41
@cowboyd cowboyd force-pushed the cl/external-references branch 2 times, most recently from 67eed14 to b481348 Compare November 20, 2022 17:50
The entire point of PlatformScript is to compose pieces of the
platform. In order to do that, we have to be able to represent those
pieces as PlatformScript values that can be passed around.

This introduces a new type `PSExternal` which can appear anywhere a
`PSValue` can. It supports de-referencing via an optional `view`
property which is a function receiving a path that should produce a
new `PSValue`

To help creating values for embedders, there is a set of top-level
constructors for creating PlatformScript values from JavaScript
values. e.g.

```ts
import * as ps from 'platformscript';

let scope = ps.map({
  num: ps.number(10),
  bool: ps.boolean(true),
  extern: ps.external({}),
})

let platformscript = ps.createPlatformScript(scope);

let prog = platformscript.parse("Hello %($num). That is %($bool)");

await platformscript.eval(prog);
```
@cowboyd cowboyd force-pushed the cl/external-references branch from b481348 to 2901fc5 Compare November 20, 2022 17:52
Copy link
Copy Markdown
Member

@taras taras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good in theory. @dagda1 will be able to tell how well I it works for him

@cowboyd cowboyd merged commit cc22e7a into main Nov 20, 2022
@cowboyd cowboyd deleted the cl/external-references branch November 20, 2022 21:46
@cowboyd cowboyd mentioned this pull request Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants