📄 cref.tm
字号:
\-1 upon failure.\example The destroy method for \var{SLANG_STRING_TYPE} looks like:#v+ static void string_destroy (unsigned char type, VOID_STAR ptr) { char *s = *(char **) ptr; if (s != NULL) SLang_free_slstring (*(char **) s); }#v-\notes Data types of class SLANG_CLASS_TYPE_SCALAR do not require a destroy callback. However, other classes do.\seealso{SLclass_allocate_class, SLclass_register_class}\done\function{SLclass_set_push_function}\synopsis{Set the push callback for a new data type}\usage{int SLclass_set_push_function (cl, push_fun)}#v+ SLang_Class_Type *cl int (*push_fun) (unsigned char, VOID_STAR);#v-\description \var{SLclass_set_push_function} is used to set the push callback for a new data type specified by \var{cl}, which must have been previously obtained via \var{SLclass_allocate_class}. The parameter \var{push_fun} is a pointer to the push callback. It is required to take two arguments: an unsigned character representing the data type, and the address of the object to be pushed. It must return zero upon success, or \-1 upon failure. \var{SLclass_set_push_function} returns zero upon success, or \-1 upon failure.\example The push callback for \var{SLANG_COMPLEX_TYPE} looks like:#v+ static int complex_push (unsigned char type, VOID_STAR ptr) { double *z = *(double **) ptr; return SLang_push_complex (z[0], z[1]); }#v-\seealso{SLclass_allocate_class, SLclass_register_class}\done\function{SLclass_set_pop_function}\synopsis{Set the pop callback for a new data type}\usage{int SLclass_set_pop_function (cl, pop_fun)}#v+ SLang_Class_Type *cl int (*pop_fun) (unsigned char, VOID_STAR);#v-\description \var{SLclass_set_pop_function} is used to set the callback for popping an object from the stack for a new data type specified by \var{cl}, which must have been previously obtained via \var{SLclass_allocate_class}. The parameter \var{pop_fun} is a pointer to the pop callback function, which is required to take two arguments: an unsigned character representing the data type, and the address of the object to be popped. It must return zero upon success, or \-1 upon failure. \var{SLclass_set_pop_function} returns zero upon success, or \-1 upon failure.\example The pop callback for \var{SLANG_COMPLEX_TYPE} looks like:#v+ static int complex_push (unsigned char type, VOID_STAR ptr) { double *z = *(double **) ptr; return SLang_pop_complex (&z[0], &z[1]); }#v-\seealso{SLclass_allocate_class, SLclass_register_class}\done\function{SLclass_get_datatype_name}\synopsis{Get the name of a data type}\usage{char *SLclass_get_datatype_name (unsigned char type)}\description The \var{SLclass_get_datatype_name} function returns the name of the data type specified by \var{type}. For example, if \var{type} is \var{SLANG_INT_TYPE}, the string \exmp{"Integer_Type"} will be returned. This function returns a pointer that should not be modified or freed.\seealso{SLclass_allocate_class, SLclass_register_class}\done\function{SLang_free_mmt}\synopsis{Free a memory managed type}\usage{void SLang_free_mmt (SLang_MMT_Type *mmt)}\description The \var{SLang_MMT_Type} function is used to free a memory managed data type.\seealso{SLang_object_from_mmt, SLang_create_mmt}\done\function{SLang_object_from_mmt}\synopsis{Get a pointer to the value of a memory managed type}\usage{VOID_STAR SLang_object_from_mmt (SLang_MMT_Type *mmt)}\description The \var{SLang_object_from_mmt} function returns a pointer to the actual object whose memory is being managed by the interpreter.\seealso{SLang_free_mmt, SLang_create_mmt}\done\function{SLang_create_mmt}\synopsis{Create a memory managed data type}\usage{SLang_MMT_Type *SLang_create_mmt (unsigned char t, VOID_STAR ptr)}\description The \var{SLang_create_mmt} function returns a pointer to a new memory managed object. This object contains information necessary to manage the memory associated with the pointer \var{ptr} which represents the application defined data type of type \var{t}.\seealso{SLang_object_from_mmt, SLang_push_mmt, SLang_free_mmt}\done\function{SLang_push_mmt}\synopsis{Push a memory managed type}\usage{int SLang_push_mmt (SLang_MMT_Type *mmt)}\description This function is used to push a memory managed type onto the interpreter stack. It returns zero upon success, or \exmp{-1} upon failure.\seealso{SLang_create_mmt, SLang_pop_mmt}\done\function{SLang_pop_mmt}\synopsis{Pop a memory managed data type}\usage{SLang_MMT_Type *SLang_pop_mmt (unsigned char t)}\description The \var{SLang_pop_mmt} function may be used to pop a memory managed type of type \var{t} from the stack. It returns a pointer to the memory managed object upon success, or \var{NULL} upon failure. The function \var{SLang_object_from_mmt} should be used to access the actual pointer to the data type.\seealso{SLang_object_from_mmt, SLang_push_mmt}\done\function{SLang_inc_mmt}\synopsis{Increment a memory managed type reference count}\usage{void SLang_inc_mmt (SLang_MMT_Type *mmt);}\description The \var{SLang_inc_mmt} function may be used to increment the reference count associated with the memory managed data type given by \var{mmt}.\seealso{SLang_free_mmt, SLang_create_mmt, SLang_pop_mmt, SLang_pop_mmt}\done\function{SLang_vmessage}\synopsis{Display a message to the message device}\usage{void SLang_vmessage (char *fmt, ...)}\description This function prints a \var{printf} style formatted variable argument list to the message device. The default message device is \var{stdout}.\seealso{SLang_verror}\done\function{SLang_exit_error}\synopsis{Exit the program and display an error message}\usage{void SLang_exit_error (char *fmt, ...)}\description The \var{SLang_exit_error} function terminates the program and displays an error message using a \var{printf} type variable argument list. The default behavior to this function is to write the message to \var{stderr} and exit with the \var{exit} system call. If the function pointer \var{SLang_Exit_Error_Hook} is non-NULL, the function to which it points will be called. This permits an application to perform whatever cleanup is necessary. This hook has the prototype:#v+ void (*SLang_Exit_Error_Hook)(char *, va_list);#v-\seealso{SLang_verror, exit}\done\function{SLang_init_slang}\synopsis{Initialize the interpreter}\usage{int SLang_init_slang (void)}\description The \var{SLang_init_slang} function must be called by all applications that use the \slang interpreter. It initializes the interpreter, defines the built-in data types, and adds a set of core intrinsic functions. The function returns \var{0} upon success, or \var{-1} upon failure.\seealso{SLang_init_slfile, SLang_init_slmath, SLang_init_slunix}\done\function{SLang_init_slfile}\synopsis{Initialize the interpreter file I/O intrinsics}\usage{int SLang_init_slfile (void)}\description This function initializes the interpreters file I/O intrinsic functions. This function adds intrinsic functions such as \var{fopen}, \var{fclose}, and \var{fputs} to the interpreter. It returns \exmp{0} if successful, or \exmp{-1} upon error.\notes Before this function can be called, it is first necessary to call \var{SLang_init_slang}. It also adds the preprocessor symbol \var{__SLFILE__} to the interpreter.\seealso{SLang_init_slang, SLang_init_slunix, SLang_init_slmath}\done\function{SLang_init_slmath}\synopsis{Initialize the interpreter math intrinsics}\usage{int SLang_init_slmath (void)}\description The \var{SLang_init_slmath} function initializes the interpreter's mathematical intrinsic functions and makes them available to the language. The intrinsic functions include \var{sin}, \var{cos}, \var{tan}, etc... It returns \exmp{0} if successful, or \exmp{-1} upon failure.\notes This function must be called after \var{SLang_init_slang}. It adds the preprocessor symbol \var{__SLMATH__} to the interpreter.\seealso{SLang_init_slang, SLang_init_slfile, SLang_init_slunix}\done\function{SLang_init_slunix}\synopsis{Make available some unix system calls to the interpreter}\usage{int SLang_init_slunix (void)}\description The \var{SLang_init_slunix} function initializes the interpreter's unix system call intrinsic functions and makes them available to the language. Examples of functions made available by \var{SLang_init_slunix} include \var{chmod}, \var{chown}, and \var{stat_file}. It returns \exmp{0} if successful, or \exmp{-1} upon failure.\notes This function must be called after \var{SLang_init_slang}. It adds the preprocessor symbol \var{__SLUNIX__} to the interpreter.\seealso{SLang_init_slang, SLang_init_slfile, SLang_init_slmath}\done\function{SLadd_intrin_fun_table}\synopsis{Add a table of intrinsic functions to the interpreter}\usage{int SLadd_intrin_fun_table(SLang_Intrin_Fun_Type *tbl, char *pp_name);}\description The \var{SLadd_intrin_fun_table} function adds an array, or table, of \var{SLang_Intrin_Fun_Type} objects to the interpreter. The first parameter, \var{tbl} specifies the table to be added. The second parameter \var{pp_name}, if non-NULL will be added to the list of preprocessor symbols. This function returns \-1 upon failure or zero upon success.\notes A table should only be loaded one time and it is considered to be an error on the part of the application if it loads a table more than once.\seealso{SLadd_intrin_var_table, SLadd_intrinsic_function, SLdefine_for_ifdef}\done\function{SLadd_intrin_var_table}\synopsis{Add a table of intrinsic variables to the interpreter}\usage{int SLadd_intrin_var_table (SLang_Intrin_Var_Type *tbl, char *pp_name);}\description The \var{SLadd_intrin_var_table} function adds an array, or table, of \var{SLang_Intrin_Var_Type} objects to the interpreter. The first parameter, \var{tbl} specifies the table to be added. The second parameter \var{pp_name}, if non-NULL will be added to the list of preprocessor symbols. This function returns \-1 upon failure or zero upon success.\notes A table should only be loaded one time and it is considered to be an error on the part of the application if it loads a table more than once.\seealso{SLadd_intrin_var_table, SLadd_intrinsic_function, SLdefine_for_ifdef}\done\function{SLang_load_file}\synopsis{Load a file into the interpreter}\usage{int SLang_load_file (char *fn)}\description The \var{SLang_load_file} function opens the file whose name is specified by \var{fn} and feeds it to the interpreter, line by line, for execution. If \var{fn} is \var{NULL}, the function will take input from \var{stdin}. If no error occurs, it returns \exmp{0}; otherwise, it returns \exmp{-1}, and sets \var{SLang_Error} accordingly. For example, if it fails to open the file, it will return \exmp{-1} with \var{SLang_Error} set to \var{SL_OBJ_NOPEN}.\notes If the hook \var{SLang_Load_File_Hook} declared as#v+ int (*SLang_Load_File_Hook)(char *);#v- is non-NULL, the function point to by it will be used to load the file. For example, the \jed editor uses this hook to load files via its own routines.\seealso{SLang_load_object, SLang_load_string}\done\function{SLang_restart}\synopsis{Reset the interpreter after an error}\usage{void SLang_restart (int full)}\description The \var{SLang_restart} function should be called by the application at top level if an error occurs. If the parameter \var{full} is non-zero, any objects on the \slang run time stack will be removed from the stack; otherwise, the stack will be left intact. Any time the stack is believed to be trashed, this routine should be called with a non-zero argument (e.g., if \var{setjmp}/\var{longjmp} is called). Calling \var{SLang_restart} does not reset the global variable \var{SLang_Error} to zero. It is up to the application to reset that variable to zero after calling \var{SLang_restart}.\example#v+ while (1) { if (SLang_Error) { SLang_restart (1); SLang_Error = 0; } (void) SLang_load_file (NULL); }#v-\seealso{SLang_init_slang, SLang_load_file}\done\function{SLang_byte_compile_file}\synopsis{Byte-compile a file for faster loading}\usage{int SLang_byte_compile_file(char *fn, int reserved)}\description The \var{SLang_byte_compile_file} function ``byte-compiles'' the file \var{fn} for faster loading by the interpreter. This produces a new file whose filename is equivalent to the one specified by \var{fn}, except that a \var{'c'} is appended to the name. For example, if \var{fn} is set to \exmp{init.sl}, then the new file will have the name exmp{init.slc}. The meaning of the second parameter, \var{reserved}, is reserved for future use. For now, set it to \var{0}. The function returns zero upon success, or \exmp{-1} upon error and sets SLang_Error accordingly.\seealso{SLang_load_file, SLang_init_slang}\done\function{SLang_autoload}\synopsis{Autoload a function from a file}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -