diff --git a/examples/chokidar-as-cli/index.js b/examples/chokidar-as-cli/index.js index 9a389ff..80da5a0 100644 --- a/examples/chokidar-as-cli/index.js +++ b/examples/chokidar-as-cli/index.js @@ -36,6 +36,7 @@ const processFile = (path, event) => { exec(`cd ../.. && bedoc ${standardOptions.join(" ")} --input "${path}"`, (error, stdout, stderr) => { if(error) { console.error(`Error processing file ${path}:`, error.message) + return } diff --git a/examples/chokidar-as-cli/source/arrays.c b/examples/chokidar-as-cli/source/arrays.c deleted file mode 100644 index 1b74059..0000000 --- a/examples/chokidar-as-cli/source/arrays.c +++ /dev/null @@ -1,220 +0,0 @@ -/** - * Returns a new array containing the distinct elements of the input - * array. - * - * @param {mixed*} arr An array of mixed types. - * @return {mixed*} A new array with distinct elements from the input array. - * @example - * ```c - * distinct_array(({1, 2, 3, 4, 5, 1, 2, 3, 4, 5})); - * // Returns: ({1, 2, 3, 4, 5}) - * ``` - */ -mixed *distinct_array(mixed *arr) {} - -/** - * Returns a new array containing the elements of the input array - * from index 0 to start-1, and from end+1 to the end of the input - * array. If start is greater than end, the new array will contain - * all the elements of the input array. - * - * @param {mixed*} arr The input array. - * @param {int} start The starting index of elements to be removed. - * @param {int} end The ending index of elements to be removed. Defaults to - * start if not specified. - * @return {mixed*} A new array with specified elements removed. - * @example - * ```c - * remove_array_element(({1, 2, 3, 4, 5}), 1, 3); - * // Returns: ({1, 5}) - * ``` - */ -varargs mixed *remove_array_element(mixed *arr, int start, int end) {} - -/** - * Modifies the content of an array by removing existing elements - * and/or adding new elements. Returns a new array with the - * modifications. - * - * @param {mixed*} arr The array from which elements will be removed and to - * which new elements may be added. - * @param {int} start The zero-based index at which to start changing the - * array. If negative, it will begin that many elements - * from the end. - * @param {int} delete_count The number of elements to remove from the array, - * starting from the index specified by start. If - * delete_count is 0, no elements are removed. - * @param {mixed*} items_to_add An array of elements to add to the array at - * the start index. Can be omitted or passed as - * null if no elements are to be added. - * @return {mixed*} A new array reflecting the desired modifications. - * @example - * ```c - * splice(({1, 2, 3, 4, 5}), 1, 2, ({6, 7})); - * // Returns: ({1, 6, 7, 4, 5}) - * ``` - */ -varargs mixed *splice(mixed *arr, int start, int delete_count, mixed *items_to_add) {} - -/** - * Returns a new array with the elements of the input array in - * reverse order. - * - * @param {mixed*} arr The input array. - * @return {mixed*} A new array with elements in reverse order. - * @example - * ```c - * reverse_array(({1, 2, 3, 4, 5})); - * // Returns: ({5, 4, 3, 2, 1}) - * ``` - */ -mixed *reverse_array(mixed *arr) {} - -/** - * Checks if all elements in the input array are of the specified - * type. If the array is of size 0, it is considered uniform. - * - * @param {string} type The type to check for. - * @param {mixed*} arr The array to check. - * @return {int} Returns 1 if all elements are of the specified type, 0 - * otherwise. - * @example - * ```c - * uniform_array("int", ({1, 2, 3, 4, 5})); - * // Returns: 1 - * uniform_array("int", ({1, 2, 3, 4, "5"})); - * // Returns: 0 - * ``` - */ -int uniform_array(string type, mixed *arr) {} - -/** - * Returns an array filled with the specified value. If no array - * is provided, an empty array is created. If no value is - * provided, 0 is used as the value to fill the array with. If no - * start index is provided, the array is filled from the end. - * - * @param {mixed*} arr The array to fill. - * @param {mixed} value The value to fill the array with. - * @param {int} start_index The index at which to start filling the array. (optional) - * @return {mixed} The filled array. - * @example - * ```c - * array_fill(({1, 2, 3, 4, 5}), 0, 10, 0); - * // Returns: ({0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) - * ``` - */ -varargs mixed array_fill(mixed *arr, mixed value, int size, int start_index) {} - -/** - * Returns a new array of the specified size, filled with the - * specified value. If the array is larger than the specified size, - * the array is truncated to the specified size. - * - * @param {mixed*} arr The array to pad. - * @param {int} size The size of the array to create. - * @param {mixed} value The value to fill the array with. - * @param {int} beginning Whether to fill the array from the beginning. (optional) - * @return {mixed} The padded array. - * @example - * ```c - * array_pad(({1, 2, 3, 4, 5}), 10, 0, 1); - * // Returns: ({0, 0, 0, 0, 0, 1, 2, 3, 4, 5}) - * ``` - */ -varargs mixed array_pad(mixed *arr, int size, mixed value, int beginning) {} - -/** - * Removes and returns the last element of the array. - * - * @param {mixed*} arr The array from which to pop an element. - * @return {mixed} The last element of the array. - * @example - * ```c - * mixed *arr = ({1, 2, 3, 4, 5}); - * pop(ref arr); - * // Array: ({1, 2, 3, 4}) - * // Returns: 5 - * ``` - */ -mixed pop(mixed ref *arr) {} - -/** - * Adds a new element to the end of the array and returns the new - * size of the array. - * - * @param {mixed*} arr The array to which to push an element. - * @param {mixed} value The element to push onto the array. - * @return {int} The new size of the array. - * @example - * ```c - * mixed *arr = ({1, 2, 3, 4, 5}); - * push(ref arr, 6); - * // Array: ({1, 2, 3, 4, 5, 6}) - * // Returns: 6 - * ``` - */ -int push(mixed ref *arr, mixed value) {} - -/** - * Removes and returns the first element of the array. - * - * @param {mixed*} arr The array from which to shift an element. - * @return {mixed} The first element of the array. - * @example - * ```c - * mixed *arr = ({1, 2, 3, 4, 5}); - * shift(ref arr); - * // Array: ({2, 3, 4, 5}) - * // Returns: 1 - * ``` - */ -mixed shift(mixed ref *arr) {} - -/** - * Adds a new element to the beginning of the array and returns - * the new size of the array. - * - * @param {mixed*} arr The array to which to unshift an element. - * @param {mixed} value The element to unshift onto the array. - * @return {int} The new size of the array. - * @example - * ```c - * mixed *arr = ({1, 2, 3, 4, 5}); - * unshift(ref arr, 0); - * // Array: ({0, 1, 2, 3, 4, 5}) - * // Returns: 6 - * ``` - */ -int unshift(mixed ref *arr, mixed value) {} - -/** - * Returns a new array containing the elements of the input array - * from the start index to the end index. If the end index is - * negative, it will start from the end of the array. - * - * @param {mixed*} arr The array to slice. - * @param {int} start The starting index of the slice. - * @param {int} end The ending index of the slice. - * @return {mixed*} A new array with the specified elements. - * @example - * ```c - * array_slice(({1, 2, 3, 4, 5}), 1, 3) ; - * // Returns: ({2, 3, 4}) - * ``` - */ -varargs mixed *array_slice(mixed *arr, int start, int end) {} - -/** - * Merges two arrays into a single array. - * - * @param {mixed*} arr1 The first array to merge. - * @param {mixed*} arr2 The second array to merge. - * @return {mixed*} A new array with elements from both input arrays. - * @example - * ```c - * array_merge(({1, 2, 3}), ({4, 5, 6})); - * // Returns: ({1, 2, 3, 4, 5, 6}) - * ``` - */ -mixed *array_merge(mixed *arr1, mixed *arr2) {} diff --git a/examples/chokidar-as-cli/source/base64.c b/examples/chokidar-as-cli/source/base64.c deleted file mode 100644 index f416738..0000000 --- a/examples/chokidar-as-cli/source/base64.c +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Encodes a given string or buffer into Base64 format. - * - * @param {mixed} source_str The string or buffer to be encoded. This is a really long string. What do you think? - * I do be lovin' it, fo sho. - * @return {string} The Base64 encoded string. - * @example - * ```c - * base64_encode("Hello, world!") - * // "SGVsbG8sIHdvcmxkIQ==" - * ``` - */ -string base64_encode(mixed source_str) {} - -/** - * Decodes a given Base64 encoded string. - * - * @param {string} source The Base64 encoded string to be decoded. - * @return {string} The decoded string. - * @example - * ```c - * base64_decode("SGVsbG8sIHdvcmxkIQ==") - * // "Hello, world!" - * ``` - */ -string base64_decode(string source) {} diff --git a/examples/chokidar-as-cli/source/description.c b/examples/chokidar-as-cli/source/description.c deleted file mode 100644 index ad76426..0000000 --- a/examples/chokidar-as-cli/source/description.c +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Returns the short description of an object, optionally - * including extra short descriptions in parentheses. - * @param {object} ob The object to get the short description of. - * @param {int} extras Whether to include extra short descriptions. - * Defaults to 1 (include extras). - * @return {string} The short description of the object, including any - * extra short descriptions. - */ -varargs string get_short(object ob, int extras) {} - -/** - * Returns the long description of an object, optionally - * including extra long descriptions. - * @param {object} ob The object to get the long description of. - * @param {int} extras Whether to include extra long descriptions. - * Defaults to 1 (include extras). - * @return {string} The long description of the object, including any - * extra long descriptions. - */ -string get_long(object ob, int extras) {} - -/** - * Generates a description for an object based on its properties. - * @param {object} obj The object to generate a description for. - * @return {string} The generated description. - */ -string generate_description(object obj) {} - -/** - * Sets the description for an object. - * @param {object} obj The object to set the description for. - * @param {string} desc The description to set. - */ -void set_description(object obj, string desc) {} - -/** - * Appends additional information to an object's description. - * @param {object} obj The object to append the description to. - * @param {string} additional_desc The additional description to append. - */ -void append_description(object obj, string additional_desc) {} - -/** - * Clears the description of an object. - * @param {object} obj The object to clear the description for. - */ -void clear_description(object obj) {} diff --git a/examples/chokidar-as-cli/source/directory.c b/examples/chokidar-as-cli/source/directory.c deleted file mode 100644 index f030506..0000000 --- a/examples/chokidar-as-cli/source/directory.c +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Ensures that a directory exists by creating it and its parent directories if - * necessary. - * - * @param {string} path The path of the directory to ensure. - * @return {int} 1 if successful, 0 if failed. - */ -mixed assure_dir(string path) {} - -/** - * Returns the directory of the given object. - * - * @param {object} ob The object to query (optional, default: previous object). - * @return {string} The directory path of the object. - */ -string query_directory(object ob) {} diff --git a/examples/chokidar-as-cli/source/english.c b/examples/chokidar-as-cli/source/english.c deleted file mode 100644 index 49cb4f8..0000000 --- a/examples/chokidar-as-cli/source/english.c +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Capitalizes the first letter of each word in a string. - * - * @param {string} str The string to capitalize. - * @return {string} The capitalized string. - */ -string cap_words(string str) {} - -/** - * Capitalizes significant words in a string, ignoring certain - * insignificant words. Optionally capitalizes the first word - * as a title. - * - * @param {string} str The string to capitalize. - * @param {int} title Whether to capitalize the first word as a title (optional). - * @return {string} The string with significant words capitalized. - */ -varargs string cap_significant_words(string str, int title) {} - -/** - * Returns the possessive form of a noun. If the noun ends with 's', - * it adds an apostrophe; otherwise, it adds 's. - * - * @param {mixed} ob The object or string to convert to possessive form. - * @return {string} The possessive form of the noun. - */ -string possessive_noun(mixed ob) {} - -/** - * Returns the possessive form of a proper noun. Applies 's to the - * end of the noun. - * - * @param {mixed} ob The object or string to convert to possessive form. - * @return {string} The possessive form of the proper noun. - */ -string possessive_proper_noun(mixed ob) {} - -/** - * Returns the possessive pronoun corresponding to the object's - * gender. Defaults to "its" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The possessive pronoun - */ -string possessive_pronoun(mixed ob) {} - -/** - * Returns the possessive adjective corresponding to the object's - * gender. Defaults to "its" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The possessive adjective - */ -string possessive(mixed ob) {} - -/** - * Returns the reflexive pronoun corresponding to the object's - * gender. Defaults to "itself" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The reflexive pronoun - */ -string reflexive(mixed ob) {} - -/** - * Returns the objective pronoun corresponding to the object's - * gender. Defaults to "it" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The objective pronoun - */ -string objective(mixed ob) {} - -/** - * Returns the subjective pronoun corresponding to the object's - * gender. Defaults to "it" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The subjective pronoun - */ -string subjective(mixed ob) {} - -/** - * Returns the article corresponding to the noun. If definite - * is true, returns "the"; otherwise, returns "a" or "an" - * depending on the noun's initial letter - * @param {string} str The noun to determine the article for - * @param {int} definite Whether to return the definite article (defaults to 0) - * @return {string} The article - */ -varargs string article(string str, int definite) {} - -/** - * Adds an article to a string. If definite is true, adds "the"; - * otherwise, adds "a" or "an" depending on the noun's initial - * letter - * @param {string} str The string to add the article to - * @param {int} definite Whether to add the definite article (defaults to 0) - * @return {string} The string with the article prepended - */ -varargs string add_article(string str, int definite) {} - -/** - * Removes an article from a string. If the string begins with - * "the ", "a ", or "an ", removes the article - * @param {string} str The string to remove the article from - * @return {string} The string with the article removed - */ -string remove_article(string str) {} diff --git a/examples/chokidar-as-cli/source/exists.c b/examples/chokidar-as-cli/source/exists.c deleted file mode 100644 index d4dbeda..0000000 --- a/examples/chokidar-as-cli/source/exists.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Checks if a directory exists. - * - * @param {string} dirname The name of the directory to check. - * @return {int} 1 if exists, 0 if not. - */ -int directory_exists(string dirname) {} - -/** - * Checks if a file exists. - * - * @param {string} file The name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int file_exists(string file) {} - -/** - * Checks if a compiled file (.c) exists. - * - * @param {string} file The base name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int cfile_exists(string file) {} - -/** - * Checks if a save file exists. - * - * @param {string} file The base name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int ofile_exists(string file) {} - -/** - * Checks if a user data file exists. - * - * @param {string} user The username to check. - * @return {int} 1 if exists, 0 if not. - */ -int user_exists(string user) {} diff --git a/examples/chokidar-as-cli/source/file.c b/examples/chokidar-as-cli/source/file.c deleted file mode 100644 index f9dc0b7..0000000 --- a/examples/chokidar-as-cli/source/file.c +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Ensures that the directory structure leading to a file exists. - * - * @param {string} file The path of the file to ensure. - * @return {mixed} 1 if successful, string with error message if failed. - */ -mixed assure_file(string file) {} - -/** - * Determines the owner of a file based on its path. - * - * @param {string} file The path of the file to check. - * @return {string} The owner of the file, or 0 if not found. - */ -string file_owner(string file) {} - -/** - * Returns the last few lines of a file. - * - * @param {string} path The path of the file to read. - * @param {int} line_count Number of lines to read (optional, default: 25). - * @return {string} The last few lines of the file. - */ -varargs string tail(string path, int line_count) {} - -/** - * Writes a log message to a specified log file. - * - * @param {string} file The name of the log file. - * @param {string} str The log message to write. - * @param {mixed} arg Additional arguments for the log message (optional). - * @return {int} 1 if successful, 0 if failed. - */ -varargs int log_file(string file, string str, mixed arg...) {} - -/** - * Reads a file and returns its content as an array of lines. - * - * @param {string} file The path of the file to read. - * @return {string*} Array of lines, excluding comments and empty lines. - */ -string *explode_file(string file) {} - -/** - * Writes an array of lines to a file. - * - * @param {string} file The path of the file to write to. - * @param {string*} lines The array of lines to write. - * @param {int} overwrite Whether to overwrite existing content (optional, default: 0). - */ -varargs void implode_file(string file, string *lines, int overwrite) {} - -/** - * Returns the name of the file for a given object. - * - * @param {object} ob The object to query (optional, default: previous object). - * @return {string} The name of the file. - */ -string query_file_name(object ob) {} - -/** - * Generates a temporary file name. - * - * @param {mixed} arg The file or object to create temp file for (optional, default: previous object). - * @return {string} The path to the temporary file. - */ -varargs string temp_file(mixed arg) {} - -/** - * Extracts directory and file components from a path. - * - * @param {mixed} path The path or object to process. - * @return {string*} Array containing [directory, filename]. - */ -string *dir_file(mixed path) {} - -/** - * Validates and extracts directory and file components. - * - * @param {string} path The path to check. - * @param {int} file_too Whether the file should exist (optional). - * @return {string*} Array containing [directory, filename] or null if invalid. - */ -varargs string *valid_dir_file(string path, int file_too) {} - -/** - * Creates an empty file at the specified path. - * - * @param {string} file The path of the file to create. - * @return {int} 1 if successful, 0 if failed. - */ -int touch(string file) {} diff --git a/examples/chokidar-as-cli/source/grammar.c b/examples/chokidar-as-cli/source/grammar.c deleted file mode 100644 index 7e6376a..0000000 --- a/examples/chokidar-as-cli/source/grammar.c +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Converts an integer to its ordinal string representation. - * - * @param {int} n The integer to convert. - * @return {string} The ordinal string representation of the integer. - */ -string ordinal(int n) {} - -/** - * Converts a numerical number to its worded number representation. - * Originally written by Domini@Ultimate (22-08-93) as fullnum(). - * Renamed by Mobydick@TMI-2 (93-08-22). - * - * @param {int} num The numerical number to convert. - * @return {string} The worded number representation of the integer. - */ -string int_string(int num) {} - -/** - * Returns a consolidated string for a given quantity and item - * description, handling pluralization and special cases. - * - * @param {int} x The quantity of items. - * @param {string} str The description of the item(s). - * @return {string} The consolidated string. - */ -string consolidate(int x, string str) {} diff --git a/examples/chokidar-as-cli/source/object.c b/examples/chokidar-as-cli/source/object.c deleted file mode 100644 index 0764d87..0000000 --- a/examples/chokidar-as-cli/source/object.c +++ /dev/null @@ -1,251 +0,0 @@ -/** - * Retrieves the unique object ID of the given object. - * - * @param {object} ob The object to get the ID of. - * @return {int} The unique object ID. - */ -int getoid(object ob) {} - -/* -// get_object() and get_objects() -// Created by Pallando@Ephemeral Dale (92-06) -// Created by Watcher@TMI (92-09-27) -// Revised by Watcher and Pallando (92-12-11) -// Re-written by Pallando (92-12-18) -// get_objects() added by Pallando@Tabor (93-03-02) -// "s", "c" & ">" added by Grendel@TMI-2 (93-07-14) -// -// Use all possible methods to locate an object by the inputed -// name and return the object pointer if located. -// Ideas for future expansion (please, anyone feel free to add them if they -// have the time) -// "wizards" the subset of "users" who are wizards. -// "livings" all living objects -// "objects" all loaded objects -// check the capitalized and lower_case version of str -// check wizard's home directories. -*/ - -/** - * Attempts to locate an object by the given name and returns the - * object pointer if found. - * - * @param {string} str The name of the object to locate. - * @param {object} player The player object to use as a reference for searching (optional). - * @return {object} The located object, or 0 if not found. - */ -varargs object get_object(string str, object player) {} - -/** - * Locates objects based on the specified search string, which can - * include various search criteria and options. - * - * @param {string} str The search string specifying the objects to locate. - * @param {object} player The player object to use as a reference for searching. - * @param {int} no_arr If specified, only a single object or 0 will be returned, - * otherwise an array of objects may be returned (optional). - * @return {mixed} The located object(s), or 0 if not found. - */ -varargs mixed get_objects(string str, object player, int no_arr) {} - -/** - * Searches for an object within a container or environment - * using the specified criteria. - * - * @param {mixed} ob The object or name of the object to find. - * @param {mixed} cont The container or environment to search within (optional, default: previous object). - * @param {function} f An optional function to further filter the search (optional). - * @return {object} The found object, or 0 if not found. - */ -varargs object find_ob(mixed ob, mixed cont, function f) {} - -/** - * Retrieves the top-level environment of the specified object, - * traversing up through nested environments. - * - * @param {object} ob The object to get the top-level environment of. - * @return {object} The top-level environment of the object. - */ -object top_environment(object ob) {} - -/** - * Retrieves all environments of the specified object, traversing - * up through nested environments. - * - * @param {object} ob The object to get the environments of. - * @return {object*} An array of environments of the object. - */ -object *all_environment(object ob) {} - -/** - * Retrieves all living objects present in the specified room. - * - * @param {object} room The room to search for living objects in. - * @return {object*} An array of living objects present in the room. - */ -object *present_livings(object room) {} - -/** - * Retrieves all player objects present in the specified room. - * - * @param {object} room The room to search for player objects in. - * @return {object*} An array of player objects present in the room. - */ -object *present_players(object room) {} - -/** - * Retrieves all non-player characters (NPCs) present in the - * specified room. - * - * @param {object} room The room to search for NPCs in. - * @return {object*} An array of NPC objects present in the room. - */ -object *present_npcs(object room) {} - -/** - * Locates a living object by the specified name within the - * specified room. - * - * @param {string} name The name of the living object to locate. - * @param {object} room The room to search for the living object in. - * @return {object} The located living object, or 0 if not found. - */ -object get_living(string name, object room) {} - -/** - * Locates living objects by the specified names within the - * specified room. - * - * @param {string|string*} names The name of the living objects to locate. - * @param {object} room The room to search for the living objects in. - * @return {object*} An array of located living objects. - */ -object *get_livings(mixed names, object room) {} - -/** - * Locates a player object by the specified name within the - * specified room. - * - * @param {string} name The name of the player to locate. - * @param {object} room The room to search for the player in. - * @return {object} The located player object, or 0 if not found. - */ -object get_player(string name, object room) {} - -/** - * Locates player objects by the specified names within the - * specified room. - * - * @param {string|string*} names The name of the player objects to locate. - * @param {object} room The room to search for the player objects in. - * @return {object*} An array of located player objects. - */ -object *get_players(mixed names, object room) {} - -/** - * Returns the body of the current interactive user. It is used as a - * replacement for this_player(). - * - * @return {object} The body of the current calling player. - */ -object this_body() {} - -/** - * Returns the object that called the current operation. This may be - * this_body(), but it may also be a shadow another player who initiated - * the chain. For example, a wizard using the force command. - * - * Be careful with this one, you don't want to accidentally - * perform operations on the wrong object. - * - * @return {object} The object that called the current operation. - */ -object this_caller() {} - -/** - * Retrieves all clones of the specified file present in the - * specified container. If the file is an object, it will - * retrieve all clones using the object's base name. - * - * @param {mixed} file The file or object to find clones of. - * @param {object} container The container to search within. - * @return {object*} An array of clones of the specified file present in - * the container. - */ -object *present_clones(mixed file, object container) {} - -/** - * Returns 1 if the caller of the current operation is the specified - * object, or if the caller is the object with the specified file name. - * - * *NOTE* This will not succeed when called from other functions in the - * simul_efun object, as previous_object() does not count the object - * itself in its call list. - * - * @param {mixed} ob The object or file name to compare the caller to. - * @return {int} 1 if the caller is the specified object, 0 otherwise. - */ -int caller_is(mixed ob) {} - -/** - * Returns 1 if the two objects are in the same environment, or 0 if - * they are not. - * - * @param {object} one The first object to compare. - * @param {object} two The second object to compare. - * @param {int} top_env Whether to check the top-level environment (optional). - * @return {int} 1 if the objects are in the same environment, 0 otherwise. - */ -varargs int same_env_check(object one, object two, int top_env) {} - -/** - * Finds all objects in a container that match the specified argument. - * The argument can be a name, ID, or other identifier. Objects are - * filtered based on visibility and an optional custom filter function. - * - * @param {object} tp The body object of the player or NPC searching. - * @param {string} arg The argument to match objects against. - * @param {object} source The object to search within (optional, default: caller's environment). - * @param {function} f An optional custom filter function (optional). - * @return {object*} An array of located objects or 0 if none are found. - */ -varargs object *find_targets(object tp, string arg, object source, function f) {} - -/** - * Finds a single object in a container that matches the specified argument. - * The argument can be a name, ID, or other identifier. Objects are - * filtered based on visibility and an optional custom filter function. - * - * @param {object} tp The body object of the player or NPC searching. - * @param {string} arg The argument to match objects against. - * @param {object} source The object to search within (optional, default: caller's environment). - * @param {function} f An optional custom filter function (optional). - * @return {object} The located object, or 0 if not found. - */ -varargs object find_target(object tp, string arg, object source, function f) {} - -/** - * Retrieves all clones of the specified file in the game. If the file - * is an object, it will retrieve all clones using the object's base name. - * - * @param {mixed} file The file or object to find clones of. - * @param {int} env_only Whether to only return clones that have an environment (optional). - * @return {object*} An array of objects that are clones of the specified file. - */ -varargs object *clones(mixed file, int env_only) {} - -/** - * Gets the root uid of an object or the MUD. - * - * @param {object} ob The object to check (optional, default: master object). - * @return {string} The root uid. - */ -varargs string get_root_uid(object ob) {} - -/** - * Checks if an object is a clone. - * - * @param {object} ob The object to check (optional, default: previous object). - * @return {int} 1 if clone, 0 if not. - */ -varargs int clonep(object ob) {} diff --git a/examples/chokidar-as-cli/source/random.c b/examples/chokidar-as-cli/source/random.c deleted file mode 100644 index 1876f00..0000000 --- a/examples/chokidar-as-cli/source/random.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Generates a random float between 0 and upper_bound. - * - * @param {mixed} upper_bound The upper bound for the random float. - * @return {float} The random float between 0 and upper_bound. - */ -float random_float(mixed upper_bound) {} - -/** - * Selects an element from a weighted mapping based on their weights. - * - * @param {mapping} m The weighted mapping to select from, where keys are the - * elements and values are their weights. - * @return {mixed} The selected element. - */ -mixed element_of_weighted(mapping m) {} - -/** - * Generates a random integer within a specified range. - * - * @param {int} min The lower bound (inclusive) of the range. - * @param {int} max The upper bound (inclusive) of the range. - * @return {int} A random number in the specified range. - */ -int random_clamp(int min, int max) {} - -/* PRANDOM 128 */ -/** - * Sanitizes the seed for the random number generator. Ensures that the seed - * is a non-zero integer and within the range of a 64-bit unsigned integer. - * - * @param {mixed} seed The seed to sanitize. - * @return {int*} The sanitized seed. - */ -public int *sanitize_seed(mixed seed) {} - -/** - * Generates a random number within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {int} size The upper bound for the random number. - * @return {int*} A two element array where the first element is the - * updated seed and the second is the random number. - */ -int *prandom(mixed seed, int size) {} - -/** - * Generates a random float within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {float} size The upper bound for the random float. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the random float. - */ -mixed *prandom_float(mixed seed, float size) {} - -/** - * Shuffles an array using the xorshift128+ algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mixed*} arr The array to shuffle. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the shuffled array. - */ -mixed *pshuffle(mixed seed, mixed *arr) {} - -/** - * Selects an element from an array using the xorshift128+ algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mixed*} arr The array to select an element from. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the selected element. - */ -mixed *pelement_of(mixed seed, mixed *arr) {} - -/** - * Generates a random number within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {int} min The lower bound (inclusive) of the range. - * @param {int} max The upper bound (inclusive) of the range. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the random number. - */ -mixed *prandom_clamp(mixed seed, int min, int max) {} - -/** - * Selects an element from a weighted mapping using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mapping} weights The weighted mapping to select from, where keys - * are the elements and values are their weights. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the selected element. - */ -mixed *pelement_of_weighted(mixed seed, mapping weights) {} diff --git a/examples/chokidar-as-cli/source/resolve_path.c b/examples/chokidar-as-cli/source/resolve_path.c deleted file mode 100644 index beb3888..0000000 --- a/examples/chokidar-as-cli/source/resolve_path.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Resolves a given path relative to the current path, handling - * special cases such as user directories and relative paths. - * - * @param {string} base_dir The current path. - * @param {string} path The next path to resolve. - * @return {string} The resolved absolute path. - */ -string resolve_path(string base_dir, string path) {} - -/** - * Resolves and validates a path, checking if it exists as either - * a file or directory. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The path to resolve and validate. - * @return {string|int} The resolved absolute path if valid, or 0 if invalid. - */ -string valid_path(string base_dir, string path) {} - -/** - * Resolves and validates a file path, checking if it exists as a - * file. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The file path to resolve and validate. - * @return {string|int} The resolved absolute file path if valid, or 0 if invalid. - */ -string valid_file(string base_dir, string path) {} - -/** - * Resolves and validates a directory path, checking if it exists - * as a directory. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The directory path to resolve and validate. - * @return {string|int} The resolved absolute directory path if valid, or 0 if invalid. - */ -string valid_dir(string base_dir, string path) {} - -/** - * Resolves a file path without checking its existence. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The file path to resolve. - * @return {string} The resolved absolute file path. - */ -string resolve_file(string base_dir, string path) {} - -/** - * Resolves a directory path without checking its existence, - * ensuring it ends with a slash. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The directory path to resolve. - * @return {string} The resolved absolute directory path, ending with a slash. - */ -string resolve_dir(string base_dir, string path) {} - -/** - * Resolves a path and returns an array of matching files, supporting - * wildcard pattern. If no wildcard is present in the pattern, "*" is - * appended. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The path or pattern to resolve and search for files. - * @return {string[]} An array of matching file paths, or ({}) if invalid. - */ -string *get_files(string base_dir, string path) {} diff --git a/examples/chokidar-as-cli/source/signal.c b/examples/chokidar-as-cli/source/signal.c deleted file mode 100644 index 7c2c064..0000000 --- a/examples/chokidar-as-cli/source/signal.c +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Emit a signal to all objects that have registered a slot for - * the signal. - * - * @param {int} sig The signal number. - * @param {mixed} arg The arguments to pass to the signal (optional). - */ -void emit(int sig, mixed arg...) {} - -/** - * Register a slot for a signal. - * - * @param {int} sig The signal number. - * @param {string} func The function to call when the signal is emitted. - * @return {int} `SIG_SLOT_OK` if the slot was registered successfully. - * See `include/signal.h` for other return values. - */ -int slot(int sig, string func) {} - -/** - * Unregister a slot for a signal. - * - * @param {int} sig The signal number. - * @return {int} `SIG_SLOT_OK` if the slot was unregistered successfully. - * See `include/signal.h` for other return values. - */ -int unslot(int sig) {} - -/** - * Get the signal daemon object. - * - * @return {object} The signal daemon object. - */ -object signal_d() {} diff --git a/examples/chokidar-as-cli/src/data.c b/examples/chokidar-as-cli/src/data.c deleted file mode 100644 index 4b2b823..0000000 --- a/examples/chokidar-as-cli/src/data.c +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Retrieves the value associated with a given key from a file. - * - * @param {string} file The file to read from. - * @param {string} key The key to search for. - * @param {mixed} def The default value to return if the key is not found. (optional) - * @return {mixed} The value associated with the key, or the default value if - * the key is not found. - */ -varargs mixed data_value(string file, string key, mixed def) {} - -/** - * Writes a key-value pair to a file. If the key already exists, - * the value is updated. - * - * @param {string} file The file to write to. - * @param {string} key The key to write. - * @param {mixed} data The value(s) to write. - */ -varargs void data_write(string file, string key, mixed data...) {} - -/** - * Deletes the key-value pair from the file. - * - * @param {string} file The file to modify. - * @param {string} key The key to delete. - * @return {int} 1 if the key was found and deleted, 0 otherwise. - */ -int data_del(string file, string key) {} - -/** - * Increments the value associated with the given key in the file - * by the specified amount. If the key does not exist, it is - * created with the increment value. - * - * @param {string} file The file to modify. - * @param {string} key The key to increment the value for. - * @param {int} inc The amount to increment by. - * @return {int} The new value after incrementing. - */ -varargs int data_inc(string file, string key, int inc) {} - -/** - * Serializes data to a string. - * - * @param {mixed} data The data to serialize. - * @return {string} The serialized data as a string. - */ -string serialize(mixed data) {} - -/** - * Deserializes a string to data. - * - * @param {string} str The string to deserialize. - * @return {mixed} The deserialized data. - */ -mixed deserialize(string str) {} - -/** - * Compresses a string using gzip. - * - * @param {string} str The string to compress. - * @return {string} The compressed string. - */ -string gzip_compress(string str) {} - -/** - * Decompresses a gzip compressed string. - * - * @param {string} str The compressed string to decompress. - * @return {string} The decompressed string. - */ -string gzip_decompress(string str) {} diff --git a/examples/chokidar-as-cli/src/function.c b/examples/chokidar-as-cli/src/function.c deleted file mode 100644 index fa49df8..0000000 --- a/examples/chokidar-as-cli/src/function.c +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Checks if a given function is valid and not owned by a destructed - * object. - * - * @param {mixed} f The function to check. - * @return {int} 1 if the function is valid, otherwise 0. - */ -int valid_function(mixed f) {} - -/** - * Returns a formatted string of the current call stack trace. - * - * @param {int} colour Whether to include colour codes (optional, default: 0) - * @return {string} The formatted call stack trace. - */ -varargs string call_trace(int colour) {} - -/** - * Assembles a callback function from the provided arguments. - * This function is used to create a callable structure that can be - * invoked later. The callback can be either a method on an object or - * a function. - * - * Usage: - * When you need to create a callback for an object method: - * `assemble_call_back(object, "method", args...)` - * When you need to create a callback for a function: - * `assemble_call_back(function, args...)` - * - * The function performs the following steps: - * 1. Checks if the provided arguments form a valid array - * 2. Determines the size of the arguments array - * 3. Checks if the first argument is an object. If so, it verifies that - * the second argument is a valid method name on the object - * 4. If the first argument is a function, it creates a callback with the - * function and any additional arguments - * 5. Returns the assembled callback as an array - * - * @param {mixed} arg The arguments to assemble into a callback. - * @return {mixed*} The assembled callback. - */ -mixed *assemble_call_back(mixed arg...) {} - -/** - * Executes a callback with the given arguments. - * - * @param {mixed} cb The callback to execute. - * @param {mixed} new_arg The arguments to pass to the callback (optional). - * @return {mixed} The result of the callback execution. - */ -mixed call_back(mixed cb, mixed new_arg...) {} - -/** - * Calls the specified function on the given object if it exists. - * - * @param {mixed} ob The object to call the function on. - * @param {string} func The name of the function to call. - * @param {mixed} arg The argument to pass to the function (optional). - * @return {mixed} The return value of the function, or null if the function - * does not exist. - */ -varargs mixed call_if(mixed ob, string func, mixed arg...) {} - -/** - * Delays an action for a specified amount of time. - * - * @param {string} action The action to delay. - * @param {float} delay The amount of time to delay the action. - * @param {mixed*} cb The callback to execute after the delay. - * @return {int} The ID of the delayed action. - */ -varargs int delay_act(string act, float delay, mixed *cb) {} - -/** - * Asserts that a statement is true. If the statement is false, it - * will throw an error with the given message. If no message is - * provided, it will use a default message. - * - * @param {mixed} statement The statement to assert. - * @param {string} message The message to display if the condition is false (optional). - */ -varargs void assert(mixed statement, string message) {} diff --git a/examples/chokidar-as-cli/src/numbers.c b/examples/chokidar-as-cli/src/numbers.c deleted file mode 100644 index 5a45bdd..0000000 --- a/examples/chokidar-as-cli/src/numbers.c +++ /dev/null @@ -1,99 +0,0 @@ -#include - -/** - * Calculates what `a` percent of `b` is. - * - * @param {float} a The percentage value. - * @param {float} b The whole value. - * @return {float} The value that is `a` percent of `b`. - */ -float percent_of(float a, float b) {} - -/** - * Calculates what percentage `a` is of `b`. - * - * @param {float} a The part value. - * @param {float} b The whole value. - * @return {float} The percentage of `a` out of `b`. - */ -float percent(float a, float b) {} - -/** - * Ensures a value is within a specified range. - * - * @param {float} min The minimum value. - * @param {float} max The maximum value. - * @param {float} val The value to check. - * @return {float} The value, constrained within the range of `min` to `max`. - */ -float clamp(float min, float max, float val) {} - -/** - * Calculates the remainder of `a` divided by `b`. If either value is an integer, - * it will be converted to float before calculation. - * - * @param {mixed} a The dividend. - * @param {mixed} b The divisor. - * @return {float} The remainder of `a` divided by `b`. - */ -varargs float remainder(mixed a, mixed b) {} - -/** - * Calculates the sum of all elements in an array. - * - * @param {mixed*} arr The array of numbers to sum. - * @return {int} The sum of all elements in the array. - */ -int sum(mixed *arr) {} - -/** - * Evaluates a number against a condition. The condition can be a - * simple comparison, or a compound condition using `AND` and `OR`. - * This system allows for the evaluation of numeric conditions - * using a specific set of operators and syntax rules. - * - * Basic Operators: - * `<` Less than - * `>` Greater than - * `<=` Less than or equal to - * `>=` Greater than or equal to - * `=` or `==` Equal to - * `!=` Not equal to - * `%` Checks if a number is divisible by the given value - * - * Range Operator: - * Use a hyphen (`-`) to specify a range, inclusive of both ends. - * Example: `5-15` means any number from `5` to `15`, including - * `5` and `15`. - * - * Set Inclusion/Exclusion: - * `[a,b,c]` Checks if a number is one of the listed values - * `![a,b,c]` Checks if a number is not one of the listed values - * - * Logical Operators: - * `AND` Both conditions must be true - * `OR` At least one condition must be true - * - * Grouping: - * Use parentheses `()` to group conditions and override default precedence. - * - * Precedence (from highest to lowest): - * 1. Parentheses `()` - * 2. Basic operators, Range, Modulo, Set inclusion/exclusion - * 3. `AND` - * 4. `OR` - * - * Syntax Rules: - * No spaces are allowed in the condition string - * Operators must be used exactly as specified - * Set values must be comma-separated without spaces - * - * Example: `(5-15AND%3)OR[20,25,30]` - * This checks if a number is between `5` and `15` (inclusive) AND - * divisible by `3`, OR if it's `20`, `25`, or `30`. - * - * @param {int} number The number to evaluate. - * @param {string} condition The condition to evaluate against. - * @return {int} 1 if the condition evaluates to true, 0 otherwise. - */ -int evaluate_number(int number, string condition) {} diff --git a/examples/chokidar-as-cli/src/string.c b/examples/chokidar-as-cli/src/string.c deleted file mode 100644 index 22360e8..0000000 --- a/examples/chokidar-as-cli/src/string.c +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Appends a string to another string if it is not already there. If the string - * is already present, the original string is returned. - * - * @param {string} source The string to append to. - * @param {string} to_append The string to append. - * @return {string} The original string with the appended string if it was not - * already present. - */ -string append(string source, string to_append) {} - -/** - * Prepends a string to another string if it is not already there. - * If the string is already present, the original string is returned. - * - * @param {string} source The string to prepend to. - * @param {string} to_prepend The string to prepend. - * @return {string} The original string with the prepended string if it was not - * already present. - */ -string prepend(string source, string to_prepend) {} - -/** - * Chops a substring off the end or beginning of another string if - * it is present. If the substring is not present, the original - * string is returned. If no direction is specified, chops from - * the right (-1). - * - * @param {string} str The string to chop from. - * @param {string} sub The substring to chop. - * @param {int} dir The direction to chop: 1 for left, -1 for right (optional, default: -1) - * @return {string} The string with the substring chopped off if it was present. - */ -varargs string chop(string str, string sub, int dir) {} - -/** - * Extracts a substring from a string. If no ending position is provided, - * extracts from the starting position to the end of the string. - * - * @param {string} str The string to extract from. - * @param {int} from The starting position to extract from. - * @param {int} to The ending position to extract to (optional) - * @return {string} The extracted substring. - */ -varargs string extract(string str, int from, int to) {} - -/** - * Returns a string with all colour codes removed. - * - * @param {string} str The string to remove colour from. - * @return {string} The string without colour. - */ -string no_ansi(string str) {} - -/** - * Returns a string that is a simple list of the elements of an array, - * joined by a conjunction. If no conjunction is provided, "and" will be used. - * - * @param {string*} arr The array to make a list from. - * @param {string} conjunction The word to join the last two elements (optional, default: "and") - * @return {string} The simple list string. - */ -varargs string simple_list(string *arr, string conjunction) {} - -/** - * Returns a substring of a string, starting from 0 and ending at the - * first occurrence of another string within it. If the reverse flag - * is set, the substring will start at the last occurrence of the - * substring within the string. - * - * @param {string} str The string to extract from. - * @param {string} sub The substring to extract to. - * @param {int} reverse If set, the substring will start at the last occurrence (optional, default: 0) - * @return {string} The extracted substring. - */ -varargs string substr(string str, string sub, int reverse) {} - -/** - * Converts a string representation of an LPC value to the - * corresponding LPC value. If the flag is set, returns an array with - * the value and the remaining string. - * - * @param {string} str The string to convert. - * @param {int} flag If set, returns an array with the value and remaining string (optional, default: 0) - * @return {mixed} The LPC value represented by the string. - */ -varargs mixed from_string(string str, int flag) {} - -/** - * Converts an LPC value to its string representation. - * - * @param {mixed} val The value to convert. - * @return {string} The string representation of the value. - */ -string stringify(mixed val) {} - -/** - * Returns a string with commas added to the number. Handles both integer - * and floating point numbers, as well as strings that can be converted to numbers. - * For negative numbers, the negative sign is preserved at the start. - * - * @param {mixed} number The number to add commas to. - * @return {string} The number with commas added as a string. - */ -string add_commas(mixed number) {} - -/** - * Reverses a string. - * - * @param {string} str The string to reverse. - * @return {string} The reversed string. - */ -string reverse_string(string str) {} - -/** - * Searches for a substring in a string starting from a given position - * and moving backwards. If no starting position is provided, starts from - * the beginning of the string. - * - * @param {string} str The string to search in. - * @param {string} sub The substring to search for. - * @param {int} start The starting position to search from (optional, default: 0) - * @return {int} The position of the substring in the string, or -1 if not found. - */ -varargs int reverse_strsrch(string str, string sub, int start) {} - -/** - * Searches for the position of a substring in a string using a - * regular expression. If reverse is set, the search will start from - * the end of the string. - * - * @param {string} str The string to search in. - * @param {string} substr The regular expression to search for. - * @param {int} reverse If set, the search will start from the end (optional, default: 0) - * @return {int} The position of the substring in the string, or -1 if not found. - */ -varargs int pcre_strsrch(string str, string substr, int reverse) {} - -/** - * Returns 1 if the string contains colour codes, 0 if not. - * - * @param {string} str The string to check. - * @return {int} 1 if the string contains colour codes, otherwise 0. - */ -int colourp(string str) {} - -/** - * Trims whitespace from both ends of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string trim(string str) {} - -/** - * Trims whitespace from the start of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string ltrim(string str) {} - -/** - * Trims whitespace from the end of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string rtrim(string str) {} diff --git a/examples/chokidar-as-npm/source/directory.c b/examples/chokidar-as-npm/source/directory.c deleted file mode 100644 index f030506..0000000 --- a/examples/chokidar-as-npm/source/directory.c +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Ensures that a directory exists by creating it and its parent directories if - * necessary. - * - * @param {string} path The path of the directory to ensure. - * @return {int} 1 if successful, 0 if failed. - */ -mixed assure_dir(string path) {} - -/** - * Returns the directory of the given object. - * - * @param {object} ob The object to query (optional, default: previous object). - * @return {string} The directory path of the object. - */ -string query_directory(object ob) {} diff --git a/examples/chokidar-as-npm/source/english.c b/examples/chokidar-as-npm/source/english.c deleted file mode 100644 index 49cb4f8..0000000 --- a/examples/chokidar-as-npm/source/english.c +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Capitalizes the first letter of each word in a string. - * - * @param {string} str The string to capitalize. - * @return {string} The capitalized string. - */ -string cap_words(string str) {} - -/** - * Capitalizes significant words in a string, ignoring certain - * insignificant words. Optionally capitalizes the first word - * as a title. - * - * @param {string} str The string to capitalize. - * @param {int} title Whether to capitalize the first word as a title (optional). - * @return {string} The string with significant words capitalized. - */ -varargs string cap_significant_words(string str, int title) {} - -/** - * Returns the possessive form of a noun. If the noun ends with 's', - * it adds an apostrophe; otherwise, it adds 's. - * - * @param {mixed} ob The object or string to convert to possessive form. - * @return {string} The possessive form of the noun. - */ -string possessive_noun(mixed ob) {} - -/** - * Returns the possessive form of a proper noun. Applies 's to the - * end of the noun. - * - * @param {mixed} ob The object or string to convert to possessive form. - * @return {string} The possessive form of the proper noun. - */ -string possessive_proper_noun(mixed ob) {} - -/** - * Returns the possessive pronoun corresponding to the object's - * gender. Defaults to "its" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The possessive pronoun - */ -string possessive_pronoun(mixed ob) {} - -/** - * Returns the possessive adjective corresponding to the object's - * gender. Defaults to "its" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The possessive adjective - */ -string possessive(mixed ob) {} - -/** - * Returns the reflexive pronoun corresponding to the object's - * gender. Defaults to "itself" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The reflexive pronoun - */ -string reflexive(mixed ob) {} - -/** - * Returns the objective pronoun corresponding to the object's - * gender. Defaults to "it" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The objective pronoun - */ -string objective(mixed ob) {} - -/** - * Returns the subjective pronoun corresponding to the object's - * gender. Defaults to "it" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The subjective pronoun - */ -string subjective(mixed ob) {} - -/** - * Returns the article corresponding to the noun. If definite - * is true, returns "the"; otherwise, returns "a" or "an" - * depending on the noun's initial letter - * @param {string} str The noun to determine the article for - * @param {int} definite Whether to return the definite article (defaults to 0) - * @return {string} The article - */ -varargs string article(string str, int definite) {} - -/** - * Adds an article to a string. If definite is true, adds "the"; - * otherwise, adds "a" or "an" depending on the noun's initial - * letter - * @param {string} str The string to add the article to - * @param {int} definite Whether to add the definite article (defaults to 0) - * @return {string} The string with the article prepended - */ -varargs string add_article(string str, int definite) {} - -/** - * Removes an article from a string. If the string begins with - * "the ", "a ", or "an ", removes the article - * @param {string} str The string to remove the article from - * @return {string} The string with the article removed - */ -string remove_article(string str) {} diff --git a/examples/chokidar-as-npm/source/exists.c b/examples/chokidar-as-npm/source/exists.c deleted file mode 100644 index d4dbeda..0000000 --- a/examples/chokidar-as-npm/source/exists.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Checks if a directory exists. - * - * @param {string} dirname The name of the directory to check. - * @return {int} 1 if exists, 0 if not. - */ -int directory_exists(string dirname) {} - -/** - * Checks if a file exists. - * - * @param {string} file The name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int file_exists(string file) {} - -/** - * Checks if a compiled file (.c) exists. - * - * @param {string} file The base name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int cfile_exists(string file) {} - -/** - * Checks if a save file exists. - * - * @param {string} file The base name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int ofile_exists(string file) {} - -/** - * Checks if a user data file exists. - * - * @param {string} user The username to check. - * @return {int} 1 if exists, 0 if not. - */ -int user_exists(string user) {} diff --git a/examples/chokidar-as-npm/source/file.c b/examples/chokidar-as-npm/source/file.c deleted file mode 100644 index f9dc0b7..0000000 --- a/examples/chokidar-as-npm/source/file.c +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Ensures that the directory structure leading to a file exists. - * - * @param {string} file The path of the file to ensure. - * @return {mixed} 1 if successful, string with error message if failed. - */ -mixed assure_file(string file) {} - -/** - * Determines the owner of a file based on its path. - * - * @param {string} file The path of the file to check. - * @return {string} The owner of the file, or 0 if not found. - */ -string file_owner(string file) {} - -/** - * Returns the last few lines of a file. - * - * @param {string} path The path of the file to read. - * @param {int} line_count Number of lines to read (optional, default: 25). - * @return {string} The last few lines of the file. - */ -varargs string tail(string path, int line_count) {} - -/** - * Writes a log message to a specified log file. - * - * @param {string} file The name of the log file. - * @param {string} str The log message to write. - * @param {mixed} arg Additional arguments for the log message (optional). - * @return {int} 1 if successful, 0 if failed. - */ -varargs int log_file(string file, string str, mixed arg...) {} - -/** - * Reads a file and returns its content as an array of lines. - * - * @param {string} file The path of the file to read. - * @return {string*} Array of lines, excluding comments and empty lines. - */ -string *explode_file(string file) {} - -/** - * Writes an array of lines to a file. - * - * @param {string} file The path of the file to write to. - * @param {string*} lines The array of lines to write. - * @param {int} overwrite Whether to overwrite existing content (optional, default: 0). - */ -varargs void implode_file(string file, string *lines, int overwrite) {} - -/** - * Returns the name of the file for a given object. - * - * @param {object} ob The object to query (optional, default: previous object). - * @return {string} The name of the file. - */ -string query_file_name(object ob) {} - -/** - * Generates a temporary file name. - * - * @param {mixed} arg The file or object to create temp file for (optional, default: previous object). - * @return {string} The path to the temporary file. - */ -varargs string temp_file(mixed arg) {} - -/** - * Extracts directory and file components from a path. - * - * @param {mixed} path The path or object to process. - * @return {string*} Array containing [directory, filename]. - */ -string *dir_file(mixed path) {} - -/** - * Validates and extracts directory and file components. - * - * @param {string} path The path to check. - * @param {int} file_too Whether the file should exist (optional). - * @return {string*} Array containing [directory, filename] or null if invalid. - */ -varargs string *valid_dir_file(string path, int file_too) {} - -/** - * Creates an empty file at the specified path. - * - * @param {string} file The path of the file to create. - * @return {int} 1 if successful, 0 if failed. - */ -int touch(string file) {} diff --git a/examples/chokidar-as-npm/source/function.c b/examples/chokidar-as-npm/source/function.c deleted file mode 100644 index fa49df8..0000000 --- a/examples/chokidar-as-npm/source/function.c +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Checks if a given function is valid and not owned by a destructed - * object. - * - * @param {mixed} f The function to check. - * @return {int} 1 if the function is valid, otherwise 0. - */ -int valid_function(mixed f) {} - -/** - * Returns a formatted string of the current call stack trace. - * - * @param {int} colour Whether to include colour codes (optional, default: 0) - * @return {string} The formatted call stack trace. - */ -varargs string call_trace(int colour) {} - -/** - * Assembles a callback function from the provided arguments. - * This function is used to create a callable structure that can be - * invoked later. The callback can be either a method on an object or - * a function. - * - * Usage: - * When you need to create a callback for an object method: - * `assemble_call_back(object, "method", args...)` - * When you need to create a callback for a function: - * `assemble_call_back(function, args...)` - * - * The function performs the following steps: - * 1. Checks if the provided arguments form a valid array - * 2. Determines the size of the arguments array - * 3. Checks if the first argument is an object. If so, it verifies that - * the second argument is a valid method name on the object - * 4. If the first argument is a function, it creates a callback with the - * function and any additional arguments - * 5. Returns the assembled callback as an array - * - * @param {mixed} arg The arguments to assemble into a callback. - * @return {mixed*} The assembled callback. - */ -mixed *assemble_call_back(mixed arg...) {} - -/** - * Executes a callback with the given arguments. - * - * @param {mixed} cb The callback to execute. - * @param {mixed} new_arg The arguments to pass to the callback (optional). - * @return {mixed} The result of the callback execution. - */ -mixed call_back(mixed cb, mixed new_arg...) {} - -/** - * Calls the specified function on the given object if it exists. - * - * @param {mixed} ob The object to call the function on. - * @param {string} func The name of the function to call. - * @param {mixed} arg The argument to pass to the function (optional). - * @return {mixed} The return value of the function, or null if the function - * does not exist. - */ -varargs mixed call_if(mixed ob, string func, mixed arg...) {} - -/** - * Delays an action for a specified amount of time. - * - * @param {string} action The action to delay. - * @param {float} delay The amount of time to delay the action. - * @param {mixed*} cb The callback to execute after the delay. - * @return {int} The ID of the delayed action. - */ -varargs int delay_act(string act, float delay, mixed *cb) {} - -/** - * Asserts that a statement is true. If the statement is false, it - * will throw an error with the given message. If no message is - * provided, it will use a default message. - * - * @param {mixed} statement The statement to assert. - * @param {string} message The message to display if the condition is false (optional). - */ -varargs void assert(mixed statement, string message) {} diff --git a/examples/chokidar-as-npm/source/grammar.c b/examples/chokidar-as-npm/source/grammar.c deleted file mode 100644 index 7e6376a..0000000 --- a/examples/chokidar-as-npm/source/grammar.c +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Converts an integer to its ordinal string representation. - * - * @param {int} n The integer to convert. - * @return {string} The ordinal string representation of the integer. - */ -string ordinal(int n) {} - -/** - * Converts a numerical number to its worded number representation. - * Originally written by Domini@Ultimate (22-08-93) as fullnum(). - * Renamed by Mobydick@TMI-2 (93-08-22). - * - * @param {int} num The numerical number to convert. - * @return {string} The worded number representation of the integer. - */ -string int_string(int num) {} - -/** - * Returns a consolidated string for a given quantity and item - * description, handling pluralization and special cases. - * - * @param {int} x The quantity of items. - * @param {string} str The description of the item(s). - * @return {string} The consolidated string. - */ -string consolidate(int x, string str) {} diff --git a/examples/chokidar-as-npm/source/numbers.c b/examples/chokidar-as-npm/source/numbers.c deleted file mode 100644 index 5a45bdd..0000000 --- a/examples/chokidar-as-npm/source/numbers.c +++ /dev/null @@ -1,99 +0,0 @@ -#include - -/** - * Calculates what `a` percent of `b` is. - * - * @param {float} a The percentage value. - * @param {float} b The whole value. - * @return {float} The value that is `a` percent of `b`. - */ -float percent_of(float a, float b) {} - -/** - * Calculates what percentage `a` is of `b`. - * - * @param {float} a The part value. - * @param {float} b The whole value. - * @return {float} The percentage of `a` out of `b`. - */ -float percent(float a, float b) {} - -/** - * Ensures a value is within a specified range. - * - * @param {float} min The minimum value. - * @param {float} max The maximum value. - * @param {float} val The value to check. - * @return {float} The value, constrained within the range of `min` to `max`. - */ -float clamp(float min, float max, float val) {} - -/** - * Calculates the remainder of `a` divided by `b`. If either value is an integer, - * it will be converted to float before calculation. - * - * @param {mixed} a The dividend. - * @param {mixed} b The divisor. - * @return {float} The remainder of `a` divided by `b`. - */ -varargs float remainder(mixed a, mixed b) {} - -/** - * Calculates the sum of all elements in an array. - * - * @param {mixed*} arr The array of numbers to sum. - * @return {int} The sum of all elements in the array. - */ -int sum(mixed *arr) {} - -/** - * Evaluates a number against a condition. The condition can be a - * simple comparison, or a compound condition using `AND` and `OR`. - * This system allows for the evaluation of numeric conditions - * using a specific set of operators and syntax rules. - * - * Basic Operators: - * `<` Less than - * `>` Greater than - * `<=` Less than or equal to - * `>=` Greater than or equal to - * `=` or `==` Equal to - * `!=` Not equal to - * `%` Checks if a number is divisible by the given value - * - * Range Operator: - * Use a hyphen (`-`) to specify a range, inclusive of both ends. - * Example: `5-15` means any number from `5` to `15`, including - * `5` and `15`. - * - * Set Inclusion/Exclusion: - * `[a,b,c]` Checks if a number is one of the listed values - * `![a,b,c]` Checks if a number is not one of the listed values - * - * Logical Operators: - * `AND` Both conditions must be true - * `OR` At least one condition must be true - * - * Grouping: - * Use parentheses `()` to group conditions and override default precedence. - * - * Precedence (from highest to lowest): - * 1. Parentheses `()` - * 2. Basic operators, Range, Modulo, Set inclusion/exclusion - * 3. `AND` - * 4. `OR` - * - * Syntax Rules: - * No spaces are allowed in the condition string - * Operators must be used exactly as specified - * Set values must be comma-separated without spaces - * - * Example: `(5-15AND%3)OR[20,25,30]` - * This checks if a number is between `5` and `15` (inclusive) AND - * divisible by `3`, OR if it's `20`, `25`, or `30`. - * - * @param {int} number The number to evaluate. - * @param {string} condition The condition to evaluate against. - * @return {int} 1 if the condition evaluates to true, 0 otherwise. - */ -int evaluate_number(int number, string condition) {} diff --git a/examples/chokidar-as-npm/source/object.c b/examples/chokidar-as-npm/source/object.c deleted file mode 100644 index 0764d87..0000000 --- a/examples/chokidar-as-npm/source/object.c +++ /dev/null @@ -1,251 +0,0 @@ -/** - * Retrieves the unique object ID of the given object. - * - * @param {object} ob The object to get the ID of. - * @return {int} The unique object ID. - */ -int getoid(object ob) {} - -/* -// get_object() and get_objects() -// Created by Pallando@Ephemeral Dale (92-06) -// Created by Watcher@TMI (92-09-27) -// Revised by Watcher and Pallando (92-12-11) -// Re-written by Pallando (92-12-18) -// get_objects() added by Pallando@Tabor (93-03-02) -// "s", "c" & ">" added by Grendel@TMI-2 (93-07-14) -// -// Use all possible methods to locate an object by the inputed -// name and return the object pointer if located. -// Ideas for future expansion (please, anyone feel free to add them if they -// have the time) -// "wizards" the subset of "users" who are wizards. -// "livings" all living objects -// "objects" all loaded objects -// check the capitalized and lower_case version of str -// check wizard's home directories. -*/ - -/** - * Attempts to locate an object by the given name and returns the - * object pointer if found. - * - * @param {string} str The name of the object to locate. - * @param {object} player The player object to use as a reference for searching (optional). - * @return {object} The located object, or 0 if not found. - */ -varargs object get_object(string str, object player) {} - -/** - * Locates objects based on the specified search string, which can - * include various search criteria and options. - * - * @param {string} str The search string specifying the objects to locate. - * @param {object} player The player object to use as a reference for searching. - * @param {int} no_arr If specified, only a single object or 0 will be returned, - * otherwise an array of objects may be returned (optional). - * @return {mixed} The located object(s), or 0 if not found. - */ -varargs mixed get_objects(string str, object player, int no_arr) {} - -/** - * Searches for an object within a container or environment - * using the specified criteria. - * - * @param {mixed} ob The object or name of the object to find. - * @param {mixed} cont The container or environment to search within (optional, default: previous object). - * @param {function} f An optional function to further filter the search (optional). - * @return {object} The found object, or 0 if not found. - */ -varargs object find_ob(mixed ob, mixed cont, function f) {} - -/** - * Retrieves the top-level environment of the specified object, - * traversing up through nested environments. - * - * @param {object} ob The object to get the top-level environment of. - * @return {object} The top-level environment of the object. - */ -object top_environment(object ob) {} - -/** - * Retrieves all environments of the specified object, traversing - * up through nested environments. - * - * @param {object} ob The object to get the environments of. - * @return {object*} An array of environments of the object. - */ -object *all_environment(object ob) {} - -/** - * Retrieves all living objects present in the specified room. - * - * @param {object} room The room to search for living objects in. - * @return {object*} An array of living objects present in the room. - */ -object *present_livings(object room) {} - -/** - * Retrieves all player objects present in the specified room. - * - * @param {object} room The room to search for player objects in. - * @return {object*} An array of player objects present in the room. - */ -object *present_players(object room) {} - -/** - * Retrieves all non-player characters (NPCs) present in the - * specified room. - * - * @param {object} room The room to search for NPCs in. - * @return {object*} An array of NPC objects present in the room. - */ -object *present_npcs(object room) {} - -/** - * Locates a living object by the specified name within the - * specified room. - * - * @param {string} name The name of the living object to locate. - * @param {object} room The room to search for the living object in. - * @return {object} The located living object, or 0 if not found. - */ -object get_living(string name, object room) {} - -/** - * Locates living objects by the specified names within the - * specified room. - * - * @param {string|string*} names The name of the living objects to locate. - * @param {object} room The room to search for the living objects in. - * @return {object*} An array of located living objects. - */ -object *get_livings(mixed names, object room) {} - -/** - * Locates a player object by the specified name within the - * specified room. - * - * @param {string} name The name of the player to locate. - * @param {object} room The room to search for the player in. - * @return {object} The located player object, or 0 if not found. - */ -object get_player(string name, object room) {} - -/** - * Locates player objects by the specified names within the - * specified room. - * - * @param {string|string*} names The name of the player objects to locate. - * @param {object} room The room to search for the player objects in. - * @return {object*} An array of located player objects. - */ -object *get_players(mixed names, object room) {} - -/** - * Returns the body of the current interactive user. It is used as a - * replacement for this_player(). - * - * @return {object} The body of the current calling player. - */ -object this_body() {} - -/** - * Returns the object that called the current operation. This may be - * this_body(), but it may also be a shadow another player who initiated - * the chain. For example, a wizard using the force command. - * - * Be careful with this one, you don't want to accidentally - * perform operations on the wrong object. - * - * @return {object} The object that called the current operation. - */ -object this_caller() {} - -/** - * Retrieves all clones of the specified file present in the - * specified container. If the file is an object, it will - * retrieve all clones using the object's base name. - * - * @param {mixed} file The file or object to find clones of. - * @param {object} container The container to search within. - * @return {object*} An array of clones of the specified file present in - * the container. - */ -object *present_clones(mixed file, object container) {} - -/** - * Returns 1 if the caller of the current operation is the specified - * object, or if the caller is the object with the specified file name. - * - * *NOTE* This will not succeed when called from other functions in the - * simul_efun object, as previous_object() does not count the object - * itself in its call list. - * - * @param {mixed} ob The object or file name to compare the caller to. - * @return {int} 1 if the caller is the specified object, 0 otherwise. - */ -int caller_is(mixed ob) {} - -/** - * Returns 1 if the two objects are in the same environment, or 0 if - * they are not. - * - * @param {object} one The first object to compare. - * @param {object} two The second object to compare. - * @param {int} top_env Whether to check the top-level environment (optional). - * @return {int} 1 if the objects are in the same environment, 0 otherwise. - */ -varargs int same_env_check(object one, object two, int top_env) {} - -/** - * Finds all objects in a container that match the specified argument. - * The argument can be a name, ID, or other identifier. Objects are - * filtered based on visibility and an optional custom filter function. - * - * @param {object} tp The body object of the player or NPC searching. - * @param {string} arg The argument to match objects against. - * @param {object} source The object to search within (optional, default: caller's environment). - * @param {function} f An optional custom filter function (optional). - * @return {object*} An array of located objects or 0 if none are found. - */ -varargs object *find_targets(object tp, string arg, object source, function f) {} - -/** - * Finds a single object in a container that matches the specified argument. - * The argument can be a name, ID, or other identifier. Objects are - * filtered based on visibility and an optional custom filter function. - * - * @param {object} tp The body object of the player or NPC searching. - * @param {string} arg The argument to match objects against. - * @param {object} source The object to search within (optional, default: caller's environment). - * @param {function} f An optional custom filter function (optional). - * @return {object} The located object, or 0 if not found. - */ -varargs object find_target(object tp, string arg, object source, function f) {} - -/** - * Retrieves all clones of the specified file in the game. If the file - * is an object, it will retrieve all clones using the object's base name. - * - * @param {mixed} file The file or object to find clones of. - * @param {int} env_only Whether to only return clones that have an environment (optional). - * @return {object*} An array of objects that are clones of the specified file. - */ -varargs object *clones(mixed file, int env_only) {} - -/** - * Gets the root uid of an object or the MUD. - * - * @param {object} ob The object to check (optional, default: master object). - * @return {string} The root uid. - */ -varargs string get_root_uid(object ob) {} - -/** - * Checks if an object is a clone. - * - * @param {object} ob The object to check (optional, default: previous object). - * @return {int} 1 if clone, 0 if not. - */ -varargs int clonep(object ob) {} diff --git a/examples/chokidar-as-npm/source/random.c b/examples/chokidar-as-npm/source/random.c deleted file mode 100644 index 1876f00..0000000 --- a/examples/chokidar-as-npm/source/random.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Generates a random float between 0 and upper_bound. - * - * @param {mixed} upper_bound The upper bound for the random float. - * @return {float} The random float between 0 and upper_bound. - */ -float random_float(mixed upper_bound) {} - -/** - * Selects an element from a weighted mapping based on their weights. - * - * @param {mapping} m The weighted mapping to select from, where keys are the - * elements and values are their weights. - * @return {mixed} The selected element. - */ -mixed element_of_weighted(mapping m) {} - -/** - * Generates a random integer within a specified range. - * - * @param {int} min The lower bound (inclusive) of the range. - * @param {int} max The upper bound (inclusive) of the range. - * @return {int} A random number in the specified range. - */ -int random_clamp(int min, int max) {} - -/* PRANDOM 128 */ -/** - * Sanitizes the seed for the random number generator. Ensures that the seed - * is a non-zero integer and within the range of a 64-bit unsigned integer. - * - * @param {mixed} seed The seed to sanitize. - * @return {int*} The sanitized seed. - */ -public int *sanitize_seed(mixed seed) {} - -/** - * Generates a random number within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {int} size The upper bound for the random number. - * @return {int*} A two element array where the first element is the - * updated seed and the second is the random number. - */ -int *prandom(mixed seed, int size) {} - -/** - * Generates a random float within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {float} size The upper bound for the random float. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the random float. - */ -mixed *prandom_float(mixed seed, float size) {} - -/** - * Shuffles an array using the xorshift128+ algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mixed*} arr The array to shuffle. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the shuffled array. - */ -mixed *pshuffle(mixed seed, mixed *arr) {} - -/** - * Selects an element from an array using the xorshift128+ algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mixed*} arr The array to select an element from. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the selected element. - */ -mixed *pelement_of(mixed seed, mixed *arr) {} - -/** - * Generates a random number within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {int} min The lower bound (inclusive) of the range. - * @param {int} max The upper bound (inclusive) of the range. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the random number. - */ -mixed *prandom_clamp(mixed seed, int min, int max) {} - -/** - * Selects an element from a weighted mapping using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mapping} weights The weighted mapping to select from, where keys - * are the elements and values are their weights. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the selected element. - */ -mixed *pelement_of_weighted(mixed seed, mapping weights) {} diff --git a/examples/chokidar-as-npm/source/resolve_path.c b/examples/chokidar-as-npm/source/resolve_path.c deleted file mode 100644 index beb3888..0000000 --- a/examples/chokidar-as-npm/source/resolve_path.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Resolves a given path relative to the current path, handling - * special cases such as user directories and relative paths. - * - * @param {string} base_dir The current path. - * @param {string} path The next path to resolve. - * @return {string} The resolved absolute path. - */ -string resolve_path(string base_dir, string path) {} - -/** - * Resolves and validates a path, checking if it exists as either - * a file or directory. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The path to resolve and validate. - * @return {string|int} The resolved absolute path if valid, or 0 if invalid. - */ -string valid_path(string base_dir, string path) {} - -/** - * Resolves and validates a file path, checking if it exists as a - * file. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The file path to resolve and validate. - * @return {string|int} The resolved absolute file path if valid, or 0 if invalid. - */ -string valid_file(string base_dir, string path) {} - -/** - * Resolves and validates a directory path, checking if it exists - * as a directory. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The directory path to resolve and validate. - * @return {string|int} The resolved absolute directory path if valid, or 0 if invalid. - */ -string valid_dir(string base_dir, string path) {} - -/** - * Resolves a file path without checking its existence. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The file path to resolve. - * @return {string} The resolved absolute file path. - */ -string resolve_file(string base_dir, string path) {} - -/** - * Resolves a directory path without checking its existence, - * ensuring it ends with a slash. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The directory path to resolve. - * @return {string} The resolved absolute directory path, ending with a slash. - */ -string resolve_dir(string base_dir, string path) {} - -/** - * Resolves a path and returns an array of matching files, supporting - * wildcard pattern. If no wildcard is present in the pattern, "*" is - * appended. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The path or pattern to resolve and search for files. - * @return {string[]} An array of matching file paths, or ({}) if invalid. - */ -string *get_files(string base_dir, string path) {} diff --git a/examples/chokidar-as-npm/source/signal.c b/examples/chokidar-as-npm/source/signal.c deleted file mode 100644 index 7c2c064..0000000 --- a/examples/chokidar-as-npm/source/signal.c +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Emit a signal to all objects that have registered a slot for - * the signal. - * - * @param {int} sig The signal number. - * @param {mixed} arg The arguments to pass to the signal (optional). - */ -void emit(int sig, mixed arg...) {} - -/** - * Register a slot for a signal. - * - * @param {int} sig The signal number. - * @param {string} func The function to call when the signal is emitted. - * @return {int} `SIG_SLOT_OK` if the slot was registered successfully. - * See `include/signal.h` for other return values. - */ -int slot(int sig, string func) {} - -/** - * Unregister a slot for a signal. - * - * @param {int} sig The signal number. - * @return {int} `SIG_SLOT_OK` if the slot was unregistered successfully. - * See `include/signal.h` for other return values. - */ -int unslot(int sig) {} - -/** - * Get the signal daemon object. - * - * @return {object} The signal daemon object. - */ -object signal_d() {} diff --git a/examples/chokidar-as-npm/source/string.c b/examples/chokidar-as-npm/source/string.c deleted file mode 100644 index 22360e8..0000000 --- a/examples/chokidar-as-npm/source/string.c +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Appends a string to another string if it is not already there. If the string - * is already present, the original string is returned. - * - * @param {string} source The string to append to. - * @param {string} to_append The string to append. - * @return {string} The original string with the appended string if it was not - * already present. - */ -string append(string source, string to_append) {} - -/** - * Prepends a string to another string if it is not already there. - * If the string is already present, the original string is returned. - * - * @param {string} source The string to prepend to. - * @param {string} to_prepend The string to prepend. - * @return {string} The original string with the prepended string if it was not - * already present. - */ -string prepend(string source, string to_prepend) {} - -/** - * Chops a substring off the end or beginning of another string if - * it is present. If the substring is not present, the original - * string is returned. If no direction is specified, chops from - * the right (-1). - * - * @param {string} str The string to chop from. - * @param {string} sub The substring to chop. - * @param {int} dir The direction to chop: 1 for left, -1 for right (optional, default: -1) - * @return {string} The string with the substring chopped off if it was present. - */ -varargs string chop(string str, string sub, int dir) {} - -/** - * Extracts a substring from a string. If no ending position is provided, - * extracts from the starting position to the end of the string. - * - * @param {string} str The string to extract from. - * @param {int} from The starting position to extract from. - * @param {int} to The ending position to extract to (optional) - * @return {string} The extracted substring. - */ -varargs string extract(string str, int from, int to) {} - -/** - * Returns a string with all colour codes removed. - * - * @param {string} str The string to remove colour from. - * @return {string} The string without colour. - */ -string no_ansi(string str) {} - -/** - * Returns a string that is a simple list of the elements of an array, - * joined by a conjunction. If no conjunction is provided, "and" will be used. - * - * @param {string*} arr The array to make a list from. - * @param {string} conjunction The word to join the last two elements (optional, default: "and") - * @return {string} The simple list string. - */ -varargs string simple_list(string *arr, string conjunction) {} - -/** - * Returns a substring of a string, starting from 0 and ending at the - * first occurrence of another string within it. If the reverse flag - * is set, the substring will start at the last occurrence of the - * substring within the string. - * - * @param {string} str The string to extract from. - * @param {string} sub The substring to extract to. - * @param {int} reverse If set, the substring will start at the last occurrence (optional, default: 0) - * @return {string} The extracted substring. - */ -varargs string substr(string str, string sub, int reverse) {} - -/** - * Converts a string representation of an LPC value to the - * corresponding LPC value. If the flag is set, returns an array with - * the value and the remaining string. - * - * @param {string} str The string to convert. - * @param {int} flag If set, returns an array with the value and remaining string (optional, default: 0) - * @return {mixed} The LPC value represented by the string. - */ -varargs mixed from_string(string str, int flag) {} - -/** - * Converts an LPC value to its string representation. - * - * @param {mixed} val The value to convert. - * @return {string} The string representation of the value. - */ -string stringify(mixed val) {} - -/** - * Returns a string with commas added to the number. Handles both integer - * and floating point numbers, as well as strings that can be converted to numbers. - * For negative numbers, the negative sign is preserved at the start. - * - * @param {mixed} number The number to add commas to. - * @return {string} The number with commas added as a string. - */ -string add_commas(mixed number) {} - -/** - * Reverses a string. - * - * @param {string} str The string to reverse. - * @return {string} The reversed string. - */ -string reverse_string(string str) {} - -/** - * Searches for a substring in a string starting from a given position - * and moving backwards. If no starting position is provided, starts from - * the beginning of the string. - * - * @param {string} str The string to search in. - * @param {string} sub The substring to search for. - * @param {int} start The starting position to search from (optional, default: 0) - * @return {int} The position of the substring in the string, or -1 if not found. - */ -varargs int reverse_strsrch(string str, string sub, int start) {} - -/** - * Searches for the position of a substring in a string using a - * regular expression. If reverse is set, the search will start from - * the end of the string. - * - * @param {string} str The string to search in. - * @param {string} substr The regular expression to search for. - * @param {int} reverse If set, the search will start from the end (optional, default: 0) - * @return {int} The position of the substring in the string, or -1 if not found. - */ -varargs int pcre_strsrch(string str, string substr, int reverse) {} - -/** - * Returns 1 if the string contains colour codes, 0 if not. - * - * @param {string} str The string to check. - * @return {int} 1 if the string contains colour codes, otherwise 0. - */ -int colourp(string str) {} - -/** - * Trims whitespace from both ends of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string trim(string str) {} - -/** - * Trims whitespace from the start of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string ltrim(string str) {} - -/** - * Trims whitespace from the end of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string rtrim(string str) {} diff --git a/examples/source/lpc/directory.c b/examples/source/lpc/directory.c deleted file mode 100644 index f030506..0000000 --- a/examples/source/lpc/directory.c +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Ensures that a directory exists by creating it and its parent directories if - * necessary. - * - * @param {string} path The path of the directory to ensure. - * @return {int} 1 if successful, 0 if failed. - */ -mixed assure_dir(string path) {} - -/** - * Returns the directory of the given object. - * - * @param {object} ob The object to query (optional, default: previous object). - * @return {string} The directory path of the object. - */ -string query_directory(object ob) {} diff --git a/examples/source/lpc/english.c b/examples/source/lpc/english.c deleted file mode 100644 index 49cb4f8..0000000 --- a/examples/source/lpc/english.c +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Capitalizes the first letter of each word in a string. - * - * @param {string} str The string to capitalize. - * @return {string} The capitalized string. - */ -string cap_words(string str) {} - -/** - * Capitalizes significant words in a string, ignoring certain - * insignificant words. Optionally capitalizes the first word - * as a title. - * - * @param {string} str The string to capitalize. - * @param {int} title Whether to capitalize the first word as a title (optional). - * @return {string} The string with significant words capitalized. - */ -varargs string cap_significant_words(string str, int title) {} - -/** - * Returns the possessive form of a noun. If the noun ends with 's', - * it adds an apostrophe; otherwise, it adds 's. - * - * @param {mixed} ob The object or string to convert to possessive form. - * @return {string} The possessive form of the noun. - */ -string possessive_noun(mixed ob) {} - -/** - * Returns the possessive form of a proper noun. Applies 's to the - * end of the noun. - * - * @param {mixed} ob The object or string to convert to possessive form. - * @return {string} The possessive form of the proper noun. - */ -string possessive_proper_noun(mixed ob) {} - -/** - * Returns the possessive pronoun corresponding to the object's - * gender. Defaults to "its" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The possessive pronoun - */ -string possessive_pronoun(mixed ob) {} - -/** - * Returns the possessive adjective corresponding to the object's - * gender. Defaults to "its" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The possessive adjective - */ -string possessive(mixed ob) {} - -/** - * Returns the reflexive pronoun corresponding to the object's - * gender. Defaults to "itself" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The reflexive pronoun - */ -string reflexive(mixed ob) {} - -/** - * Returns the objective pronoun corresponding to the object's - * gender. Defaults to "it" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The objective pronoun - */ -string objective(mixed ob) {} - -/** - * Returns the subjective pronoun corresponding to the object's - * gender. Defaults to "it" for non-string or unknown gender - * @param {mixed} ob The object or gender string to convert - * @return {string} The subjective pronoun - */ -string subjective(mixed ob) {} - -/** - * Returns the article corresponding to the noun. If definite - * is true, returns "the"; otherwise, returns "a" or "an" - * depending on the noun's initial letter - * @param {string} str The noun to determine the article for - * @param {int} definite Whether to return the definite article (defaults to 0) - * @return {string} The article - */ -varargs string article(string str, int definite) {} - -/** - * Adds an article to a string. If definite is true, adds "the"; - * otherwise, adds "a" or "an" depending on the noun's initial - * letter - * @param {string} str The string to add the article to - * @param {int} definite Whether to add the definite article (defaults to 0) - * @return {string} The string with the article prepended - */ -varargs string add_article(string str, int definite) {} - -/** - * Removes an article from a string. If the string begins with - * "the ", "a ", or "an ", removes the article - * @param {string} str The string to remove the article from - * @return {string} The string with the article removed - */ -string remove_article(string str) {} diff --git a/examples/source/lpc/exists.c b/examples/source/lpc/exists.c deleted file mode 100644 index d4dbeda..0000000 --- a/examples/source/lpc/exists.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Checks if a directory exists. - * - * @param {string} dirname The name of the directory to check. - * @return {int} 1 if exists, 0 if not. - */ -int directory_exists(string dirname) {} - -/** - * Checks if a file exists. - * - * @param {string} file The name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int file_exists(string file) {} - -/** - * Checks if a compiled file (.c) exists. - * - * @param {string} file The base name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int cfile_exists(string file) {} - -/** - * Checks if a save file exists. - * - * @param {string} file The base name of the file to check. - * @return {int} 1 if exists, 0 if not. - */ -int ofile_exists(string file) {} - -/** - * Checks if a user data file exists. - * - * @param {string} user The username to check. - * @return {int} 1 if exists, 0 if not. - */ -int user_exists(string user) {} diff --git a/examples/source/lpc/file.c b/examples/source/lpc/file.c deleted file mode 100644 index f9dc0b7..0000000 --- a/examples/source/lpc/file.c +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Ensures that the directory structure leading to a file exists. - * - * @param {string} file The path of the file to ensure. - * @return {mixed} 1 if successful, string with error message if failed. - */ -mixed assure_file(string file) {} - -/** - * Determines the owner of a file based on its path. - * - * @param {string} file The path of the file to check. - * @return {string} The owner of the file, or 0 if not found. - */ -string file_owner(string file) {} - -/** - * Returns the last few lines of a file. - * - * @param {string} path The path of the file to read. - * @param {int} line_count Number of lines to read (optional, default: 25). - * @return {string} The last few lines of the file. - */ -varargs string tail(string path, int line_count) {} - -/** - * Writes a log message to a specified log file. - * - * @param {string} file The name of the log file. - * @param {string} str The log message to write. - * @param {mixed} arg Additional arguments for the log message (optional). - * @return {int} 1 if successful, 0 if failed. - */ -varargs int log_file(string file, string str, mixed arg...) {} - -/** - * Reads a file and returns its content as an array of lines. - * - * @param {string} file The path of the file to read. - * @return {string*} Array of lines, excluding comments and empty lines. - */ -string *explode_file(string file) {} - -/** - * Writes an array of lines to a file. - * - * @param {string} file The path of the file to write to. - * @param {string*} lines The array of lines to write. - * @param {int} overwrite Whether to overwrite existing content (optional, default: 0). - */ -varargs void implode_file(string file, string *lines, int overwrite) {} - -/** - * Returns the name of the file for a given object. - * - * @param {object} ob The object to query (optional, default: previous object). - * @return {string} The name of the file. - */ -string query_file_name(object ob) {} - -/** - * Generates a temporary file name. - * - * @param {mixed} arg The file or object to create temp file for (optional, default: previous object). - * @return {string} The path to the temporary file. - */ -varargs string temp_file(mixed arg) {} - -/** - * Extracts directory and file components from a path. - * - * @param {mixed} path The path or object to process. - * @return {string*} Array containing [directory, filename]. - */ -string *dir_file(mixed path) {} - -/** - * Validates and extracts directory and file components. - * - * @param {string} path The path to check. - * @param {int} file_too Whether the file should exist (optional). - * @return {string*} Array containing [directory, filename] or null if invalid. - */ -varargs string *valid_dir_file(string path, int file_too) {} - -/** - * Creates an empty file at the specified path. - * - * @param {string} file The path of the file to create. - * @return {int} 1 if successful, 0 if failed. - */ -int touch(string file) {} diff --git a/examples/source/lpc/function.c b/examples/source/lpc/function.c deleted file mode 100644 index fa49df8..0000000 --- a/examples/source/lpc/function.c +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Checks if a given function is valid and not owned by a destructed - * object. - * - * @param {mixed} f The function to check. - * @return {int} 1 if the function is valid, otherwise 0. - */ -int valid_function(mixed f) {} - -/** - * Returns a formatted string of the current call stack trace. - * - * @param {int} colour Whether to include colour codes (optional, default: 0) - * @return {string} The formatted call stack trace. - */ -varargs string call_trace(int colour) {} - -/** - * Assembles a callback function from the provided arguments. - * This function is used to create a callable structure that can be - * invoked later. The callback can be either a method on an object or - * a function. - * - * Usage: - * When you need to create a callback for an object method: - * `assemble_call_back(object, "method", args...)` - * When you need to create a callback for a function: - * `assemble_call_back(function, args...)` - * - * The function performs the following steps: - * 1. Checks if the provided arguments form a valid array - * 2. Determines the size of the arguments array - * 3. Checks if the first argument is an object. If so, it verifies that - * the second argument is a valid method name on the object - * 4. If the first argument is a function, it creates a callback with the - * function and any additional arguments - * 5. Returns the assembled callback as an array - * - * @param {mixed} arg The arguments to assemble into a callback. - * @return {mixed*} The assembled callback. - */ -mixed *assemble_call_back(mixed arg...) {} - -/** - * Executes a callback with the given arguments. - * - * @param {mixed} cb The callback to execute. - * @param {mixed} new_arg The arguments to pass to the callback (optional). - * @return {mixed} The result of the callback execution. - */ -mixed call_back(mixed cb, mixed new_arg...) {} - -/** - * Calls the specified function on the given object if it exists. - * - * @param {mixed} ob The object to call the function on. - * @param {string} func The name of the function to call. - * @param {mixed} arg The argument to pass to the function (optional). - * @return {mixed} The return value of the function, or null if the function - * does not exist. - */ -varargs mixed call_if(mixed ob, string func, mixed arg...) {} - -/** - * Delays an action for a specified amount of time. - * - * @param {string} action The action to delay. - * @param {float} delay The amount of time to delay the action. - * @param {mixed*} cb The callback to execute after the delay. - * @return {int} The ID of the delayed action. - */ -varargs int delay_act(string act, float delay, mixed *cb) {} - -/** - * Asserts that a statement is true. If the statement is false, it - * will throw an error with the given message. If no message is - * provided, it will use a default message. - * - * @param {mixed} statement The statement to assert. - * @param {string} message The message to display if the condition is false (optional). - */ -varargs void assert(mixed statement, string message) {} diff --git a/examples/source/lpc/grammar.c b/examples/source/lpc/grammar.c deleted file mode 100644 index 7e6376a..0000000 --- a/examples/source/lpc/grammar.c +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Converts an integer to its ordinal string representation. - * - * @param {int} n The integer to convert. - * @return {string} The ordinal string representation of the integer. - */ -string ordinal(int n) {} - -/** - * Converts a numerical number to its worded number representation. - * Originally written by Domini@Ultimate (22-08-93) as fullnum(). - * Renamed by Mobydick@TMI-2 (93-08-22). - * - * @param {int} num The numerical number to convert. - * @return {string} The worded number representation of the integer. - */ -string int_string(int num) {} - -/** - * Returns a consolidated string for a given quantity and item - * description, handling pluralization and special cases. - * - * @param {int} x The quantity of items. - * @param {string} str The description of the item(s). - * @return {string} The consolidated string. - */ -string consolidate(int x, string str) {} diff --git a/examples/source/lpc/numbers.c b/examples/source/lpc/numbers.c deleted file mode 100644 index 5a45bdd..0000000 --- a/examples/source/lpc/numbers.c +++ /dev/null @@ -1,99 +0,0 @@ -#include - -/** - * Calculates what `a` percent of `b` is. - * - * @param {float} a The percentage value. - * @param {float} b The whole value. - * @return {float} The value that is `a` percent of `b`. - */ -float percent_of(float a, float b) {} - -/** - * Calculates what percentage `a` is of `b`. - * - * @param {float} a The part value. - * @param {float} b The whole value. - * @return {float} The percentage of `a` out of `b`. - */ -float percent(float a, float b) {} - -/** - * Ensures a value is within a specified range. - * - * @param {float} min The minimum value. - * @param {float} max The maximum value. - * @param {float} val The value to check. - * @return {float} The value, constrained within the range of `min` to `max`. - */ -float clamp(float min, float max, float val) {} - -/** - * Calculates the remainder of `a` divided by `b`. If either value is an integer, - * it will be converted to float before calculation. - * - * @param {mixed} a The dividend. - * @param {mixed} b The divisor. - * @return {float} The remainder of `a` divided by `b`. - */ -varargs float remainder(mixed a, mixed b) {} - -/** - * Calculates the sum of all elements in an array. - * - * @param {mixed*} arr The array of numbers to sum. - * @return {int} The sum of all elements in the array. - */ -int sum(mixed *arr) {} - -/** - * Evaluates a number against a condition. The condition can be a - * simple comparison, or a compound condition using `AND` and `OR`. - * This system allows for the evaluation of numeric conditions - * using a specific set of operators and syntax rules. - * - * Basic Operators: - * `<` Less than - * `>` Greater than - * `<=` Less than or equal to - * `>=` Greater than or equal to - * `=` or `==` Equal to - * `!=` Not equal to - * `%` Checks if a number is divisible by the given value - * - * Range Operator: - * Use a hyphen (`-`) to specify a range, inclusive of both ends. - * Example: `5-15` means any number from `5` to `15`, including - * `5` and `15`. - * - * Set Inclusion/Exclusion: - * `[a,b,c]` Checks if a number is one of the listed values - * `![a,b,c]` Checks if a number is not one of the listed values - * - * Logical Operators: - * `AND` Both conditions must be true - * `OR` At least one condition must be true - * - * Grouping: - * Use parentheses `()` to group conditions and override default precedence. - * - * Precedence (from highest to lowest): - * 1. Parentheses `()` - * 2. Basic operators, Range, Modulo, Set inclusion/exclusion - * 3. `AND` - * 4. `OR` - * - * Syntax Rules: - * No spaces are allowed in the condition string - * Operators must be used exactly as specified - * Set values must be comma-separated without spaces - * - * Example: `(5-15AND%3)OR[20,25,30]` - * This checks if a number is between `5` and `15` (inclusive) AND - * divisible by `3`, OR if it's `20`, `25`, or `30`. - * - * @param {int} number The number to evaluate. - * @param {string} condition The condition to evaluate against. - * @return {int} 1 if the condition evaluates to true, 0 otherwise. - */ -int evaluate_number(int number, string condition) {} diff --git a/examples/source/lpc/object.c b/examples/source/lpc/object.c deleted file mode 100644 index 0764d87..0000000 --- a/examples/source/lpc/object.c +++ /dev/null @@ -1,251 +0,0 @@ -/** - * Retrieves the unique object ID of the given object. - * - * @param {object} ob The object to get the ID of. - * @return {int} The unique object ID. - */ -int getoid(object ob) {} - -/* -// get_object() and get_objects() -// Created by Pallando@Ephemeral Dale (92-06) -// Created by Watcher@TMI (92-09-27) -// Revised by Watcher and Pallando (92-12-11) -// Re-written by Pallando (92-12-18) -// get_objects() added by Pallando@Tabor (93-03-02) -// "s", "c" & ">" added by Grendel@TMI-2 (93-07-14) -// -// Use all possible methods to locate an object by the inputed -// name and return the object pointer if located. -// Ideas for future expansion (please, anyone feel free to add them if they -// have the time) -// "wizards" the subset of "users" who are wizards. -// "livings" all living objects -// "objects" all loaded objects -// check the capitalized and lower_case version of str -// check wizard's home directories. -*/ - -/** - * Attempts to locate an object by the given name and returns the - * object pointer if found. - * - * @param {string} str The name of the object to locate. - * @param {object} player The player object to use as a reference for searching (optional). - * @return {object} The located object, or 0 if not found. - */ -varargs object get_object(string str, object player) {} - -/** - * Locates objects based on the specified search string, which can - * include various search criteria and options. - * - * @param {string} str The search string specifying the objects to locate. - * @param {object} player The player object to use as a reference for searching. - * @param {int} no_arr If specified, only a single object or 0 will be returned, - * otherwise an array of objects may be returned (optional). - * @return {mixed} The located object(s), or 0 if not found. - */ -varargs mixed get_objects(string str, object player, int no_arr) {} - -/** - * Searches for an object within a container or environment - * using the specified criteria. - * - * @param {mixed} ob The object or name of the object to find. - * @param {mixed} cont The container or environment to search within (optional, default: previous object). - * @param {function} f An optional function to further filter the search (optional). - * @return {object} The found object, or 0 if not found. - */ -varargs object find_ob(mixed ob, mixed cont, function f) {} - -/** - * Retrieves the top-level environment of the specified object, - * traversing up through nested environments. - * - * @param {object} ob The object to get the top-level environment of. - * @return {object} The top-level environment of the object. - */ -object top_environment(object ob) {} - -/** - * Retrieves all environments of the specified object, traversing - * up through nested environments. - * - * @param {object} ob The object to get the environments of. - * @return {object*} An array of environments of the object. - */ -object *all_environment(object ob) {} - -/** - * Retrieves all living objects present in the specified room. - * - * @param {object} room The room to search for living objects in. - * @return {object*} An array of living objects present in the room. - */ -object *present_livings(object room) {} - -/** - * Retrieves all player objects present in the specified room. - * - * @param {object} room The room to search for player objects in. - * @return {object*} An array of player objects present in the room. - */ -object *present_players(object room) {} - -/** - * Retrieves all non-player characters (NPCs) present in the - * specified room. - * - * @param {object} room The room to search for NPCs in. - * @return {object*} An array of NPC objects present in the room. - */ -object *present_npcs(object room) {} - -/** - * Locates a living object by the specified name within the - * specified room. - * - * @param {string} name The name of the living object to locate. - * @param {object} room The room to search for the living object in. - * @return {object} The located living object, or 0 if not found. - */ -object get_living(string name, object room) {} - -/** - * Locates living objects by the specified names within the - * specified room. - * - * @param {string|string*} names The name of the living objects to locate. - * @param {object} room The room to search for the living objects in. - * @return {object*} An array of located living objects. - */ -object *get_livings(mixed names, object room) {} - -/** - * Locates a player object by the specified name within the - * specified room. - * - * @param {string} name The name of the player to locate. - * @param {object} room The room to search for the player in. - * @return {object} The located player object, or 0 if not found. - */ -object get_player(string name, object room) {} - -/** - * Locates player objects by the specified names within the - * specified room. - * - * @param {string|string*} names The name of the player objects to locate. - * @param {object} room The room to search for the player objects in. - * @return {object*} An array of located player objects. - */ -object *get_players(mixed names, object room) {} - -/** - * Returns the body of the current interactive user. It is used as a - * replacement for this_player(). - * - * @return {object} The body of the current calling player. - */ -object this_body() {} - -/** - * Returns the object that called the current operation. This may be - * this_body(), but it may also be a shadow another player who initiated - * the chain. For example, a wizard using the force command. - * - * Be careful with this one, you don't want to accidentally - * perform operations on the wrong object. - * - * @return {object} The object that called the current operation. - */ -object this_caller() {} - -/** - * Retrieves all clones of the specified file present in the - * specified container. If the file is an object, it will - * retrieve all clones using the object's base name. - * - * @param {mixed} file The file or object to find clones of. - * @param {object} container The container to search within. - * @return {object*} An array of clones of the specified file present in - * the container. - */ -object *present_clones(mixed file, object container) {} - -/** - * Returns 1 if the caller of the current operation is the specified - * object, or if the caller is the object with the specified file name. - * - * *NOTE* This will not succeed when called from other functions in the - * simul_efun object, as previous_object() does not count the object - * itself in its call list. - * - * @param {mixed} ob The object or file name to compare the caller to. - * @return {int} 1 if the caller is the specified object, 0 otherwise. - */ -int caller_is(mixed ob) {} - -/** - * Returns 1 if the two objects are in the same environment, or 0 if - * they are not. - * - * @param {object} one The first object to compare. - * @param {object} two The second object to compare. - * @param {int} top_env Whether to check the top-level environment (optional). - * @return {int} 1 if the objects are in the same environment, 0 otherwise. - */ -varargs int same_env_check(object one, object two, int top_env) {} - -/** - * Finds all objects in a container that match the specified argument. - * The argument can be a name, ID, or other identifier. Objects are - * filtered based on visibility and an optional custom filter function. - * - * @param {object} tp The body object of the player or NPC searching. - * @param {string} arg The argument to match objects against. - * @param {object} source The object to search within (optional, default: caller's environment). - * @param {function} f An optional custom filter function (optional). - * @return {object*} An array of located objects or 0 if none are found. - */ -varargs object *find_targets(object tp, string arg, object source, function f) {} - -/** - * Finds a single object in a container that matches the specified argument. - * The argument can be a name, ID, or other identifier. Objects are - * filtered based on visibility and an optional custom filter function. - * - * @param {object} tp The body object of the player or NPC searching. - * @param {string} arg The argument to match objects against. - * @param {object} source The object to search within (optional, default: caller's environment). - * @param {function} f An optional custom filter function (optional). - * @return {object} The located object, or 0 if not found. - */ -varargs object find_target(object tp, string arg, object source, function f) {} - -/** - * Retrieves all clones of the specified file in the game. If the file - * is an object, it will retrieve all clones using the object's base name. - * - * @param {mixed} file The file or object to find clones of. - * @param {int} env_only Whether to only return clones that have an environment (optional). - * @return {object*} An array of objects that are clones of the specified file. - */ -varargs object *clones(mixed file, int env_only) {} - -/** - * Gets the root uid of an object or the MUD. - * - * @param {object} ob The object to check (optional, default: master object). - * @return {string} The root uid. - */ -varargs string get_root_uid(object ob) {} - -/** - * Checks if an object is a clone. - * - * @param {object} ob The object to check (optional, default: previous object). - * @return {int} 1 if clone, 0 if not. - */ -varargs int clonep(object ob) {} diff --git a/examples/source/lpc/random.c b/examples/source/lpc/random.c deleted file mode 100644 index 1876f00..0000000 --- a/examples/source/lpc/random.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Generates a random float between 0 and upper_bound. - * - * @param {mixed} upper_bound The upper bound for the random float. - * @return {float} The random float between 0 and upper_bound. - */ -float random_float(mixed upper_bound) {} - -/** - * Selects an element from a weighted mapping based on their weights. - * - * @param {mapping} m The weighted mapping to select from, where keys are the - * elements and values are their weights. - * @return {mixed} The selected element. - */ -mixed element_of_weighted(mapping m) {} - -/** - * Generates a random integer within a specified range. - * - * @param {int} min The lower bound (inclusive) of the range. - * @param {int} max The upper bound (inclusive) of the range. - * @return {int} A random number in the specified range. - */ -int random_clamp(int min, int max) {} - -/* PRANDOM 128 */ -/** - * Sanitizes the seed for the random number generator. Ensures that the seed - * is a non-zero integer and within the range of a 64-bit unsigned integer. - * - * @param {mixed} seed The seed to sanitize. - * @return {int*} The sanitized seed. - */ -public int *sanitize_seed(mixed seed) {} - -/** - * Generates a random number within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {int} size The upper bound for the random number. - * @return {int*} A two element array where the first element is the - * updated seed and the second is the random number. - */ -int *prandom(mixed seed, int size) {} - -/** - * Generates a random float within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {float} size The upper bound for the random float. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the random float. - */ -mixed *prandom_float(mixed seed, float size) {} - -/** - * Shuffles an array using the xorshift128+ algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mixed*} arr The array to shuffle. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the shuffled array. - */ -mixed *pshuffle(mixed seed, mixed *arr) {} - -/** - * Selects an element from an array using the xorshift128+ algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mixed*} arr The array to select an element from. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the selected element. - */ -mixed *pelement_of(mixed seed, mixed *arr) {} - -/** - * Generates a random number within a specified range using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {int} min The lower bound (inclusive) of the range. - * @param {int} max The upper bound (inclusive) of the range. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the random number. - */ -mixed *prandom_clamp(mixed seed, int min, int max) {} - -/** - * Selects an element from a weighted mapping using the xorshift128+ - * algorithm. - * - * @param {mixed} seed The seed for the random number generator. - * @param {mapping} weights The weighted mapping to select from, where keys - * are the elements and values are their weights. - * @return {mixed*} A two element array where the first element is the - * updated seed and the second is the selected element. - */ -mixed *pelement_of_weighted(mixed seed, mapping weights) {} diff --git a/examples/source/lpc/resolve_path.c b/examples/source/lpc/resolve_path.c deleted file mode 100644 index beb3888..0000000 --- a/examples/source/lpc/resolve_path.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Resolves a given path relative to the current path, handling - * special cases such as user directories and relative paths. - * - * @param {string} base_dir The current path. - * @param {string} path The next path to resolve. - * @return {string} The resolved absolute path. - */ -string resolve_path(string base_dir, string path) {} - -/** - * Resolves and validates a path, checking if it exists as either - * a file or directory. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The path to resolve and validate. - * @return {string|int} The resolved absolute path if valid, or 0 if invalid. - */ -string valid_path(string base_dir, string path) {} - -/** - * Resolves and validates a file path, checking if it exists as a - * file. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The file path to resolve and validate. - * @return {string|int} The resolved absolute file path if valid, or 0 if invalid. - */ -string valid_file(string base_dir, string path) {} - -/** - * Resolves and validates a directory path, checking if it exists - * as a directory. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The directory path to resolve and validate. - * @return {string|int} The resolved absolute directory path if valid, or 0 if invalid. - */ -string valid_dir(string base_dir, string path) {} - -/** - * Resolves a file path without checking its existence. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The file path to resolve. - * @return {string} The resolved absolute file path. - */ -string resolve_file(string base_dir, string path) {} - -/** - * Resolves a directory path without checking its existence, - * ensuring it ends with a slash. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The directory path to resolve. - * @return {string} The resolved absolute directory path, ending with a slash. - */ -string resolve_dir(string base_dir, string path) {} - -/** - * Resolves a path and returns an array of matching files, supporting - * wildcard pattern. If no wildcard is present in the pattern, "*" is - * appended. - * - * @param {string} base_dir The base directory to resolve relative paths from. - * @param {string} path The path or pattern to resolve and search for files. - * @return {string[]} An array of matching file paths, or ({}) if invalid. - */ -string *get_files(string base_dir, string path) {} diff --git a/examples/source/lpc/signal.c b/examples/source/lpc/signal.c deleted file mode 100644 index 7c2c064..0000000 --- a/examples/source/lpc/signal.c +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Emit a signal to all objects that have registered a slot for - * the signal. - * - * @param {int} sig The signal number. - * @param {mixed} arg The arguments to pass to the signal (optional). - */ -void emit(int sig, mixed arg...) {} - -/** - * Register a slot for a signal. - * - * @param {int} sig The signal number. - * @param {string} func The function to call when the signal is emitted. - * @return {int} `SIG_SLOT_OK` if the slot was registered successfully. - * See `include/signal.h` for other return values. - */ -int slot(int sig, string func) {} - -/** - * Unregister a slot for a signal. - * - * @param {int} sig The signal number. - * @return {int} `SIG_SLOT_OK` if the slot was unregistered successfully. - * See `include/signal.h` for other return values. - */ -int unslot(int sig) {} - -/** - * Get the signal daemon object. - * - * @return {object} The signal daemon object. - */ -object signal_d() {} diff --git a/examples/source/lpc/string.c b/examples/source/lpc/string.c deleted file mode 100644 index 22360e8..0000000 --- a/examples/source/lpc/string.c +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Appends a string to another string if it is not already there. If the string - * is already present, the original string is returned. - * - * @param {string} source The string to append to. - * @param {string} to_append The string to append. - * @return {string} The original string with the appended string if it was not - * already present. - */ -string append(string source, string to_append) {} - -/** - * Prepends a string to another string if it is not already there. - * If the string is already present, the original string is returned. - * - * @param {string} source The string to prepend to. - * @param {string} to_prepend The string to prepend. - * @return {string} The original string with the prepended string if it was not - * already present. - */ -string prepend(string source, string to_prepend) {} - -/** - * Chops a substring off the end or beginning of another string if - * it is present. If the substring is not present, the original - * string is returned. If no direction is specified, chops from - * the right (-1). - * - * @param {string} str The string to chop from. - * @param {string} sub The substring to chop. - * @param {int} dir The direction to chop: 1 for left, -1 for right (optional, default: -1) - * @return {string} The string with the substring chopped off if it was present. - */ -varargs string chop(string str, string sub, int dir) {} - -/** - * Extracts a substring from a string. If no ending position is provided, - * extracts from the starting position to the end of the string. - * - * @param {string} str The string to extract from. - * @param {int} from The starting position to extract from. - * @param {int} to The ending position to extract to (optional) - * @return {string} The extracted substring. - */ -varargs string extract(string str, int from, int to) {} - -/** - * Returns a string with all colour codes removed. - * - * @param {string} str The string to remove colour from. - * @return {string} The string without colour. - */ -string no_ansi(string str) {} - -/** - * Returns a string that is a simple list of the elements of an array, - * joined by a conjunction. If no conjunction is provided, "and" will be used. - * - * @param {string*} arr The array to make a list from. - * @param {string} conjunction The word to join the last two elements (optional, default: "and") - * @return {string} The simple list string. - */ -varargs string simple_list(string *arr, string conjunction) {} - -/** - * Returns a substring of a string, starting from 0 and ending at the - * first occurrence of another string within it. If the reverse flag - * is set, the substring will start at the last occurrence of the - * substring within the string. - * - * @param {string} str The string to extract from. - * @param {string} sub The substring to extract to. - * @param {int} reverse If set, the substring will start at the last occurrence (optional, default: 0) - * @return {string} The extracted substring. - */ -varargs string substr(string str, string sub, int reverse) {} - -/** - * Converts a string representation of an LPC value to the - * corresponding LPC value. If the flag is set, returns an array with - * the value and the remaining string. - * - * @param {string} str The string to convert. - * @param {int} flag If set, returns an array with the value and remaining string (optional, default: 0) - * @return {mixed} The LPC value represented by the string. - */ -varargs mixed from_string(string str, int flag) {} - -/** - * Converts an LPC value to its string representation. - * - * @param {mixed} val The value to convert. - * @return {string} The string representation of the value. - */ -string stringify(mixed val) {} - -/** - * Returns a string with commas added to the number. Handles both integer - * and floating point numbers, as well as strings that can be converted to numbers. - * For negative numbers, the negative sign is preserved at the start. - * - * @param {mixed} number The number to add commas to. - * @return {string} The number with commas added as a string. - */ -string add_commas(mixed number) {} - -/** - * Reverses a string. - * - * @param {string} str The string to reverse. - * @return {string} The reversed string. - */ -string reverse_string(string str) {} - -/** - * Searches for a substring in a string starting from a given position - * and moving backwards. If no starting position is provided, starts from - * the beginning of the string. - * - * @param {string} str The string to search in. - * @param {string} sub The substring to search for. - * @param {int} start The starting position to search from (optional, default: 0) - * @return {int} The position of the substring in the string, or -1 if not found. - */ -varargs int reverse_strsrch(string str, string sub, int start) {} - -/** - * Searches for the position of a substring in a string using a - * regular expression. If reverse is set, the search will start from - * the end of the string. - * - * @param {string} str The string to search in. - * @param {string} substr The regular expression to search for. - * @param {int} reverse If set, the search will start from the end (optional, default: 0) - * @return {int} The position of the substring in the string, or -1 if not found. - */ -varargs int pcre_strsrch(string str, string substr, int reverse) {} - -/** - * Returns 1 if the string contains colour codes, 0 if not. - * - * @param {string} str The string to check. - * @return {int} 1 if the string contains colour codes, otherwise 0. - */ -int colourp(string str) {} - -/** - * Trims whitespace from both ends of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string trim(string str) {} - -/** - * Trims whitespace from the start of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string ltrim(string str) {} - -/** - * Trims whitespace from the end of a string. - * - * @param {string} str The string to trim. - * @return {string} The trimmed string. - */ -string rtrim(string str) {} diff --git a/examples/source/lua-library-source/date.lua b/examples/source/lua-library-source/date.lua deleted file mode 100644 index 2433dae..0000000 --- a/examples/source/lua-library-source/date.lua +++ /dev/null @@ -1,32 +0,0 @@ ----@meta DateClass - ------------------------------------------------------------------------------- --- DateClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class DateClass - - ---Converts a number of seconds into a human-readable string. By default, the - ---result is returned as a table of three strings. However, if the `as_string` - ---parameter is provided, the result is returned as a single string. - --- - ---@example - ---```lua - ---date.shms(6543) - -----"01" - -----"49" - -----"03" - --- - ---date.shms(6453, true) - ----- "1h 49m 3s" - ---``` - --- - ---@name shms - ---@param seconds number - The number of seconds to convert. - ---@param as_string boolean? - Whether to return the result as a string. - ---@return string[]|string # The resulting string or table of strings. - function date.shms(seconds, as_string) end - -end diff --git a/examples/source/lua-library-source/func.lua b/examples/source/lua-library-source/func.lua deleted file mode 100644 index b75fd7c..0000000 --- a/examples/source/lua-library-source/func.lua +++ /dev/null @@ -1,50 +0,0 @@ ----@meta FuncClass - ------------------------------------------------------------------------------- --- FuncClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class FuncClass - - --- Delays the execution of a function. - --- - ---@example - ---```lua - ---func.delay(function() print("Hello, world!") end, 1) - ---``` - ---@name delay - ---@param func function - The function to delay. - ---@param delay number - The delay in seconds. - function func.delay(func, delay, ...) end - - --- Wraps a function in another function. - --- - ---@example - ---```lua - ---local becho = func.wrap(cecho, function(func, text) - --- func("{text}") - ---end) - --- - ---becho("Hello, world!") - --- -- Hello, world! - ---``` - ---@name wrap - ---@param func function - The function to wrap. - ---@param wrapper function - The wrapper function. - function func.wrap(func, wrapper) end - - --- Repeats a function a given number of times. - --- - ---@example - ---```lua - ---func.repeater(function() print("Hello, world!") end, 1, 3) - ---``` - ---@name repeater - ---@param func function - The function to repeat. - ---@param interval number? - The interval between repetitions (Optional. Default is 1). - ---@param times number? - The number of times to repeat the function (Optional. Default is 1). - function func.repeater(func, interval, times, ...) end - -end diff --git a/examples/source/lua-library-source/string.lua b/examples/source/lua-library-source/string.lua deleted file mode 100644 index baab07a..0000000 --- a/examples/source/lua-library-source/string.lua +++ /dev/null @@ -1,276 +0,0 @@ ----@meta StringClass - ------------------------------------------------------------------------------- --- StringClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - ---@class StringClass - - ---Appends a suffix to a string if it does not already end with that suffix. The check - ---is done using PCRE regex pattern matching to ensure accurate suffix detection. - --- - ---@example - ---```lua - ---string.append("hello", " world") -- "hello world" - ---string.append("hello world", "world") -- "hello world" - ---``` - --- - ---@name append - ---@param str string - The string to append to. - ---@param suffix string - The suffix to append to the string. - ---@return string # The resulting string. - function string.append(str, suffix) end - - ---Checks if a string contains a given pattern using PCRE regex. This is for finding - ---patterns anywhere within the string. The pattern must not start with "^" or end - ---with "$" - use starts_with() or ends_with() for those cases instead. - --- - ---@example - ---```lua - ---string.contains("hello world", "world") -- true - ---string.contains("hello world", "goodbye") -- false - ---``` - --- - ---@name contains - ---@param str string - The string to check. - ---@param pattern string - The pattern to check for. - ---@return boolean # Whether the string contains the pattern. - function string.contains(str, pattern) end - - ---Checks if a string ends with a given pattern using PCRE regex. If the pattern - ---doesn't already end with "$", it will be automatically appended to ensure matching - ---at the end of the string. - --- - ---@example - ---```lua - ---string.ends_with("hello world", "world") -- true - ---string.ends_with("hello world", "hello") -- false - ---string.ends_with("test.lua", "\\.lua$") -- true - ---``` - --- - ---@name ends_with - ---@param str string - The string to check. - ---@param ending string - The pattern to check for. - ---@return boolean # Whether the string ends with the pattern. - function string.ends_with(str, ending) end - - ---Formats a number with thousands separators and decimal places. Works with both - ---numbers and numeric strings. If not specified, uses "," for thousands and "." - ---for decimal separator. Handles negative numbers and maintains decimal precision. - --- - ---@example - ---```lua - ---string.format_number(1234567.89) -- "1,234,567.89" - ---string.format_number(-1234.56) -- "-1,234.56" - ---string.format_number(1234567, ".", ",") -- "1.234.567" - ---``` - --- - ---@name format_number - ---@param number number|string - The number to format. - ---@param thousands string? - The thousands separator. - ---@param decimal string? - The decimal separator. - ---@return string # The formatted number. - function string.format_number(number, thousands, decimal) end - - ---Removes whitespace characters from the beginning (left side) of a string. - ---Whitespace includes spaces, tabs, and newlines. - --- - ---@example - ---```lua - ---string.ltrim(" hello world ") -- "hello world " - ---string.ltrim("\t\nhello") -- "hello" - ---``` - --- - ---@name ltrim - ---@param str string - The string to remove whitespace from. - ---@return string # The resulting string without whitespace on the left. - function string.ltrim(str) end - - ---Converts a formatted number string back into a number. Handles thousands and - ---decimal separators, removing the thousands separators and converting the decimal - ---separator to a period if necessary. - --- - ---@example - ---```lua - ---string.parse_formatted_number("1,234,567.89") -- 1234567.89 - ---string.parse_formatted_number("1.234.567,89", ".", ",") -- 1234567.89 - ---``` - --- - ---@name parse_formatted_number - ---@param str string - The string to parse. - ---@param thousands string? - The thousands separator. - ---@param decimal string? - The decimal separator. - ---@return number # The parsed number. - function string.parse_formatted_number(str, thousands, decimal) end - - ---Prepends a prefix to a string if it does not already start with that prefix. - ---Uses PCRE regex pattern matching to ensure accurate prefix detection. - --- - ---@example - ---```lua - ---string.prepend("world", "hello ") -- "hello world" - ---string.prepend("hello world", "hello") -- "hello world" - ---``` - --- - ---@name prepend - ---@param str string - The string to prepend to. - ---@param prefix string - The prefix to prepend to the string. - ---@return string # The resulting string. - function string.prepend(str, prefix) end - - ---Performs pattern matching using reg_assoc with PCRE regex support. Associates - ---patterns with tokens and returns both the matched segments and their corresponding - ---token assignments. - --- - ---@example - ---```lua - ---local results, tokens = string.reg_assoc( - --- "hello world", - --- {"hello", "world"}, - --- {"greeting", "place"} - ---) - ---- results: {"hello", " ", "world"} - ---- tokens: {"greeting", -1, "place"} - ---``` - --- - ---@name reg_assoc - ---@param text string - The text to search through - ---@param patterns table - The patterns to search for - ---@param tokens table - The tokens to replace the patterns with - ---@param default_token string? - The default token for unmatched text - ---@return table,table # The results table and token list - function string.reg_assoc(text, patterns, tokens, default_token) end - - ---Replaces all occurrences of a pattern in a string with a replacement string. - ---Continues replacing until no more matches are found to handle overlapping or - ---repeated patterns. - --- - ---@example - ---```lua - ---string.replace("hello world", "o", "a") -- "hella warld" - ---string.replace("test", "t", "p") -- "pesp" - ---``` - --- - ---@name replace - ---@param str string - The string to replace the pattern in. - ---@param pattern string - The pattern to replace. - ---@param replacement string - The replacement string. - ---@return string # The resulting string. - function string.replace(str, pattern, replacement) end - - ---Removes whitespace characters from the end (right side) of a string. - ---Whitespace includes spaces, tabs, and newlines. - --- - ---@example - ---```lua - ---string.rtrim(" hello world ") -- " hello world" - ---string.rtrim("hello\t\n") -- "hello" - ---``` - --- - ---@name rtrim - ---@param str string - The string to remove whitespace from. - ---@return string # The resulting string without whitespace on the right. - function string.rtrim(str) end - - ---Splits a string into a table of strings using PCRE regex. If no delimiter - ---is provided, it defaults to ".", which will split the string into individual - ---characters. The delimiter is treated as a regex pattern. - --- - ---@example - ---```lua - ---string.split("hello world") -- {"h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"} - ---string.split("hello world", " ") -- {"hello", "world"} - ---string.split("hello.world", "\\.") -- {"hello", "world"} - ---string.split("hello world", "o") -- {"hell", " w", "rld"} - ---``` - --- - ---@name split - ---@param str string - The string to split. - ---@param delimiter string? - The regex delimiter to split the string by. - ---@return string[] # The resulting array of strings. - function string.split(str, delimiter) end - - ---Checks if a string starts with a given pattern using PCRE regex. If the pattern - ---doesn't already start with "^", it will be automatically prepended to ensure - ---matching at the start of the string. - --- - ---@example - ---```lua - ---string.starts_with("hello world", "hello") -- true - ---string.starts_with("hello world", "world") -- false - ---string.starts_with("test.lua", "^test") -- true - ---``` - --- - ---@name starts_with - ---@param str string - The string to check. - ---@param start string - The pattern to check for. - ---@return boolean # Whether the string starts with the pattern. - function string.starts_with(str, start) end - - ---Removes all line breaks from a string, including both \r and \n characters. - ---Useful for converting multi-line text into a single line. - --- - ---@example - ---```lua - ---string.strip_linebreaks("hello\nworld") -- "helloworld" - ---string.strip_linebreaks("hello\r\nworld") -- "helloworld" - ---``` - --- - ---@name strip_linebreaks - ---@param str string - The string to strip line breaks from. - ---@return string # The resulting string without line breaks. - function string.strip_linebreaks(str) end - - ---Removes whitespace from both the beginning and end of a string. - ---Whitespace includes spaces, tabs, and newlines. - --- - ---@example - ---```lua - ---string.trim(" hello world ") -- "hello world" - ---string.trim("\t\nhello\n\t") -- "hello" - ---``` - --- - ---@name trim - ---@param str string - The string to trim. - ---@return string # The trimmed string. - function string.trim(str) end - - ---Creates an iterator that walks through a string character by character or by - ---split segments if a delimiter is provided. Returns index and value pairs. - --- - ---@example - ---```lua - ---for i, part in string.walk("hello world") do - --- print(i, part) -- prints: 1,"h" 2,"e" 3,"l" 4,"l" 5,"o" 6," " 7,"w" 8,"o" 9,"r" 10,"l" 11,"d" - ---end - --- - ---for i, part in string.walk("a,b,c", ",") do - --- print(i, part) -- prints: 1,"a" 2,"b" 3,"c" - ---end - ---``` - --- - ---@name walk - ---@param input string - The string to walk through. - ---@param delimiter string? - The delimiter to split the string by. - ---@return function # The iterator function. - function string.walk(input, delimiter) end - - ---Returns the index of the first occurrence of a pattern in a string. - ---This function uses PCRE regex to find the pattern. - --- - ---@example - ---```lua - ---string.index_of("hello world", "world") -- 7 - ---string.index_of("hello world", "o") -- 4 - ---string.index_of("hello world", "x") -- nil - ---string.index_of("hello world", "[aeiou]") -- 2 - ---string.index_of("hello world", "\\s") -- 5 - ---``` - --- - ---@name index_of - ---@param str string - The string to search through. - ---@param pattern string - The pattern to search for. - ---@return number # The index of the pattern. - function string.index_of(str, pattern) end -end diff --git a/examples/source/lua-library-source/table.lua b/examples/source/lua-library-source/table.lua deleted file mode 100644 index e2606a4..0000000 --- a/examples/source/lua-library-source/table.lua +++ /dev/null @@ -1,643 +0,0 @@ ----@meta TableClass - ------------------------------------------------------------------------------- --- TableClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class TableClass - - ---Adds a second associative table to a first associative table, merging the - ---second table into the first. - --- - ---@example - ---```lua - ---table.add({ a = 1 }, { b = 2 }) - ----- { a = 1, b = 2 } - --- - ---table.add({ a = 1, b = 2 }, { b = 3, c = 4 }) - ----- { a = 1, b = 3, c = 4 } - ---``` - --- - ---@name add - ---@param table1 table - The table to add the value to. - ---@param table2 table - The table to add to the first table. - ---@return table # The first table with the second table added. - function table.add(table1, table2) end - - ---Allocates a new table with given an initial indexed table and a - ---specification for the new table. - --- - ---The specification can be: - ---* another indexed table, in which case the new table will be created with - --- the same values as the source table, but with the values in the spec table - --- applied to each corresponding value in the source table. The second table - --- must have the same number of elements as the source table. - ---* a function, in which case the function will be applied to each value in - --- the source table to produce the values in the new table. - ---* a single type, in which case all values in the new table will be of - --- that type - --- - ---@example - ---```lua - ---table.allocate({"a", "b", "c"}, "x") - ----- {a = "x", b = "x", c = "x"} - --- - ---table.allocate({"a","b","c"}, {1, 2, 3}) - ----- {a = 1, b = 2, c = 3} - --- - ---table.allocate({ "a", "b", "c" }, function(k, v) - --- return string.byte(v) - ---end) - ----- {a = 97, b = 98, c = 99} - ---``` - ---@name allocate - ---@param source table - The table to copy. - ---@param spec table - The specification for the new table. - ---@return table # The new table. - function table.allocate(source, spec) end - - ---Returns true if the table is associative, false otherwise. - --- - ---@example - ---```lua - ---table.associative({ a = 1, b = 2 }) - ----- true - --- - ---table.associative({ 1, 2, 3 }) - ----- false - ---``` - --- - ---@name associative - ---@param t table - The table to check. - ---@return boolean # True if the table is associative, false otherwise. - function table.associative(t) end - - ---Returns a table of tables, each containing a slice of the original table - ---of specified size. If there are not enough elements to fill the last - ---chunk, the last chunk will contain the remaining elements. - --- - ---@example - ---```lua - ---table.chunk({1, 2, 3, 4, 5}, 2) - ----- {{1, 2}, {3, 4}, {5}} - ---``` - --- - ---@name chunk - ---@param t table - The table to chunk. - ---@param size number - The size of each chunk. - ---@return table # A table of tables, each containing a slice of the original table. - function table.chunk(t, size) end - - ---Creates a new table by concatenating the original table with any - ---additional arrays and/or values. If the arguments contains tables, they - ---will be concatenated with the original table. Otherwise, the values will - ---be added to the end of the original table. - ---@example - ---```lua - ---table.concat({1}, 2, {3}, {{4}}) - ----- {1, 2, 3, {4}} - ---``` - --- - ---@name concat - ---@param tbl table - The first table to concatenate. - ---@param ... any - Additional tables and/or values to concatenate. - ---@return table # A new table containing the concatenated tables. - function table.concat(tbl, ...) end - - ---Drops the first n elements from an indexed table. - --- - ---@name drop - ---@param tbl table - The table to drop elements from. - ---@param n number - The number of elements to drop. - ---@return table # A new table with the first n elements removed. - function table.drop(tbl, n) end - - ---Drops the last n elements from an indexed table. - --- - ---@name drop_right - ---@param tbl table - The table to drop elements from. - ---@param n number - The number of elements to drop. - ---@return table # A new table with the last n elements removed. - function table.drop_right(tbl, n) end - - ---Returns a random element from the keys of a table, with each value - ---representing a weight. - --- - ---@example - ---```lua - ---table.element_of_weighted({ [1] = 10, [2] = 20, [3] = 70 }) - ----- 3 - ---``` - --- - ---@name element_of_weighted - ---@param list table - The table to choose an element from. - ---@return any # A random element from the table. - function table.element_of_weighted(list) end - - ---Returns a random element from an indexed table. - --- - ---@example - ---```lua - ---table.element_of({1, 2, 3}) - ----- 2 - ---``` - --- - ---@name element_of - ---@param list table - The table to choose an element from. - ---@return any # A random element from the table. - function table.element_of(list) end - - ---Fills an indexed table with a value. - --- - ---If the start index is not provided, it will fill from the beginning of the - ---table. If the stop index is not provided, it will fill to the end of the - ---table. - --- - ---@example - ---```lua - ---table.fill({1, 2, 3, 4, 5}, "x") - ----- {"x", "x", "x", "x", "x"} - --- - ---table.fill({1, 2, 3, 4, 5}, "x", 2) - ----- {1, "x", "x", 4, 5} - --- - ---table.fill({1, 2, 3, 4, 5}, "x", 2, 4) - ----- {1, "x", "x", "x", 5} - ---``` - --- - ---@name fill - ---@param tbl table - The table to fill. - ---@param value any - The value to fill the table with. - ---@param start number? - The start index to fill. - ---@param stop number? - The stop index to fill. - ---@return table # The filled table. - function table.fill(tbl, value, start, stop) end - - ---Returns the index of the first element in a table that satisfies a - ---predicate function. - --- - ---@example - ---```lua - ---table.find({1, 2, 3, 4, 5}, function(v) return v > 3 end) - ----- 4 - ---``` - --- - ---@name find - ---@param tbl table - The table to find the index of the first element in. - ---@param fn function - The predicate function to satisfy. - ---@return number|nil # The index of the first element that satisfies the predicate function, or nil if no element satisfies the predicate. - function table.find(tbl, fn) end - - - ---Returns the index of the last element in a table that satisfies a - ---predicate function. - --- - ---@example - ---```lua - ---table.find_last({1, 2, 3, 4, 5}, function(v) return v > 3 end) - ----- 4 - ---``` - --- - ---@name find_last - ---@param tbl table - The table to find the index of the last element in. - ---@param fn function - The predicate function to satisfy. - ---@return number? # The index of the last element that satisfies the predicate function, or nil if no element satisfies the predicate. - function table.find_last(tbl, fn) end - - ---Flattens a table of tables into a single table recursively. - --- - ---@example - ---```lua - ---table.flatten_deeply({1, {2, {3, {4}}, 5}}) - ----- {1, 2, 3, 4, 5} - ---``` - --- - ---@name flatten_deeply - ---@param tbl table - The table to flatten recursively. - ---@return table # A new table containing the flattened table. - function table.flatten_deeply(tbl) end - - ---Flattens a table of tables into a single table. - --- - ---@example - ---```lua - ---table.flatten({1, {2, {3, {4}}, 5}}) - ----- {1, 2, 3, 4, 5} - ---``` - --- - ---@name flatten - ---@param tbl table - The table to flatten. - ---@return table # A new table containing the flattened table. - function table.flatten(tbl) end - - ---Returns a table of the functions in a table. - --- - ---@example - ---```lua - ---table.functions({a = 1, b = 2, c = end}) - ----- {c = function()} - ---``` - --- - ---@name functions - ---@param tbl table - The table to get the functions from. - ---@param inherited boolean? - Whether to include inherited functions. - ---@return table # A table of the functions in the table. - function table.functions(tbl, inherited) end - - ---Returns true if an indexed table includes a value, false otherwise. - --- - ---@example - ---```lua - ---table.includes({1, 2, 3}, 2) - ----- true - ---``` - --- - ---@name includes - ---@param tbl table - The table to check. - ---@param value any - The value to check for. - ---@return boolean # True if the table includes the value, false otherwise. - function table.includes(tbl, value) end - - ---Returns true if a table is indexed, false otherwise. - --- - ---@example - ---```lua - ---table.indexed({1, 2, 3}) - ----- true - --- - ---table.indexed({ a = 1, b = 2 }) - ----- false - ---``` - --- - ---@name indexed - ---@param t table - The table to check. - ---@return boolean # True if the table is indexed, false otherwise. - function table.indexed(t) end - - ---Returns an indexed table with the last element removed from the original - ---indexed table. - --- - ---@example - ---```lua - ---table.initial({1, 2, 3, 4, 5}) - ----- {1, 2, 3, 4} - ---``` - --- - ---@name initial - ---@param tbl table - The table to remove the last element from. - ---@return table # A new table with the last element removed. - function table.initial(tbl) end - - ---Returns true if a table is an object, false otherwise. - --- - ---@example - ---```lua - ---local object1 = {1,2,3} - ---local object2 = {} - ---setmetatable(object2, { __index = object1 }) - --- - ---table.object(object1) - ----- false - ---table.object(object2) - ----- true - ---``` - --- - ---@name object - ---@param tbl table - The table to check. - ---@return boolean # True if the table is an object, false otherwise. - function table.object(tbl) end - - ---Returns a new table with a function applied to each element of the original - ---table, transforming each element into a new value. - --- - ---@example - ---```lua - ---table.map({1, 2, 3}, function(v) return v * 2 end) - ----- {2, 4, 6} - ---``` - --- - ---@name map - ---@param t table - The table to map over. - ---@param fn function - The function to map over the table. - ---@param ... any - Additional arguments to pass to the function. - ---@return table # A new table with the function applied to each element. - function table.map(t, fn, ...) end - - ---Appends or inserts a second indexed table into a first indexed table at - ---a specified index. - --- - ---If the index is not provided, the second table is appended to the end of - ---the first table. If the index is provided, the second table is inserted into - ---the first table at the specified index. - --- - ---@example - ---```lua - ---table.n_add({1, 2, 3}, {4, 5, 6}) - ----- {1, 2, 3, 4, 5, 6} - --- - ---table.n_add({1, 2, 3}, {4, 5, 6}, 2) - ----- { 1, 4, 5, 6, 2, 3 } - ---``` - --- - ---@name n_add - ---@param tbl1 table - The first table to add the value to. - ---@param tbl2 table - The second table to add to the first table. - ---@param index number? - The index to add the second table to. - ---@return table # The first table with the second table added. - function table.n_add(tbl1, tbl2, index) end - - ---Casts a value to an indexed table if it is not already one. - --- - ---@example - ---```lua - ---table.n_cast(1) - ----- {1} - --- - ---table.n_cast({1, 2, 3}) - ----- {1, 2, 3} - ---``` - --- - ---@name n_cast - ---@param ... any - The value to cast. - ---@return table # A new indexed table with the value or the value itself if it is already indexed. - function table.n_cast(...) end - - ---Returns a new table with the distinct elements of an indexed table. - --- - ---@example - ---```lua - ---table.n_distinct({1, 2, 3, 2, 1}) - ----- {1, 2, 3} - ---``` - --- - ---@name n_distinct - ---@param t table - The table to get the distinct elements from. - ---@return table # A new table with the distinct elements. - function table.n_distinct(t) end - - ---Returns true or false if all elements in an indexed table are of the same - ---type. If a type is not provided, it will check if all elements are of the - ---same type as the first element in the table. - --- - ---@example - ---```lua - ---table.n_uniform({1, 2, 3}, "number") - ----- true - ---``` - --- - ---@name n_uniform - ---@param t table - The table to check. - ---@param typ string? - The type to check for. - ---@return boolean # True if all elements are of the same type, false otherwise. - function table.n_uniform(t, typ) end - - ---Creates a new table with weak references. Valid options are "v" for - ---weak values, "k" for weak keys, and "kv" or "vk" for weak keys and - ---values. - --- - ---@example - ---```lua - ---table.new_weak("v") - ----- A table with weak value references - ---``` - --- - ---@name new_weak - ---@param opt string? - The reference type. - ---@return table # A new table with weak references. - function table.new_weak(opt) end - - ---Removes and returns the last element of an indexed table. - --- - ---@example - ---```lua - ---local sample = {1, 2, 3} - ---table.pop(sample) - ----- 3 - ----- sample = {1, 2} - ---``` - --- - ---@name pop - ---@param t table - The table to remove the last element from. - ---@return any # The last element of the table. - function table.pop(t) end - - ---Returns a table of the properties of a table. This function only returns - ---the properties of the table itself, not the properties of any metatables, - ---and no functions. - --- - ---If the inherited parameter is true, it will include the properties of any - ---metatables. - --- - ---@example - ---```lua - ---table.properties({a = 1, b = 2}) - ----- {a = 1, b = 2} - ---``` - --- - ---@name properties - ---@param tbl table - The table to get the properties from. - ---@param inherited boolean? - Whether to include inherited properties. - ---@return table # A table of the properties of the table. - function table.properties(tbl, inherited) end - - ---Adds a value to the end of an indexed table, returning the new length of - ---the table. - --- - ---@example - ---```lua - ---table.push({1, 2, 3}, 4) - ----- 4 - ---``` - --- - ---@name push - ---@param t table - The table to append the value to. - ---@param v any - The value to append to the table. - ---@return number # The new length of the table. - function table.push(t, v) end - - ---Reduces an indexed table to a single value using a reducer function. - --- - ---@example - ---```lua - ---table.reduce({1, 2, 3}, function(acc, v) return acc + v end, 0) - ----- 6 - ---``` - --- - ---@name reduce - ---@param t table - The table to reduce. - ---@param fn function - The reducer function. - ---@param initial any? - The initial value. - ---@return any # The reduced value. - function table.reduce(t, fn, initial) end - - ---Removes and returns a slice of a table from the start index to the stop - ---index. If the stop index is not provided, it will only remove the element - ---at the start index. A second return value is also provided containing the - ---removed slice. - --- - ---@example - ---```lua - ---table.remove({1, 2, 3, 4, 5}, 2, 4) - ----- {1, 5} - ----- {2, 3, 4} - --- - ---table.remove({1, 2, 3, 4, 5}, 2) - ----- {1, 3, 4, 5} - ----- {2} - ---``` - --- - ---@name remove - ---@param t table - The table to remove the slice from. - ---@param start number - The start index of the slice. - ---@param stop number? - The stop index of the slice. - ---@return table # A new table containing the removed slice. - function table.remove(t, start, stop) end - - ---Reverses an indexed table. - --- - ---@example - ---```lua - ---table.reverse({1, 2, 3}) - ----- {3, 2, 1} - ---``` - --- - ---@name reverse - ---@param tbl table - The table to reverse. - ---@return table # A new reversed table. - function table.reverse(tbl) end - - ---Removes and returns the first element of an indexed table. - --- - ---@example - ---```lua - ---table.shift({1, 2, 3}) - ----- 1 - ---``` - --- - ---@name shift - ---@param t table - The table to remove the first element from. - ---@return any # The first element of the table. - function table.shift(t) end - - ---Returns a slice of an indexed table. - --- - ---@example - ---```lua - ---table.slice({1, 2, 3, 4, 5}, 2, 4) - ----- {2, 3, 4} - ---``` - --- - ---@name slice - ---@param t table - The table to slice. - ---@param start number? - The start index. - ---@param stop number? - The stop index. - ---@return table # A new table with the slice. - function table.slice(t, start, stop) end - - ---Returns a new table with the unique elements of an indexed table. - --- - ---@example - ---```lua - ---table.uniq({1, 2, 3, 2, 1}) - ----- {1, 2, 3} - ---``` - --- - ---@name uniq - ---@param tbl table - The table to get the unique elements from. - ---@return table # A new table with the unique elements. - function table.uniq(tbl) end - - ---Adds a value to the beginning of an indexed table. - --- - ---@example - ---```lua - ---table.unshift({1, 2, 3}, 4) - ----- 4 - ---``` - --- - ---@name unshift - ---@param t table - The table to add the value to. - ---@param v any - The value to add to the table. - ---@return number # The new length of the table. - function table.unshift(t, v) end - - ---Unzips a table of tables into a table of tables. The index of the new - ---sub-tables will be the same as the index of the sub-tables in the original - ---table. - --- - ---@example - ---```lua - ---local combined = {{"John", 25}, {"Jane", 30}, {"Jim", 35}} - ---local names, ages = unpack(table.unzip(combined)) - ----- names = {"John", "Jane", "Jim"} - ----- ages = {25, 30, 35} - ---``` - --- - ---@name unzip - ---@param tbl table - The table to unzip. - ---@return table # A table of tables. - function table.unzip(tbl) end - - ---Returns an indexed table with the values of an associative table. - --- - ---@example - ---```lua - ---table.values({a = 1, b = 2}) - ----- {1, 2} - ---``` - --- - ---@name values - ---@param t table - The table to get the values from. - ---@return table # An indexed table with the values. - function table.values(t) end - - ---Returns an iterator function that can be used to walk over an indexed - ---table. - --- - ---@example - ---```lua - ---table.walk({1, 2, 3}, function(v) print(v) end) - ----- 1 - ----- 2 - ----- 3 - ---``` - --- - ---@name walk - ---@param tbl table - The table to walk over. - ---@return function # An iterator function. - function table.walk(tbl) end - - ---Returns a new table with weak references. Valid options are "v" for - ---weak values, "k" for weak keys, and "kv" or "vk" for weak keys and - ---values. - --- - ---@example - ---```lua - ---table.weak("v") - ----- A table with weak value references - ---``` - --- - ---@name weak - ---@param opt string? - The reference type. - ---@return table # A new table with weak references. - function table.weak(opt) end - - ---Zips multiple tables together. The tables must all be of the same length. - --- - ------ @example - ---```lua - ---local names = {"John", "Jane", "Jim"} - ---local ages = {25, 30, 35} - --- - ---table.zip(names, ages) - ----- {{"John", 25}, {"Jane", 30}, {"Jim", 35}} - ---``` - --- - ---@name zip - ---@param ... table - The tables to zip together. - ---@return table # A new table containing the zipped tables. - function table.zip(...) end - -end diff --git a/examples/source/lua/fd.lua b/examples/source/lua/fd.lua deleted file mode 100644 index f1bcbe6..0000000 --- a/examples/source/lua/fd.lua +++ /dev/null @@ -1,251 +0,0 @@ ----@meta FdClass - ------------------------------------------------------------------------------- --- FdClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class FdClass - - --- Splits a path into a directory and file. - --- - --- If the directory is required and does not exist, nil is returned. - --- - ---@example - ---```lua - ---fd.dir_file("path/to/file.txt") - ----- "path/to", "file.txt" - ---``` - ---@name dir_file - ---@param path string - The path to split. - ---@param dir_required boolean? - Whether the directory is required (Optional. Default is false). - ---@return string?,string? # A table with the directory and file, or nil if the path is invalid. - function fd.dir_file(path, dir_required) end - - --- Gets the root of a path, as well as the directory and file. - --- - ---@example - ---```lua - ---fd.root_dir_file("c:\\test\\moo") - ----- "c:", "test", "moo" - ---``` - --- - ---@name root_dir_file - ---@param path string - The path to get the root of. - ---@return string?,string?,string? # The root, directory, and file, or nil if the path is invalid. - function fd.root_dir_file(path) end - - --- Checks if a file exists. - --- - ---@example - ---```lua - ---fd.file_exists("path/to/file/that/does/exist.txt") - ----- true - --- - ---fd.file_exists("file/that/definitely/doesnt/exist.mp3") - ----- false - ---``` - ---@name file_exists - ---@param path string - The path to check. - ---@return boolean # Whether the file exists. - function fd.file_exists(path) end - - --- Reads a file. - --- - ---@example - ---```lua - ---fd.read_file("path/to/file.txt") - --- -- "contents of file" - ---``` - ---@name read_file - ---@param path string - The path to the file. - ---@param binary boolean? - Whether the file is binary (default false). - ---@return string|nil,string|nil,number|nil # The contents of the file, or nil, the error message, and the error code. - function fd.read_file(path, binary) end - - --- Writes to a file. - --- - ---@example - ---```lua - ---fd.write_file("path/to/file.txt", "contents of file") - --- -- "path/to/file.txt", "contents of file", nil - ---``` - ---@name write_file - ---@param path string - The path to the file. - ---@param data string - The data to write to the file. - ---@param overwrite boolean? - Whether to overwrite the file (default false). - ---@param binary boolean? - Whether the file is binary (default false). - ---@return string|table # The path to the file or nil, a table with the error and code, or the attributes of the file. - function fd.write_file(path, data, overwrite, binary) end - - --- Fixes a path to use forward slashes. - --- - ---@example - ---```lua - ---fd.fix_path("path\\to\\file.txt") - ----- "path/to/file.txt" - --- - ---fd.fix_path("c:\\test\\moo") - ----- "c:/test/moo" - ---``` - ---@name fix_path - ---@param path string - The path to fix. - ---@return string, number # The fixed path and the number of replacements made. - function fd.fix_path(path) end - - --- Determines the path separator of a path. - --- - ---@example - ---```lua - ---fd.determine_path_separator("path\\to\\file.txt") - ----- "\\" - ---``` - ---@name determine_path_separator - ---@param path string - The path to determine the separator of. - ---@return string # The path separator. - function fd.determine_path_separator(path) end - - --- Checks if a path is valid. - --- - ---@example - ---```lua - ---fd.valid_path_string("path/to/file.txt") - ----- true - ---``` - ---@name valid_path_string - ---@param path string - The path to check. - ---@return boolean # Whether the path is valid. - function fd.valid_path_string(path) end - - --- Checks if a table of paths are valid. - --- - ---@example - ---```lua - ---fd.valid_path_table({"path/to/file.txt", "path/to/directory"}) - ----- true - ---``` - ---@name valid_path_table - ---@param paths table - The table of paths to check. - ---@return boolean # Whether the table of paths is valid. - function fd.valid_path_table(paths) end - - --- Checks if a path is valid. - --- - ---@example - ---```lua - ---fd.valid_path_table_or_string({"path/to/file.txt", "path/to/directory"}) - ----- true - ---``` - ---@name valid_path_table_or_string - ---@param path string|table - The path to check. - ---@return boolean # Whether the path is valid. - function fd.valid_path_table_or_string(path) end - - --- Checks if a path is valid. - --- - ---@example - ---```lua - ---fd.valid_path("path/to/file.txt") - ----- true - ---``` - ---@name valid_path - ---@param path string - The path to check. - ---@return boolean # Whether the path is valid. - function fd.valid_path(path) end - - --- Checks if a table of paths are valid. - --- - ---@example - ---```lua - ---fd.valid_paths({"path/to/file.txt", "path/to/directory"}) - ----- true - ---``` - ---@name valid_paths - ---@param paths table - The table of paths to check. - ---@return boolean # Whether the table of paths is valid. - function fd.valid_paths(paths) end - - --- Ensures that a directory exists. - ---@param path string - The path to the directory. - ---@return table|nil, string|nil, number|nil # A table of created directories, the error message, and the error code. - ---@example - ---```lua - ---fd.assure_dir("path/to/directory") - ---``` - function fd.assure_dir(path) end - - - --- Determines the root of a path. - --- - ---@example - ---```lua - ---fd.determine_root("c:\\test\\moo") - --- -- "c:" - ---``` - ---@name determine_root - ---@param path string - The path to determine the root of. - ---@return string? # The root of the path, or nil if the path is invalid. - function fd.determine_root(path) end - - - --- Removes a file. - --- - ---@example - ---```lua - ---fd.rmfile("path/to/file.txt") - --- -- true - ---``` - ---@name rmfile - ---@param path string - The path to the file. - ---@return boolean?, string? # Whether the file was removed, or nil and the error message. - function fd.rmfile(path) end - - --- Removes a directory. - --- - ---@example - ---```lua - ---fd.rmdir("path/to/directory") - --- -- true - ---``` - ---@name rmdir - ---@param path string - The path to the directory. - ---@return boolean?, string? # Whether the directory was removed, or nil and the error message. - function fd.rmdir(path) end - - --- Checks if a directory is empty. - --- - ---@example - ---```lua - ---fd.dir_empty("/path/to/directory") - ----- true - ---``` - ---@name dir_empty - ---@param path string - The path to the directory. - ---@return boolean # Whether the directory is empty. - function fd.dir_empty(path) end - - --- Gets the files in a directory. - --- - ---@example - ---```lua - ---fd.get_dir("/path/to/directory") - --- -- {"file1", "file2", "file3"} - ---``` - ---@name get_dir - ---@param path string - The path to the directory. - ---@param include_dots boolean? - Whether to include the "." and ".." directories (default false). - ---@return table # A table of files in the directory. - function fd.get_dir(path, include_dots) end - - --- Creates a temporary directory. - --- - ---@return string?, string?, number? # The path to the temporary directory, the error message, and the error code. - ---@example - ---```lua - ---fd.temp_dir() - --- -- "path/to/temporary/directory", nil, nil - ---``` - ---@name temp_dir - function fd.temp_dir() end -end diff --git a/examples/source/lua/func.lua b/examples/source/lua/func.lua deleted file mode 100644 index a60b3b2..0000000 --- a/examples/source/lua/func.lua +++ /dev/null @@ -1,52 +0,0 @@ -local FuncClass = Glu.glass.register({ - name = "func", - class_name = "FuncClass", - dependencies = {}, - setup = function(___, self) - function self.delay(func, delay, ...) - ___.v.type(func, "function", 1, false) - ___.v.type(delay, "number", 2, false) - - ---@diagnostic disable-next-line: return-type-mismatch - return tempTimer(delay, function(...) - func(...) - end) - end - - function self.wrap(func, wrapper) - --- ```lua - --- local becho = function.wrap(cecho, function(func, text) - --- func("{text}") - --- end) - --- - --- becho("Hello, world!") - --- -- Hello, world! - --- ``` - ___.v.type(func, "function", 1, false) - ___.v.type(wrapper, "function", 2, false) - - return function(...) - return wrapper(func, ...) - end - end - - function self.repeater(func, interval, times, ...) - ___.v.type(func, "function", 1, false) - ___.v.type(interval, "number", 2, true) - ___.v.type(times, "number", 3, true) - - interval = interval or 1 - times = times or 1 - - local count = 0 - local function _repeat(...) - if count < times then - func(...) - count = count + 1 - tempTimer(interval, _repeat, ...) - end - end - _repeat(...) - end - end -}) diff --git a/examples/source/lua/glass.lua b/examples/source/lua/glass.lua deleted file mode 100644 index cebb3f7..0000000 --- a/examples/source/lua/glass.lua +++ /dev/null @@ -1,28 +0,0 @@ ----@meta Glass - ------------------------------------------------------------------------------- --- Glass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class Glass - - ---Register a class with the Glu framework. - --- - ---The following options are available: - --- - ---* `class_name` `string` - The name of the class, usually in the form of `NameClass`. - ---* `name` `string` - The name of the class, usually in the form of `name`. - ---* `inherit_from` `string?` - The class to inherit from, in the form of the class's `name`. - ---* `dependencies` `string[]` - The dependencies of the class, in the form of the class's `name` . - ---* `inherit` `table` - The functions to inherit, in the form of `function_name = function(self, ...) end`. - ---* `setup` `function` - The setup function, in the form of `function(self, ...) end`. - ---* `valid` `function` - The valid function, in the form of `function(self, ...) end`. - --- - ---@name register - ---@param class_opts table - The class options. - ---@return Glass # The class. - function Glass.register(class_opts) end - -end diff --git a/examples/source/lua/glass_loader.lua b/examples/source/lua/glass_loader.lua deleted file mode 100644 index ddcb413..0000000 --- a/examples/source/lua/glass_loader.lua +++ /dev/null @@ -1,31 +0,0 @@ ----@meta GlassLoaderClass - ------------------------------------------------------------------------------- --- GlassLoaderClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class GlassLoaderClass - - --- Loads a glass script from a path or url. - ---@example - ---```lua - ---glass_loader.load_glass({ - --- path = "path/to/glass.lua", - --- cb = function(result) - --- print(result) - --- end, - --- execute = true - ---}) - ---``` - --- - ---@name load_glass - ---@param opts table - The options table. - ---@param opts.path string - The path or url to the glass script. - ---@param opts.cb function - The callback function. - ---@param opts.execute boolean? - Whether to execute the glass script. - ---@return any # The result of the glass script. - function glass_loader.load_glass(opts) end - -end diff --git a/examples/source/lua/glu.lua b/examples/source/lua/glu.lua deleted file mode 100644 index 8ef1aaa..0000000 --- a/examples/source/lua/glu.lua +++ /dev/null @@ -1,90 +0,0 @@ ----@meta Glu - ------------------------------------------------------------------------------- --- Glu ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class Glu - - ---Instantiate a new Glu instance. Can be invoked by its class name or - ---by the `new` function. - --- - ---@example - ---```lua - ---local glu = Glu.new("MyPackage", "MyModule") - ---local glu = Glu("MyPackage", "MyModule") - ---``` - --- - ---@name new - ---@param package_name string - The name of the package to which this module belongs. - ---@param module_dir_name string? - The directory name inside the package directory where the modules are located. - ---@return Glu # A new Glu instance. - function Glu.new(package_name, module_dir_name) end - - ---Generate a unique identifier, producing a version 4 UUID. - --- - ---@name id - ---@return string # A unique identifier. - ---@example - ---```lua - ---local id = Glu.id() - ---``` - ---@name id - function Glu.id() end - - ---Get all glasses. - --- - ---@name get_glasses - ---@return Glass[] # A table of glasses. - ---@example - ---```lua - ---local glasses = Glu.get_glasses() - ---``` - --- - function Glu.get_glasses() end - - ---Get all glass names. - --- - ---@name get_glass_names - ---@return string[] # A table of glass names. - ---@example - ---```lua - ---local glass_names = Glu.get_glass_names() - ---``` - --- - function Glu.get_glass_names() end - - ---Get a glass by name. - --- - ---@name get_glass - ---@param glass_name string - The name of the glass to retrieve. - ---@return Glass? # The glass, or nil if it does not exist. - ---@example - ---```lua - ---local glass = Glu.get_glass("MyGlass") - ---``` - --- - function Glu.get_glass(glass_name) end - - ---Check if a glass exists. - --- - ---@name has_glass - ---@param glass_name string - The name of the glass to check for. - ---@return boolean # True if the glass exists, false otherwise. - ---@example - ---```lua - ---local exists = Glu.has_glass("MyGlass") - ---``` - --- - function Glu.has_glass(glass_name) end - - ---Get the last traceback line. Used for validation functions, or any - ---time you need to get the last line of a traceback. Also available - ---via the `v` table from the anchor. - --- - ---@name get_last_traceback_line - ---@return string # The last traceback line. - function Glu.get_last_traceback_line() end -end diff --git a/examples/source/lua/lua.editorconfig b/examples/source/lua/lua.editorconfig deleted file mode 100644 index 02c7bbc..0000000 --- a/examples/source/lua/lua.editorconfig +++ /dev/null @@ -1,171 +0,0 @@ - -# see https://github.com/CppCXY/EmmyLuaCodeStyle -[*.luax] -# [basic] - -# optional space/tab -indent_style = space -# if indent_style is space, this is valid -indent_size = 2 -# if indent_style is tab, this is valid -tab_width = 2 -# none/single/double -quote_style = none - -continuation_indent = 4 -## extend option -# continuation_indent.before_block = 4 -# continuation_indent.in_expr = 4 -# continuation_indent.in_table = 4 - -# this mean utf8 length , if this is 'unset' then the line width is no longer checked -# this option decides when to chopdown the code -max_line_length = 120 - -# optional crlf/lf/cr/auto, if it is 'auto', in windows it is crlf other platforms are lf -# in neovim the value 'auto' is not a valid option, please use 'unset' -end_of_line = auto - -# none/ comma / semicolon / only_kv_colon -table_separator_style = none - -#optional keep/never/always/smart -trailing_table_separator = keep - -# keep/remove/remove_table_only/remove_string_only -call_arg_parentheses = keep - -detect_end_of_line = false - -# this will check text end with new line -insert_final_newline = true - -# [space] -space_around_table_field_list = true - -space_before_attribute = true - -space_before_function_open_parenthesis = false - -space_before_function_call_open_parenthesis = false - -space_before_closure_open_parenthesis = true - -# optional always/only_string/only_table/none -# or true/false -space_before_function_call_single_arg = always -## extend option -## always/keep/none -# space_before_function_call_single_arg.table = always -## always/keep/none -# space_before_function_call_single_arg.string = always - -space_before_open_square_bracket = false - -space_inside_function_call_parentheses = false - -space_inside_function_param_list_parentheses = false - -space_inside_square_brackets = false - -# like t[#t+1] = 1 -space_around_table_append_operator = false - -ignore_spaces_inside_function_call = false - -# detail number or 'keep' -space_before_inline_comment = 1 - -# convert '---' to '--- ' or '--' to '-- ' -space_after_comment_dash = false - -# [operator space] -space_around_math_operator = true -# space_around_math_operator.exponent = false - -space_after_comma = true - -space_after_comma_in_for_statement = true - -# true/false or none/always/no_space_asym -space_around_concat_operator = true - -space_around_logical_operator = true - -# true/false or none/always/no_space_asym -space_around_assign_operator = true - -# [align] - -align_call_args = false - -align_function_params = true - -# true/false or always -align_continuous_assign_statement = true - -align_continuous_rect_table_field = true - -align_continuous_line_space = 2 - -align_if_branch = false - -# option none / always / contain_curly/ -align_array_table = true - -align_continuous_similar_call_args = false - -align_continuous_inline_comment = true -# option none / always / only_call_stmt -align_chain_expr = none - -# [indent] - -never_indent_before_if_condition = false - -never_indent_comment_on_if_branch = false - -keep_indents_on_empty_lines = false - -allow_non_indented_comments = false -# [line space] - -# The following configuration supports four expressions -# keep -# fixed(n) -# min(n) -# max(n) -# for eg. min(2) - -line_space_after_if_statement = keep - -line_space_after_do_statement = keep - -line_space_after_while_statement = keep - -line_space_after_repeat_statement = keep - -line_space_after_for_statement = keep - -line_space_after_local_or_assign_statement = keep - -line_space_after_function_statement = fixed(2) - -line_space_after_expression_statement = keep - -line_space_after_comment = keep - -line_space_around_block = fixed(1) -# [line break] -break_all_list_when_line_exceed = false - -auto_collapse_lines = false - -break_before_braces = false - -# [preference] -ignore_space_after_colon = false - -remove_call_expression_list_finish_comma = false -# keep / always / same_line / replace_with_newline / never -end_statement_with_semicolon = keep diff --git a/examples/source/lua/number.lua b/examples/source/lua/number.lua deleted file mode 100644 index 43e1a1b..0000000 --- a/examples/source/lua/number.lua +++ /dev/null @@ -1,179 +0,0 @@ ----@meta NumberClass ------------------------------------------------------------------------------- --- NumberClass ------------------------------------------------------------------------------- -if false then -- ensure that functions do not get defined - - ---@class NumberClass - - local number - - ---Calculates the average of a list of numbers. The input can be a single - ---table of numbers or multiple numbers as individual arguments. - --- - ---@param ... number|number[] - The numbers to average. - ---@return number # The average of the numbers. - function number.average(...) end - - ---Clamps a number between a minimum and maximum value. - --- - ---@param num number - The number to clamp. - ---@param min number - The minimum value. - ---@param max number - The maximum value. - ---@return number # The clamped number. - function number.clamp(num, min, max) end - - ---Constrains a number to a certain precision. - --- - ---@param num number - The number to constrain. - ---@param precision number - The precision (e.g., 0.1, 0.01, etc.). - ---@return number # The constrained number. - function number.constrain(num, precision) end - - ---Checks if two numbers are approximately equal, given a percentage tolerance. - --- - ---@param a number - The first number. - ---@param b number - The second number. - ---@param percent_tolerance number - The percentage tolerance. - ---@return boolean # Whether the numbers are approximately equal. - function number.is_approximate(a, b, percent_tolerance) end - - ---Checks if a number is between a minimum and maximum value. - --- - ---@param num number - The number to check. - ---@param min number - The minimum value. - ---@param max number - The maximum value. - ---@return boolean # Whether the number is between the minimum and maximum values. - function number.is_between(num, min, max) end - - ---Linearly interpolates between two values, easing in at the beginning. - --- - ---@param start number - The starting value. - ---@param end_val number - The ending value. - ---@param t number - The interpolation factor. - ---@return number # The interpolated value. - function number.lerp_ease_in(start, end_val, t) end - - ---Linearly interpolates between two values, easing out at the end. - --- - ---@param start number - The starting value. - ---@param end_val number - The ending value. - ---@param t number - The interpolation factor. - ---@return number # The interpolated value. - function number.lerp_ease_out(start, end_val, t) end - - ---Linearly interpolates between two values, smoothly easing in and out. - --- - ---@param start number - The starting value. - ---@param end_val number - The ending value. - ---@param t number - The interpolation factor. - ---@return number # The interpolated value. - function number.lerp_smooth(start, end_val, t) end - - ---Linearly interpolates between two values, smoothly easing in and out. - --- - ---@param start number - The starting value. - ---@param end_val number - The ending value. - ---@param t number - The interpolation factor. - ---@return number # The interpolated value. - function number.lerp_smoother(start, end_val, t) end - - ---Linearly interpolates between two values. - --- - ---@param a number - The starting value. - ---@param b number - The ending value. - ---@param t number - The interpolation factor. - ---@return number # The interpolated value. - function number.lerp(a, b, t) end - - ---Maps a value from one range to another. The input value is scaled to the - ---output range. - --- - ---@param value number - The value to map. - ---@param in_min number - The minimum value of the input range. - ---@param in_max number - The maximum value of the input range. - ---@param out_min number - The minimum value of the output range. - ---@param out_max number - The maximum value of the output range. - ---@return number # The mapped value. - function number.map(value, in_min, in_max, out_min, out_max) end - - ---Returns the maximum value from a list of numbers. The input can be a single - ---table of numbers or multiple numbers as individual arguments. - --- - ---@param ... number|number[] - The numbers to compare. - ---@return number # The maximum value. - function number.max(...) end - - ---Returns the minimum value from a list of numbers. The input can be a single - ---table of numbers or multiple numbers as individual arguments. - --- - ---@param ... number|number[] - The numbers to compare. - ---@return number # The minimum value. - function number.min(...) end - - ---Normalizes a number to a range between 0 and 1. - --- - ---@param num number - The number to normalize. - ---@param min number - The minimum value of the range. - ---@param max number - The maximum value of the range. - ---@return number # The normalized number. - function number.normalize(num, min, max) end - - ---Calculates the percentage of the first value relative to the second value. - --- - ---@example - ---```lua - ---number.percent_of(5, 20) - ----- 5 - ---``` - ---@param numerator number - The numerator of the percentage. - ---@param denominator number - The denominator of the percentage. - ---@param round_digits number? - The number of digits to round the result to. - ---@return number # The percentage of the numerator relative to the denominator. - function number.percent_of(numerator, denominator, round_digits) end - - ---Returns the value of a percentage relative to a total. - --- - ---@example - ---```lua - ---number.percent(5, 20) - ----- 1 - ---``` - ---@param percent number - The percentage - ---@param total number - The total value. - ---@param round_digits number? - The number of digits to round the result to. - ---@return number # The value of the percentage relative to the total. - function number.percent(percent, total, round_digits) end - - ---Checks if a number is positive. - --- - ---@param num number - The number to check. - ---@return boolean # Whether the number is positive. - function number.positive(num) end - - ---Returns a random number between a minimum and maximum value. - --- - ---@example - ---```lua - ---number.random_clamp(1, 10) - ----- 5 - ---``` - ---@param min number - The minimum value. - ---@param max number - The maximum value. - ---@return number # A random number between the minimum and maximum values. - function number.random_clamp(min, max) end - - ---Rounds a number to a certain precision. - --- - ---@param num number - The number to round. - ---@param digits number? - The number of digits to round to. - ---@return number # The rounded number. - function number.round(num, digits) end - - ---Sums a list of numbers. The input can be a single table of numbers or - ---multiple numbers as individual arguments. - --- - ---@param ... number|number[] - The numbers to sum. - ---@return number # The sum of the numbers. - function number.sum(...) end -end diff --git a/examples/source/lua/preferences.lua b/examples/source/lua/preferences.lua deleted file mode 100644 index 534ec7d..0000000 --- a/examples/source/lua/preferences.lua +++ /dev/null @@ -1,42 +0,0 @@ ----@meta PreferencesClass - ------------------------------------------------------------------------------- --- PreferencesClass ------------------------------------------------------------------------------- - -if false then -- ensure that functions do not get defined - - ---@class PreferencesClass - - ---Loads preferences from a file. If a package name is provided, it will be - ---used to construct the path. Otherwise, the file will be loaded from the - ---profile directory. - --- - ---@example - ---```lua - ---preferences.load("my_package", "settings", { default_value = 1 }) - ---``` - --- - ---@name load - ---@param pkg string? - The package name. (Optional. Default is nil.) - ---@param file string - The file name. - ---@param defaults table - The default values. - ---@return table # The loaded preferences. - function preferences.load(pkg, file, defaults) end - - ---Saves preferences to a file. If a package name is provided, it will be - ---used to construct the path. Otherwise, the file will be saved to the - ---profile directory. - --- - ---@example - ---```lua - ---preferences.save("my_package", "settings", { default_value = 1 }) - --- ``` - --- - ---@name save - ---@param pkg string? - The package name. (Optional. Default is nil.) - ---@param file string - The file name. - ---@param prefs table - The preferences to save. - function preferences.save(pkg, file, prefs) end - -end diff --git a/examples/source/lua/string.lua b/examples/source/lua/string.lua deleted file mode 100644 index 8bb07e3..0000000 --- a/examples/source/lua/string.lua +++ /dev/null @@ -1,535 +0,0 @@ -local StringClass = Glu.glass.register({ - name = "string", - class_name = "StringClass", - dependencies = { "table" }, - setup = function(___, self) - --- Capitalizes the first character of a string. - --- - --- @param str string - The string to capitalize. - --- @return string - The capitalized string. - --- @example - --- ```lua - --- string.capitalize("hello") - --- -- "Hello" - --- ``` - function self.capitalize(str) - ___.v.type(str, "string", 1, false) - assert(str ~= "", "Expected a non-empty string") - - local result = str:gsub("^%l", string.upper) - return result or str - end - - --- Trims whitespace from the beginning and end of a string. - --- - --- @param str string - The string to trim. - --- @return string - The trimmed string. - --- @example - --- ```lua - --- string.trim(" hello ") - --- -- "hello" - --- ``` - function self.trim(str) - ___.v.type(str, "string", 1, false) - return str:match("^%s*(.-)%s*$") - end - - --- Trims whitespace from the left side of a string. - --- - --- @param str string - The string to trim. - --- @return string - The trimmed string. - --- @example - --- ```lua - --- string.ltrim(" hello ") - --- -- "hello " - --- ``` - function self.ltrim(str) - ___.v.type(str, "string", 1, false) - return str:match("^%s*(.-)$") - end - - --- Trims whitespace from the right side of a string. - --- - --- @param str string - The string to trim. - --- @return string - The trimmed string. - --- @example - --- ```lua - --- string.rtrim(" hello ") - --- -- " hello" - --- ``` - function self.rtrim(str) - ___.v.type(str, "string", 1, false) - return str:match("^.-%s*$") - end - - --- Strips line breaks from a string. - --- - --- @param str string - The string to strip line breaks from. - --- @return string - The string with line breaks removed. - --- @example - --- ```lua - --- string.strip_linebreaks("hello\nworld") - --- -- "helloworld" - --- ``` - function self.strip_linebreaks(str) - ___.v.type(str, "string", 1, false) - local result = str:gsub("[\r\n]", "") - return result or str - end - - --- Replaces all occurrences of a pattern in a string. - --- - --- @param str string - The string to replace occurrences in. - --- @param pattern string - The pattern to replace. - --- @param replacement string - The replacement string. - --- @return string - The string with occurrences replaced. - --- @example - --- ```lua - --- string.replace("hello world", "o", "a") - --- -- "hella warld" - --- ``` - function self.replace(str, pattern, replacement) - ___.v.type(str, "string", 1, false) - ___.v.type(pattern, "string", 2, false) - ___.v.type(replacement, "string", 3, false) - - while string.find(str, pattern) do - str = string.gsub(str, pattern, replacement) or str - end - - return str - end - - --- Splits a string into a table of strings using PCRE regex. If no - --- delimiter is provided, it defaults to ".", which will split the string - --- into individual characters. - --- - --- @param str string - The string to split. - --- @param delimiter string - The regex delimiter to split the string by. - --- @return table - The split string. - --- @example - --- ```lua - --- string.split("hello world") - --- -- {"h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"} - --- - --- string.split("hello world", " ") - --- -- {"hello", "world"} - --- - --- string.split("hello.world", "\\.") - --- -- {"hello", "world"} - --- - --- string.split("hello world", "o") - --- -- {"hell", " w", "rld"} - --- ``` - function self.split(str, delimiter) - ___.v.type(str, "string", 1, false) - ___.v.type(delimiter, "string", 2, true) - - local t = {} - delimiter = delimiter or "." - - for part in str:gmatch("[^" .. delimiter .. "]+") do - table.insert(t, part) - end - - return t - end - - --- Walks over a string or table, splitting the string with a PCRE regex - --- delimiter and returning an iterator. - --- - --- @param input string - The string to walk over. - --- @param delimiter string - The regex delimiter to split the string by. - --- @return function - The iterator function. - --- @example - --- ```lua - --- for i, part in string.walk("hello world") do - --- print(i, part) -- prints 1=h, 2=e, 3=l, 4=l, 5=o, 6= , 7=w, 8=o, 9=r, 10=l, 11=d - --- end - --- ``` - function self.walk(input, delimiter) - ___.v.type(input, "string", 1, false) - ___.v.type(delimiter, "string", 2, true) - - local data - if type(input) == "string" then - data = self.split(input, delimiter) - else - data = input - end - - return ___.table.walk(data) - end - - --- Formats a number with thousands separators and decimal places. - --- If not specified, defaults to "," for thousands and "." for decimal. - --- - --- @example - --- ```lua - --- string.format_number(1234567.89) - --- -- "1,234,567.89" - --- ``` - --- @param number string|number - The number to format (number or string) - --- @param thousands string - The thousands separator (optional, defaults to ",") - --- @param decimal string - The decimal separator (optional, defaults to ".") - --- @return string - The formatted number - function self.format_number(number, thousands, decimal) - ___.v.type(number, { "number|string" }, 1, false) - ___.v.type(thousands, "string", 2, true) - ___.v.type(decimal, "string", 3, true) - - -- Set defaults - thousands = thousands or "," - decimal = decimal or "." - - number = tonumber(number) or 0 - local is_negative = not ___.number.positive(number) - number = math.abs(number) - - -- Convert to string if needed - local numStr = tostring(number) - - -- Split integer and decimal parts - local intPart, decPart = numStr:match("([^%.]*)%.?(.*)") - - -- Add thousands separators to integer part - local formatted = "" - local length = #intPart - - for i = 1, length do - if i > 1 and (length - i + 1) % 3 == 0 then - formatted = thousands .. formatted - end - formatted = intPart:sub(length - i + 1, length - i + 1) .. formatted - end - - -- Add decimal part if it exists - if decPart and decPart ~= "" then - formatted = formatted .. decimal .. decPart - end - - -- Restore negative sign if needed - if is_negative then formatted = "-" .. formatted end - - return formatted - end - - --- Parses a formatted number string back to a number. - --- - --- @param str string - The formatted number string. - --- @param thousands string - The thousands separator (optional, defaults to ","). - --- @param decimal string - The decimal separator (optional, defaults to "."). - --- @return number - The parsed number. - --- @example - --- ```lua - --- string.parse_formatted_number("1,234,567.89") - --- -- 1234567.89 - --- ``` - function self.parse_formatted_number(str, thousands, decimal) - ___.v.type(str, "string", 1, false) - ___.v.type(thousands, "string", 2, true) - ___.v.type(decimal, "string", 3, true) - - thousands = thousands or "," - decimal = decimal or "." - - -- Remove thousands separators - str = str:gsub(thousands, "") or str - - -- Convert decimal separator to period if different - if decimal ~= "." then - str = str:gsub(decimal, ".") or str - end - - -- Convert to number - return tonumber(str) or 0 - end - - --- Checks if a string starts with a given PCRE regex pattern. - --- If the pattern does not start with "^", it is prepended with "^". - --- - --- @param str string - The string to check. - --- @param start string - The pattern to check for. - --- @return boolean - Whether the string starts with the pattern. - --- @example - --- ```lua - --- string.starts_with("hello world", "hello") - --- -- true - --- ``` - function self.starts_with(str, start) - ___.v.type(str, "string", 1, false) - ___.v.type(start, "string", 2, false) - - start = string.sub(start, 1) == "^" and start or "^" .. start - - return rex.match(str, start) ~= nil - end - - --- Checks if a string ends with a given PCRE regex pattern. - --- If the pattern does not end with "$", it is appended with "$". - --- - --- @param str string - The string to check. - --- @param ending string - The pattern to check for. - --- @return boolean - Whether the string ends with the pattern. - --- @example - --- ```lua - --- string.ends_with("hello world", "world") - --- -- true - --- ``` - function self.ends_with(str, ending) - ___.v.type(str, "string", 1, false) - ___.v.type(ending, "string", 2, false) - - ending = string.sub(ending, 1) == "$" and ending or ending .. "$" - - return rex.match(str, ending) ~= nil - end - - --- Checks if a string contains a given PCRE regex pattern. The pattern - --- may not start with "^" or end with "$". For those, use - --- `string.starts_with` and `string.ends_with`. - --- - --- @param str string - The string to check. - --- @param pattern string - The pattern to check for. - --- @return boolean - Whether the string contains the pattern. - --- @example - --- ```lua - --- string.contains("hello world", "world") - --- -- true - --- ``` - function self.contains(str, pattern) - ___.v.type(str, "string", 1, false) - ___.v.type(pattern, "string", 2, false) - ___.v.test(not self.starts_with(pattern, "^"), "Expected pattern to not start with ^", 2) - ___.v.test(not self.ends_with(pattern, "$"), "Expected pattern to not end with $", 2) - - return rex.match(str, pattern) ~= nil - end - - --- Appends a suffix to a string if it does not already end with the suffix. - --- - --- @param str string - The string to append to. - --- @param suffix string - The suffix to append. - --- @return string - The string with the suffix appended. - --- @example - --- ```lua - --- string.append("hello", " world") - --- -- "hello world" - --- ``` - function self.append(str, suffix) - ___.v.type(str, "string", 1, false) - ___.v.type(suffix, "string", 2, false) - - return self.ends_with(str, suffix) and str or str .. suffix - end - - --- Prepends a prefix to a string if it does not already start with the prefix. - --- - --- @param str string - The string to prepend to. - --- @param prefix string - The prefix to prepend. - --- @return string - The string with the prefix prepended. - --- @example - --- ```lua - --- string.prepend("world", "hello ") - --- -- "hello world" - --- ``` - function self.prepend(str, prefix) - ___.v.type(str, "string", 1, false) - ___.v.type(prefix, "string", 2, false) - - return self.starts_with(str, prefix) and str or prefix .. str - end - - --- Implementation of reg_assoc for Mudlet using rex PCRE support - --- @param text string - The text to search through - --- @param patterns table - The patterns to search for - --- @param tokens table - The tokens to replace the patterns with - --- @param default_token string - The default token to use if no pattern is found (optional, defaults to "") - --- @return table,table - A table of results and token list - --- @example - --- ```lua - --- string.reg_assoc("hello world", {"hello", "world"}, {"foo", "bar"}) - --- -- {"foo", "bar"} - --- ``` - function self.reg_assoc(text, patterns, tokens, default_token) - default_token = default_token or -1 - local work = text - - local results = {} - local token_list = {} - - - while #work > 0 do - local nearest_from, nearest_match, nearest_token = nil, nil, nil - - for i, pattern in ipairs(patterns) do - local from, to = rex.find(work, pattern) - if from and to then - if not nearest_from or from < nearest_from then - nearest_from, nearest_match, nearest_token = - from, work:sub(from, to), tokens[i] or default_token - end - end - end - - local prematch = "" - local token = nearest_token or default_token - local match = nearest_match or work - nearest_from = nearest_from or #work - prematch = work:sub(1, nearest_from - 1 or nil) - print("Prematch = `" .. - tostring(prematch) .. "` with token `" .. tostring(token) .. "` and match `" .. tostring(match) .. "`") - - work = work:sub(nearest_from + #match) or "" - --[[ - if nearest_from then - token = nearest_token or default_token - match = nearest_match or work - prematch = "" - else - token = default_token - nearest_from = #work - match = work - work = "" - break - end - - -- The text between 1 and the nearest match - local pre_match = work:sub(1, nearest_from - 1 or nil) ---]] - -- Add it to the results - table.insert(results, pre_match) - table.insert(token_list, default_token) - - if #match > 0 then - table.insert(results, match) - table.insert(token_list, token) - end - end - - return results, token_list - end - - function is_alpha(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^[a-zA-Z]$") ~= nil - end - - function is_numeric(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^[0-9]$") ~= nil - end - - function is_alphanumeric(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^[a-zA-Z0-9]$") ~= nil - end - - function is_whitespace(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^%s$") ~= nil - end - - function is_punctuation(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^[^a-zA-Z0-9%s]$") ~= nil - end - - function is_uppercase(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^[A-Z]$") ~= nil - end - - -- TODO: handle 1 or more - function is_lowercase(char) - ___.v.type(char, "string", 1, false) - ___.v.test(#char == 1, "Expected a single character", 1) - - return rex.match(char, "^[a-z]$") ~= nil - end - - function split_natural(str) - ___.v.type(str, "string", 1, false) - - local resulit, current, is_numeric = {}, {}, false - - local chars = {} - for c in self.walk(str) do - local new_is_num = self.is_numeric(c) - - if i > 1 and new_is_num ~= is_num then - local chunk = table.concat(current) - if is_num then - table.push(result, tonumber(chunk)) - else - table.insert(result, chunk) - end - current = {} - end - - if #current > 0 then - local chunk = table.concat(current) - if is_num then - self.push(result, tonumber(chunk)) - else - table.insert(result, chunk) - end - end - end - end - - function natural_compare(a, b) - local a_parts = self.split_natural(a) - local b_parts = self.split_natural(b) - - local len = math.min(#a_parts, #b_parts) - - for i = 1, len do - local a_part, b_part = a_parts[i], b_parts[i] - local a_type, b_type = type(a_part), type(b_part) - - if a_type == "number" and b_type == "number" then - if a_part ~= b_part then - return a_part < b_part - end - elseif a_type == "string" and b_type == "string" then - if a_part ~= b_part then - return a_part < b_part - end - else - local str_a, str_b = tostring(a_part), tostring(b_part) - - if str_a ~= str_b then - return str_a < str_b - end - end - end - - return #a_parts < #b_parts - end - - function self.index_of(str, pattern) - ___.v.type(str, "string", 1, false) - ___.v.type(pattern, "string", 2, false) - - return rex.find(str, pattern) - end - end -}) - --- { "this", " ", "is", " ", "a", " ", "test" } --- { 1, nil, 1, nil, 1, nil, 1 } - --- this is a thing that is num3rically unsoundh4444, and my favourite number is forty2 diff --git a/examples/source/lua/table.lua b/examples/source/lua/table.lua deleted file mode 100644 index 4289960..0000000 --- a/examples/source/lua/table.lua +++ /dev/null @@ -1,722 +0,0 @@ -local TableClass = Glu.glass.register({ - name = "table", - class_name = "TableClass", - dependencies = {}, - setup = function(___, self) - function self.n_cast(...) - if type(...) == "table" and self.indexed(...) then - return ... - end - - return { ... } - end - - self.assure_indexed = self.n_cast - - function self.map(t, fn, ...) - ___.v.type(t, "table", 1, false) - ___.v.type(fn, "function", 2, false) - - local result = {} - for k, v in pairs(t) do - result[k] = fn(k, v, ...) - end - return result - end - - function self.values(t) - ___.v.type(t, "table", 1, false) - - local result = {} - for _, v in pairs(t) do - result[#result + 1] = v - end - return result - end - - function self.n_uniform(t, typ) - ___.v.type(t, "table", 1, false) - ___.v.indexed(t, 1, false) - ___.v.type(typ, "string", 2, true) - - typ = typ or type(t[1]) - - for _, v in pairs(t) do - if type(v) ~= typ then - return false - end - end - - return true - end - - function self.n_distinct(t) - ___.v.indexed(t, 1, false) - - local result, seen = {}, {} - for _, v in ipairs(t) do - if not seen[v] then - seen[v] = true - result[#result + 1] = v - end - end - return result - end - - function self.pop(t) - ___.v.type(t, "table", 1, false) - ___.v.indexed(t, 1, false) - return table.remove(t, #t) - end - - function self.push(t, v) - ___.v.type(t, "table", 1, false) - ___.v.type(v, "any", 2, false) - ___.v.indexed(t, 1, false) - table.insert(t, v) - - return #t - end - - function self.unshift(t, v) - ___.v.type(t, "table", 1, false) - ___.v.type(v, "any", 2, false) - ___.v.indexed(t, 1, false) - table.insert(t, 1, v) - - return #t - end - - function self.shift(t) - ___.v.type(t, "table", 1, false) - ___.v.indexed(t, 1, false) - return table.remove(t, 1) - end - - function self.allocate(source, spec) - local spec_type = type(spec) - ___.v.type(source, "table", 1, false) - ___.v.not_empty(source, 1, false) - ___.v.indexed(source, 1, false) - if spec_type == ___.TYPE.TABLE then - ___.v.indexed(spec, 2, false) - assert(#source == #spec, "Expected source and spec to have the same number of elements") - elseif spec_type == ___.TYPE.FUNCTION then - ___.v.type(spec, "function", 2, false) - end - - local result = {} - - if spec_type == ___.TYPE.TABLE then - for i = 1, #spec do - result[source[i]] = spec[i] - end - elseif spec_type == ___.TYPE.FUNCTION then - for i = 1, #source do - result[source[i]] = spec(i, source[i]) - end - else - for i = 1, #source do - result[source[i]] = spec - end - end - - return result - end - - function self.indexed(t) - ___.v.type(t, "table", 1, false) - - local index = 1 - for k in pairs(t) do - if k ~= index then - return false - end - index = index + 1 - end - return true - end - - function self.associative(t) - ___.v.type(t, "table", 1, false) - - for k, _ in pairs(t) do - if type(k) ~= "number" or k % 1 ~= 0 or k <= 0 then - return true - end - end - return false - end - - function self.reduce(t, fn, initial) - ___.v.indexed(t, 1, false) - ___.v.type(fn, "function", 2, false) - ___.v.type(initial, "any", 3, false) - - local acc = initial - for k, v in pairs(t) do - acc = fn(acc, v, k) - end - return acc - end - - function self.slice(t, start, stop) - ___.v.indexed(t, 1, false) - ___.v.type(start, "number", 2, false) - ___.v.type(stop, "number", 3, true) - ___.v.test(start >= 1, 2, false) - ___.v.test(table.size(t) >= start, 2, false) - ___.v.test(stop and stop >= start, 3, true) - - if not stop then - stop = #t - end - - local result = {} - for i = start, stop do - result[#result + 1] = t[i] - end - return result - end - - function self.remove(t, start, stop) - ___.v.indexed(t, 1, false) - ___.v.type(start, "number", 2, false) - ___.v.type(stop, "number", 3, true) - ___.v.test(start >= 1, 2, false) - ___.v.test(table.size(t) >= start, 2, false) - ___.v.test(stop and stop >= start, 3, true) - - local snipped = {} - if not stop then stop = start end - local count = stop - start + 1 - for i = 1, count do - table.insert(snipped, table.remove(t, start)) - end - return t, snipped - end - - function self.chunk(t, size) - ___.v.indexed(t, 1, false) - ___.v.type(size, "number", 2, false) - - local result = {} - for i = 1, #t, size do - result[#result + 1] = ___.slice(t, i, i + size - 1) - end - return result - end - - function self.concat(tbl, ...) - ___.v.indexed(tbl, 1, false) - - local args = { ... } - - for _, tbl_value in ipairs(args) do - if type(tbl_value) == "table" then - for _, value in ipairs(tbl_value) do - table.insert(tbl, value) - end - else - table.insert(tbl, tbl_value) - end - end - - return tbl - end - - function self.drop(tbl, n) - ___.v.indexed(tbl, 1, false) - ___.v.type(n, "number", 2, false) - ___.v.test(n >= 1, 2, false) - return self.slice(___, tbl, n + 1) - end - - function self.drop_right(tbl, n) - ___.v.indexed(tbl, 1, false) - ___.v.type(n, "number", 2, false) - ___.v.test(n >= 1, 2, false) - return self.slice(___, tbl, 1, #tbl - n) - end - - function self.fill(tbl, value, start, stop) - ___.v.indexed(tbl, 1, false) - ___.v.type(value, "any", 2, false) - ___.v.type(start, "number", 3, true) - ___.v.type(stop, "number", 4, true) - ___.v.test(start and start >= 1, value, 3, true) - ___.v.test(stop and stop >= start, value, 4, true) - - for i = start or 1, stop or #tbl do - tbl[i] = value - end - return tbl - end - - function self.find(tbl, fn) - ___.v.indexed(tbl, 1, false) - ___.v.type(fn, "function", 2, false) - - for i = 1, #tbl do - if fn(i, tbl[i]) then - return i - end - end - return nil - end - - function self.find_last(tbl, fn) - ___.v.indexed(tbl, 1, false) - ___.v.type(fn, "function", 2, false) - - for i = #tbl, 1, -1 do - if fn(i, tbl[i]) then - return i - end - end - return nil - end - - function self.flatten(tbl) - ___.v.indexed(tbl, 1, false) - - local result = {} - for _, v in ipairs(tbl) do - if type(v) == "table" then - ___.concat(result, v) - else - table.insert(result, v) - end - end - - return result - end - - function self.flatten_deeply(tbl) - ___.v.indexed(tbl, 1, false) - - local result = {} - for _, v in ipairs(tbl) do - if type(v) == "table" then - self.concat(result, self.flatten_deeply(v)) - else - table.insert(result, v) - end - end - - return result - end - - function self.initial(tbl) - ___.v.indexed(tbl, 1, false) - return self.slice(___, tbl, 1, #tbl - 1) - end - - function self.pull(tbl, ...) - ___.v.indexed(tbl, 1, false) - - local args = { ... } - if #args == 0 then return tbl end - - local removeSet = {} - for _, value in ipairs(args) do - removeSet[value] = true - end - - for i = #tbl, 1, -1 do - if removeSet[tbl[i]] then - table.remove(tbl, i) - end - end - - return tbl - end - - function self.reverse(tbl) - ___.v.indexed(tbl, 1, false) - - local len, midpoint = #tbl, math.floor(#tbl / 2) - for i = 1, midpoint do - tbl[i], tbl[len - i + 1] = tbl[len - i + 1], tbl[i] - end - return tbl - end - - function self.uniq(tbl) - ___.v.indexed(tbl, 1, false) - - local seen = {} - local writeIndex = 1 - - for readIndex = 1, #tbl do - local value = tbl[readIndex] - if not seen[value] then - seen[value] = true - tbl[writeIndex] = value - writeIndex = writeIndex + 1 - end - end - - -- Remove excess elements beyond writeIndex - for i = #tbl, writeIndex, -1 do - tbl[i] = nil - end - - return tbl - end - - function self.unzip(tbl) - ___.v.indexed(tbl, 1, false) - - local size_of_table = #tbl - -- Ensure that all sub-tables are of the same length - local size_of_elements = #tbl[1] - for _, t in ipairs(tbl) do ___.v.test(size_of_elements == #t, t, 1, false) end - - local num_new_sub_tables = size_of_elements -- yes, this is redundant, but it's more readable - local new_sub_table_size = size_of_table -- this is the size of the sub-tables - local result = {} - - for i = 1, num_new_sub_tables do - result[i] = {} - end - - for _, source_table in ipairs(tbl) do - for i, value in ipairs(source_table) do - table.insert(result[i], value) - end - end - - return result - end - - function self.new_weak(opt) - ___.v.test(rex.match(opt, "^(k?v?|v?k?)$"), opt, 1, true) - - opt = opt or "v" - - return setmetatable({}, { __mode = opt }) - end - - function self.weak(tbl) - ___.v.type(tbl, "table", 1, false) - return getmetatable(tbl) and getmetatable(tbl).__mode ~= nil - end - - function self.zip(...) - local tbls = { ... } - local results = {} - - local size = #tbls[1] - for _, t in ipairs(tbls) do ___.v.test(size == #t, t, 1, false) end - - for i = 1, size do - results[i] = {} - for _, t in ipairs(tbls) do - table.insert(results[i], t[i]) - end - end - return results - end - - function self.includes(tbl, value) - ___.v.indexed(tbl, 1, false) - ___.v.type(value, "any", 2, false) - return table.index_of(tbl, value) ~= nil - end - - local function collect_tables(tbl, extending) - -- Check if the table is a valid object with a metatable and an __index field - ___.v.object(tbl, 1, false) - ___.v.type(extending, "boolean", 2, true) - - -- Set-like table to track visited tables - local visited = {} - local tables = {} - - local function add_table(t) - if not visited[t] then - table.insert(tables, t) - visited[t] = true - end - end - - -- Start by adding the main table - add_table(tbl) - - if extending then - local mt = getmetatable(tbl) - while mt and mt.__index do - local extendingTbl = mt.__index - if type(extendingTbl) == "table" then - add_table(extendingTbl) - end - mt = getmetatable(extendingTbl) - end - end - - return tables - end - - local function get_types(tbl, test) - ___.v.type(tbl, "table", 1, false) - ___.v.type(test, "function", 2, false) - - local keys = table.keys(tbl) - keys = table.n_filter(keys, function(k) return test(tbl, k) end) or {} - return keys - end - - local function assemble_results(tables, test) - local result = {} - for _, t in ipairs(tables) do - local keys = get_types(t, test) or {} - for _, k in ipairs(keys) do - if not ___.table.includes(result, k) then - table.insert(result, k) - end - end - end - return result - end - - function self.functions(tbl, extending) - ___.v.object(tbl, 1, false) - ___.v.type(extending, "boolean", 2, true) - - local tables = collect_tables(tbl, extending) or {} - local test = function(t, k) return type(t[k]) == "function" end - - return assemble_results(tables, test) - end - -- Alias for functions - self.methods = self.functions - - function self.properties(tbl, extending) - ___.v.object(tbl, 1, false) - ___.v.type(extending, "boolean", 2, true) - - local tables = collect_tables(tbl, extending) or {} - local test = function(t, k) return type(t[k]) ~= "function" end - - return assemble_results(tables, test) - end - - function self.object(tbl) - ___.v.type(tbl, "table", 1, false) - return tbl.object == true - end - - function self.add(tbl, value) - ___.v.associative(tbl, 1, false) - ___.v.associative(value, 2, false) - - for k, v in pairs(value) do - tbl[k] = v - end - - return tbl - end - - function self.n_add(tbl1, tbl2, index) - ___.v.indexed(tbl1, 1, false) - ___.v.indexed(tbl2, 2, false) - ___.v.range(index, 1, #tbl1 + 1, 3, true) - - -- We are not adding +1 to the end index because we will be doing +1 - -- in the loop below - index = index or #tbl1 + 1 - - for i = 1, #tbl2 do - table.insert(tbl1, index + i - 1, tbl2[i]) - end - - return tbl1 - end - - function self.walk(tbl) - ___.v.indexed(tbl, 1, false) - - local i = 0 - return function() - i = i + 1 - if tbl[i] then return i, tbl[i] end - end - end - - function self.element_of(list) - ___.v.type(list, "table", 1, false) - - local max = #list - return list[math.random(max)] - end - - function self.element_of_weighted(list) - ___.v.type(list, "table", 1, false) - - local total = 0 - for _, value in pairs(list) do - total = total + value - end - - local random = math.random(total) - - for key, value in pairs(list) do - random = random - value - if random <= 0 then - return key - end - end - end - - local assure_equality_function = function(condition) - if type(condition) ~= "function" then - condition = function(_, k) return k == condition end - end - return condition - end - - function self.all(tbl, condition) - ___.v.indexed(tbl, 1, false) - ___.v.type(condition, "any", 2, false) - - local count = 0 - - condition = assure_equality_function(condition) - - local result = table.n_filter(tbl, condition) - if result then - count = #result - end - - return count == #tbl - end - - function self.some(tbl, condition) - ___.v.indexed(tbl, 1, false) - ___.v.type(condition, "any", 2, false) - - condition = assure_equality_function(condition) - - return table.n_filter(tbl, condition) ~= nil - end - - function self.none(tbl, condition) - ___.v.indexed(tbl, 1, false) - ___.v.type(condition, "any", 2, false) - - condition = assure_equality_function(condition) - - return table.n_filter(tbl, condition) == nil - end - - function self.one(tbl, condition) - ___.v.indexed(tbl, 1, false) - ___.v.type(condition, "any", 2, false) - - condition = assure_equality_function(condition) - - return table.n_filter(tbl, condition) ~= nil and #table.n_filter(tbl, condition) == 1 - end - - function self.count(tbl, condition) - ___.v.indexed(tbl, 1, false) - ___.v.type(condition, "any", 2, false) - - condition = assure_equality_function(condition) - - return #table.n_filter(tbl, condition) - end - - function self.natural_sort(tble) - print("We here") - ___.v.indexed(tble, 1, false) - - local sorted = {} - for i = 1, #tble do - sorted[i] = tble[i] - end - table.sort(sorted, ___.string.natural_compare) - return sorted - end - - function self.sort(tbl, arg) - ___.v.indexed(tbl, 1, false) - - if type (arg) == "function" then - table.sort(tbl, arg) - else - return self.natural_sort(tbl) - end - end - - end, - valid = function(___, self) - return { - not_empty = function(value, argument_index, nil_allowed) - assert(type(value) == "table", "Invalid type to argument " .. - argument_index .. ". Expected table, got " .. type(value) .. " in\n" .. - ___.get_last_traceback_line()) - if nil_allowed and value == nil then - return - end - - local last = ___.get_last_traceback_line() - assert(not table.is_empty(value), "Invalid value to argument " .. - argument_index .. ". Expected non-empty in\n" .. last) - end, - - n_uniform = function(value, expected_type, argument_index, nil_allowed) - if nil_allowed and value == nil then - return - end - - local last = ___.get_last_traceback_line() - assert(self.n_uniform(value, expected_type), - "Invalid type to argument " .. argument_index .. ". Expected an " .. - "indexed table of " .. expected_type .. " in\n" .. last) - end, - indexed = function(value, argument_index, nil_allowed) - if nil_allowed and value == nil then - return - end - - local last = ___.get_last_traceback_line() - assert(self.indexed(value), "Invalid value to argument " .. - argument_index .. ". Expected indexed table, got " .. type(value) .. - " in\n" .. last) - end, - associative = function(value, argument_index, nil_allowed) - if nil_allowed and value == nil then - return - end - - local last = ___.get_last_traceback_line() - - assert(self.associative(value), - "Invalid value to argument " .. argument_index .. ". Expected " .. - "associative table, got " .. type(value) .. " in\n" .. last) - end, - object = function(value, argument_index, nil_allowed) - if nil_allowed and value == nil then - return - end - - local last = ___.get_last_traceback_line() - assert(self.object(value), "Invalid value to argument " .. - argument_index .. ". Expected object, got " .. type(value) .. - " in\n" .. last) - end, - option = function(value, options, argument_index) - ___.v.type(value, "any", argument_index, false) - ___.v.indexed(options, argument_index, false) - ___.v.type(argument_index, "number", 3, false) - - local last = ___.get_last_traceback_line() - assert(table.index_of(options, value) ~= nil, "Invalid value to " .. - "argument " .. argument_index .. ". Expected one of " .. - table.concat(options, ", ") .. ", got " .. value .. " in\n" .. last) - end - } - end, -})