Coder Social home page Coder Social logo

Comments (4)

ysbaddaden avatar ysbaddaden commented on June 29, 2024 1

I wondered "how does Rust do it" and they annotate the type declaration (system is stdcall on windows x86):

type PHANDLER_ROUTINE = Option<unsafe extern "system" fn(CtrlType: DWORD) -> BOOL>;
pub unsafe extern "system" fn SetConsoleCtrlHandler(HandlerRoutine: PHANDLER_ROUTINE, Add: BOOL) -> BOOL;

type PEVENT_CALLBACK = Option<unsafe extern "system" fn(pEvent: PEVENT_TRACE)>;
pub unsafe fn EventCallback(&self) -> &PEVENT_CALLBACK;

What's the issue with annotating the type?

from crystal.

straight-shoota avatar straight-shoota commented on June 29, 2024

To avoid attaching calling conventions to types themselves

Why would you want to avoid that? In the C headers, its also attached to the function type, right? So I figure it would make sense to do the same in Crystal lib definition.
That means if you want to call the same function signature with different calling conventions, you'll need to define separate proc types for that. I don't see how this could be a problem, though.

from crystal.

HertzDevil avatar HertzDevil commented on June 29, 2024

Maybe we could allow the alias to "carry" a @[CallConvention] annotation that is only meaningful in those lib fun contexts. What I mean is that IMO we should strive to avoid making Callback an entirely different Crystal type from Proc because that would be quite a significant breaking change.

from crystal.

straight-shoota avatar straight-shoota commented on June 29, 2024

But if alias means more than just a different name, it would also be quite a change.

I think this needs to go on the Proc type itself. This could work based on just an annotation, meaning @[CallingConventionA] Proc(Int) is a different type from Proc(Int).

However, maybe an optional generic type argument would be better suited for that? Proc(Int, calling_convention: CallingConventionA)

from crystal.

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.