WelcomeWhat's NewsORLibraryDownloadsLinksWebMaster@OnyxRing.com

This site
pageviews since

Today's date:

Author: Jim Fisher
Title: Using SYSTEM_FILE & REPLACE in the Same Source

Creation Date: 8/6/2004 10:38:26 PM
Last Updated: 8/6/2004 10:38:26 PM

Using the "system_file" and "replace" Directives In the Same Source File

here is an obscurity that presents itself when using both the replace and system_file directives in the same file.

First, to bring this article into context, let me describe briefly what they each do:

The system_file directive tells the compiler that the following routines, contained in the current source file, can be overridden via the replace directive. (It actually does more, but this is the behavior that is relevant)

The replace directive, generally called before the inclusion of the system_file, is used to indicate that certain routines are to be replaced. Specifically, when the replace directive is used to specify a routine name, instances of that routine, which occur under the scope of the system_file directive, are ignored. This way a new version, specified in a non-system file can be used instead.

The problem-behavior is that a file, which 1) specifies a function to be replaced, 2) implements a new version of the function, and 3) is designated as a system_file, has just specified its own implementation of the replaced function to be ignored as well. Compiling this file will result in an error message similar to:

 testgame.inf(62): Error: There is no action routine called "ScoreSub" 

For personal library extensions in particular, the need to replace standard library routines and provide new routines that can be replaced as well is common. What we seem to need, in cases like this is to specify some routines as replaceable and other routines as not replaceable.

The solution is rooted in the fact that the name of the system_file directive is potentially misleading since it seems to imply an entire file will be treated as a system file. Actually, this is not true. The manner in which the Inform compiler handles files designated as "system files" begins only when the directive is encountered and stops at the end of the file. This enables us to move the system_file directive down in our source file. The routines specified after the system_file directive will be able to be replaced by games implementing the file, while the routines above the system_file directive will be compiled without the system_file qualifier and can therefore be used as replacements to library routines.

The following code snip demonstrates:

 replace ScoreSub;

    !...personal implementation of ScoreSub


 !...other code eligible to be replaced later goes here...

Copyright 2004 - 2017 : Jim Fisher
OnyxRing.com has been given the potentially non-exclusive right to display the content of this article. However the original author retains all rights. Permission to reproduce this article -- either in part or in whole -- is left strictly to the discretion of the original author.

Table of ContentsAuthorsSearchIndex
Would you
recommend this
article to
someone else?
You bet I would! Heck No!