### Example: Build Xmake Server Target Source: https://github.com/altmp/altv-js-module-v2/blob/dev/docs/building.md An illustrative example demonstrating how to build the 'server' target specifically using the Xmake build system, useful for focused development or deployment. ```Shell xmake build server ``` -------------------------------- ### Start Receiving Data on UDP Socket (C) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/udp.rst Prepares a UDP socket to start receiving data. If not previously bound, it will bind to 0.0.0.0 and a random port. Requires allocation and receive callbacks. ```APIDOC Function: int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb) Description: Prepare for receiving data. If the socket has not previously been bound with uv_udp_bind it is bound to 0.0.0.0 (the \"all interfaces\" IPv4 address) and a random port number. Parameters: handle: UDP handle. Should have been initialized with uv_udp_init. alloc_cb: Callback to invoke when temporary storage is needed. recv_cb: Callback to invoke with received data. Returns: 0 on success, or an error code < 0 on failure. ``` -------------------------------- ### Install alt:V JS Module v2 Binaries Source: https://github.com/altmp/altv-js-module-v2/blob/dev/README.md Use the npx altv-pkg release command to install all required binaries for the alt:V JS Module v2. This command leverages altv-pkg to fetch and set up the module dependencies. ```bash npx altv-pkg release ``` -------------------------------- ### Install alt:V JS Module v2 Server Typings Source: https://github.com/altmp/altv-js-module-v2/blob/dev/types/server/README.md Installs the development dependencies for alt:V JS module v2 server type definitions using npm. ```Shell npm i -D @altv/server ``` -------------------------------- ### C API: Get System Load Average Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets the load average. Returns [0,0,0] on Windows (i.e., it's not implemented). See: https://en.wikipedia.org/wiki/Load_(computing) ```APIDOC void uv_loadavg(double avg[3]) avg: An array of 3 doubles to store the 1, 5, and 15-minute load averages. ``` -------------------------------- ### Install Jinja2 with pip Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/third_party/jinja2/README.rst This snippet shows how to install or update the Jinja2 templating engine using the `pip` package installer. The `-U` flag ensures the package is updated if already installed. ```text $ pip install -U Jinja2 ``` -------------------------------- ### API: uv_exepath - Get Executable Path Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets the full path to the current executable. It is crucial to call `uv_setup_args` before invoking this function to ensure proper initialization. The path is stored in `buffer`, and `*size` manages the buffer's capacity and the returned path's length. ```APIDOC int uv_exepath(char* buffer, size_t* size) buffer: char* - Buffer to store the executable path. size: size_t* - Pointer to buffer size; updated with required size on UV_ENOBUFS or actual length on success. Returns: int - 0 on success, UV_ENOBUFS if buffer is too small, or a negative error code. ``` -------------------------------- ### Install alt:V JS Module v2 Client Typings Source: https://github.com/altmp/altv-js-module-v2/blob/dev/types/client/README.md Provides the command to install the alt:V JS module v2 client type definitions as a development dependency using npm. ```Shell npm i -D @altv/client ``` -------------------------------- ### APIDOC: Start File System Event Monitoring Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs_event.rst Starts monitoring a specified path for changes using the provided callback function and flags. Currently, only UV_FS_EVENT_RECURSIVE is supported on OSX and Windows. ```APIDOC uv_fs_event_start: int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, const char* path, unsigned int flags) handle: The uv_fs_event_t handle. cb: The callback function to be invoked on changes. path: The file system path to monitor. flags: An ORed mask of uv_fs_event_flags to control behavior (e.g., UV_FS_EVENT_RECURSIVE). Returns: 0 on success, or an error code < 0 on failure. ``` -------------------------------- ### C API: Get System Uptime Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets the current system uptime. Depending on the system, full or fractional seconds are returned. The `uptime` pointer will be updated with the uptime value. ```APIDOC int uv_uptime(double* uptime) uptime: Pointer to a double to store the system uptime. Returns: int (0 on success, <0 on error) ``` -------------------------------- ### C: Example uv_alloc_cb Implementation Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/handle.rst Provides an example implementation for the `uv_alloc_cb` callback, demonstrating how to allocate memory for a buffer using `malloc` and set its base and length. This callback is essential for functions like `uv_read_start` and `uv_udp_recv_start` to manage memory for incoming data. ```C static void my_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { buf->base = malloc(suggested_size); buf->len = suggested_size; } ``` -------------------------------- ### C Function: uv_setup_args Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Stores program arguments, which is necessary for getting or setting the process title or executable path. Libuv may take ownership of the argv memory. This function should be called exactly once at program startup. ```APIDOC char** uv_setup_args(int argc, char** argv) Description: Store the program arguments. Required for getting / setting the process title or the executable path. Libuv may take ownership of the memory that argv points to. This function should be called exactly once, at program start-up. Parameters: argc: The argument count. argv: The argument vector. Returns: char** (May return a copy of argv.) Example: argv = uv_setup_args(argc, argv); /* May return a copy of argv. */ ``` -------------------------------- ### C API: Get Resident Set Size (RSS) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets the resident set size (RSS) for the current process. This function is thread-safe on all supported platforms since version 1.18.1. It returns an error if `uv_setup_args` is needed but hasn't been called, since version 1.39.0. ```APIDOC int uv_resident_set_memory(size_t* rss) rss: Pointer to a size_t to store the resident set size. Returns: int (0 on success, <0 on error) ``` -------------------------------- ### Install alt:V WebView Typings Source: https://github.com/altmp/altv-js-module-v2/blob/dev/types/webview/README.md Installs the alt:V JS module v2 WebView type definitions as a development dependency using npm. This package provides type hints and autocompletion for WebView-related code. ```Shell npm i -D @altv/webview ``` -------------------------------- ### C: Print All Handles Example Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst This example demonstrates how to use `uv_print_all_handles` to print all active and inactive handles associated with the default libuv loop to standard error. The output format includes flags indicating handle status (Referenced, Active, Internal), handle type, and memory address. ```c uv_print_all_handles(uv_default_loop(), stderr); /* [--I] signal 0x1a25ea8 [-AI] async 0x1a25cf0 [R--] idle 0x1a7a8c8 */ ``` -------------------------------- ### Install alt:V JS Module v2 Shared Typings Source: https://github.com/altmp/altv-js-module-v2/blob/dev/types/shared/README.md Installs the shared type definitions for alt:V JS module v2 as a development dependency using npm. ```Shell npm i -D @altv/shared ``` -------------------------------- ### libuv uv_prepare_t API Functions Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/prepare.rst Provides functions to initialize, start, and stop `uv_prepare_t` handles, controlling their execution within the event loop. These handles execute their callback once per loop iteration before I/O polling. ```APIDOC uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare): Description: Initialize the handle. This function always succeeds. Parameters: loop: The event loop. prepare: The prepare handle to initialize. Returns: 0 uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb): Description: Start the handle with the given callback. Parameters: prepare: The prepare handle. cb: The callback function to be called. Returns: 0 on success, or UV_EINVAL when cb == NULL. uv_prepare_stop(uv_prepare_t* prepare): Description: Stop the handle, the callback will no longer be called. This function always succeeds. Parameters: prepare: The prepare handle to stop. Returns: 0 ``` -------------------------------- ### APIDOC: Start uv_check_t Handle Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/check.rst Starts a `uv_check_t` handle, causing its associated callback to be invoked once per loop iteration after I/O polling. Fails if the callback is `NULL`. ```APIDOC Function: int uv_check_start(uv_check_t* check, uv_check_cb cb) Description: Start the handle with the given callback. This function always succeeds, except when `cb` is `NULL`. Parameters: check: The uv_check_t handle to start. cb: The callback function to be called once per loop iteration. Returns: 0 on success, or UV_EINVAL when `cb == NULL`. ``` -------------------------------- ### CMake Project Initialization and Dependency Path Setup Source: https://github.com/altmp/altv-js-module-v2/blob/dev/client/CMakeLists.txt This snippet sets the minimum required CMake version, defines the project name 'altv-client-jsv2', and configures the base directory for project dependencies. It also sets a 'BINDINGS_SCOPE' variable, indicating the context for code generation. ```CMake cmake_minimum_required (VERSION 3.19) set(BINDINGS_SCOPE "CLIENT") # include(../shared/cmake/GenerateBindings.cmake) # include(../shared/cmake/GenerateEnums.cmake) project(altv-client-jsv2) set(ALTV_JSV2_DEPS_DIR ${PROJECT_SOURCE_DIR}/deps) ``` -------------------------------- ### C API: Get System Information (uv_os_uname) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Retrieves system information including the operating system name, release, version, and machine. On non-Windows systems, uv_os_uname() is a thin wrapper around uname(2). ```C int uv_os_uname(uv_utsname_t* buffer) ``` ```APIDOC Parameters: buffer: Pointer to a uv_utsname_t structure to store the system information. Returns: 0 on success, or a non-zero error value otherwise. ``` -------------------------------- ### C API: Get CPU Information Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets information about the CPUs on the system. The `cpu_infos` array will have `count` elements and needs to be freed with `uv_free_cpu_info`. Use `uv_available_parallelism` if you need to know how many CPUs are available for threads or child processes. ```APIDOC int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) cpu_infos: Pointer to a pointer that will be allocated to an array of uv_cpu_info_t structures. count: Pointer to an int that will store the number of elements in the cpu_infos array. Returns: int (0 on success, <0 on error) ``` -------------------------------- ### APIDOC: Initialize uv_fs_event_t Handle Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs_event.rst Initializes a uv_fs_event_t handle, preparing it for use with a given event loop. This function must be called before starting the event monitoring. ```APIDOC uv_fs_event_init: int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) loop: The event loop to associate the handle with. handle: The uv_fs_event_t handle to initialize. Returns: 0 on success, or an error code < 0 on failure. ``` -------------------------------- ### C Function: uv_dlopen Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/dll.rst Opens a shared library. The filename is in utf-8. Returns 0 on success and -1 on error. Call uv_dlerror to get the error message. ```APIDOC int uv_dlopen(const char* filename, uv_lib_t* lib) ``` -------------------------------- ### Run Local System Analyzer Server Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/tools/system-analyzer/index.html This command starts a local symbol server using the `local-server.sh` script, which allows for obtaining detailed C++ symbols for local binaries. The analyzer can then be accessed via a web browser. ```Bash tools/system-analyzer/local-server.sh ``` -------------------------------- ### JavaScript Global Setup and Utility Functions Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/tools/callstats.html Initializes Google Charts, provides a polyfill for NodeList.prototype.forEach for broader browser compatibility, and declares global variables used throughout the application for managing versions, pages, and selected data. ```JavaScript "use strict" google.charts.load('current', { packages: ['corechart'] }); // Did anybody say monkeypatching? if (!NodeList.prototype.forEach) { NodeList.prototype.forEach = function (func) { for (let i = 0; i < this.length; i++) { func(this[i]); } } } let versions; let pages; let selectedPage; let baselineVersion; let selectedEntry; let sortByLabel = false; // Marker to programatically replace the defaultData. let defaultData = /*default-data-start*/ undefined /*default-data-end*/; ``` -------------------------------- ### APIDOC: uv_async_init - Initialize Async Handle Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/async.rst Initializes an `uv_async_t` handle, associating it with a specific event loop and an optional callback. Unlike other handle initialization functions, it immediately starts the handle. Returns 0 on success or an error code on failure. ```APIDOC int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) Parameters: loop: uv_loop_t* - The event loop to associate the handle with. async: uv_async_t* - The async handle to initialize. async_cb: uv_async_cb - The callback function to be called when the handle is triggered. A NULL callback is allowed. Returns: int - 0 on success, or an error code < 0 on failure. Notes: - Immediately starts the handle upon initialization. ``` -------------------------------- ### Configure altv-pkg to Load JS Module v2 Source: https://github.com/altmp/altv-js-module-v2/blob/dev/README.md Create a .altvpkgrc.json file in your server directory to enable loading of the JSv2 module. This configuration tells altv-pkg to include the necessary module during installation. ```json { "loadJSV2Module": true } ``` -------------------------------- ### libuv uv_signal_t API Documentation Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/signal.rst Comprehensive API documentation for the `uv_signal_t` handle type in libuv, including data types, public members, and functions for initializing, starting, and stopping signal watchers. It details the purpose, parameters, and behavior of each API element. ```APIDOC Data Types: uv_signal_t: Description: Signal handle type. uv_signal_cb: Signature: void (*uv_signal_cb)(uv_signal_t* handle, int signum) Description: Type definition for callback passed to uv_signal_start. Public Members: uv_signal_t.signum: Type: int Description: Signal being monitored by this handle. Readonly. API Functions: uv_signal_init: Signature: int uv_signal_init(uv_loop_t* loop, uv_signal_t* signal) Description: Initialize the handle. Parameters: loop: uv_loop_t* - The event loop. signal: uv_signal_t* - The signal handle to initialize. uv_signal_start: Signature: int uv_signal_start(uv_signal_t* signal, uv_signal_cb cb, int signum) Description: Start the handle with the given callback, watching for the given signal. Parameters: signal: uv_signal_t* - The signal handle. cb: uv_signal_cb - The callback function to be called when the signal is received. signum: int - The signal number to watch for. uv_signal_start_oneshot: Signature: int uv_signal_start_oneshot(uv_signal_t* signal, uv_signal_cb cb, int signum) Description: Same functionality as uv_signal_start but the signal handler is reset the moment the signal is received. (Added in 1.12.0) Parameters: signal: uv_signal_t* - The signal handle. cb: uv_signal_cb - The callback function. signum: int - The signal number. uv_signal_stop: Signature: int uv_signal_stop(uv_signal_t* signal) Description: Stop the handle, the callback will no longer be called. Parameters: signal: uv_signal_t* - The signal handle. ``` -------------------------------- ### API: uv_get_total_memory - Get Total System Memory Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Retrieves the total amount of physical memory installed in the system. The value is returned in bytes. This function provides a way to query the total RAM capacity of the machine. ```APIDOC uint64_t uv_get_total_memory(void) Returns: uint64_t - The total amount of physical memory in bytes. ``` -------------------------------- ### Get Current Timestamp (uv_now) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/loop.rst Returns the current timestamp in milliseconds. This timestamp is cached at the start of the event loop tick to reduce system calls. It increases monotonically from an arbitrary point in time. For sub-millisecond granularity, use `uv_hrtime`. ```APIDOC uint64_t uv_now(const uv_loop_t* loop) Returns: uint64_t (current timestamp in milliseconds) Note: Use uv_hrtime if you need sub-millisecond granularity. ``` -------------------------------- ### Migrating libuv Loop Initialization and Closing Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/migration_010_100.rst This snippet illustrates the change in libuv's loop management. In 0.10, loops were created and destroyed using `uv_loop_new` and `uv_loop_delete`. In 1.0, users are responsible for memory allocation (`malloc`/`free`) and then initializing/closing the loop with `uv_loop_init` and `uv_loop_close`. ```C uv_loop_t* loop = uv_loop_new(); ... uv_loop_delete(loop); ``` ```C uv_loop_t* loop = malloc(sizeof *loop); uv_loop_init(loop); ... uv_loop_close(loop); free(loop); ``` -------------------------------- ### Configure Xmake Project Source: https://github.com/altmp/altv-js-module-v2/blob/dev/docs/building.md Use this command to generate and configure the project files without initiating a full build. It sets up the project environment for subsequent build operations. ```Shell xmake config ``` -------------------------------- ### Retrieve JavaScript Binding Export in C++ (v8::Value) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/docs/js-bindings.md This C++ example shows how to retrieve a previously registered JavaScript binding export using `IResource::GetBindingExport`. It demonstrates getting a `v8::Function` and checking if it's empty before use. The template argument specifies the desired `v8::Value` derived type. ```cpp js::IResource* resource = GetCurrentResource(); // Fictional function, get the current resource pointer via e.g. `ctx.GetResource()` v8::Local myExportedFunction = resource->GetBindingExport(js::BindingExport::MY_EXPORT); if(myExportedFunction.IsEmpty()) return; // Check if the binding exists, accessing an empty local otherwise crashes. // Do whatever the export is needed for ``` -------------------------------- ### uv_timer_t API Reference Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/timer.rst Detailed API documentation for the `uv_timer_t` handle, including its data types and functions for initializing, starting, stopping, and managing timers within an event loop. This covers scheduling callbacks, setting repeat intervals, and querying timer status. ```APIDOC Data Types: uv_timer_t: Timer handle type. void (*uv_timer_cb)(uv_timer_t* handle): Type definition for callback passed to uv_timer_start. API Functions: int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) Description: Initialize the timer handle. int uv_timer_start(uv_timer_t* handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat) Description: Start the timer. Parameters: handle: The timer handle. cb: The callback function to be called. timeout: Initial delay in milliseconds. repeat: Repeat interval in milliseconds (0 for non-repeating). Notes: - If timeout is zero, the callback fires on the next event loop iteration. - If repeat is non-zero, the callback fires first after timeout milliseconds and then repeatedly after repeat milliseconds. - Does not update the event loop's concept of "now". - If the timer is already active, it is simply updated. int uv_timer_stop(uv_timer_t* handle) Description: Stop the timer; the callback will not be called anymore. int uv_timer_again(uv_timer_t* handle) Description: Stop the timer, and if it is repeating, restart it using the repeat value as the timeout. Returns: UV_EINVAL if the timer has never been started before. void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat) Description: Set the repeat interval value in milliseconds. Parameters: handle: The timer handle. repeat: The new repeat interval in milliseconds. Notes: - If the repeat value is set from a timer callback, it does not immediately take effect. - If the timer was non-repeating before, it will have been stopped. - If it was repeating, then the old repeat value will have been used to schedule the next timeout. uint64_t uv_timer_get_repeat(const uv_timer_t* handle) Description: Get the timer repeat value. Returns: The repeat interval in milliseconds. uint64_t uv_timer_get_due_in(const uv_timer_t* handle) Description: Get the timer due value or 0 if it has expired. Returns: The time relative to uv_now(). Version: 1.40.0 ``` -------------------------------- ### Install Python SciPy Dependency Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/tools/callstats.html Installs the SciPy library for Python using `aptitude`, which is a prerequisite for running `callstats.py`. ```Shell sudo aptitude install python-scipy ``` -------------------------------- ### Initialize Git Submodules Source: https://github.com/altmp/altv-js-module-v2/blob/dev/docs/building.md This command is essential after cloning the repository to pull all required dependencies located in Git submodules, ensuring the project has all necessary components. ```Shell git submodule update --init --recursive ``` -------------------------------- ### Display Xmake Configuration Options Source: https://github.com/altmp/altv-js-module-v2/blob/dev/docs/building.md Executes the Xmake command to display all available configuration options for the project. These options can be set during project configuration to customize the build process. ```Shell xmake f --help ``` -------------------------------- ### Initialize V8 Zone Statistics Visualizer Web Page Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/tools/zone-stats/index.html This snippet provides the initial setup for the V8 Zone Statistics visualizer's web page. It includes basic CSS for styling, JavaScript for strict mode, loading Google Charts, and utility functions for DOM manipulation and state management. These functions are foundational for the visualizer's interactive components. ```CSS body { font-family: 'Roboto', sans-serif; margin-left: 5%; margin-right: 5%; } ``` ```JavaScript 'use strict'; google.charts.load('current', {'packages':['line', 'corechart', 'bar']}); function $(id) { return document.querySelector(id); } function removeAllChildren(node) { while (node.firstChild) { node.removeChild(node.firstChild); } } let state = Object.create(null); ``` -------------------------------- ### C API: Get Resource Usage Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets the resource usage measures for the current process. On Windows, not all fields are set; the unsupported fields are filled with zeroes. Refer to `uv_rusage_t` for more details. ```APIDOC int uv_getrusage(uv_rusage_t* rusage) rusage: Pointer to a uv_rusage_t structure to store resource usage information. Returns: int (0 on success, <0 on error) ``` -------------------------------- ### C Function: uv_get_process_title Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Retrieves the title of the current process. On Unix and AIX, uv_setup_args must be called first; otherwise, UV_ENOBUFS is returned. Returns UV_EINVAL if buffer is NULL or size is zero, and UV_ENOBUFS if the buffer is too small. On BSD, uv_setup_args is needed for the initial title, which is empty until set. ```APIDOC int uv_get_process_title(char* buffer, size_t size) Description: Gets the title of the current process. You must call uv_setup_args before calling this function on Unix and AIX systems. If uv_setup_args has not been called on systems that require it, then UV_ENOBUFS is returned. If buffer is NULL or size is zero, UV_EINVAL is returned. If size cannot accommodate the process title and terminating nul character, the function returns UV_ENOBUFS. Parameters: buffer: Buffer to store the process title. size: Size of the buffer. Returns: int (0 on success, UV_ENOBUFS if uv_setup_args not called or buffer too small, UV_EINVAL if buffer is NULL or size is zero.) Notes: - On BSD systems, uv_setup_args is needed for getting the initial process title. The process title returned will be an empty string until either uv_setup_args or uv_set_process_title is called. Version Changed: - 1.18.1: now thread-safe on all supported platforms. - 1.39.0: now returns an error if uv_setup_args is needed but hasn't been called. ``` -------------------------------- ### Initialize Indicium Web Application Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/tools/system-analyzer/index.html This JavaScript snippet initializes the main Indicium web application. It first imports the log file reader, then asynchronously loads the main application module and instantiates the App class, making it globally accessible. ```JavaScript // Force instantiating the log-reader before anything else. import "./view/log-file-reader.mjs"; // Delay loading of the main App (async function() { let module = await import('./index.mjs'); globalThis.app = new module.App(); })(); ``` -------------------------------- ### C API: Get Network Interface Addresses Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets address information about the network interfaces on the system. An array of `count` elements is allocated and returned in `addresses`. It must be freed by the user, calling `uv_free_interface_addresses`. ```APIDOC int uv_interface_addresses(uv_interface_address_t** addresses, int* count) addresses: Pointer to a pointer that will be allocated to an array of uv_interface_address_t structures. count: Pointer to an int that will store the number of elements in the addresses array. Returns: int (0 on success, <0 on error) ``` -------------------------------- ### Basic Jinja Template with Inheritance and Loop Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/third_party/jinja2/README.rst This Jinja template demonstrates fundamental features: extending a base HTML template, defining content blocks, and iterating over a collection of `users` to display their links. It showcases how to combine static HTML with dynamic content using Jinja's syntax. ```jinja {% extends "base.html" %} {% block title %}Members{% endblock %} {% block content %} {% endblock %} ``` -------------------------------- ### Libuv Versioning Functions Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/version.rst Documentation for libuv C functions that provide the library's version information. ```APIDOC unsigned int uv_version(void): Returns UV_VERSION_HEX. const char* uv_version_string(void): Returns the libuv version number as a string. For non-release versions the version suffix is included. ``` -------------------------------- ### Start Monitoring Path with uv_fs_poll_t Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs_poll.rst Starts monitoring a specified file path for changes using a `uv_fs_poll_t` handle. The provided callback will be invoked at a given interval when changes are detected. It's recommended to use multi-second intervals for portability. ```APIDOC uv_fs_poll_start: Signature: int uv_fs_poll_start(uv_fs_poll_t* handle, uv_fs_poll_cb poll_cb, const char* path, unsigned int interval) Description: Check the file at path for changes every interval milliseconds. Parameters: handle: Pointer to the uv_fs_poll_t handle. poll_cb: The callback function (uv_fs_poll_cb) to be called on changes. path: The file path to monitor. interval: The polling interval in milliseconds. Notes: For maximum portability, use multi-second intervals. Sub-second intervals will not detect all changes on many file systems. ``` -------------------------------- ### Libuv Versioning Macros Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/version.rst Documentation for libuv C preprocessor macros used to retrieve different components of the library's version number and status. ```APIDOC UV_VERSION_MAJOR: libuv version's major number. UV_VERSION_MINOR: libuv version's minor number. UV_VERSION_PATCH: libuv version's patch number. UV_VERSION_IS_RELEASE: Set to 1 to indicate a release version of libuv, 0 for a development snapshot. UV_VERSION_SUFFIX: libuv version suffix. Certain development releases such as Release Candidates might have a suffix such as "rc". UV_VERSION_HEX: Returns the libuv version packed into a single integer. 8 bits are used for each component, with the patch number stored in the 8 least significant bits. E.g. for libuv 1.2.3 this would be 0x010203. (versionadded:: 1.7.0) ``` -------------------------------- ### Reference libuv Threading and Synchronization API Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/threading.rst Comprehensive API documentation for libuv's cross-platform threading and synchronization primitives. Includes data type definitions, thread creation and management functions, thread affinity and priority controls, and notes on thread-local storage. ```APIDOC Data Types: uv_thread_t: Thread data type. uv_thread_cb(void* arg): Callback invoked to initialize thread execution. `arg` is the value passed to `uv_thread_create`. uv_key_t: Thread-local key data type. uv_once_t: Once-only initializer data type. uv_mutex_t: Mutex data type. uv_rwlock_t: Read-write lock data type. uv_sem_t: Semaphore data type. uv_cond_t: Condition data type. uv_barrier_t: Barrier data type. Threads API: uv_thread_options_t: Description: Options for spawning a new thread (passed to `uv_thread_create_ex`). Fields: flags: Enum for thread options. UV_THREAD_NO_FLAGS = 0x00 UV_THREAD_HAS_STACK_SIZE = 0x01 stack_size: Specifies a stack size for the new thread. `0` indicates default. Other values are rounded up to nearest page boundary. Notes: More fields may be added to this struct at any time, so its exact layout and size should not be relied upon. (versionadded: 1.26.0) uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg): Description: Creates a new thread. Parameters: tid: Pointer to `uv_thread_t` to store the new thread's ID. entry: Callback function to be invoked for thread execution. arg: Argument passed to the `entry` callback. Returns: `int` (0 on success, UV_E* error code on failure). (versionchanged: 1.4.1) uv_thread_create_ex(uv_thread_t* tid, const uv_thread_options_t* params, uv_thread_cb entry, void* arg): Description: Like `uv_thread_create`, but specifies options for creating a new thread. Parameters: tid: Pointer to `uv_thread_t` to store the new thread's ID. params: Pointer to `uv_thread_options_t` for thread creation options. If `UV_THREAD_HAS_STACK_SIZE` is set, `stack_size` specifies a stack size. `0` indicates default. entry: Callback function to be invoked for thread execution. arg: Argument passed to the `entry` callback. Returns: `int` (0 on success, UV_E* error code on failure). (versionadded: 1.26.0) uv_thread_setaffinity(uv_thread_t* tid, char* cpumask, char* oldmask, size_t mask_size): Description: Sets the specified thread's CPU affinity. Parameters: tid: Pointer to `uv_thread_t` for the target thread. cpumask: CPU mask in bytes to set the affinity to. oldmask: Optional. Pointer to buffer to return the previous affinity setting. mask_size: Number of entries (bytes) in `cpumask` / `oldmask`. Must be >= `uv_cpumask_size`. Returns: `int` (0 on success, <0 on failure). Notes: Uses `pthread_setaffinity_np(3)` on Unix, `SetThreadAffinityMask()` on Windows. Not atomic on Windows. Unsupported on macOS. (versionadded: 1.45.0) uv_thread_getaffinity(uv_thread_t* tid, char* cpumask, size_t mask_size): Description: Gets the specified thread's CPU affinity setting. Parameters: tid: Pointer to `uv_thread_t` for the target thread. cpumask: Pointer to buffer to store the CPU mask in bytes. mask_size: Number of entries (bytes) in `cpumask`. Must be >= `uv_cpumask_size`. Returns: `int` (0 on success, <0 on failure). Notes: Uses `pthread_getaffinity_np(3)` on Unix. Not atomic on Windows. Unsupported on macOS. (versionadded: 1.45.0) uv_thread_getcpu(void): Description: Gets the CPU number on which the calling thread is running. Returns: `int` (CPU number). Notes: Currently only implemented on Windows, Linux and FreeBSD. (versionadded: 1.45.0) uv_thread_self(void): Description: Returns the `uv_thread_t` for the calling thread. Returns: `uv_thread_t` (thread ID). uv_thread_join(uv_thread_t *tid): Description: Waits for the ``` -------------------------------- ### Install alt:V JS Module v2 Natives Typings Source: https://github.com/altmp/altv-js-module-v2/blob/dev/types/natives/README.md Install the alt:V JS module v2 natives type definitions package using npm. This package provides type definitions for JavaScript/TypeScript projects. ```Shell npm i -D @altv/natives ``` -------------------------------- ### C Function: uv_fs_mkdir Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs.rst This function creates a directory, similar to the POSIX `mkdir(2)` system call. Note that the `mode` argument, which specifies permissions, is currently not implemented on Windows. ```C int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) ``` -------------------------------- ### Initialize UDP handle (uv_udp_init) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/udp.rst Initializes a new UDP handle. The actual socket creation is deferred until needed. Returns 0 on successful initialization. ```APIDOC int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) Initialize a new UDP handle. The actual socket is created lazily. Returns 0 on success. ``` -------------------------------- ### APIDOC: uv_is_active Function Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/handle.rst Documents the `uv_is_active` function, which determines if a handle is currently active. The definition of 'active' varies by handle type; for I/O handles, it means performing an I/O operation, while for others like `uv_check_t`, it means being started by its respective `start()` function. ```APIDOC uv_is_active(const uv_handle_t* handle): int Description: Returns non-zero if the handle is active, zero if it's inactive. What "active" means depends on the type of handle: - A uv_async_t handle is always active and cannot be deactivated, except by closing it with uv_close(). - A uv_pipe_t, uv_tcp_t, uv_udp_t, etc. handle - basically any handle that deals with i/o - is active when it is doing something that involves i/o, like reading, writing, connecting, accepting new connections, etc. - A uv_check_t, uv_idle_t, uv_timer_t, etc. handle is active when it has been started with a call to uv_check_start(), uv_idle_start(), etc. Rule of thumb: if a handle of type `uv_foo_t` has a `uv_foo_start()` function, then it's active from the moment that function is called. Likewise, `uv_foo_stop()` deactivates the handle again. ``` -------------------------------- ### C API: uv_process_options_t Structure for Process Spawning Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/process.rst Defines the configuration options for spawning a new child process using `uv_spawn`. This structure includes fields for an exit callback, executable file path, command-line arguments, environment variables, current working directory, process flags, standard I/O setup, and user/group IDs for privilege control. ```C typedef struct uv_process_options_s { uv_exit_cb exit_cb; const char* file; char** args; char** env; const char* cwd; unsigned int flags; int stdio_count; uv_stdio_container_t* stdio; uv_uid_t uid; uv_gid_t gid; } uv_process_options_t; ``` -------------------------------- ### C API: Get Parent Process ID Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Returns the parent process ID. This function was added in version 1.16.0. ```APIDOC uv_pid_t uv_os_getppid(void) Returns: uv_pid_t (The parent process ID) ``` -------------------------------- ### Import Modules and Initialize DOM Event Listener Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/v8/tools/parse-processor.html This snippet handles module imports for the ParseProcessor and related constants. It also initializes the Google Charts library and sets up a 'DOMContentLoaded' event listener to focus on the upload input field when the page finishes loading. ```javascript import { ParseProcessor, kSecondsToMillis, BYTES, PERCENT } from "./parse-processor.mjs"; google.charts.load('current', {packages: ['corechart']}); function $(query) { return document.querySelector(query); } window.addEventListener('DOMContentLoaded', (event) => { $("#uploadInput").focus(); }); ``` -------------------------------- ### C API: Get Current Process ID Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Returns the current process ID. This function was added in version 1.18.0. ```APIDOC uv_pid_t uv_os_getpid(void) Returns: uv_pid_t (The current process ID) ``` -------------------------------- ### APIDOC: uv_fs_t.loop Member Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs.rst The event loop that started this file system request and where its completion will be reported. This member is read-only. ```APIDOC uv_loop_t* uv_fs_t.loop ``` -------------------------------- ### Build Specific Xmake Target Source: https://github.com/altmp/altv-js-module-v2/blob/dev/docs/building.md This command allows building a particular target within the project. Replace with an available target like 'client' or 'server' to compile only that component. ```Shell xmake build ``` -------------------------------- ### Get file descriptor for a libuv handle Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/handle.rst Gets the platform-dependent file descriptor equivalent for the given handle. This function supports TCP, pipes, TTY, UDP, and poll handles. Passing any other handle type will result in `UV_EINVAL`. If a handle does not yet have an attached file descriptor or if the handle itself has been closed, this function will return `UV_EBADF`. Caution: Be very careful when using this function, as libuv assumes it controls the file descriptor, and any external changes may lead to malfunction. ```APIDOC int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) handle: The handle (TCP, pipe, TTY, UDP, poll). fd: Pointer to `uv_os_fd_t` to store the file descriptor. Returns: 0 on success, negative error code on failure (e.g., `UV_EINVAL`, `UV_EBADF`). ``` -------------------------------- ### Get Loop Data Pointer (uv_loop_get_data) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/loop.rst Returns the `data` pointer associated with the event loop, which can be used to store arbitrary user-defined data. ```APIDOC void* uv_loop_get_data(const uv_loop_t* loop) Version Added: 1.19.0 Returns: void* (the loop's data pointer) ``` -------------------------------- ### Get File System Request Type: uv_fs_get_type Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs.rst Returns the `fs_type` field from the `uv_fs_t` request structure. Added in version 1.19.0. ```C uv_fs_type uv_fs_get_type(const uv_fs_t* req) ``` -------------------------------- ### C API: Get Current Time (uv_gettimeofday) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Provides a cross-platform implementation of gettimeofday(2). The timezone argument to gettimeofday() is not supported, as it is considered obsolete. ```C int uv_gettimeofday(uv_timeval64_t* tv) ``` ```APIDOC Parameters: tv: Pointer to a uv_timeval64_t structure to store the current time. Returns: 0 on success, or a non-zero error value on failure. ``` -------------------------------- ### C Function: Get TTY Window Size Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/tty.rst Retrieves the current window size of the TTY. On success, it returns 0 and populates the width and height pointers. ```APIDOC int uv_tty_get_winsize(uv_tty_t* handle, int* width, int* height) handle: uv_tty_t* - The TTY handle. width: int* - Pointer to store the window width. height: int* - Pointer to store the window height. Returns: int - 0 on success. ``` -------------------------------- ### Get Poll Timeout (uv_backend_timeout) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/loop.rst Retrieves the current poll timeout value for the event loop. The return value indicates the timeout in milliseconds, or -1 if there is no timeout. ```APIDOC int uv_backend_timeout(const uv_loop_t* loop) Returns: int (timeout in milliseconds, or -1 for no timeout) ``` -------------------------------- ### CMake Configuration of Linker Libraries Source: https://github.com/altmp/altv-js-module-v2/blob/dev/client/CMakeLists.txt This snippet defines the libraries required for linking the project. It includes platform-specific binaries like `Winmm.lib` and `DbgHelp.lib`, along with the V8 JavaScript engine's monolithic library, conditionally selecting debug or release versions based on the build configuration. ```CMake set(ALTV_JS_LINKS # Platform binaries Winmm.lib DbgHelp.lib shlwapi.lib # V8 ${ALTV_JSV2_DEPS_DIR}/v8/lib/$,Debug,Release>/v8_monolith.lib ) ``` -------------------------------- ### Libuv Stream Handle API Functions Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/stream.rst Provides functions for managing stream connections, including shutting down, listening for, accepting, and starting reads on duplex communication channels. ```APIDOC uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb): Shutdown the outgoing (write) side of a duplex stream. It waits for pending write requests to complete. req: An uninitialized shutdown request struct. handle: An initialized stream handle. cb: Callback called after shutdown is complete. uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb): Start listening for incoming connections. stream: The stream handle to listen on. backlog: Indicates the number of connections the kernel might queue, same as "listen(2)". cb: Callback called when a new incoming connection is received. uv_accept(uv_stream_t* server, uv_stream_t* client): Used in conjunction with "uv_listen" to accept incoming connections. Call this function after receiving a "uv_connection_cb" to accept the connection. Before calling this function the client handle must be initialized. < 0 return value indicates an error. server: The server stream handle. client: The client handle (must be initialized). Note: "server" and "client" must be handles running on the same loop. Note: When the "uv_connection_cb" callback is called it is guaranteed that this function will complete successfully the first time. If you attempt to use it more than once, it may fail. It is suggested to only call this function once per "uv_connection_cb" call. uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb): Start reading data from a stream. stream: The stream handle to read from. alloc_cb: Callback to allocate buffer for reading. read_cb: Callback called when data is read. ``` -------------------------------- ### C Type: uv_lib_t Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/dll.rst Shared library data type. ```APIDOC uv_lib_t ``` -------------------------------- ### Get Stream Write Queue Size (libuv C) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/stream.rst Returns the current size of the stream's write queue, which indicates the amount of data currently buffered for writing. ```APIDOC size_t uv_stream_get_write_queue_size(const uv_stream_t* stream) stream: The stream handle. Returns: The size of the write queue. ``` -------------------------------- ### C Function: uv_set_process_title Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Sets the current process title. uv_setup_args must be called beforehand on Unix and AIX systems, otherwise UV_ENOBUFS is returned. On platforms with fixed-size buffers, the title will be truncated if too long. Other platforms may return UV_ENOMEM if memory cannot be allocated. ```APIDOC int uv_set_process_title(const char* title) Description: Sets the current process title. You must call uv_setup_args before calling this function on Unix and AIX systems. If uv_setup_args has not been called on systems that require it, then UV_ENOBUFS is returned. On platforms with a fixed size buffer for the process title the contents of title will be copied to the buffer and truncated if larger than the available space. Other platforms will return UV_ENOMEM if they cannot Parameters: title: The new process title. Returns: int (0 on success, UV_ENOBUFS if uv_setup_args not called, UV_ENOMEM on allocation failure on some platforms.) ``` -------------------------------- ### UV_FS_O_SYMLINK Macro Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/fs.rst Opens the symbolic link itself rather than the resource it points to. ```APIDOC Macro: UV_FS_O_SYMLINK Description: Open the symbolic link itself rather than the resource it points to. ``` -------------------------------- ### Get event loop associated with a libuv handle Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/handle.rst Returns the `uv_loop_t` instance that the given handle is associated with. This function was added in libuv version 1.19.0. ```APIDOC uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle) handle: The handle. Returns: A pointer to the `uv_loop_t` instance associated with the handle. ``` -------------------------------- ### APIDOC: uv_get_available_memory Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Gets the amount of free memory still available to the process (in bytes), considering OS-imposed limits. If no such constraint exists or is unknown, the returned amount will be identical to uv_get_free_memory. ```APIDOC Function: uint64_t uv_get_available_memory(void) Description: Gets the amount of free memory that is still available to the process (in bytes), taking into account any limits imposed by the OS. Returns: uint64_t: Amount of free memory in bytes. Notes: - If no constraint or unknown, identical to uv_get_free_memory. - Currently returns a different value from uv_get_free_memory only on Linux (cgroups). Version Added: 1.45.0 ``` -------------------------------- ### C API: Convert Network Address to Presentation (inet_ntop) Source: https://github.com/altmp/altv-js-module-v2/blob/dev/server/deps/nodejs/deps/uv/docs/src/misc.rst Cross-platform IPv6-capable implementation of `inet_ntop(3)`. On success, returns 0. In case of error, the target `dst` pointer is unmodified. ```APIDOC int uv_inet_ntop(int af, const void* src, char* dst, size_t size) af: Address family (e.g., AF_INET, AF_INET6). src: Pointer to the network address structure. dst: Buffer to store the resulting presentation string. size: Size of the destination buffer. Returns: int (0 on success, <0 on error) ```