GithubHelp home page GithubHelp logo

Comments (4)

ndmitchell avatar ndmitchell commented on May 20, 2024

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.

oakash avatar oakash commented on May 20, 2024

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.

oakash avatar oakash commented on May 20, 2024

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.

ndmitchell avatar ndmitchell commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.