Go to main content

include

This function is used to include a file.

INCLUDE

NAME

include - This function is used to include a file.

SYNOPSIS

include([once:bool,exec:bool,load_functions:bool,error:variable,] (textfile|binaryfile|file|compilefile):"…", …) %include[binary|text] "filename"

DESCRIPTION

The first form of this function is used to include a file. The file text is not parse or executed. The file with argument binary is compile and executed The file with argument file is either binary or text. If the suffix if snc, it is assumed binary code compile by Extenso.

The path of the file start from the root to the website or relative to the current file. You cannot go above the root directory define in the configuration file. If version if specify, than the file is loaded into memory the first time and include. The second time, this file is included, we check in memory if its the same version. If not the file is read again. If yes, than the file is not read again.

The second form of the include is done while compiling the program. If the filename start with a / then the path is absolute from the root of the website as defined in the configuration file. If the filename does not start with /, than the filename is relative to the current filename that is beeing compiled. If binary is specified, than the file is assumed to be a compiled file. If text is specified, than the file is compile and the result is place in the current compilation. If nothing is specify, than all files with extention .snc are treated as binary. All others will be compiled.

In this version, include in the first form can not be use to include a function.

PARAMETERS

load_functions
The parameter load_functions is set to false by default will load the functions in the include file so that they can be executed fater the load.
exec
The parameter exec is set to true by default will execute the include file. If exec is false, the file will not be executed. A text file will be included even if exec is false. Exec can be used when you want to load functions but not execute the code in the include file.
error
The parameter error is used to save error in the variable if an error occured. If the file is outside the root of the website, the error is silently ignore in that case and the file is not include.
 
once
The parameter will make sure this file is loaded only once. Availabl from version 5.173

RETURN

None.

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

%include text "inc4.sn";
%include binary "inc3.snc";
%include text "inc3.sn";
%include "inc3.sn";
%include "inc2.sn";
%include "inc1.sn"

res={_{include("../lib/files.c");}}. return .*Can't merge root.*
res={_{include("../../../../etc/passwd");}}. return .*Can't merge root.*
res={_{include("tests/test-include-1.sn");}}. return res=test include 1.
res={_{include("tests/test-include-1.sn","tests/test-include-2.sn");}}. return res=test include 1test include 2.
    {_{include("tests/test-include-1.sn");}}. return test include 1.
res={_{include("../../../../etc/passwd");}}. return .*Can't merge root.*
res={_{include("/wqdqwindex.sn");}}. return .*Can't open file.*
res={_{include(error:a,textfile:"tests/test-include-1.sn"); a.errcode;}}.), q(res=test include 10.));
res={_{include(textfile:"tests/test-include-1.sn");}}.), q(res=test include 1.));
res={_{include(textfile:"../lib/files.c");}}.), q(.*No such file.*));
res={_{include(textfile:"../../../../etc/passwd");}}.), q(.*above the root path.*));
res={_{include(textfile:"/html/tests/test-include-1.sn");}}.), q(res=test include 1.));
res={_{include(textfile:"/../v5/html/tests/test-include-1.sn");}}.), q(res=test include 1.));
res={_{include("/tests/sample.sn"); }}.), qq(res=res from sample = 512 11..),{asm => "-a"});
res={_{include(compilefile:"/tests/sample.sn"); }}.), qq(res=res from sample = 512 11..),{asm => "-a"});
res={_{
      remove("/tmp/tib.sn");
      write(data:"test 0",file:"/tmp/tib.sn");
      compile(src:"/tmp/tib.sn",dst:"/tmp/tib.snc");
      c=12;
      include("/tmp/tib.snc");
      c;
    }}. return res=test 6060.

SEE ALSO

AUTHOR

Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

1.1 2014-12-14 17:27:00 laplante@sednove.com Add args load_functions & exec

1.2 2022-01-09 laplante@sednove.com Add once at version 5.173

Edit

© 2022 extenso Inc. All rights reserved.