📄 cref.tm
字号:
\usage{int SLang_autoload(char *funct, char *filename)}\description The \var{SLang_autoload} function may be used to associate a \var{slang} function name \var{funct} with the file \var{filename} such that if \var{funct} has not already been defined when needed, it will be loaded from \var{filename}. \var{SLang_autoload} has no effect if \var{funct} has already been defined. Otherwise it declares \var{funct} as a user-defined \slang function. It returns \exmp{0} upon success, or \exmp{-1} upon error.\seealso{SLang_load_file, SLang_is_defined}\done\function{SLang_load_string}\synopsis{Interpret a string}\usage{int SLang_load_string(char *str)}\description The \var{SLang_load_string} function feeds the string specified by \var{str} to the interpreter for execution. It returns zero upon success, or \exmp{-1} upon failure.\seealso{SLang_load_file, SLang_load_object}\done\function{SLdo_pop}\synopsis{Delete an object from the stack}\usage{int SLdo_pop(void)}\description This function removes an object from the top of the interpeter's run-time stack and frees any memory associated with it. It returns zero upon success, or \var{-1} upon error (most likely due to a stack-underflow).\seealso{SLdo_pop_n, SLang_pop_integer, SLang_pop_string}\done\function{SLdo_pop_n}\synopsis{Delete n objects from the stack}\usage{int SLdo_pop_n (unsigned int n)}\description The \var{SLdo_pop_n} function removes the top \var{n} objects from the interpreter's run-time stack and frees all memory associated with the objects. It returns zero upon success, or \var{-1} upon error (most likely due to a stack-underflow).\seealso{SLdo_pop, SLang_pop_integer, SLang_pop_string}\done\function{SLang_pop_integer}\synopsis{Pop an integer off the stack}\usage{int SLang_pop_integer (int *i)}\description The \var{SLang_pop_integer} function removes an integer from the top of the interpreter's run-time stack and returns its value via the pointer \var{i}. If successful, it returns zero. However, if the top stack item is not of type \var{SLANG_INT_TYPE}, or the stack is empty, the function will return \exmp{-1} and set \var{SLang_Error} accordingly.\seealso{SLang_push_integer, SLang_pop_double}\done\function{SLpop_string}\synopsis{Pop a string from the stack}\usage{int SLpop_string (char **strptr);}\description The \var{SLpop_string} function pops a string from the stack and returns it as a malloced pointer. It is up to the calling routine to free this string via a call to \var{free} or \var{SLfree}. If successful, \var{SLpop_string} returns zero. However, if the top stack item is not of type \var{SLANG_STRING_TYPE}, or the stack is empty, the function will return \exmp{-1} and set \var{SLang_Error} accordingly.\example#v+ define print_string (void) { char *s; if (-1 == SLpop_string (&s)) return; fputs (s, stdout); SLfree (s); }#v-\notes This function should not be confused with \var{SLang_pop_slstring}, which pops a \em{hashed} string from the stack.\seealso{SLang_pop_slstring. SLfree}\done\function{SLang_pop_string}\synopsis{Pop a string from the stack}\usage{int SLang_pop_string(char **strptr, int *do_free)}\description The \var{SLpop_string} function pops a string from the stack and returns it as a malloced pointer via \var{strptr}. After the function returns, the integer pointed to by the second parameter will be set to a non-zero value if \var{*strptr} should be freed via \var{free} or \var{SLfree}. If successful, \var{SLpop_string} returns zero. However, if the top stack item is not of type \var{SLANG_STRING_TYPE}, or the stack is empty, the function will return \exmp{-1} and set \var{SLang_Error} accordingly.\notes This function is considered obsolete and should not be used by applications. If one requires a malloced string for modification, \var{SLpop_string} should be used. If one requires a constant string that will not be modifed by the application, \var{SLang_pop_slstring} should be used.\seealso{SLang_pop_slstring, SLpop_string}\done\function{SLang_pop_slstring}\synopsis{Pop a hashed string from the stack}\usage{int SLang_pop_slstring (char **s_ptr)}\description The \var{SLang_pop_slstring} function pops a hashed string from the \slang run-time stack and returns it via \var{s_ptr}. It returns zero if successful, or \-1 upon failure. The resulting string should be freed via a call to \var{SLang_free_slstring} after use.\example#v+ void print_string (void) { char *s; if (-1 == SLang_pop_slstring (&s)) return; fprintf (stdout, "%s\n", s); SLang_free_slstring (s); }#v-\notes \var{SLang_free_slstring} is the preferred function for popping strings. This is a result of the fact that the interpreter uses hashed strings as the native representation for string data. One must \em{never} free a hashed string using \var{free} or \var{SLfree}. In addition, one must never make any attempt to modify a hashed string and doing so will result in memory corruption.\seealso{SLang_free_slstring, SLpop_string}\done\function{SLang_pop_double}\synopsis{Pop a double from the stack}\usage{int SLang_pop_double (double *dptr, int *iptr, int *conv)}\description The \var{SLang_pop_double} function pops a double precision number from the stack and returns it via \var{dptr}. If the number was derived from an integer, \var{*conv} will be set to \exmp{1} upon return, otherwise, \var{*conv} will be set to \exmp{0}. This function returns \0 upon success, otherwise it returns \-1 and sets \var{SLang_Error} accordingly.\notes If one does not care whether or not \exmp{*dptr} was derived from an integer, \var{iptr} and \var{conv} may be passed as \var{NULL} pointers.\seealso{SLang_pop_integer, SLang_push_double}\done\function{SLang_pop_complex}\synopsis{Pop a complex number from the stack}\usage{int SLang_pop_complex (double *re, double *im)}\description \var{SLang_pop_complex} pops a complex number from the stack and returns it via the parameters \var{re} and \var{im} as the real and imaginary parts of the complex number, respectively. This function automatically converts objects of type \var{SLANG_DOUBLE_TYPE} and \var{SLANG_INT_TYPE} to \var{SLANG_COMPLEX_TYPE}, if necessary. It returns zero upon success, or \-1 upon error setting \var{SLang_Error} accordingly.\seealso{SLang_pop_integer, SLang_pop_double, SLang_push_complex}\done\function{SLang_push_complex}\synopsis{Push a complex number onto the stack}\usage{int SLang_push_complex (double re, double im)}\description \var{SLang_push_complex} may be used to push the complex number whose real and imaginary parts are given by \var{re} and \var{im}, respectively. It returns zero upon success, or \-1 upon error setting \var{SLang_Error} accordingly.\seealso{SLang_pop_complex, SLang_push_double}\done\function{SLang_push_double}\synopsis{Push a double onto the stack}\usage{int SLang_push_double(double d)}\description \var{SLang_push_double} may be used to push the double precision floating point number \var{d} onto the interpreter's run-time stack. It returns zero upon success, or \-1 upon error setting \var{SLang_Error} accordingly.\seealso{SLang_pop_double, SLang_push_integer}\done\function{SLang_push_string}\synopsis{Push a string onto the stack}\usage{int SLang_push_string (char *s)}\description \var{SLang_push_string} pushes a copy of the string specified by \var{s} onto the interpreter's run-time stack. It returns zero upon success, or \-1 upon error setting \var{SLang_Error} accordingly.\notes If \var{s} is \var{NULL}, this function pushes \var{NULL} (\var{SLANG_NULL_TYPE}) onto the stack.\seealso{SLang_push_malloced_string}\done\function{SLang_push_integer}\synopsis{Push an integer onto the stack}\usage{int SLang_push_integer (int i)}\description \var{SLang_push_integer} the integer \var{i} onto the interpreter's run-time stack. It returns zero upon success, or \-1 upon error setting \var{SLang_Error} accordingly.\seealso{SLang_pop_integer, SLang_push_double, SLang_push_string}\done\function{SLang_push_malloced_string}\synopsis{Push a malloced string onto the stack}\usage{int SLang_push_malloced_string (char *s);}\description \var{SLang_push_malloced_string} may be used to push a malloced string onto the interpreter's run-time stack. It returns zero upon success, or \-1 upon error setting \var{SLang_Error} accordingly.\example The following example illustrates that it is up to the calling routine to free the string if \var{SLang_push_malloced_string} fails:#v+ int push_hello (void) { char *s = malloc (6); if (s == NULL) return -1; strcpy (s, "hello"); if (-1 == SLang_push_malloced_string (s)) { free (s); return -1; } return 0; }#v-\example The function \var{SLang_create_slstring} returns a hashed string. Such a string may not be malloced and should not be passed to \var{SLang_push_malloced_string}.\notes If \var{s} is \var{NULL}, this function pushes \var{NULL} (\var{SLANG_NULL_TYPE}) onto the stack.\seealso{SLang_push_string, SLmake_string}\done\function{SLang_is_defined}\synopsis{Check to see if the interpreter defines an object}\usage{int SLang_is_defined (char *nm)}\description The \var{SLang_is_defined} function may be used to determine whether or not a variable or function whose name is given by \var{em} has been defined. It returns zero if no such object has been defined. Othewise it returns a non-zero value whose meaning is given by the following table:#v+ 1 intrinsic function (SLANG_INTRINSIC) 2 user-defined slang function (SLANG_FUNCTION) -1 intrinsic variable (SLANG_IVARIABLE) -2 user-defined global variable (SLANG_GVARIABLE)#v-\seealso{SLadd_intrinsic_function, SLang_run_hooks, SLang_execute_function}\done\function{SLang_run_hooks}\synopsis{Run a user-defined hook with arguments}\usage{int SLang_run_hooks (char *fname, unsigned int n, ...)}\description The \var{SLang_run_hooks} function may be used to execute a user-defined function named \var{fname}. Before execution of the function, the \var{n} string arguments specified by the variable parameter list are pushed onto the stack. If the function \var{fname} does not exist, \var{SLang_run_hooks} returns zero; otherwise, it returns \exmp{1} upon successful execution of the function, or \-1 if an error occurred.\example The \jed editor uses \var{SLang_run_hooks} to setup the mode of a buffer based on the filename extension of the file associated with the buffer:#v+ char *ext = get_filename_extension (filename); if (ext == NULL) return -1; if (-1 == SLang_run_hooks ("mode_hook", 1, ext)) return -1; return 0;#v-\seealso{SLang_is_defined, SLang_execute_function}\done\function{SLang_execute_function}\synopsis{Execute a user or intrinsic function}\usage{int SLang_execute_function (char *fname)}\description This function may be used to execute either a user-defined function or an intrinisic function. The name of the function is specified by \var{fname}. It returns zero if \var{fname} is not defined, or \exmp{1} if the function was successfully executed, or \-1 upon error.\notes The function \var{SLexecute_function} may be a better alternative for some uses.\seealso{SLang_run_hooks, SLexecute_function, SLang_is_defined}\done\function{SLang_verror}\synopsis{Signal an error with a message}\usage{void SLang_verror (int code, char *fmt, ...);}\description The \var{SLang_verror} function sets \var{SLang_Error} to \var{code} if \var{SLang_Error} is 0. It also displays the error message implied by the \var{printf} variable argument list using \var{fmt} as the format.\example#v+ FILE *open_file (char *file) { char *file = "my_file.dat"; if (NULL == (fp = fopen (file, "w"))) SLang_verror (SL_INTRINSIC_ERROR, "Unable to open %s", file); return fp; }#v-\seealso{SLang_vmessage, SLang_exit_error}\done\function{SLang_doerror}\synopsis{Signal an error}\usage{void SLang_doerror (char *err_str)}\description The \var{SLang_doerror} function displays the string \var{err_str} to the error device and signals a \slang error.\notes \var{SLang_doerror} is considered to obsolete. Applications should use the \var{SLang_verror} function instead.\seealso{SLang_verror, SLang_exit_error}\done\function{SLang_get_function}\synopsis{Get a pointer to a \slang function}\usage{SLang_Name_Type *SLang_get_function (char *fname)}\description This function returns a pointer to the internal \slang table entry of a function whose name is given by \var{fname}. It returns \var{NULL} upon failure. The value returned by this function can be used \var{SLexecute_function} to call the function directly from C.\seealso{SLexecute_function}\done\function{SLexecute_function}\synopsis{Execute a \slang or intrinsic function}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -