Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Expand macro for multiple functions #9

Merged
merged 1 commit into from
Aug 30, 2017
Merged

Conversation

arcnmx
Copy link
Contributor

@arcnmx arcnmx commented Aug 24, 2017

A simple extension to the lambda!() macro syntax to allow exporting multiple handler functions:

lambda! {
    "handler" => my_handler,
    "handler2" => |event, context| { ... },
}

The basic syntax lambda!(f); is equivalent to lambda { "handler" => f }

@arcnmx
Copy link
Contributor Author

arcnmx commented Aug 24, 2017

And the strange extra part of these macro changes is the ability to customize the name of the library. The syntax here is:

lambda! {
    crate (liblambda, initliblambda, PyInit_liblambda) {
        "handler" => f,
    }
}

It's awkward due to the lack of a working concat_idents!() and the python export naming reqiurements... A procedural macro could work around this but might be overkill for this simple macro (and would bring in extra build dependencies for macro parsing).

Also I think we may be able to get away with crate (initliblambda, PyInit_liblambda) because the first identifier just needs to be something unique, while the latter two must be the same name as the library. Needs checking out.

Needs a decision made on this. As much as I want the ability to customize the library name it could be removed until a better syntax is found...

@iliana iliana mentioned this pull request Aug 24, 2017
@iliana
Copy link
Owner

iliana commented Aug 30, 2017

Needs a decision made on this. As much as I want the ability to customize the library name it could be removed until a better syntax is found...

I'm tempted to wait until concat_idents!() lands in stable to land something that allows you to change the library name, but the syntax isn't terribly clunky and might make something possible that isn't possible now. (I'm honestly not sure what, though.)

I'm happy to land the crate (liblambda, initliblambda, PyInit_liblambda) syntax if you are. If anything, we can always deprecate it later when possible.

@arcnmx
Copy link
Contributor Author

arcnmx commented Aug 30, 2017

Besides being unstable, concat_idents!() doesn't actually work (and has never worked). I'm not sure if there are plans to fix the macro system to make it useful, but it's not likely to be an option for years.

If you're okay with the syntax let's go for it then!

@iliana iliana merged commit fcbdffd into iliana:master Aug 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants