Skip to content
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

Host SDK: add some host-side functions missing from the kernel. #11

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

evacchi
Copy link
Contributor

@evacchi evacchi commented Oct 7, 2024

Adding a few missing host functions, sketching a "nice" API for end users at the same time.

We introduce ExtismHostFunction as an abstraction over Chicory's native HostFunction, taking a CurrentPlugin reference instead of a bare Instance. CurrentPlugin exposes some methods in Plugin and the new HostEnv.
HostEnv wraps and exposes functions from the Kernel and defines its own, namely log, config and var.

To simulate name-spacing, HostEnv define inner classes to HostEnv, that cannot be instantiated from the outside, so that we get a nice "fluent" API to invoke them; e.g.:

        var f = ExtismHostFunction.of("myfunc", List.of(), List.of(),
                (CurrentPlugin p, Value... args) -> {
                    p.log().log(LogLevel.INFO, "hello world");
                    return null;
        });

I defined some tests to go along with these to show them. Will add some more tests and/or together with #10 and #9.

@evacchi evacchi marked this pull request as ready for review October 8, 2024 20:58
@evacchi evacchi requested a review from bhelx October 8, 2024 20:58
@evacchi
Copy link
Contributor Author

evacchi commented Oct 8, 2024

I have already integrated this locally to #10 and it seems fine.

@evacchi evacchi mentioned this pull request Oct 8, 2024
hostEnv.var().set("test", bytes);
assertSame(hostEnv.var().get("test"), bytes);

hostEnv.log().log(LogLevel.INFO, "hello world");
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a side note, should we consider convenience methods for the levels? hostEnv.log().info("hello world");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do in a follow-up!

@evacchi evacchi merged commit f4eed9a into extism:main Oct 9, 2024
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