OspreyForth has the following commands incorporated into the interpreter. You can find the code for these commands in the file pfcustom.c in the csrc folder
c:str:create ( str count -- cstring )
Creates a C-style string from a Forth string. Also takes advantage for entities.c by Christoph Gärtner which allows using HTML and XML entities as a placeholder for UTF-8 and control characters. See csrc/entities.c for a complete list
c:mem:free ( cstring -- )
This can be used to free memory, usually associated with a C string
c:str:length ( cstring -- cstring count )
This puts a number on the stack indicating the number of characters in a C string. Once this is done, the OspreyForth interpreter can print out the string using the usual Forth methods (although Forth does not recognize the "\0" delmiter, which is why the count is needed)
dynlib:open ( str count -- libptr )
Given a Forth string indicating the location of a dynamic library and the attendant string count, dynlib:open will attempt to locate and load a dynamic library.
dynlib:close ( libptr -- resultcode )
Given a pointer on the stack, dynlib:close will try to unload the pointer and will deliver a status code of 0 if successful or -1 otherwise
dynlib:error ( -- 0 ) or ( -- cstring count )
If something goes wrong with loading the dynamic library, dynlib:error can be used to check if there is an error message. If 0 is returned, nothing registered an error. If something did register an error, dynlib:error will leave a C string and a count for the interpreter to display.
dynlib:sym ( str count libptr -- 0 ) or ( str count libptr -- funcptr )
This will retrieve a function pointer from a loaded library. If it successful, it will return a function pointer to call
ffi:type:select ( number -- typeptr )
For dynamic library functions to be called, OspreyForth must use LibFFI's type functions. Given a number between 0 and 20, ffi:type:select will return a pointer for one of a series of different defined types. 0 will actually return a pointer to ffi_type_void, which should only be used for return values from a function.
ffi:function:call ( libptr cstring number number -- )
This function assembles and calls a foreign (C language) interface. It's important to understand that arguments in the function signature are not the full set of arguments to use in a given function call. The arguments listed are only there to tell the function what to pull off the stack to complete a function call. For a complete example, see the file named "call_puts.fth"