current stable:
cvs (0.99.7)
  Home / News
  The Team

  Source Tarball
  CVS Web View
  Misc. Files

The Manual
  Download [html]
  Download [pdf]
  View Online
  Download [html]
  View Online
  Script Examples

Developer Guide
  Download [html]
  Download [pdf]
  View Online
Ferite C API
  Download [html]
  View Online

Open Source Approved

SourceForge Logo - browse the Keyword Map of

[previous] Classes and Objects (and references)[up][toc]Regular Expressions [next]


Namespaces are defined in the following manner:

    namespace name of namespace {
    	variable, namespace, class, and function declarations

All languages have namespaces, Java's are governed by static members to classes but C has no means of explicitly defining them. The are a means of grouping likewise data and functions into a group such that there doesn't exist conflicts with names (hence namespace). Functions, Variables, Classes and even other namespaces can be defined within a namespace.


A standard error message for two different systems within the same program - Text and Graphical. In C it would have to be done like so:

    void text_print_error_message( char *msg );
    void graphical_print_error_message( char *msg );

Whereas in ferite you would use namespaces:

    namespace Text {
    	function printErrorMessage( string msg ){}
    	// other stuff to do with text
    namespace Graphical {
    	function printErrorMessage( string msg ){}
    	// other stuff to do with graphical

The ferite method is cleaner as it is more obvious what belongs to what, and also allows the programmer using the Graphical and the Text API's to know that if they want to show an error message they merely call the printErrorMessage() function in which ever namespace they want. If you combine this with the ability to assign a namespace reference to a void variable - very powerfull abilities become apparent. Using the above code:

    void outputMechanism;
    if( wantGUI )
    	outputMechanism = Graphical;
    	outputMechanism = Text;
    outputMechanism.printErrorMessage( "We have an Error" );

They promote clean and precise code. When a function is defined within a namespace it has to reference stuff within the namespace as code out side does, e.g. namespace.resource.

It is important to note that you can't use the shortcut method to access functions and variables that is used in objects e.g. .someVariable. You must use the full name to access anything within namespaces.

Modifying Existing Namespaces

There is also an alternative syntax for namespaces allowing you to extend an already existing namespace or create a new one if it doesn't already exist. This is done like so:

    namespace modifies name of namespace {
    	variable, namespace, class and function declarations

When this modifies the namespace it places all items within it in the block in the namespace mentioned. Eg:

    namespace foo {
    	number i;
    namespace modifies foo {
    	number j;

In the above example the namespace foo has a number i and a number j. The main reason for this syntax was to allow module writers to easily intermingle native and script code within the namespace. There is also times when placing something in another namespace makes more sense. e.g. Placing a custom written network protocol within a Network namespace.

It is possible to use the same delete and rename functions as in classes, in namespaces.

[previous] Classes and Objects (and references)[up][toc]Regular Expressions [next]
ferite et al © 2000-2004, Chris Ross