### Test File Format Example Source: https://github.com/gnome/gimp/blob/master/plug-ins/python/tests/test-file-plug-ins/README.md Example of a .files format used to list images for testing, including optional expected results like EXPECTED_FAIL or SKIP. ```text badbitcount.bmp, EXPECTED_FAIL badbitssize.bmp baddens1.bmp baddens2.bmp, SKIP ``` -------------------------------- ### BMP Test Configuration Example Source: https://github.com/gnome/gimp/blob/master/plug-ins/python/tests/test-file-plug-ins/README.md Example of a per-format configuration file for testing BMP files. It specifies enabled tests, descriptions, data folders, and associated files. ```ini [test-1] enabled=True description=Test loading bmpsuite good images folder=bmp/bmpsuite/g/ files=bmpsuite-g-tests.files source=https://github.com/jsummers/bmpsuite ``` -------------------------------- ### TinyScheme Standalone Usage Examples Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Demonstrates command-line usage for the TinyScheme interpreter, including help, file processing, and executing Scheme commands directly. ```shell tinyscheme -? ``` ```shell tinyscheme [ ...] ``` ```shell -1 [ ...] ``` ```shell -c [ ...] ``` -------------------------------- ### Example of TinyScheme Exception Handling Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Demonstrates the use of 'catch' and 'throw' for handling potential errors, such as division by zero, within a Scheme program. ```scheme (define (foo x) (write x) (newline) (/ x 0)) (catch (begin (display "Error!\n") 0) (write "Before foo ... ") (foo 5) (write "After foo")) ``` -------------------------------- ### Convert MIT Scheme Example to GIMP Test Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md Convert examples from the MIT Scheme Reference into GIMP's testing framework format using the assert function. Ensure the left and right-hand sides of the MIT spec are correctly placed within the assert call. ```scheme (assert '(equal? (vector 'a 'b 'c) #(a b c))) ``` -------------------------------- ### Define Character Literals Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Shows examples of character literals, including space and newline, and hexadecimal/octal representations for string literals. ```scheme #\space ``` ```scheme #\newline ``` -------------------------------- ### Execute Scheme Script with #! Shebang Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Example of using the '-1' flag with a shebang line in a script to execute Scheme code, passing arguments to the script. ```scheme #! /somewhere/tinyscheme -1 (display *args*) ``` -------------------------------- ### Find GIMP PDB Procedures Tested Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md This command-line snippet helps identify GIMP PDB procedures that are called within the test suite. It navigates to the PDB test directory, finds all .scm files, extracts procedure names starting with 'gimp-', sorts them, and lists unique entries. ```bash >cd test/tests/PDB >find . -name "*.scm" -exec grep -o "gimp-[a-z\-]*" {} \; | sort | uniq ``` -------------------------------- ### Python 3 Unit Test Structure Source: https://github.com/gnome/gimp/blob/master/libgimp/tests/README.md Add Python 3 unit tests using this structure. Utilize gimp_assert() for assertions and ensure the file starts with the correct shebang. ```python #!/usr/bin/env python3 # Add your test code here. # Then test that it succeeded with the assert-like test: gimp_assert('Test name for easy debugging', testme > 0) # Repeat with more tests as needed. ``` -------------------------------- ### Get the size of a file in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `file-size` to retrieve the size of a file in bytes. Returns #f if the file does not exist or is inaccessible. ```scheme (file-size filename) ``` -------------------------------- ### Read a directory entry in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `dir-read-entry` to get the name of the next entry in a directory stream. Returns `eof` when all entries are read. ```scheme (dir-read-entry dirstream) ``` -------------------------------- ### Get the type of a file in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `file-type` to get the type of a file (regular, directory, link, or other). Returns FILE_TYPE_OTHER (0) for non-existent files or insufficient privileges. ```scheme (file-type filename) ``` -------------------------------- ### Check if All Tests Passed Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md Use the `testing:all-passed?` predicate to get a boolean indicating the overall testing framework state. ```scheme (testing:all-passed?) ``` -------------------------------- ### Define a C Foreign Function for TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Example of a C function that squares its numeric argument. Foreign functions must accept a `scheme *sc` and `pointer args`, and return a `pointer`. ```c pointer square(scheme *sc, pointer args) { if(args!=sc->NIL) { if(sc->isnumber(sc->pair_car(args))) { double v=sc->rvalue(sc->pair_car(args)); return sc->mk_real(sc,v*v); } } return sc->NIL; } ``` -------------------------------- ### Get time of day in microseconds in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt The `gettimeofday` function returns a list containing seconds from the beginning of the day and microseconds within the current second. ```scheme (gettimeofday) ``` -------------------------------- ### Get Memory Block Length in GIMP Scheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Retrieves the length of a given memory block. It checks if the provided argument is indeed a memory block. ```c case OP_BLOCKLEN: /* block-length */ if(!ismemblock(car(sc->args))) { Error_1(sc,"block-length: not a memory block:",car(sc->args)); } s_return(sc,mk_integer(sc,keynum(car(sc->args)))); ``` -------------------------------- ### Get current local time in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt The `time` function returns the current local time as a list: (year month day-of-month hour min sec millisec). Year is an offset from 1900. ```scheme (time) ``` -------------------------------- ### Create a directory in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `dir-make` to create a new directory. An optional mode argument can specify permissions. Returns #t on success, #f on failure (e.g., directory exists, insufficient permissions). ```scheme (dir-make dirname . mode) ``` -------------------------------- ### Load a Test Script in GIMP Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md To run tests, load the desired test script using the SF Console. Ensure GIMP is a non-stable build. ```scheme (testing:load-test "tinyscheme.scm") ``` -------------------------------- ### GIMP Package Definition and Usage Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Demonstrates defining a package and accessing its members using the colon qualifier syntax. Requires USE_COLON_HOOK=1. ```scheme (define toto (package (define foo 1) (define bar +))) foo ==> Error, "foo" undefined (eval 'foo) ==> Error, "foo" undefined (eval 'foo toto) ==> 1 toto::foo ==> 1 ((eval 'bar toto) 2 (eval 'foo toto)) ==> 3 (toto::bar 2 toto::foo) ==> 3 (eval (bar 2 foo) toto) ==> 3 ``` -------------------------------- ### Scheme Reference - Environments Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Documentation for environment-related functions in TinyScheme. ```APIDOC ## Scheme Reference - Environments ### (interaction-environment) Returns the interaction environment. In TinyScheme, this is an immutable list of association lists. ### (current-environment) Returns the environment in effect at the time of the call. This can be used to define local environments, as shown in the `package` macro example in `init.scm`. ### (defined? ) (defined? ) Checks whether the given symbol is defined in the current or a specified environment. ``` -------------------------------- ### Run File Import Tests from Terminal Source: https://github.com/gnome/gimp/blob/master/plug-ins/python/tests/test-file-plug-ins/README.md Execute file import tests from the command line by piping a Python script to gimp-console. Configure necessary environment variables like PYTHONPATH, GIMP_TESTS_CONFIG_FILE, GIMP_TESTS_LOG_FILE, and GIMP_TESTS_DATA_FOLDER. ```bash # Mandatory - the python script is passed via pipe to stdin and the python interpreter # therefore cannot depend on __file__ and __name__ variables to establish the environment, # this is especially important here, where it imports external modules. export PYTHONPATH="/location/of/your/python/script/" # Optional export GIMP_TESTS_CONFIG_FILE="/location/of/config.ini" # Default: ./tests/config.ini export GIMP_TESTS_LOG_FILE="/location/of/logfile.log" # Default: ./tests/gimp-tests.log export GIMP_TESTS_DATA_FOLDER="/location/of/test-images/rootfolder/" # Default: ./tests/ cd location/of/plug-in/gimp-file-plugin-tests cat batch-import-tests.py | gimp-console-2.99 -idf --batch-interpreter python-fu-eval -b - --quit ``` -------------------------------- ### Run File Import Tests with Flatpak Source: https://github.com/gnome/gimp/blob/master/plug-ins/python/tests/test-file-plug-ins/README.md Execute file import tests for the Flatpak version of GIMP. Environment variables like PYTHONPATH and GIMP_TESTS_DATA_FOLDER are passed using the --env flag. ```bash cd location/of/plug-in/gimp-file-plugin-tests cat batch-import-tests.py | flatpak run \ --env=PYTHONPATH=$(pwd) \ --env=GIMP_TESTS_DATA_FOLDER= \ --env=GIMP_TESTS_CONFIG_FILE=$(pwd)/tests/batch-config.ini \ org.gimp.GIMP -idf --batch-interpreter=python-fu-eval -b - --quit ``` -------------------------------- ### Scheme Initialization Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt The interpreter state is initialized with the 'scheme_init' procedure. ```scheme scheme_init ``` -------------------------------- ### Download GIMP Test Images Source: https://github.com/gnome/gimp/blob/master/plug-ins/python/tests/test-file-plug-ins/README.md Clone the GIMP test images repository and set the GIMP_TESTS_DATA_FOLDER environment variable to point to the downloaded data. ```bash git clone git@ssh.gitlab.gnome.org:Infrastructure/gimp-test-images.git # as for convenience, during the tests, you can point at like export GIMP_TESTS_DATA_FOLDER= ``` -------------------------------- ### TinyScheme Overview Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt General information about TinyScheme, its purpose, and licensing. ```APIDOC ## TinyScheme Overview ### Description TinyScheme is a lightweight Scheme interpreter designed for embedding into other programs. It implements a significant subset of R5RS, balancing features with a small footprint. It allows for multiple interpreter states and easy integration of C foreign functions. ### License This software is open source, covered by a BSD-style license. Please read the accompanying file COPYING. ### Based On This Scheme interpreter is based on MiniSCHEME version 0.85k4. ``` -------------------------------- ### C Unit Test Structure Source: https://github.com/gnome/gimp/blob/master/libgimp/tests/README.md Use this template for C unit tests. Each test must be enclosed by GIMP_TEST_START() and GIMP_TEST_END() macros, followed by GIMP_TEST_RETURN. ```c static GimpValueArray * gimp_c_test_run (GimpProcedure *procedure, GimpRunMode run_mode, GimpImage *image, gint n_drawables, GimpDrawable **drawables, GimpProcedureConfig *config, gpointer run_data) { /* Each test must be surrounded by GIMP_TEST_START() and GIMP_TEST_END() * macros this way: */ GIMP_TEST_START("Test name for easy debugging") /* Run some code and finish by an assert-like test. */ GIMP_TEST_END(testme > 0) /* Do more tests as needed. */ /* Mandatorily end the function by this macro: */ GIMP_TEST_RETURN } ``` -------------------------------- ### Scheme Oblist and Macro Expansion Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Provides access to the oblist (all symbols) and allows for macro expansion. ```scheme (oblist) (macro-expand
) ``` -------------------------------- ### Open a directory stream in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `dir-open-stream` to open a directory stream for reading entries. Remember to close the stream with `dir-close-stream`. ```scheme (dir-open-stream path) ``` -------------------------------- ### Define Package Macro Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt This macro defines a package, allowing for local definitions within a closure. It returns the current environment. ```scheme (macro (package form) `(apply (lambda () ,@(cdr form) (current-environment)))) ``` -------------------------------- ### Scheme Reference - Directives Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Documentation for interpreter control directives in TinyScheme. ```APIDOC ## Scheme Reference - Directives ### (gc) Performs garbage collection immediately. ### (gcverbose) (gcverbose ) Controls whether garbage collection produces visible output. Defaults to `#t`. ### (quit) (quit ) Stops the interpreter and sets the internal `retcode` field. Defaults to `0`. This value is returned as the exit code to the OS when the interpreter is run standalone. ### (tracing ) Turns tracing on (`1`) or off (`0`). This functionality is conditional on `USE_TRACING` being enabled. ``` -------------------------------- ### Scheme Reference - Supported Types Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Overview of data types supported by TinyScheme. ```APIDOC ## Scheme Reference - Supported Types TinyScheme supports the following data types: - Numbers (integers and reals) - Symbols - Pairs - Strings - Characters - Ports - Eof object - Environments - Vectors ``` -------------------------------- ### Check if a file exists in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `file-exists?` to determine if a file exists and is accessible. Accessibility is based on real user/group IDs. ```scheme (file-exists? filename) ``` -------------------------------- ### Scheme Reference - Literals Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Details on string and character literal syntax in TinyScheme. ```APIDOC ## Scheme Reference - Literals ### String Literals String literals can contain escaped quotes (`\") as usual. They also support escape sequences for newline (`\n`), carriage return (`\r`), tab (`\t`), hexadecimal representations (`\xDD`), and octal representations (`\DDD`). Literal newlines are also permitted within string literals, functioning similarly to HERE-strings. Example: ```scheme (define s "String with newline here and here that can function like a HERE-string") ``` ### Character Literals Character literals include standard characters like `#\space` and `#\newline`. ``` -------------------------------- ### Scheme Reference - Symbols Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Documentation for symbol manipulation in TinyScheme. ```APIDOC ## Scheme Reference - Symbols ### (gensym) Returns a new interned symbol each time it is called. This function might be moved to the library once `string->symbol` is implemented. ``` -------------------------------- ### File System Functions Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Functions for interacting with the file system, including checking file existence, type, size, deletion, and directory operations. ```APIDOC ## File System Functions ### Description Provides functions for interacting with the file system. ### Functions #### `file-exists?` ##### Description Checks if a file exists and is accessible. ##### Parameters - **filename** (string) - The path to the file. ##### Returns - `#t` if the file exists and is accessible, `#f` otherwise. #### `file-type` ##### Description Determines the type of a file. ##### Parameters - **filename** (string) - The path to the file. ##### Returns - `FILE_TYPE_FILE` (1) for regular files. - `FILE_TYPE_DIR` (2) for directories. - `FILE_TYPE_LINK` (3) for symbolic links. - `FILE_TYPE_OTHER` (0) if the file type cannot be determined or the file does not exist. #### `file-size` ##### Description Gets the size of a file in bytes. ##### Parameters - **filename** (string) - The path to the file. ##### Returns - The size of the file in bytes, or `#f` if the file does not exist or is not accessible. #### `file-delete` ##### Description Removes a file. ##### Parameters - **filename** (string) - The path to the file to delete. ##### Returns - `#t` if the operation succeeds, `#f` otherwise. #### `dir-open-stream` ##### Description Opens a directory stream for reading directory entries. ##### Parameters - **path** (string) - The path to the directory. ##### Returns - A directory stream object. #### `dir-read-entry` ##### Description Reads the next entry from a directory stream. ##### Parameters - **dirstream** (directory stream) - The directory stream obtained from `dir-open-stream`. ##### Returns - The name of the next directory entry, or `eof` if all entries have been read. #### `dir-rewind` ##### Description Resets a directory stream to the beginning. ##### Parameters - **dirstream** (directory stream) - The directory stream to rewind. ##### Returns - `#t` if the operation succeeds, `#f` otherwise. #### `dir-close-stream` ##### Description Closes a directory stream. ##### Parameters - **dirstream** (directory stream) - The directory stream to close. #### `dir-make` ##### Description Creates a new directory. ##### Parameters - **dirname** (string) - The name of the directory to create. - **mode** (integer, optional) - Permissions for the new directory. ##### Returns - `#t` if the operation succeeds, `#f` otherwise. ``` -------------------------------- ### TinyScheme Sharp Hook for Reader Extensions Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Defines a procedure '*sharp-hook*' that is called when the reader encounters an unknown character following '#'. This allows for custom syntax. ```scheme *sharp-hook* ``` -------------------------------- ### Scheme Reference - Mathematical Functions Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Details on supported mathematical functions in TinyScheme. ```APIDOC ## Scheme Reference - Mathematical Functions ### Supported Functions Due to the absence of rational and complex numbers, corresponding functions are also missing. Supported functions include: - `exp`, `log`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `floor`, `ceiling`, `trunc`, `round` - `sqrt`, `expt` (when `USE_MATH=1`) - Number-theoretical quotient, remainder, modulo, `gcd`, `lcm` ### Library Functions - `exact?`, `inexact?`, `odd?`, `even?`, `zero?`, `positive?`, `negative?` - `exact->inexact` - `inexact->exact` (core function) ``` -------------------------------- ### Scheme List and Pair Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Core procedures for constructing and manipulating lists and pairs, including mapping, folding, and appending. ```scheme cons car cdr list length map for-each foldr list-tail list-ref last-pair reverse append member memq memv assoc assq assv ``` -------------------------------- ### Scheme Reference - Type Predicates Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt List of type predicate functions available in TinyScheme. ```APIDOC ## Scheme Reference - Type Predicates TinyScheme supports the following type predicate functions: - `boolean?` - `eof-object?` - `symbol?` - `number?` - `string?` - `integer?` - `real?` - `list?` - `null?` - `char?` - `port?` - `input-port?` - `output-port?` - `procedure?` - `pair?` - `environment?` - `vector?` - `closure?` - `macro?` ``` -------------------------------- ### Scheme Dynamic Extension Loading Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Loads dynamically linked extensions, allowing for the integration of foreign procedures. ```scheme (load-extension ) ``` -------------------------------- ### Format Memory Block for Printing Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Add a case to `atom2str` to format memory blocks for printing, displaying them as '#'. ```c else if (ismemblock(l)) { p = "#"; ``` -------------------------------- ### Make Memory Block in GIMP Scheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Creates a new memory block of a specified length, optionally filled with a character. Handles invalid input for length and fill character. ```c case OP_MKBLOCK: { int fill=0; int len; if(!isnumber(car(sc->args))) { Error_1(sc,"make-block: not a number:",car(sc->args)); } len=ivalue(car(sc->args)); if(len<=0) { Error_1(sc,"make-block: not positive:",car(sc->args)); } if(cdr(sc->args)!=sc->NIL) { if(!isnumber(cadr(sc->args)) || ivalue(cadr(sc->args))<0) { Error_1(sc,"make-block: not a positive number:",cadr(sc->args)); } fill=charvalue(cadr(sc->args))%255; } s_return(sc,mk_memblock(sc,len,(char)fill)); } ``` -------------------------------- ### Known Issues and Missing Features Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Details on known bugs and features that are not implemented in TinyScheme. ```APIDOC ## Known Issues and Missing Features ### Known Bugs TinyScheme is known to misbehave when memory is exhausted. ### Missing Features - Hygienic macros - Rational and complex numbers - unwind-protect and call-with-values - Decent debugging facilities (only tracing is supported natively) ### Potential Enhancements - Subset of SLIB might work with TinySCHEME. - String->symbol implementation is pending. ``` -------------------------------- ### Scheme Define with Return Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt A variant of 'define' that makes the continuation available as 'return' within the procedure, useful for imperative programming. ```scheme (define-with-return ( ...) ) ``` -------------------------------- ### Scheme String Port Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Enables I/O operations using strings as ports, facilitating reading from and writing to string buffers. ```scheme open-input-string open-output-string get-output-string open-input-output-string ``` -------------------------------- ### TinyScheme Catch Exception Block Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Establishes a scope for exception handling. Any expression within the 'catch' block that throws an exception will be caught, and the first argument to 'catch' will be evaluated. ```scheme (catch ... ) ``` -------------------------------- ### Scheme String Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Offers a comprehensive set of procedures for string manipulation, including creation, length, element access, substring extraction, and comparison. ```scheme string make-string list->string string-length string-ref string-set! substring string->list string-fill! string-append string-copy string=? string? string<=? string>=? string->number number->string atom->string string->atom ``` -------------------------------- ### Create New Memory Block Function Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Implement the `mk_memblock` function to create a new memory block of a specified length, optionally filled with a byte. It handles memory allocation and initialization. ```c static pointer mk_memblock(scheme *sc, int len, char fill) { pointer x; char *p=(char*)sc->malloc(len); if(p==0) { return sc->NIL; } x = get_cell(sc, sc->NIL, sc->NIL); typeflag(x) = T_MEMBLOCK|T_ATOM; strvalue(x)=p; keynum(x)=len; memset(p,fill,len); return (x); } ``` -------------------------------- ### Unit Test Assertion Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md Use `assert` for normal operation unit tests in the testing framework. ```scheme assert ``` -------------------------------- ### Suspend execution in microseconds in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `usleep` to pause the current thread for a specified number of microseconds. ```scheme (usleep microsec) ``` -------------------------------- ### Define a Foreign Function in TinyScheme Environment Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Registers a C foreign function named 'square' into the global environment of the TinyScheme interpreter. Ensure the 'square' C function is defined and accessible. ```scheme sc->interface->scheme_define( sc, sc->global_env, sc->interface->mk_symbol(sc,"square"), sc->interface->mk_foreign_func(sc, square)); ``` -------------------------------- ### Configure Error Line Display in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md Modify the `SHOW_ERROR_LINE` macro in `libscriptfu/tinyscheme/scheme.h` to control line number display in error messages. Setting it to `0` is recommended for portable error testing. ```c # define SHOW_ERROR_LINE 0 ``` -------------------------------- ### Scheme Closure Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Procedures for retrieving the code of a closure and for creating new closures within a specified environment. ```scheme (get-closure-code ) (make-closure ) ``` -------------------------------- ### Scheme Memory Allocation Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Allows for dynamic allocation of additional memory segments. ```scheme (new-segment ) ``` -------------------------------- ### Close a directory stream in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `dir-close-stream` to close an open directory stream. No further `dir-read-entry` calls should be made after closing. ```scheme (dir-close-stream dirstream) ``` -------------------------------- ### Define Custom Error Hook in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Sets the '*error-hook*' variable to the 'throw' procedure, enabling a custom exception handling mechanism for system errors. ```scheme (define *error-hook* throw) ``` -------------------------------- ### Scheme Stream Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Procedures for working with streams, including accessing their head and tail, and constructing new streams. ```scheme head tail cons-stream ``` -------------------------------- ### Rewind a directory stream in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `dir-rewind` to reset a directory stream, allowing `dir-read-entry` to read from the beginning again. Returns #t on success, #f if the stream is invalid. ```scheme (dir-rewind dirstream) ``` -------------------------------- ### Scheme Vector Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Provides functions for creating, manipulating, and querying vectors, including length, element access, and conversion to/from lists. ```scheme make-vector vector vector-length vector-ref vector-set! list->vector vector-fill! vector->list vector-equal? ``` -------------------------------- ### Scheme Property List Operations Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Procedures for managing property lists associated with symbols. ```scheme put get ``` -------------------------------- ### Delete a file in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Use `file-delete` to remove a specified file. Returns #t on success, #f if the file is read-only or does not exist. ```scheme (file-delete filename) ``` -------------------------------- ### Define String Literal with Newlines Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Demonstrates defining a string literal that spans multiple lines, functioning similarly to a HERE-string. ```scheme (define s "String with newline here and here that can function like a HERE-string") ``` -------------------------------- ### Scheme Obsolete Procedure Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt An obsolete procedure for printing the width of an object. ```scheme (print-width ) ``` -------------------------------- ### Throw an Exception in TinyScheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Throws a custom exception with a given message. If used outside a 'catch' block, it reverts to the default 'error' behavior. ```scheme (throw "message") ``` -------------------------------- ### Scheme Symbol Conversion Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Procedures for converting between symbols and their string representations. ```scheme symbol->string string->symbol ``` -------------------------------- ### Scheme Control Features Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Procedures related to control flow, including mapping, iteration, and continuation handling. ```scheme procedure? macro? closure? map for-each force delay call-with-current-continuation eval apply ``` -------------------------------- ### Time Functions Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/ftx/ftx-functions.txt Functions for retrieving and manipulating time information. ```APIDOC ## Time Functions ### Description Provides functions for working with time. ### Functions #### `time` ##### Description Returns the current local time. ##### Returns - A list of integers: `(year month day-of-month hour min sec millisec)`. - `year` is an offset from 1900. #### `gettimeofday` ##### Description Returns the current time in seconds and microseconds from the beginning of the day. ##### Returns - A list containing: seconds from the beginning of the day, microseconds within the current second. #### `usleep` ##### Description Suspends execution for a specified number of microseconds. ##### Parameters - **microsec** (integer) - The number of microseconds to sleep. ##### Returns - None. ``` -------------------------------- ### Unit Test Expected Runtime Error Assertion Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/test/tests/readme.md Use `assert-error` for testing expected runtime errors in unit tests. ```scheme assert-error ``` -------------------------------- ### Define Helper Macro for Memory Block Check Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Define a macro or function to check if a pointer refers to a memory block. This is useful for exported functions. ```c #define is_memblock(p) (type(p)==T_MEMBLOCK) ``` -------------------------------- ### Scheme Character Conversion Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Functions for converting between characters and their integer representations, and for character comparison. ```scheme integer->char char->integer char=? char? char<=? char>=? ``` -------------------------------- ### Reference Element in Memory Block in GIMP Scheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Accesses and returns the character at a specific index within a memory block. Performs bounds checking and argument validation. ```c case OP_BLOCKREF: { /* block-ref */ char *str; int index; if(!ismemblock(car(sc->args))) { Error_1(sc,"block-ref: not a memory block:",car(sc->args)); } str=strvalue(car(sc->args)); if(cdr(sc->args)==sc->NIL) { Error_0(sc,"block-ref: needs two arguments"); } if(!isnumber(cadr(sc->args))) { Error_1(sc,"block-ref: not a number:",cadr(sc->args)); } index=ivalue(cadr(sc->args)); if(index<0 || index>=keynum(car(sc->args))) { Error_1(sc,"block-ref: out of bounds:",cadr(sc->args)); } s_return(sc,mk_integer(sc,str[index])); } ``` -------------------------------- ### Scheme Numeric Literals Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Supports various numeric bases including hexadecimal (#x), octal (#o), binary (#b), and decimal (#d). Flonums are currently read-only in decimal. ```scheme #x #o #b #d ``` -------------------------------- ### Scheme Character Literals Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Represents characters using #\ notation, supporting standard characters, control characters with ASCII names, and hex representations. ```scheme #\return #\tab #\x20 #\space ``` -------------------------------- ### Set External Data for Scheme Interpreter Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/Manual.txt Sets external data for the Scheme interpreter. This function is used to associate custom data with the interpreter's state, accessible by foreign functions. ```c void scheme_set_external_data(scheme *sc, void *p); ``` -------------------------------- ### Check if Memory Block in GIMP Scheme Source: https://github.com/gnome/gimp/blob/master/plug-ins/script-fu/libscriptfu/tinyscheme/hack.txt Predicate function to determine if an argument is a memory block. Returns a boolean value. ```c case OP_BLOCKP: /* block? */ s_retbool(ismemblock(car(sc->args))); ```