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

Give the web runtime support for resources #327

Open
Michael-F-Bryan opened this issue Sep 27, 2021 · 0 comments
Open

Give the web runtime support for resources #327

Michael-F-Bryan opened this issue Sep 27, 2021 · 0 comments
Labels
area - runtime The Rust Rune runtime category - bug Something isn't working category - enhancement New feature or request effort - easy This should be pretty simple good first issue Good for newcomers

Comments

@Michael-F-Bryan
Copy link
Contributor

In #273 we added resources to rune build and the Rust runtime, but because the web runtime can't be used outside the browser (#270) we didn't detect that the web runtime doesn't support resources.

We need to add the following host functions to the web runtime.

extern "C" {
    ...

    /// Open a named resource, returning a unique ID that can be used to .
    ///
    /// Invalid parameters will return a negative value.
    pub fn rune_resource_open(name: *const u8, name_len: u32) -> i32;

    /// Read data from a resource into the provided buffer.
    ///
    /// Invalid parameters will return a negative value.
    pub fn rune_resource_read(
        resource_id: u32,
        buffer: *mut u8,
        buffer_len: u32,
    ) -> i32;

    /// Close a resource.
    ///
    /// Invalid parameters will be ignored.
    pub fn rune_resource_close(resource_id: u32);
}

(source)

This implements a file-like API, where you'll open a resource and get a handle back (or a negative number indicating something went wrong), keep reading until EOF, then close the resource. I imagine the API changes will be something like this:

export interface Imports {
    ...
    openResource(name: string): Resource;
}

export interface Resource {
  // Read data from this Resource into the destination array, returning the 
  // number of bytes written.
  read(dest: ArrayBuffer): number;
  // Close this Resource, releasing any system resources it may be using.
  // Implementations can assume this method will be called at most once.
  close(): void;
}
@Michael-F-Bryan Michael-F-Bryan added category - bug Something isn't working category - enhancement New feature or request effort - easy This should be pretty simple area - runtime The Rust Rune runtime good first issue Good for newcomers labels Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area - runtime The Rust Rune runtime category - bug Something isn't working category - enhancement New feature or request effort - easy This should be pretty simple good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant