I am using swift as a CGI script with Apache server (just to explore). I need to split my code into different files so as to make it more manageable. Is there any way I can include one swift file into another, like we can do in PHP with “include_once”?
Hmm, what are you trying to do? The generally accepted way of splitting code between files is through the use of extensions; is this not sufficient for your needs?
Saagar Jha
···
On Feb 27, 2017, at 02:45, Rupendra Limbore via swift-users <swift-users@swift.org> wrote:
Hi All,
I am using swift as a CGI script with Apache server (just to explore). I need to split my code into different files so as to make it more manageable. Is there any way I can include one swift file into another, like we can do in PHP with “include_once”?
You should be able to simply pass multiple source files to the Swift compiler and get a single compiled output.
Max
···
On Feb 27, 2017, at 2:45 AM, Rupendra Limbore via swift-server-dev <swift-server-dev@swift.org> wrote:
Hi All,
I am using swift as a CGI script with Apache server (just to explore). I need to split my code into different files so as to make it more manageable. Is there any way I can include one swift file into another, like we can do in PHP with “include_once”?
Are you treating Swift like a shell-script, by putting a “#!” at the top of the file? That works, but it’s going to be terribly slow for a CGI script because the source code has to be compiled for every... single… HTTP… request.
It would be much more efficient to compile the Swift to an executable file, and then use that file as the CGI. And that will solve your multiple-source-files problem too.
—Jens
···
On Feb 27, 2017, at 2:45 AM, Rupendra Limbore via swift-users <swift-users@swift.org> wrote:
I am using swift as a CGI script with Apache server (just to explore).
On Feb 27, 2017, at 2:45 AM, Rupendra Limbore via swift-users swift-users@swift.org wrote:
I am using swift as a CGI script with Apache server (just to explore).
Are you treating Swift like a shell-script, by putting a “#!” at the top of the file? That works, but it’s going to be terribly slow for a CGI script because the source code has to be compiled for every... single… HTTP… request.
It would be much more efficient to compile the Swift to an executable file, and then use that file as the CGI. And that will solve your multiple-source-files problem too.
May be you could use generic preprocessor like gpp
gpp --include a.swift b.swift -o c.swift
···
Jens Alfke via swift-users <swift-users@swift.org> 於 2017年2月28日 下午3:19 寫道:
On Feb 27, 2017, at 2:45 AM, Rupendra Limbore via swift-users <swift-users@swift.org> wrote:
I am using swift as a CGI script with Apache server (just to explore).
Are you treating Swift like a shell-script, by putting a “#!” at the top of the file? That works, but it’s going to be terribly slow for a CGI script because the source code has to be compiled for every... single… HTTP… request.
It would be much more efficient to compile the Swift to an executable file, and then use that file as the CGI. And that will solve your multiple-source-files problem too.