dbohdan 2016-09-21: The following is a minimal example how you can implement a Tcl extension in Swift 3.0 under Linux. Note the sure of @_cdecl to make the function accessible to C code under a specific symbol name.
The code has been tested with Apple's official Swift 3.0-RELEASE on Ubuntu 14.04. You can install Swift by following these instructions . If you copy and paste the makefile from the be sure to replace the leading spaces with tabs in it with `sed -i 's| |\t| Makefile'.
TARGET ?= libtclswiftexample.so test: $(TARGET) bridge.h echo 'load $(TARGET); puts [hello]; puts [square 5]' | tclsh $(TARGET): tclswiftexample.swift swiftc -emit-library -import-objc-header bridge.h $< -o $(TARGET) clean: -rm $(TARGET) .PHONY: clean test
#include "/usr/include/tcl/tcl.h"
func Hello_Cmd(cdata: ClientData?, interp: UnsafeMutablePointer<Tcl_Interp>?, objc: Int32, objv: UnsafePointer<UnsafeMutablePointer<Tcl_Obj>?>?) -> Int32 { if objc != 1 { return TCL_ERROR } Tcl_SetObjResult(interp, Tcl_NewStringObj("Hello, World!", -1)) return TCL_OK } func Square_Cmd(cdata: ClientData?, interp: UnsafeMutablePointer<Tcl_Interp>?, objc: Int32, objv: UnsafePointer<UnsafeMutablePointer<Tcl_Obj>?>?) -> Int32 { if objc != 2 { return TCL_ERROR } var i: Int32 = 0 let success = Tcl_GetIntFromObj(interp, objv![1], &i) if success != TCL_OK { return TCL_ERROR } Tcl_SetObjResult(interp, Tcl_NewIntObj(i*i)) return TCL_OK } @_cdecl("Tclswiftexample_Init") public func Tclswiftexample_Init(interp: UnsafeMutablePointer<Tcl_Interp>) -> CInt { Tcl_CreateObjCommand(interp, "::hello", Hello_Cmd, nil, nil); Tcl_CreateObjCommand(interp, "::square", Square_Cmd, nil, nil); return TCL_OK }