Comments (4)
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.
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.
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.
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)
- Unable to run interpreter after building HOT 2
- Using `lld-link` as a linker HOT 1
- Interpreter bug when `require "http/server"` HOT 1
- Can't instantiate a UNIXSocket instance in the interpreter HOT 2
- Some `#[]?(Range)` methods can still raise `IndexError`
- Interpreter hits Invalid memory access (after Error: BUG: no target defs) HOT 1
- Multiplication of Int64 and Int32 may result in Int32 (risking overflows at runtime) HOT 4
- Huge `JSON::ParseException` HOT 5
- `Number#humanize` and `Int#humanize_bytes` should separate number and unit by a space HOT 1
- Regression: Interrupted system call in CI HOT 6
- Is an html strip-tags method a worth stdlib addition? HOT 7
- Unwinding is slow on WSL HOT 8
- add something like ruby un.rb or cmake -E for cross platform scripts HOT 3
- regression: XPath swallows errors and raises opaque `error in [...] expression` instead HOT 1
- Proposal: Utility method for string truncation HOT 2
- Debugging Windows binaries with LLDB doesn't break on access violation
- Manage compiler dependencies with `shards` HOT 6
- Standardizing the type for timeout values HOT 1
- Symbol casting to Enums does not work in subclass initializers HOT 5
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 crystal.