Need a way to include swift file into another swift file

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”?

Best Regards,

Rupendra Limbore

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”?

Best Regards,
Rupendra Limbore

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

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”?

Best Regards,
Rupendra Limbore

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-server-dev

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).

Thanks for the help.

Yes, I am using "#!/usr/bin/swift”. It is slow for the first time, later I am getting quicker response.

I will try using compiled executable as you suggested.

···

On Feb 28, 2017, at 12:49 PM, Jens Alfke jens@mooseyard.com wrote:

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.

—Jens

`

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.

—Jens
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users