Get a reference to a global object
Ref_Type __get_reference (String_Type nm)
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.
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.
is_defined, typeof, eval, autoload, __is_initialized, __uninitialize
Uninitialize a variable
__uninitialize (Ref_Type x)
The __uninitialize
function may be used to uninitialize the
variable referenced by the parameter x
.
The following two lines are equivalent:
() = __tmp(z);
__uninitialize (&z);
__tmp, __is_initialized
Set automatic variable declaration mode
Integer_Type _auto_declare
The _auto_declare
may be used to have all undefined variables
implicitely declared as static
. If set to zero, any variable
must be declared witha variable
declaration before it can be
used. If set to one, then any undeclared variabled will be declared
as a static
global variable.
The _auto_declare
variable is is local to each compilation unit and
setting its value in one unit has no effect upon its value in other
units. The value of this variable has no effect upon the variables
in a function.
The following code will not compile if X
not been
declared:
X = 1;
However,
_auto_declare = 1; % declare variables as static.
X = 1;
is equivalent to
static variable X = 1;
This variable should be used sparingly and is intended primarily for interactive applications where one types S-lang commands at a prompt.
Get the value of an environment variable
String_Type getenv(String_Type var)
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
.
if (NULL != getenv ("USE_COLOR"))
{
set_color ("normal", "white", "blue");
set_color ("status", "black", "gray");
USE_ANSI_COLORS = 1;
}
putenv, strlen, is_defined
Name a private namespace
implements (String_Type name);
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
.
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");
Since message
is an intrinsic function, it is global and may
not be redefined in the global namespace.
use_namespace, current_namespace, import
Add or change an environment variable
putenv (String_Type s)
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.
This function is not available on all systems.
getenv, sprintf
Change to another namespace
use_namespace (String_Type name)
The use_namespace
function changes the current namespace to
the one specified by the parameter. If the specified namespace
does not exist, an error will be generated.
implements, current_namespace, import
Get the name of the current namespace
String_Type current_namespace ()
The current_namespace
function returns the name of the
current namespace. If the current namespace is anonymous, that is,
has not been given a name via the implements
function, the
empty string ""
will be returned.
implements, use_namespace, import