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

"Context" of a Roto script #80

Closed
tertsdiepraam opened this issue Dec 4, 2024 · 1 comment
Closed

"Context" of a Roto script #80

tertsdiepraam opened this issue Dec 4, 2024 · 1 comment
Assignees

Comments

@tertsdiepraam
Copy link
Contributor

tertsdiepraam commented Dec 4, 2024

The context defines variables that are available, but not passed as arguments and also not the same value in every invocation of a script. The look like constants from the perspective of the script.

The Rust side would look something like this:

let rt = Runtime::new();

rt.register_context::<Logger>("LOGGER");

// ...

let f = rt.get_function(...).unwrap();
f.insert_ctx("LOGGER", Logger::new()).unwrap();
let f = f.finish().unwrap();

f.call(ctx, ...);

Which would make the LOGGER variable available in Roto.

An open question is how this works with registered functions and whether they can use the context. For example, it would be nice if there could be a registered log function, that automatically uses the LOGGER.

@tertsdiepraam tertsdiepraam changed the title We need a way to define the "context" of a Roto script "Context" of a Roto script Dec 4, 2024
@tertsdiepraam
Copy link
Contributor Author

tertsdiepraam commented Dec 4, 2024

This could also be provided in a more statically typed way:

#[roto_context]
struct Ctx {
   LOGGER: Logger,
}

rt.register_context::<Ctx>();

let f = rt.get_function(...).unwrap();
let mut ctx = Ctx {
    LOGGER: Logger::new();
};
f.call(&mut ctx, ...);

The most important advantage is that this struct can then also be used by registered functions. However, if they do, then they require a specific context type. That might need a bit more flexibility. They might be able to opt in to specific fields in the Ctx field.

#[roto_function]
fn log(#[ctx("LOGGER") logger: Logger, ...) { ... }

That might be possible.

@tertsdiepraam tertsdiepraam self-assigned this Jan 15, 2025
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

No branches or pull requests

1 participant