### Lua Compatibility File Format Example (JavaScript) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt Illustrates the expected Lua format for compatibility files, showing versioning and compatibility mappings for native functions based on their hash and signature. ```javascript // Output format (natives_global_client_compat.lua): // version = { 2, 0, 642, 3 } // compatibility = { // [0x3FEF770D40960D5A] = { // { "Vector3", "ulong", "ulong" }, // { "Vector3", "ulong", "ulong", "ulong" } // if signature changed // }, // [0x1234567890ABCDEF] = { // { "void", "ulong", "string" } // } // } ``` -------------------------------- ### Verify Single Native Definition File (Bash) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt Validates a single markdown file representing a native definition against the parsing pipeline. Provides examples for validating a file and describes the exit codes for success and different error conditions. ```bash # Validate a native definition file node verify-one.js data/example.md # Output (colored JSON): # { # "name": "GET_ENTITY_COORDS", # "params": [...], # "results": "Vector3", # "hash": "0x3FEF770D40960D5A", # "jhash": "0x1647F1CB" # } # Exit codes: # 0 - Success # 1 - Parse error # 2 - Invalid arguments ``` -------------------------------- ### Get Player Coordinates (Lua, JS, C#) Source: https://github.com/citizenfx/native-doc-tooling/blob/master/data/example.md Demonstrates how to get the player's current coordinates using the GET_ENTITY_COORDS native function across different scripting languages. This function returns a Vector3 object or an array of coordinates. ```lua local playerCoords = GetEntityCoords(PlayerPedId()) print(playerCoords) -- vector3(...) ``` ```javascript const [playerX, playerY, playerZ] = GetEntityCoords(PlayerPedId()); console.log(`${playerX}, ${playerY}, ${playerZ}`); ``` ```csharp using static CitizenFX.Core.API; // ... Vector3 playerCoords = GetEntityCoords(PlayerPedId()); // or Vector3 playerCoords = Game.PlayerPed.Position; ``` -------------------------------- ### Get Entity Coordinates (C++) Source: https://github.com/citizenfx/native-doc-tooling/blob/master/data/example.md Retrieves the current world coordinates (x, y, z) for a given entity. The 'alive' parameter is noted as unused in game builds but may have had a purpose in debug versions. ```cpp // 0x3FEF770D40960D5A 0x1647F1CB Vector3 GET_ENTITY_COORDS(Entity entity, BOOL alive); ``` -------------------------------- ### GET_ENTITY_COORDS Source: https://github.com/citizenfx/native-doc-tooling/blob/master/data/example.md Retrieves the current coordinates of a specified entity. This function is useful for getting the position of any entity in the game world. ```APIDOC ## GET_ENTITY_COORDS ### Description Gets the current coordinates for a specified entity. ### Method GET ### Endpoint `/citizenfx/natives/GET_ENTITY_COORDS` ### Parameters #### Path Parameters - **entity** (Entity) - Required - The entity to get the coordinates from. - **alive** (BOOL) - Optional - Unused by the game, potentially used by debug builds of GTA in order to assert whether or not an entity was alive. ### Request Example ```json { "entity": "ENTITY_ID", "alive": true } ``` ### Response #### Success Response (200) - **coordinates** (Vector3) - The current entity coordinates. #### Response Example ```json { "coordinates": { "x": 123.45, "y": 678.90, "z": 50.0 } } ``` ``` -------------------------------- ### Parse Native Function Signatures from Markdown (JavaScript) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt This snippet uses the unified, remark-frontmatter, remark-parse-yaml, remark-parse, and native-compiler modules to parse markdown files containing C function signatures and YAML frontmatter. It extracts native function data including name, hash, parameters, return types, and examples, outputting a structured JSON object. ```javascript const unified = require('unified'); const frontmatter = require('remark-frontmatter'); const rpm = require('remark-parse-yaml'); const rp = require('remark-parse'); const makeNative = require('./native-compiler'); const processor = unified() .use(rp) .use(frontmatter) .use(rpm) .use(makeNative) .freeze(); const nativeData = processor.processSync(fs.readFileSync('data/example.md')); // Output structure: // { // name: 'GET_ENTITY_COORDS', // hash: '0x3FEF770D40960D5A', // jhash: '0x1647F1CB', // params: [ // { name: 'entity', type: 'Entity', description: 'The entity to get...' }, // { name: 'alive', type: 'BOOL', description: 'Unused by the game...' } // ], // results: 'Vector3', // resultsDescription: 'The current entity coordinates.', // examples: [ // { lang: 'lua', code: 'local playerCoords = GetEntityCoords(PlayerPedId())...' }, // { lang: 'js', code: 'const [playerX, playerY, playerZ] = ...' } // ] // } ``` -------------------------------- ### Generate XML Sitemap for Native Functions (JavaScript) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt Generates an XML sitemap for all documented native functions by recursively reading markdown files, processing them with a worker farm, and using a sitemap stream. Dependencies include 'recursive-readdir', 'sitemap', 'stream', and 'worker-farm'. ```javascript const recursive = require('recursive-readdir'); const { SitemapStream, streamToPromise } = require('sitemap'); const { Readable } = require('stream'); const workerFarm = require('worker-farm'); const workers = workerFarm(require.resolve('./worker')); const links = []; recursive('./natives', ['.*', '!*.md', 'README.md'], (err, files) => { for (const file of files) { workers(file, (err, nativeData) => { const mtime = fs.statSync(file).mtime; const native = nativeData.result; links.push({ url: 'https://docs.fivem.net/natives/?_' + native.hash, lastmod: mtime.toISOString() }); if (++ret >= files.length) { const stream = new SitemapStream({ hostname: 'https://docs.fivem.net/natives/' }); streamToPromise(Readable.from(links).pipe(stream)) .then(data => console.log(data.toString())); workerFarm.end(workers); } }); } }); ``` -------------------------------- ### Generate Lua Compatibility Files from Git History (Bash) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt Analyzes git history to track native function signature changes and generates Lua compatibility files. Supports options for using full history, forcing output, specifying output file, setting version numbers, and ignoring missing input files. ```bash # Generate compatibility file from latest commit node compatgen.js # Use full git history starting from specific date node compatgen.js --use-history --start-date=2023-01-01 # Force output even if no changes detected node compatgen.js --force --out=natives_compat.lua # Set custom version numbering node compatgen.js --set-version=2.0.3.4 # Ignore missing input file on first run node compatgen.js --ignore-missing-in --in=skip ``` -------------------------------- ### Generate Lua/HTML Output with Twing Templates (JavaScript) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt Generates output in Lua or HTML using Twing templates. It includes custom Twing filters for making native function names and for Markdown processing with syntax highlighting. Dependencies include 'twing', 'fs', and 'remark' with plugins. ```javascript const fs = require('fs'); const Twing = require('twing'); let natives = JSON.parse(fs.readFileSync('natives_test.json')); const loader = new Twing.TwingLoaderFilesystem(__dirname + '/views/'); const env = new Twing.TwingEnvironment(loader, { autoescape: false }); // Add custom filters env.addFilter(new Twing.TwingFilter('makenative', async input => { return input.toLowerCase().replace('0x', 'n_0x') .replace(/_([a-z])/g, (sub, bit) => bit.toUpperCase()); })); env.addFilter(new Twing.TwingFilter('mdify', async input => { return remark() .use(highlight) .use(html) .processSync(input) .toString(); })); // Generate Lua output const out = await env.render('lua.twig', { natives }); process.stdout.write(out); // Or generate HTML reference const htmlOut = await env.render('reference.twig', { natives }); ``` -------------------------------- ### Process Multiple Markdown Files in Parallel (JavaScript) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt This script utilizes 'recursive-readdir' and 'worker-farm' to process numerous markdown files concurrently, building a comprehensive natives database. It sends each file to a worker process for compilation and aggregates the results into a JSON structure, writing the final output to 'natives_test.json'. ```javascript const recursive = require('recursive-readdir'); const workerFarm = require('worker-farm'); const workers = workerFarm(require.resolve('./worker')); const natives = {}; let processed = 0; recursive('./natives', ['.*', '!*.md', 'README.md'], (err, files) => { for (const file of files) { workers(file, (err, nativeData) => { if (err) { console.log(err); process.exit(1); return; } const native = nativeData.result; if (!natives[native.ns]) { natives[native.ns] = {}; } natives[native.ns][native.hash] = native; ++processed; if (processed >= files.length) { fs.writeFileSync('natives_test.json', JSON.stringify(natives)); workerFarm.end(workers); } }); } }); ``` -------------------------------- ### Parse C AST and Extract Type Information (JavaScript) Source: https://context7.com/citizenfx/native-doc-tooling/llms.txt This module leverages the 'libclang' library to parse C function declarations from source files. It extracts detailed information about functions, including their names, return types, parameters (with names and types), and any associated annotations like 'since' or 'until'. It can also parse enum definitions. ```javascript const libclang = require('libclang'); const cast = require('./c-ast'); // Parse C code from file const cData = cast('temp_file.cpp'); // Returns: // { // Functions: [ // { // Name: 'GET_ENTITY_COORDS', // Return: 'Vector3', // Parameters: [ // { name: 'entity', type: 'Entity', annotations: undefined }, // { name: 'alive', type: 'BOOL', annotations: undefined } // ], // Annotations: { since: '1.0', until: '2.0' } // if present // } // ], // Enums: [ // { // name: 'EntityType', // values: [ // { name: 'PED', value: 1 }, // { name: 'VEHICLE', value: 2 } // ] // } // ] // } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.