61 points · by helge5 · 9y ago · 24 comments
@_cdecl("foobar") public func foobar() {}
I haven't yet used it in anger, but that will compile in Swift 3.[0]https://news.ycombinator.com/item?id=11650628
[1]https://github.com/apple/swift/commit/013aad13d4245a012cfb76...
[2]https://swiftlang.ng.bluemix.net/#/repl/d68be430e72609717f71...
As the PR says, it also doesn't handle turning throwing functions into errors, nor does it check for collisions.
Another thing you can do is declare a function pointer type in C and assign to it from Swift by calling a C setter function (more or less a small trampoline).
Maybe I misunderstand you, but this doesn't seem to be the case, at least not in Swift 3.0-RELEASE. I was able to use @_cdecl for a callback in a Tcl extension (https://tcl.wiki/48057) on Linux.
Assigning a block to a c function pointer is an interesting alternative, I thought we tried something like that but I can't remember now.
Hopefully @_cdecl will become a documented and supported feature.
@_silgen_name("foobar") func foobar()
does seem to work just fine for now. Could change in the future of course, though I wonder how likely it is that the calling convention for this kind of Swift function is actually going to change.Note that the whole purpose of the function is to enter the Swift side from C just once. After that all is good, you can register any kind of convention-C callbacks.
What I'd like to see is the ability to specify `@convention(c)` not just on types, but also on functions and structs. That would be sweet and reduce the requirement for C wrappers even more.
It happens that @_silgen_name didn't break for me in 3.0. But I've been moving to @_cdecl.
Apache is more like an application server framework specifically targeted at executing custom code (hence modules). It is a little obscure and old fashioned but actually quite powerful and very flexible/customizable.
Since many current server side frameworks (say Node.js and all other Swift frameworks I know) do not really embed well into the server but are HTTP servers on their own, Nginx is often used as a frontend server in such contexts. It is very good for that (and Apache often overkill).
Anyways, running your code within Apache has pros&cons, as always. But this has little to do with Nginx vs Apache. (i.e. it may still make sense to use Nginx in front of Apache hosting a mod_swift application).