### Build and Install Lune from Source Source: https://github.com/lune-org/lune/wiki/Getting Started - 1 Installation Compile and install Lune directly from its source code. Requires Rust and Cargo to be installed. ```sh cargo install lune --locked ``` -------------------------------- ### Luau While Loop Example Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Translates the Bash while loop example to Luau, showing equivalent functionality. ```lua local valid = true local count = 1 while valid do print(count) if count == 5 then break end count += 1 end ``` -------------------------------- ### Install Lune with Aftman Source: https://github.com/lune-org/lune/wiki/Getting Started - 1 Installation Use this command to add Lune to your project's dependencies via Aftman. It will update or create an `aftman.toml` file. ```sh aftman add filiptibell/lune ``` -------------------------------- ### Bash While Loop Example Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Demonstrates a basic while loop in Bash that counts to 5 and breaks. ```bash #!/bin/bash VALID=true COUNT=1 while [ $VALID ] do echo $COUNT if [ $COUNT -eq 5 ]; then break fi ((COUNT++)) done ``` -------------------------------- ### serve Source: https://github.com/lune-org/lune/wiki/API Reference - Net Creates an HTTP server that listens on the given `port`. ```APIDOC ## serve ### Description Creates an HTTP server that listens on the given `port`. This will ***not*** block and will keep listening for requests on the given `port` until the `stop` function on the returned `NetServeHandle` has been called. ### Parameters * **port** (number) - The port number to listen on. ### Response * Returns a `NetServeHandle` object with a `stop` function. ``` -------------------------------- ### Import and Use Modules in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Demonstrates how to import and use functions from another module using path-relative imports. Requires the module to be structured correctly. ```lua --[[ EXAMPLE #5 Using a function from another module / script Lune has path-relative imports, similar to other popular languages such as JavaScript ]] local module = require("../modules/module") module.sayHello() ``` -------------------------------- ### Set up Lua Environment with Async Functions Source: https://github.com/lune-org/lune/blob/main/crates/mlua-luau-scheduler/README.md Initializes a new Lua environment and exposes asynchronous functions 'sleep' and 'readFile' to Lua. 'sleep' uses async_io::Timer for delays, and 'readFile' uses async_fs::read_to_string, spawning the file reading operation as a background task. ```rust let lua = Lua::new(); lua.globals().set( "sleep", lua.create_async_function(|_, duration: f64| async move { let before = Instant::now(); let after = Timer::after(Duration::from_secs_f64(duration)).await; Ok((after - before).as_secs_f64()) })?, ); lua.globals().set( "readFile", lua.create_async_function(|lua, path: String| async move { // Spawn background task that does not take up resources on the lua thread let task = lua.spawn(async move { match read_to_string(path).await { Ok(s) => Ok(Some(s)), Err(e) if e.kind() == ErrorKind::NotFound => Ok(None), Err(e) => Err(e), } }); task.await.into_lua_err() })?, ); ``` -------------------------------- ### Write with Style Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Use stdio.style to set text style and stdio.write to output it. Remember to reset the style afterwards. ```lua stdio.write(stdio.style("bold")) print("This text will be bold") stdio.write(stdio.style("reset")) print("This text will be normal") ``` -------------------------------- ### Create a new Roblox place file from scratch Source: https://github.com/lune-org/lune/wiki/Roblox Creates a new DataModel instance, populates it with nested Models and Parts, and saves it as a place file. This demonstrates creating instances that are not typically accessible in the Roblox engine. ```lua local roblox = require("@lune/roblox") local Instance = roblox.Instance -- You can even create a new DataModel using Instance.new, which is not normally possible in Roblox -- This is normal - most instances that are not normally accessible in Roblox can be manipulated using Lune! local game = Instance.new("DataModel") local workspace = game:GetService("Workspace") -- Here we just make a bunch of models with parts in them for demonstration purposes for i = 1, 50 do local model = Instance.new("Model") model.Name = "Model #" .. tostring(i) model.Parent = workspace for j = 1, 4 do local part = Instance.new("Part") part.Name = "Part #" .. tostring(j) part.Parent = model end end -- As always, we have to save the DataModel (game) to a file when we're done roblox.writePlaceFile("myPlaceWithLotsOfModels.rbxl") ``` -------------------------------- ### Write with Color Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Use stdio.color to set text color and stdio.write to output it. Remember to reset the color afterwards. ```lua stdio.write(stdio.color("red")) print("This text will be red") stdio.write(stdio.color("reset")) print("This text will be normal") ``` -------------------------------- ### Generate Luau Types and Docs for LSP Source: https://github.com/lune-org/lune/wiki/Getting Started - 4 Editor Setup Run these commands to generate necessary files for the Luau LSP. These files provide type definitions and documentation for Lune globals, improving editor support. ```bash lune --generate-luau-types ``` ```bash lune --generate-docs-file ``` -------------------------------- ### List Available Lune Scripts Source: https://github.com/lune-org/lune/wiki/Getting Started - 3 Running Scripts Use the `--list` command to display all scripts found in the `lune` or `.lune` directories, including any top-level description comments. ```sh lune --list ``` -------------------------------- ### writeDir Source: https://github.com/lune-org/lune/wiki/API Reference - FS Creates a directory, including any necessary parent directories. Throws an error if the path already exists as a file or directory, permissions are lacking, or an I/O error occurs. ```APIDOC ## writeDir ### Description Creates a directory and its parent directories if they are missing. ### Errors * `path` already points to an existing file or directory. * The current process lacks permissions to create the directory or its missing parents. * Some other I/O error occurred. ``` -------------------------------- ### Configure Selene for Lune Projects Source: https://github.com/lune-org/lune/wiki/Getting Started - 4 Editor Setup Modify your `selene.toml` configuration to specify the Luau standard library and Lune integration. Choose the appropriate `std` setting based on your project's needs. ```yaml # Use this if Lune is the only thing you use Luau files with: std = "luau+lune" # OR use this if your project also contains Roblox-specific Luau code: std = "roblox+lune" # If you are also using the Luau type definitions file, it may cause issues, and can be safely ignored: exclude = ["luneTypes.d.luau"] ``` -------------------------------- ### Generate Selene Types for Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 4 Editor Setup Execute this command to generate a Selene type definition file for Lune. This file helps Selene understand Lune-specific syntax and globals. ```bash lune --generate-selene-types ``` -------------------------------- ### stdio.prompt Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Displays a prompt to the user and captures their input. Supports various prompt types including text, confirmation, single selection, and multi-selection. ```APIDOC ## stdio.prompt ### Description Prompts for user input using the wanted kind of prompt: * `"text"` - Prompts for a plain text string from the user * `"confirm"` - Prompts the user to confirm with y / n (yes / no) * `"select"` - Prompts the user to select *one* value from a list * `"multiselect"` - Prompts the user to select *one or more* values from a list * `nil` - Equivalent to `"text"` with no extra arguments ``` -------------------------------- ### Manage Environment Variables in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Read and check the existence of environment variables. Demonstrates direct access and iteration over environment variables, indicating if they are set. ```lua --[[ EXAMPLE #3 Get & set environment variables Checks if environment variables are empty or not, prints out ❌ if empty and ✅ if they have a value ]] print("Reading current environment 🔎") -- Environment variables can be read directly assert(process.env.PATH ~= nil, "Missing PATH") assert(process.env.PWD ~= nil, "Missing PWD") -- And they can also be accessed using Luau's generalized iteration (but not pairs()) for key, value in process.env do local box = if value and value ~= "" then "✅" else "❌" print(string.format("[%s] %s", box, key)) end ``` -------------------------------- ### Prompt User Input with stdio in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Utilize the stdio library to prompt the user for text input and confirmation. Handles user responses and can trigger errors. ```lua --[[ EXAMPLE #2 Using the stdio library to prompt for terminal input ]] local text = stdio.prompt("text", "Please write some text") print("You wrote '" .. text .. "'!") local confirmed = stdio.prompt("confirm", "Please confirm that you wrote some text") if confirmed == false then error("You didn't confirm!") else print("Confirmed!") end ``` -------------------------------- ### Write a Module in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Create a simple Lua module by defining functions within a table and returning it. This allows for code organization and reusability. ```lua --[[ EXAMPLE #4 Writing a module Modularizing and splitting up your code is Lune is very straight-forward, in contrast to other scripting languages and shells such as bash ]] local module = {} function module.sayHello() print("Hello, Lune! 🌙") end return module ``` -------------------------------- ### print Source: https://github.com/lune-org/lune/wiki/API Reference - Uncategorized Prints given value(s) to stdout, formatting and prettifying them. ```APIDOC ## print ### Description Prints given value(s) to stdout. This will format and prettify values such as tables, numbers, booleans, and more. ### Method print(...values: any[]) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Spawn Concurrent Tasks in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Initiate concurrent tasks using `task.spawn` and schedule delayed tasks with `task.delay`. Allows for non-blocking operations and basic multitasking. ```lua --[[ EXAMPLE #6 Spawning concurrent tasks These tasks will run at the same time as other Lua code which lets you do primitive multitasking ]] task.spawn(function() print("Spawned a task that will run instantly but not block") task.wait(5) end) print("Spawning a delayed task that will run in 5 seconds") task.delay(5, function() print("...") task.wait(1) print("Hello again!") task.wait(1) print("Goodbye again! 🌙") end) ``` -------------------------------- ### Anchor all parts in a Roblox place file Source: https://github.com/lune-org/lune/wiki/Roblox Reads a place file, anchors all BasePart instances in the workspace, and saves the modified file. Ensure the place file exists before running. ```lua local roblox = require("@lune/roblox") -- Read the place file called myPlaceFile.rbxl into a DataModel called "game" -- This works exactly the same as in Roblox, except "game" does not exist by default - you have to load it from a file! local game = roblox.readPlaceFile("myPlaceFile.rbxl") local workspace = game:GetService("Workspace") -- Make all of the parts in the workspace anchored for _, descendant in workspace:GetDescendants() do if descendant:IsA("BasePart") then descendant.Anchored = true end end -- Save the DataModel (game) back to the file that we read it from roblox.writePlaceFile("myPlaceFile.rbxl") ``` -------------------------------- ### Instance Class Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Provides methods for manipulating Roblox instances. ```APIDOC ## Instance Class ### Description Represents a Roblox Instance. Provides methods for common instance operations. ### Implemented APIs - `Instance.new(className: string): Instance` - `Instance:Clone(): Instance` - `Instance:Destroy(): void` - `Instance:ClearAllChildren(): void` - `Instance:FindFirstAncestor(name: string): Instance?` - `Instance:FindFirstAncestorOfClass(className: string): Instance?` - `Instance:FindFirstAncestorWhichIsA(className: string): Instance?` - `Instance:FindFirstChild(name: string): Instance?` - `Instance:FindFirstChildOfClass(className: string): Instance?` - `Instance:FindFirstChildWhichIsA(className: string): Instance?` - `Instance:FindFirstDescendant(name: string): Instance?` - `Instance:GetChildren(): {Instance}` - `Instance:GetDescendants(): {Instance}` - `Instance:GetFullName(): string` - `Instance:IsA(className: string): boolean` - `Instance:IsAncestorOf(instance: Instance): boolean` - `Instance:IsDescendantOf(instance: Instance): boolean` ### Planned APIs - `Instance:GetAttribute(name: string): any` - `Instance:GetAttributes(): {[string]: any}` - `Instance:SetAttribute(name: string, value: any): void` ``` -------------------------------- ### stdio.format Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Formats provided arguments into a human-readable string, including syntax highlighting for tables. ```APIDOC ## stdio.format ### Description Formats arguments into a human-readable string with syntax highlighting for tables. ``` -------------------------------- ### Pretty Printing with stdio in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Utilize the stdio library for colored output and auto-formatting. This enhances readability of console logs, especially for complex data structures. ```lune print("Printing with pretty colors and auto-formatting 🎨") print(stdio.color("blue") .. string.rep("—", 22) .. stdio.color("reset")) info("API response:", apiResponse) warn({ Oh = { No = { TooMuch = { Nesting = { "Will not print", }, }, }, }, }) print(stdio.color("blue") .. string.rep("—", 22) .. stdio.color("reset")) ``` -------------------------------- ### Run a Lune Script from Stdin Source: https://github.com/lune-org/lune/wiki/Getting Started - 3 Running Scripts Execute a script by piping its content to Lune using stdin. This is useful for running scripts from external sources. ```sh lune - ``` -------------------------------- ### Run a Lune Script Source: https://github.com/lune-org/lune/wiki/Getting Started - 3 Running Scripts Execute a Lune script file by its name. Lune will search for the file in the current directory and specific subdirectories. ```sh lune script-name ``` -------------------------------- ### Read Directory Entries in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts List files and directories in the current directory using `fs.readDir`. Includes sorting logic to prioritize directories and alphabetical order. ```lua --[[ EXAMPLE #7 Read files in the current directory This prints out directory & file names with some fancy icons ]] print("Reading current dir đŸ—‚ī¸") local entries = fs.readDir(".") -- NOTE: We have to do this outside of the sort function -- to avoid yielding across the metamethod boundary, all -- of the filesystem APIs are asynchronous and yielding local entryIsDir = {} for _, entry in entries do entryIsDir[entry] = fs.isDir(entry) end -- Sort prioritizing directories first, then alphabetically table.sort(entries, function(entry0, entry1) if entryIsDir[entry0] ~= entryIsDir[entry1] then return entryIsDir[entry0] end return entry0 < entry1 end) -- Make sure we got some known files that should always exist assert(table.find(entries, "Cargo.toml") ~= nil, "Missing Cargo.toml") assert(table.find(entries, "Cargo.lock") ~= nil, "Missing Cargo.lock") -- Print the pretty stuff for _, entry in entries do if fs.isDir(entry) then print("📁 " .. entry) else print("📄 " .. entry) end end ``` -------------------------------- ### Configure VSCode for Luau LSP Source: https://github.com/lune-org/lune/wiki/Getting Started - 4 Editor Setup Update your VSCode settings to integrate Luau LSP with Lune. This involves specifying the require mode, and pointing to the generated type definition and documentation files. ```json { "luau-lsp.require.mode": "relativeToFile", // Set the require mode to work with Lune "luau-lsp.types.definitionFiles": ["luneTypes.d.luau"], // Add type definitions for Lune globals "luau-lsp.types.documentationFiles": ["luneDocs.json"] // Add documentation for Lune globals } ``` -------------------------------- ### Process Spawned Program Output in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Handle the result of `process.spawn`, checking for success, and parsing standard output using Lua's string matching. Exits the process with an appropriate code on failure. ```lua --[[ EXAMPLE #9 Using the result of a spawned process, exiting the process This looks scary with lots of weird symbols, but, it's just some Lua-style pattern matching to parse the lines of "min/avg/max/stddev = W/X/Y/Z ms" that the ping program outputs to us ]] if result.ok then assert(#result.stdout > 0, "Result output was empty") local min, avg, max, stddev = string.match( result.stdout, "min/avg/max/stddev = ([%d%.]+)/([%d%.]+)/([%d%.]+)/([%d%.]+) ms" ) print(string.format("Minimum ping time: %.3fms", assert(tonumber(min)))) print(string.format("Maximum ping time: %.3fms", assert(tonumber(max)))) print(string.format("Average ping time: %.3fms", assert(tonumber(avg)))) print(string.format("Standard deviation: %.3fms", assert(tonumber(stddev)))) else print("Failed to send ping to google!") print(result.stderr) process.exit(result.code) end ``` -------------------------------- ### task.spawn Source: https://github.com/lune-org/lune/wiki/API Reference - Task Instantly runs a thread or function. If the spawned task yields, the thread that spawned the task will resume, letting the spawned task run in the background. ```APIDOC ## task.spawn ### Description Instantly runs a thread or function. If the spawned task yields, the thread that spawned the task will resume, letting the spawned task run in the background. ### Method `task.spawn(thread_or_function)` ### Parameters #### Path Parameters - **thread_or_function** (Thread | Function) - Required - The thread or function to spawn. ``` -------------------------------- ### socket Source: https://github.com/lune-org/lune/wiki/API Reference - Net Connects to a web socket at the given URL. ```APIDOC ## socket ### Description Connects to a web socket at the given URL. Throws an error if the server at the given URL does not support web sockets, or if a miscellaneous network or I/O error occurs. ### Parameters * **url** (string) - The URL of the web socket. ### Response * Returns a handle to the web socket connection. ``` -------------------------------- ### Process Properties Source: https://github.com/lune-org/lune/wiki/API Reference - Process Provides information about the current process environment. ```APIDOC ## Process Properties ### arch The architecture of the processor currently being used. Possible values: * `"x86_64"` * `"aarch64"` ### cwd The current working directory in which the Lune script is running. ### os The current operating system being used. Possible values: * `"linux"` * `"macos"` * `"windows"` ``` -------------------------------- ### Execute External Programs in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Call external executables using `process.spawn`, passing arguments as a table. Useful for integrating with other system tools. ```lua --[[ EXAMPLE #8 Call out to another program / executable You can also get creative and combine this with example #6 to spawn several programs at the same time! ]] print("Sending 4 pings to google 🌏") local result = process.spawn("ping", { "google.com", "-c 4", }) ``` -------------------------------- ### writeFile Source: https://github.com/lune-org/lune/wiki/API Reference - FS Writes data to a file at the specified path. Throws an error if the parent directory does not exist, permissions are lacking, or an I/O error occurs. ```APIDOC ## writeFile ### Description Writes to a file at `path`. ### Errors * The file's parent directory does not exist. * The current process lacks permissions to write to the file. * Some other I/O error occurred. ``` -------------------------------- ### Read Roblox Place File Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Reads a place file into a DataModel instance. Ensure the correct file path is provided. ```lua local roblox = require("@lune/roblox") local game = roblox.readPlaceFile("filePath.rbxl") ``` -------------------------------- ### Run Lua Threads on the Scheduler Source: https://github.com/lune-org/lune/blob/main/crates/mlua-luau-scheduler/README.md Creates a new Scheduler, loads Lua code into threads for 'sleep' and 'readFile', pushes these threads onto the scheduler's front, and then runs the scheduler until all threads complete using block_on. ```rust let sched = Scheduler::new(&lua)?; // We can create multiple lua threads ... let sleepThread = lua.load("sleep(0.1)"); let fileThread = lua.load("readFile(\"Cargo.toml\")"); // ... spawn them both onto the scheduler ... sched.push_thread_front(sleepThread, ()); sched.push_thread_front(fileThread, ()); // ... and run until they finish block_on(sched.run()); ``` -------------------------------- ### Save Roblox instances as individual model files Source: https://github.com/lune-org/lune/wiki/Roblox Loads a place file, iterates through its children in the Workspace, and saves each child as a separate model file in a specified directory. The target directory will be created if it doesn't exist. ```lua local roblox = require("@lune/roblox") local fs = require("@lune/fs") -- Here we load a file just like in the first example local game = roblox.readPlaceFile("myPlaceFile.rbxl") local workspace = game:GetService("Workspace") -- We use a normal Lune API to make sure a directory exists to save our models in fs.writeDir("models") -- Then we save all of our instances in Workspace as model files, in our new directory -- Note that a model file can actually contain several instances at once, so we pass a table here for _, child in workspace:GetChildren() do roblox.writeModelFile("models/" .. child.Name, { child }) end ``` -------------------------------- ### warn Source: https://github.com/lune-org/lune/wiki/API Reference - Uncategorized Prints given value(s) to stdout with a leading [WARN] tag. ```APIDOC ## warn ### Description Prints given value(s) to stdout with a leading `[WARN]` tag. This will format and prettify values such as tables, numbers, booleans, and more. ### Method warn(...values: any[]) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Pass Arguments to a Lune Script Source: https://github.com/lune-org/lune/wiki/Getting Started - 3 Running Scripts Provide command-line arguments to a Lune script when running it. These arguments are accessible within the script via `process.args`. ```sh lune script-name arg1 arg2 "argument three" ``` ```lua print(process.args) --> { "arg1", "arg2", "argument three" } ``` -------------------------------- ### Write Roblox Place File Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Writes a DataModel instance to a place file. Specify the desired file path and the DataModel to write. ```lua local roblox = require("@lune/roblox") roblox.writePlaceFile("filePath.rbxl", game) ``` -------------------------------- ### Basic Assertions and Printing in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Use assert to validate conditions and print messages to the console. This is useful for debugging and verifying script logic. ```lune assert(apiResponse.title == "foo", "Invalid json response") assert(apiResponse.body == "bar", "Invalid json response") print("Got valid JSON response with changes applied") ``` -------------------------------- ### writePlaceFile Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Writes a DataModel instance to a place file. ```APIDOC ## writePlaceFile ### Description Writes a DataModel instance to a place file. ### Method `roblox.writePlaceFile(filePath: string, game: DataModel): void` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path where the place file will be written. - **game** (DataModel) - Required - The DataModel instance to write. ### Request Example ```lua local roblox = require("@lune/roblox") roblox.writePlaceFile("filePath.rbxl", game) ``` ### Response #### Success Response (void) This function does not return a value. ``` -------------------------------- ### request Source: https://github.com/lune-org/lune/wiki/API Reference - Net Sends an HTTP request using the given url and / or parameters, and returns a dictionary that describes the response received. ```APIDOC ## request ### Description Sends an HTTP request using the given url and / or parameters, and returns a dictionary that describes the response received. Only throws an error if a miscellaneous network or I/O error occurs, never for unsuccessful status codes. ### Parameters * **url** (string) - The URL to send the request to. * **options** (table, optional) - A table of options for the request (e.g., method, headers, body). ### Response * Returns a dictionary describing the response received (e.g., status code, headers, body). ``` -------------------------------- ### move Source: https://github.com/lune-org/lune/wiki/API Reference - FS Moves a file or directory to a new path. Throws an error if the target path already exists, unless overridden by options. Refer to `FsWriteOptions` for details. ```APIDOC ## move ### Description Moves a file or directory to a new path. Throws an error if a file or directory already exists at the target path. This can be bypassed by passing `true` as the third argument, or a dictionary of options. Refer to the documentation for `FsWriteOptions` for specific option keys and their values. ### Errors * The current process lacks permissions to read at `from` or write at `to`. * The new path exists on a different mount point. * Some other I/O error occurred. ``` -------------------------------- ### Process Functions Source: https://github.com/lune-org/lune/wiki/API Reference - Process Functions for controlling the current process and spawning child processes. ```APIDOC ## Process Functions ### exit Exits the currently running script as soon as possible with the given exit code. Exit code 0 is treated as a successful exit, any other value is treated as an error. Setting the exit code using this function will override any otherwise automatic exit code. ### spawn Spawns a child process that will run the program `program`, and returns a dictionary that describes the final status and ouput of the child process. The second argument, `params`, can be passed as a list of string parameters to give to the program. The third argument, `options`, can be passed as a dictionary of options to give to the child process. Refer to the documentation for `ProcessSpawnOptions` for specific option keys and their values. ``` -------------------------------- ### Import Dependencies for mlua-luau-scheduler Source: https://github.com/lune-org/lune/blob/main/crates/mlua-luau-scheduler/README.md Imports necessary modules from std, async_io, async_fs, mlua, and mlua_luau_scheduler for asynchronous operations and Lua integration. ```rust use std::time::{Duration, Instant}; use std::io::ErrorKind; use async_io::{block_on, Timer}; use async_fs::read_to_string; use mlua::prelude::*; use mlua_luau_scheduler::*; ``` -------------------------------- ### Write Roblox Model File Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Writes one or more instances to a model file. Provide the file path and a table containing the instances. ```lua local roblox = require("@lune/roblox") roblox.writeModelFile("filePath.rbxm", { instance1, instance2, ... }) ``` -------------------------------- ### Handle Program Arguments in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Access and process command-line arguments passed to a Lune script. Includes basic validation for the number of arguments. ```lua --[[ EXAMPLE #1 Using arguments given to the program ]] if #process.args > 0 then print("Got arguments:") print(process.args) if #process.args > 3 then error("Too many arguments!") end else print("Got no arguments â˜šī¸") end ``` -------------------------------- ### printinfo Source: https://github.com/lune-org/lune/wiki/API Reference - Uncategorized Prints given value(s) to stdout with a leading [INFO] tag. ```APIDOC ## printinfo ### Description Prints given value(s) to stdout with a leading `[INFO]` tag. This will format and prettify values such as tables, numbers, booleans, and more. ### Method printinfo(...values: any[]) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Network Requests and JSON Handling in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts Perform HTTP PATCH requests using the `net` library, encode request bodies as JSON, and decode JSON responses. Includes error handling for network failures. ```lua --[[ EXAMPLE #10 Using the built-in networking library, encoding & decoding json ]] print("Sending PATCH request to web API 📤") local apiResult = net.request({ url = "https://jsonplaceholder.typicode.com/posts/1", method = "PATCH", headers = { ["Content-Type"] = "application/json", }, body = net.jsonEncode({ title = "foo", body = "bar", }), }) if not apiResult.ok then print("Failed to send network request!") print(string.format("%d (%s)", apiResult.statusCode, apiResult.statusMessage)) print(apiResult.body) process.exit(1) end type ApiResponse = { id: number, title: string, body: string, userId: number, } local apiResponse: ApiResponse = net.jsonDecode(apiResult.body) ``` -------------------------------- ### Read Roblox Model File Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Reads a model file into a table of instances. Provide the correct file path for the model. ```lua local roblox = require("@lune/roblox") local instances = roblox.readModelFile("filePath.rbxm") ``` -------------------------------- ### readFile Source: https://github.com/lune-org/lune/wiki/API Reference - FS Reads the content of a file at the specified path as a UTF-8 string. Throws an error if the path is invalid, permissions are lacking, or an I/O error occurs. ```APIDOC ## readFile ### Description Reads a file at `path`. ### Errors * `path` does not point to an existing file. * The current process lacks permissions to read the file. * The contents of the file cannot be read as a UTF-8 string. * Some other I/O error occurred. ``` -------------------------------- ### writeModelFile Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Writes one or more instances to a model file. ```APIDOC ## writeModelFile ### Description Writes one or more instances to a model file. ### Method `roblox.writeModelFile(filePath: string, instances: {Instance}): void` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path where the model file will be written. - **instances** (Array) - Required - A table containing the instances to write. ### Request Example ```lua local roblox = require("@lune/roblox") roblox.writeModelFile("filePath.rbxm", { instance1, instance2, ... }) ``` ### Response #### Success Response (void) This function does not return a value. ``` -------------------------------- ### isFile Source: https://github.com/lune-org/lune/wiki/API Reference - FS Checks if a given path points to a file. Throws an error if permissions are insufficient or an I/O error occurs. ```APIDOC ## isFile ### Description Checks if a given path is a file. ### Errors * The current process lacks permissions to read at `path`. * Some other I/O error occurred. ``` -------------------------------- ### readModelFile Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Reads a model file into a table of instances. ```APIDOC ## readModelFile ### Description Reads a model file into a table of instances. ### Method `roblox.readModelFile(filePath: string): {Instance}` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the model file to read. ### Request Example ```lua local roblox = require("@lune/roblox") local instances = roblox.readModelFile("filePath.rbxm") ``` ### Response #### Success Response (Array of Instances) - **instances** (Array) - A table containing the loaded instances. ``` -------------------------------- ### readDir Source: https://github.com/lune-org/lune/wiki/API Reference - FS Reads the entries within a directory at the specified path. Throws an error if the path is invalid, permissions are lacking, or an I/O error occurs. ```APIDOC ## readDir ### Description Reads entries in a directory at `path`. ### Errors * `path` does not point to an existing directory. * The current process lacks permissions to read the contents of the directory. * Some other I/O error occurred. ``` -------------------------------- ### isDir Source: https://github.com/lune-org/lune/wiki/API Reference - FS Checks if a given path points to a directory. Throws an error if permissions are insufficient or an I/O error occurs. ```APIDOC ## isDir ### Description Checks if a given path is a directory. ### Errors * The current process lacks permissions to read at `path`. * Some other I/O error occurred. ``` -------------------------------- ### stdio.style Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Generates an ANSI escape string to modify the persistent output style. Passing 'reset' restores the default style. ```APIDOC ## stdio.style ### Description Return an ANSI string that can be used to modify the persistent output style. Pass `"reset"` to get a string that can reset the persistent output style. ### Example usage ```lua stdio.write(stdio.style("bold")) print("This text will be bold") stdio.write(stdio.style("reset")) print("This text will be normal") ``` ``` -------------------------------- ### readPlaceFile Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Reads a place file into a DataModel instance. ```APIDOC ## readPlaceFile ### Description Reads a place file into a DataModel instance. ### Method `roblox.readPlaceFile(filePath: string): DataModel` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the place file to read. ### Request Example ```lua local roblox = require("@lune/roblox") local game = roblox.readPlaceFile("filePath.rbxl") ``` ### Response #### Success Response (DataModel) - **game** (DataModel) - The loaded DataModel instance. ``` -------------------------------- ### task.wait Source: https://github.com/lune-org/lune/wiki/API Reference - Task Waits for *at least* the given amount of time. The minimum wait time possible when using `task.wait` is limited by the underlying OS sleep implementation. For most systems this means `task.wait` is accurate down to about 5 milliseconds or less. ```APIDOC ## task.wait ### Description Waits for *at least* the given amount of time. The minimum wait time possible when using `task.wait` is limited by the underlying OS sleep implementation. For most systems this means `task.wait` is accurate down to about 5 milliseconds or less. ### Method `task.wait(duration)` ### Parameters #### Path Parameters - **duration** (number) - Required - The minimum time to wait in seconds. ``` -------------------------------- ### task.defer Source: https://github.com/lune-org/lune/wiki/API Reference - Task Defers a thread or function to run at the end of the current task queue. ```APIDOC ## task.defer ### Description Defers a thread or function to run at the end of the current task queue. ### Method `task.defer(thread_or_function)` ### Parameters #### Path Parameters - **thread_or_function** (Thread | Function) - Required - The thread or function to defer. ``` -------------------------------- ### error Source: https://github.com/lune-org/lune/wiki/API Reference - Uncategorized Throws an error and prints a formatted version of it with a leading [ERROR] tag. ```APIDOC ## error ### Description Throws an error and prints a formatted version of it with a leading `[ERROR]` tag. ### Method error(message: string, ...args: any[]) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### removeDir Source: https://github.com/lune-org/lune/wiki/API Reference - FS Removes a directory and all of its contents recursively. Throws an error if the path is not an existing, empty directory, permissions are lacking, or an I/O error occurs. ```APIDOC ## removeDir ### Description Removes a directory and all of its contents. ### Errors * `path` is not an existing and empty directory. * The current process lacks permissions to remove the directory. * Some other I/O error occurred. ``` -------------------------------- ### DataModel Class Source: https://github.com/lune-org/lune/wiki/Roblox - API Reference Represents the root of a Roblox place, providing access to services. ```APIDOC ## DataModel Class ### Description Represents the root of a Roblox place and provides access to various services. ### Implemented APIs - `DataModel:GetService(serviceName: string): Service` - `DataModel:FindService(serviceName: string): Service?` ``` -------------------------------- ### stdio.color Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Generates an ANSI escape string to modify the persistent output color. Passing 'reset' restores the default color. ```APIDOC ## stdio.color ### Description Returns an ANSI string that can be used to modify the persistent output color. Pass `"reset"` to get a string that can reset the persistent output color. ### Example usage ```lua stdio.write(stdio.color("red")) print("This text will be red") stdio.write(stdio.color("reset")) print("This text will be normal") ``` ``` -------------------------------- ### urlEncode Source: https://github.com/lune-org/lune/wiki/API Reference - Net Encodes the given string using URL encoding. ```APIDOC ## urlEncode ### Description Encodes the given string using URL encoding. ### Parameters * **stringToEncode** (string) - The string to URL-encode. ### Response * Returns the URL-encoded string. ``` -------------------------------- ### removeFile Source: https://github.com/lune-org/lune/wiki/API Reference - FS Removes a file at the specified path. Throws an error if the path is not an existing file, permissions are lacking, or an I/O error occurs. ```APIDOC ## removeFile ### Description Removes a file. ### Errors * `path` does not point to an existing file. * The current process lacks permissions to remove the file. * Some other I/O error occurred. ``` -------------------------------- ### stdio.write Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Writes a string directly to the standard output stream (stdout) without appending a newline character. ```APIDOC ## stdio.write ### Description Writes a string directly to stdout, without any newline. ``` -------------------------------- ### Saying Goodbye in Lune Source: https://github.com/lune-org/lune/wiki/Getting Started - 2 Writing Scripts A simple print statement to signify the end of a script's execution. ```lune print("Goodbye, lune! 🌙") ``` -------------------------------- ### task.delay Source: https://github.com/lune-org/lune/wiki/API Reference - Task Delays a thread or function to run after `duration` seconds. ```APIDOC ## task.delay ### Description Delays a thread or function to run after `duration` seconds. ### Method `task.delay(thread_or_function, duration)` ### Parameters #### Path Parameters - **thread_or_function** (Thread | Function) - Required - The thread or function to delay. - **duration** (number) - Required - The delay in seconds. ``` -------------------------------- ### urlDecode Source: https://github.com/lune-org/lune/wiki/API Reference - Net Decodes the given string using URL decoding. ```APIDOC ## urlDecode ### Description Decodes the given string using URL decoding. ### Parameters * **encodedString** (string) - The URL-encoded string to decode. ### Response * Returns the decoded string. ``` -------------------------------- ### jsonEncode Source: https://github.com/lune-org/lune/wiki/API Reference - Net Encodes the given value as JSON. ```APIDOC ## jsonEncode ### Description Encodes the given value as JSON. ### Parameters * **value** (any) - The lua value to encode. ### Response * Returns the JSON string representation of the value. ``` -------------------------------- ### jsonDecode Source: https://github.com/lune-org/lune/wiki/API Reference - Net Decodes the given JSON string into a lua value. ```APIDOC ## jsonDecode ### Description Decodes the given JSON string into a lua value. ### Parameters * **jsonString** (string) - The JSON string to decode. ### Response * Returns the decoded lua value. ``` -------------------------------- ### stdio.ewrite Source: https://github.com/lune-org/lune/wiki/API Reference - Stdio Writes a string directly to the standard error stream (stderr) without appending a newline character. ```APIDOC ## stdio.ewrite ### Description Writes a string directly to stderr, without any newline. ``` -------------------------------- ### task.cancel Source: https://github.com/lune-org/lune/wiki/API Reference - Task Stops a currently scheduled thread from resuming. ```APIDOC ## task.cancel ### Description Stops a currently scheduled thread from resuming. ### Method `task.cancel(thread)` ### Parameters #### Path Parameters - **thread** (Thread) - Required - The thread to cancel. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.