Comments (4)
The idea of the function is that it is currently opaque - you can invoke it, but there's no way to get the and give it arguments, but you can't inspect what arguments it requires or what its name is. To change that we'd need to:
- Make some of ParametersSpec transparent - currently all you can do is give it arguments. This would require careful design to expose the right information.
- Make the FunctionInvoker you get back from .invoke give you a ParametersSpec back. This one isn't so hard.
What's the reason for wanting to understand the function arguments passed to a native function?
from starlark-rust.
I'm seeing if it is feasible to use starklark-rust
to define "callback" methods to events.
For example, a developer would pass a method to a native Rust function in that's exposed to Starklark, which would get evaluated when a particular event happens at a later time:
def handle_message(title, body):
if title == "error":
native.send_email("[email protected]", body)
native.on_message(func=handle_message)
This program would get evaluated and a reference to the callbacks to on_message
stored somewhere, for example in a database. When an event comes in, the program would get evaluated again in a different context, and handle_message
evaluated with the incoming message.
I was toying with the idea of inspecting the parameters specified on the method to match the incoming event to parameter names to make it a bit easier to use.
There are various other ways this could be achieved. For instance by evaluating the program for each message and use the Context
to determine which callbacks to trigger based on the incoming message. That's the approach I'll be trying out today.
from starlark-rust.
As I sat down to look at this again today I realize I can get pretty far by introducing a level of indirection in starlark and use kwargs
. I was bit too stuck in the Rust mindset and looking to solve it there.
Thanks for the library. I don't have a need to expose function details directly Rust integrators right now. Until that changes I'll go ahead and close this ticket.
from starlark-rust.
Glad you've figured out a way.
Note that you might want to update the code if you still have Context - the latest code has moved to use Evaluator as the name. As part of the preparation for a release (which we're planning tomorrow) we've renamed a bunch of names that hadn't been considered since the initial fork. Following our release tomorrow we expect things to be pretty stable.
There is also the function eval_function
that might be useful for what you are doing - not sure if you've seen that or not.
from starlark-rust.
Related Issues (20)
- lalrpop compile error with Rust 1.56+ HOT 9
- panicked at 'slice index starts at 2 but ends at 1' HOT 1
- panicked at 'assertion failed: old_local.is_none()' HOT 1
- panicked at 'assertion failed: self.args.is_none() && !self.no_args && self.kwargs.is_none()' HOT 1
- panicked at 'assertion failed: self.kwargs.is_none()' HOT 1
- repr("\x01") does not conform to spec
- Deal with printing recursive values
- str.find does not work correctly with non-ASCII characters
- Implement 32-bit Support HOT 5
- Clarification: "glob" / "native functions" HOT 1
- document the build instructions HOT 4
- Please update dependencies to non-vulnerable versions HOT 5
- LSP: code completion HOT 1
- main branch doesn't compile. AstSmt & AstExpr size assertions. HOT 3
- ansi_term dependency issue HOT 2
- feat: support compiling to a Web Assembly (WASM) module HOT 7
- [Question] Creating a function using the `Dict` type as an argument. HOT 4
- [Question] Using `Dict` as a function return type with string values. HOT 4
- Integrate with google/oss-fuzz for continuous fuzz testing? HOT 5
- Stack overflow bug HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starlark-rust.