Next Previous Contents

17. Miscellaneous Functions

17.1 __get_reference

Synopsis

Get a reference to a global object

Usage

Ref_Type __get_reference (String_Type nm)

Description

This function returns a reference to a global variable or function whose name is specified by nm. If no such object exists, it returns NULL, otherwise it returns a reference.

Example

For example, consider the function:

    define runhooks (hook)
    {
       variable f;
       f = __get_reference (hook);
       if (f != NULL)
         @f ();
    }
This function could be called from another S-lang function to allow customization of that function, e.g., if the function represents a mode, the hook could be called to setup keybindings for the mode.
See Also

is_defined, typeof, eval, autoload, __is_initialized

17.2 getenv

Synopsis

Get the value of an environment variable

Usage

String_Type getenv(String_Type var)

Description

The getenv function returns a string that represents the value of an environment variable var. It will return NULL if there is no environment variable whose name is given by var.

Example

    if (NULL != getenv ("USE_COLOR"))
      {
        set_color ("normal", "white", "blue");
        set_color ("status", "black", "gray");
        USE_ANSI_COLORS = 1;
      }
See Also

putenv, strlen, is_defined

17.3 implements

Synopsis

Name a private namespace

Usage

implements (String_Type name);

Description

The implements function may be used to name the private namespace associated with the current compilation unit. Doing so will enable access to the members of the namespace from outside the unit. The name of the global namespace is Global.

Example

Suppose that some file t.sl contains:

     implements ("Ts_Private");
     static define message (x)
     {
        Global->vmessage ("Ts_Private message: %s", x);
     }
     message ("hello");
will produce "Ts_Private message: hello". This message function may be accessed from outside via:
    Ts_Private->message ("hi");
Notes

Since message is an intrinsic function, it is global and may not be redefined in the global namespace.

17.4 putenv

Synopsis

Add or change an environment variable

Usage

putenv (String_Type s)

Description

This functions adds string s to the environment. Typically, s should of the form "name=value". The function signals a S-lang error upon failure.

Notes

This function is not available on all systems.

See Also

getenv, sprintf


Next Previous Contents