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
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.
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