The number of parameters passed to a function
Integer_Type _NARGS
The value of the _NARGS
variable represents the number of
arguments passed to the function. This variable is local to each
function.
This example uses the _NARGS
variable to print the list of
values passed to the function:
define print_values ()
{
variable arg;
if (_NARGS == 0)
{
message ("Nothing to print");
return;
}
foreach (__pop_args (_NARGS))
{
arg = ();
vmessage ("Argument value is: %S", arg.value);
}
}
__pop_args, __push_args, typeof
Get the symbols defined by the preprocessor
Integer_Type __get_defined_symbols ()
The __get_defined_symbols
functions is used to get the list of
all the symbols defined by the S-lang preprocessor. It pushes each
of the symbols on the stack followed by the number of items pushed.
is_defined, _apropos
Determine whether or not a variable has a value
Integer_Type __is_initialized (Ref_Type r)
This function returns non-zero of the object referenced by r
is initialized, i.e., whether it has a value. It returns 0
if the
referenced object has not been initialized.
For example, the function:
define zero ()
{
variable f;
return __is_initialized (&f);
}
will always return zero, but
define one ()
{
variable f = 0;
return __is_initialized (&f);
}
will return one.
It is easy to see why a reference to the variable must be passed to
__is_initialized
and not the variable itself; otherwise, the
value of the variable would be passed and the variable may have no
value if it was not initialized.
__get_reference, __uninitialize, is_defined, typeof, eval
Generate a list of functions and variables
Array_Type _apropos (String_Type ns, String_Type s, Integer_Type flags)
The _apropos
function may be used to get a list of all defined
objects in the namespace ns
whose name matches the regular
expression s
and whose type matches those specified by
flags
. It returns an array of strings representing the
matches.
The second parameter flags
is a bit mapped value whose bits
are defined according to the following table
1 Intrinsic Function
2 User-defined Function
4 Intrinsic Variable
8 User-defined Variable
define apropos (s)
{
variable n, name, a;
a = _apropos ("Global", s, 0xF);
vmessage ("Found %d matches:", length (a));
foreach (a)
{
name = ();
message (name);
}
}
prints a list of all matches.
If the namespace specifier ns
is the empty string ""
,
then the namespace will default to the static namespace of the
current compilation unit.
is_defined, sprintf
Returns the name of the currently executing function
String_Type _function_name ();
This function returns the name of the currently executing function. If called from top-level, it returns the empty string.
_trace_function, is_defined
Installed documentation directory
String_Type _slang_doc_dir;
The _slang_doc_dir
variable is a read-only whose value
specifies the installation location of the S-lang documentation.
get_doc_string_from_file
The S-Lang library version number
Integer_Type _slang_version
The _slang_version
variable is read-only and and whose
value represents the number of the S-lang library.
_slang_version_string
The S-Lang library version number as a string
String_Type _slang_version_string
The _slang_version_string
variable is read-only and whose
value represents the version number of the S-lang library.
_slang_version
Read documentation from a file
String_Type get_doc_string_from_file (String_Type f, String_Type t)
get_doc_string_from_file
opens the documentation file f
and searches it for topic t
. It returns the documentation for
t
upon success, otherwise it returns NULL
upon error.
It will fail if f
could not be opened or does not contain
documentation for the topic.
stat_file
_slang_doc_dir
Indicate whether a variable or function defined.
Integer_Type is_defined (String_Type obj)
This function is used to determine whether or not a function or
variable whose name is obj
has been defined. If obj
is not
defined, the function returns 0. Otherwise, it returns a non-zero
value that defpends on the type of object obj
represents.
Specifically, it returns one of the following values:
+1 if an intrinsic function
+2 if user defined function
-1 if intrinsic variable
-2 if user defined variable
0 if undefined
For example, consider the function:
define runhooks (hook)
{
if (2 == is_defined(hook)) eval(hook);
}
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.
typeof, eval, autoload, __get_reference, __is_initialized