This wiki is out of date, use the continuation of this wiki instead

Include

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 14:54, 19 March 2008 (edit)
212.123.12.180 (Talk)

← Previous diff
Revision as of 16:00, 19 March 2008 (edit) (undo)
Sandman (Talk | contribs)

Next diff →
Line 1: Line 1:
-[[Category:filetypes]]+[[Category:General]]
 +[[Category:Language]]
 + 
== Definition == == Definition ==
-Include files to the current file. These files (*.[[INC]]) contain code that gets appended to the current file. 
-== Example ==+'''Include''' "<filename>";
-main.prg:+
 +When the compiler reaches an [[Include]] statement, it continues compilation at the included file (usually *.[[FH]] or *.[[INC]]) and when it's done resumes compiling from the [[Include]] statement. In other words, these files contain code that gets inserted at the place of inclusion.
 +
 +This is very handy for breaking up your code into pieces. The handling of video in one include file, audio in another, game logic in another, etc. This makes code more maintainable and understandable; moreover it makes code reusable. The video handling include file you made for one game can be used for another game (if it was coded in a generic fashion) without spitting through the whole sourcecode of the first game.
 +
 +Also headers can be used to import [[DLL]]s and possibly give a little more functionality to that DLL. For example [[Network.DLL]] uses a .[[FH]] header file to assure the DLL is only imported once during compilation and provides a little more functionality.
 +
 +== Example ==
 +'''main.prg'''
<pre> <pre>
 +// The code in "bar.inc" will be processed first:
include "bar.inc"; include "bar.inc";
-program foo;+ 
-private+Process Main()
- int barcode;+Private
-begin+ int barcode;
- write_int(0,100,100,&barcode);+Begin
- barcode = bar();+ write_int(0,100,100,&barcode);
- repeat + barcode = bar();
- frame; + repeat
- until(key(_esc))+ frame;
-end + until(key(_ESC))
 +End
</pre> </pre>
-bar.inc:+'''bar.inc'''
- +
<pre> <pre>
-int bar()+Function int bar()
-begin+Begin
- return 5;+ return 5;
-end+End
</pre> </pre>
- +Used in example: [[Include]], [[write_int]](), [[key]]()
-== See also ==+
-* [[INC]]+
- +
-{{Filetypes}}+

Revision as of 16:00, 19 March 2008


Definition

Include "<filename>";

When the compiler reaches an Include statement, it continues compilation at the included file (usually *.FH or *.INC) and when it's done resumes compiling from the Include statement. In other words, these files contain code that gets inserted at the place of inclusion.

This is very handy for breaking up your code into pieces. The handling of video in one include file, audio in another, game logic in another, etc. This makes code more maintainable and understandable; moreover it makes code reusable. The video handling include file you made for one game can be used for another game (if it was coded in a generic fashion) without spitting through the whole sourcecode of the first game.

Also headers can be used to import DLLs and possibly give a little more functionality to that DLL. For example Network.DLL uses a .FH header file to assure the DLL is only imported once during compilation and provides a little more functionality.

Example

main.prg

// The code in "bar.inc" will be processed first:
include "bar.inc";

Process Main()
Private
    int barcode;
Begin
    write_int(0,100,100,&barcode);
    barcode = bar();
    repeat     
        frame; 
    until(key(_ESC))
End  

bar.inc

Function int bar()
Begin
    return 5;
End

Used in example: Include, write_int(), key()

Personal tools