### Install CraftOS-PC on Ubuntu/Linux Mint Source: https://www.craftos-pc.cc/docs/installation Installs CraftOS-PC on Ubuntu and Linux Mint distributions using a PPA. This involves adding the repository, updating the package list, and then installing the package. After installation, CraftOS-PC can be launched via the system's application launcher or by running the 'craftos' command in the terminal. ```shell sudo add-apt-repository ppa:jackmacwindows/ppa sudo apt update sudo apt install craftos-pc ``` -------------------------------- ### Plugin System Setup in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This snippet explains how to add plugins to CraftOS-PC. Plugins should be placed in the `/plugins` folder. Refer to `DOCUMENTATION.md` for more detailed information. ```bash # Place your plugin files in the following directory: # /plugins/ # Refer to DOCUMENTATION.md for detailed instructions on creating and managing plugins. ``` -------------------------------- ### Install CraftOS-PC on Fedora Source: https://www.craftos-pc.cc/docs/installation Installs CraftOS-PC on Fedora by first enabling a COPR repository and then installing the package. This method is maintained by LeMoonStar. Users encountering issues with the Fedora package are advised to contact the maintainer via their GitHub repository. ```shell sudo dnf copr enable lemoonstar/CraftOS-PC sudo dnf install craftos-pc ``` -------------------------------- ### Install CraftOS-PC on Raspberry Pi OS Source: https://www.craftos-pc.cc/docs/installation Installs CraftOS-PC on Raspberry Pi OS by adding a specific repository to the sources list and then installing the package. This process requires editing a system file and running a series of apt commands. The software can then be accessed from the app menu or the 'craftos' command. ```shell deb https://www.craftos-pc.cc/raspi bullseye main ``` sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 1D99413F734AA894 sudo apt update sudo apt install craftos-pc ``` -------------------------------- ### Start WebSocket Server Source: https://www.craftos-pc.cc/docs/http-server Starts a WebSocket server on a specified port. This function returns a server handle that can be used to manage the server. ```APIDOC ## http.websocketServer ### Description Starts a WebSocket server on the specified port. ### Method `http.websocketServer` ### Parameters #### Path Parameters - **port** (number) - Required - The port to listen on. ### Returns - **serverHandle** (table) - A WebSocket server handle, with `listen()` and `close()` methods. ``` -------------------------------- ### Execute CraftOS-PC with Nix/NixOS Source: https://www.craftos-pc.cc/docs/installation Executes CraftOS-PC using the 'craftos-pc' package from the nixpkgs unstable repository. This command allows users to run the application within a temporary shell environment without a permanent installation. Nix and NixOS support is maintained by tomodachi94. ```shell nix-shell -p craftos-pc --run "craftos" ``` -------------------------------- ### Configure Fullscreen Start Behavior Source: https://www.craftos-pc.cc/docs/changelog This per-computer configuration option determines whether CraftOS-PC should start in fullscreen mode. It allows users to customize the initial display state for each computer instance. ```lua -- Start CraftOS-PC in fullscreen startFullscreen = true ``` -------------------------------- ### WebSocket Server Setup in CraftOS-PC Source: https://www.craftos-pc.cc/docs/http-server CraftOS-PC enables the creation of WebSocket servers using `http.websocketServer(port)`. This function returns a server handle. The `.listen()` method on this handle waits for new client connections, returning a client handle with methods similar to regular WebSocket handles. Use `.close()` on the server handle to shut down the server. ```lua local server = http.websocketServer(1234) while true do local client = server:listen() if client then -- Handle client connection local clientId = client.clientID -- Use client methods like client:send(), client:receive(), etc. client:close() end end -- To close the server: server:close() ``` -------------------------------- ### Select Hardware Driver in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This example demonstrates how to select a specific hardware driver for the GUI terminal in CraftOS-PC. The `preferredHardwareDriver` config option or the `-r` CLI flag can be used. Available drivers include direct3d, opengl, and software, among others. Use `craftos -r` to list all available drivers on your system. ```bash # Select driver via config file preferredHardwareDriver = "opengl" # Select driver via CLI flag craftos -r opengl ``` -------------------------------- ### Plugin Initialization Function Signature Source: https://www.craftos-pc.cc/docs/plugins Defines the signature for the `plugin_init` function, which is called on the main thread when CraftOS-PC starts. It initializes the plugin and returns its information. ```cpp PluginInfo * plugin_init(const PluginFunctions * func, const path_t& path); ``` -------------------------------- ### Drive Peripheral Mounting in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This code shows how to use the `drive` peripheral in CraftOS-PC to mount folders or audio files. It includes examples of inserting a folder/audio file by path and inserting a floppy disk by its ID. ```lua -- Mount a folder or audio file by its path disk.insertDisk("/path/to/my/folder_or_audio.wav") -- Mount a floppy disk from the default disk directory using its ID -- Floppy disks are stored in ~/.craftos/computer/disk/ disk.insertDisk(5) -- Mounts disk with ID 5 ``` -------------------------------- ### CraftOS-PC Plugin API Additions Source: https://www.craftos-pc.cc/docs/changelog This snippet outlines new capabilities for CraftOS-PC plugins. It includes functions for task queuing (`register_queueTask`), retrieving computer objects by ID (`register_getComputerById`), and getting the selected renderer (`get_selectedRenderer`). ```cpp // Example of registering a queueTask function (conceptual C++) // Assumes 'plugin_api' is an accessible object or context plugin_api.register_queueTask([](void* func_ptr, void* userdata, bool async) -> void* { // Implementation details... return nullptr; }); // Example of registering getComputerById (conceptual C++) plugin_api.register_getComputerById([](int id) -> Computer* { // Implementation details... return nullptr; }); // Example of registering get_selectedRenderer (conceptual C++) plugin_api.register_get_selectedRenderer([]() -> int { // Implementation details... return 0; }); ``` -------------------------------- ### Shell Hashbang Support (`#!`) in Lua Source: https://www.craftos-pc.cc/docs/changelog This example demonstrates the shell's support for hashbangs (`#!`) in scripts, a feature added in CraftOS-PC v2.7.4. This allows specifying the interpreter for a script directly in the file. ```shell -- Create a script file named 'my_script.sh' -- First line specifies the interpreter (e.g., lua) echo "#!/usr/bin/lua" > my_script.sh echo "print('Hello from hashbang script!')" >> my_script.sh -- Make the script executable chmod +x my_script.sh -- Execute the script directly ./my_script.sh ``` -------------------------------- ### Add CCEmuX Command-Line Flags for CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog Introduces command-line flags for CCEmuX to control asset directories, computer directories, start directories, data directories, plugins, and renderers. The `--start-dir` flag specifically affects the initial computer. ```bash --assets-dir --computers-dir --start-dir --data-dir (alias of --directory) --plugin --renderer --exec ``` -------------------------------- ### HTTP Server Event Handling in CraftOS-PC Source: https://www.craftos-pc.cc/docs/http-server CraftOS-PC can queue `http_request` events when an HTTP request is made to a port with an active listener. This event provides the port, a request table, and a response table. To stop a listener started with `http.listen`, you can return `true` from the callback or queue a `server_stop` event. ```lua event.listen("http_request", function(port, req, res) -- Handle the request and response res.close() end) -- To stop the server from within a callback: -- return true -- or -- event.queue("server_stop") ``` -------------------------------- ### CraftOS-PC Installation Directory Changes Source: https://www.craftos-pc.cc/docs/changelog This entry details changes to the installation directory for CraftOS-PC on Windows and the creation of the `.craftos` directory on boot. ```bash # On Windows, the installation directory has been moved to 64-bit Program Files. # The '.craftos' directory is now created automatically on boot. ``` -------------------------------- ### Filesystem Support Extension Source: https://www.craftos-pc.cc/docs/rawmode Details how to enable and utilize the filesystem extension for remote file access. ```APIDOC ## Filesystem Support Extension ### Description Enables remote access to a computer's files using the same function set as ComputerCraft's FS API, but with different request/reply packets for efficiency. ### Enabling the Extension To indicate support for the filesystem extension, set bit 1 of the standard capability flags in a Type 6 packet during feature negotiation. ``` -------------------------------- ### Get Configuration Variable (Shell) Source: https://www.craftos-pc.cc/docs/config Retrieves the current value of a configuration variable from the CraftOS-PC shell using the 'config get' command. This is useful for checking the current state of a setting before making changes. ```bash config get ``` -------------------------------- ### List All Configuration Variables (Shell) Source: https://www.craftos-pc.cc/docs/config Displays all available configuration variables and their current values from the CraftOS-PC shell using the 'config list' command. This provides an overview of all settable options. ```bash config list ``` -------------------------------- ### Pixel Manipulation API Source: https://www.craftos-pc.cc/docs/gfxmode Functions for setting and getting individual pixels on the screen in graphics mode. Coordinates are 0-based. ```APIDOC ## POST /term/setPixel ### Description Sets a pixel at the specified coordinates to a given color. Coordinates are 0-based. ### Method POST ### Endpoint /term/setPixel ### Parameters #### Request Body - **x** (number) - Required - The X coordinate of the pixel. - **y** (number) - Required - The Y coordinate of the pixel. - **color** (color) - Required - The color of the pixel. In mode 1, this should be a color from the `colors` API. In mode 2, this should be an index from 0-255. ### Request Example ```json { "x": 0, "y": 0, "color": "colors.white" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "status": "ok" } ``` ## GET /term/getPixel ### Description Retrieves the color value of a pixel at the specified coordinates. Coordinates are 0-based. ### Method GET ### Endpoint /term/getPixel ### Parameters #### Query Parameters - **x** (number) - Required - The X coordinate of the pixel. - **y** (number) - Required - The Y coordinate of the pixel. ### Response #### Success Response (200) - **color** (color) - The color of the pixel. In 16-color mode, this will be a constant from the `colors` table. In 256-color mode, it will be a palette index. #### Response Example ```json { "color": "colors.white" } ``` ``` -------------------------------- ### Auto-Updater Functionality in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This snippet describes the auto-updater feature in CraftOS-PC, available on Windows and Mac. It allows for one-click installation of new updates and can be disabled via configuration. ```bash # Auto-updater is available on Windows and Mac platforms (v2.1+). # This feature allows for one-click installation of updates. # To disable automatic update checking, set: # checkUpdates = false # On other platforms, updates are typically handled via package managers or by rebuilding from source. ``` -------------------------------- ### Configure Chest Peripheral Emulation (CraftOS-PC) Source: https://www.craftos-pc.cc/docs/periphemu Demonstrates how to configure chest peripherals in CraftOS-PC to emulate either a double chest (`true`) or a single chest (`false`). ```lua -- Emulate a double chest periphemu.create('front', 'chest', true) -- Emulate a single chest periphemu.create('front', 'chest', false) ``` -------------------------------- ### Configure Tank Peripheral (CraftOS-PC) Source: https://www.craftos-pc.cc/docs/periphemu Illustrates the configuration of tank peripherals in CraftOS-PC, including the number of tanks, the size of each tank, and additional fluid types. ```lua periphemu.create('bottom', 'tank', 2, 1000, {'water', 'lava'}) ``` -------------------------------- ### Font File Consolidation in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This entry notes that the font is now included within the executable for CraftOS-PC, eliminating the need for a separate `craftos.bmp` file. This simplifies distribution and setup. ```bash # The font is now embedded directly into the executable. # No longer requires a separate 'craftos.bmp' file. ``` -------------------------------- ### Multi-Computer and Peripheral Management in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This code demonstrates how to manage multiple computers and peripherals within CraftOS-PC. It shows how to create new computer peripherals programmatically or via the shell, and mentions the modem peripheral which is still under development. ```lua -- Create a new computer peripheral programmatically periphemu.create(1, "computer") -- Attach a computer peripheral from the shell -- attach computer -- Note: Modem peripheral is still a work in progress. ``` -------------------------------- ### Improve `os.day/time/epoch` Locale Compatibility Source: https://www.craftos-pc.cc/docs/changelog Adds a proper `ingame` locale for `os.day/time/epoch` based on a 20-minute clock that starts on computer boot. This change enhances compatibility with CCEmuX and CC:T. ```lua -- Example of using os.time with ingame locale local startTime = os.epoch() -- Simulate time passing -- ... local currentTime = os.epoch() local elapsedTime = currentTime - startTime print("Elapsed time: " .. os.time(elapsedTime, "ingame")) ``` -------------------------------- ### Headless and Script Execution Switches in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This code demonstrates how to use command-line switches to run CraftOS-PC in headless mode or to automatically execute a script upon startup. It notes that headless mode may require recompilation on Windows. ```bash # Run CraftOS-PC in headless mode (console only) craftos-pc --headless # Automatically run a script on startup craftos-pc --script my_startup_script.lua # Note: --headless switch may not work on Windows build without recompilation for console subsystem. ``` -------------------------------- ### Configure Drive Peripheral Mount (CraftOS-PC) Source: https://www.craftos-pc.cc/docs/periphemu Shows how to configure the initial mounted path for a drive peripheral in CraftOS-PC. This includes using global paths, disk IDs, and namespaced IDs. It also mentions the `insertDisk` method for changing the mount dynamically. ```lua -- Example of attaching a drive with a specific mount periphemu.create('left', 'drive', 'treasure:my_save_folder') -- Example of using insertDisk (assuming 'myDrive' is a drive peripheral object) myDrive.insertDisk('computer:1234') ``` -------------------------------- ### Attach Peripheral from Shell (CraftOS-PC) Source: https://www.craftos-pc.cc/docs/periphemu Demonstrates how to attach a peripheral to a computer using the 'attach' command in the CraftOS-PC shell. It explains the required arguments and how to use the attached peripheral with commands like 'monitor'. Detaching is also covered. ```shell attach detach ``` -------------------------------- ### Monitor Resizing in CraftOS-PC Terminal Source: https://www.craftos-pc.cc/docs/changelog Supports terminal and monitor resizing, a feature introduced in v2.0b2. This allows the display area to adapt, improving user experience and compatibility with different screen setups. ```lua local term = require("term") -- Get current terminal size local width, height = term.getSize() print("Terminal size: " .. width .. "x" .. height) -- Example of setting a new size (if supported by the environment) -- term.setSize(80, 24) ``` -------------------------------- ### Configure Energy Peripheral (CraftOS-PC) Source: https://www.craftos-pc.cc/docs/periphemu Shows how to configure energy peripherals in CraftOS-PC, specifying the maximum energy capacity and additional energy types. ```lua periphemu.create('top', 'energy', 10000, {'rf', 'eu'}) ``` -------------------------------- ### List All Configuration Variables (Lua) Source: https://www.craftos-pc.cc/docs/config Retrieves a list of all available configuration variable names using the CraftOS-PC Lua API. This function returns a table containing the names of all configurable settings, useful for exploration or dynamic configuration management. ```lua config.list() ``` -------------------------------- ### Get Configuration Variable (Lua) Source: https://www.craftos-pc.cc/docs/config Retrieves the current value of a specified configuration variable using the CraftOS-PC Lua API. This function takes the variable name as a string and returns its value. It's useful for checking settings within Lua scripts. ```lua config.get(name) ``` -------------------------------- ### Change Configuration Variable (Shell) Source: https://www.craftos-pc.cc/docs/config Modifies configuration variables directly from the CraftOS-PC shell using the 'config' command. The 'set' subcommand allows changing a variable's value, for example, 'config set http_enable false' to disable the http API. ```bash config set ``` -------------------------------- ### Manage Peripherals with periphemu API (CraftOS-PC) Source: https://www.craftos-pc.cc/docs/periphemu Illustrates using the `periphemu` Lua API in CraftOS-PC to create and remove peripherals. It details the parameters for `periphemu.create` and `periphemu.remove`, including optional arguments for specific peripheral types like printers and drives. ```lua periphemu.create(side, type[, path]) periphemu.remove(side) periphemu.names() ``` -------------------------------- ### Get Configuration Setting Source: https://www.craftos-pc.cc/docs/plugins Retrieves the value of a custom configuration setting by its name. This function is overloaded to return settings as a string, integer, or boolean. It throws std::out_of_range if the setting does not exist and std::invalid_argument for type mismatches. ```cpp std::string getConfigSetting(const std::string & name) ``` ```cpp int getConfigSettingInt(const std::string & name) ``` ```cpp bool getConfigSettingBool(const std::string & name) ``` -------------------------------- ### HTTP Server - Simple Interface Source: https://www.craftos-pc.cc/docs/http-server The `http.listen` function allows synchronous listening on a port. It takes a port number and a callback function that is executed for each incoming request. The callback receives request and response handles with specific methods for interacting with the client. ```APIDOC ## HTTP Server - Simple Interface ### Description Listens on a specified port for incoming HTTP requests and executes a callback function for each request. ### Method `http.listen(port, callback)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Function Signature `http.listen(_number_ port, _function_ callback)` ### Arguments * `port` (_number_): The port number to listen on. * `callback` (_function_): A function that will be called with two arguments when a request is received: * `req` (_table_): A request handle with the following methods: * `getURL()`: Returns the URI endpoint of the request. * `getMethod()`: Returns the HTTP method of the request. * `getRequestHeaders()`: Returns a table of headers sent by the client. * `res` (_table_): A response handle with the following methods: * `setStatusCode(_number_ code)`: Sets the HTTP response code. * `setResponseHeader(_string_ key, _string_ value)`: Sets a response header. * `close()`: Closes the response and sends it to the client. **Must be called before returning from the callback.** ### Behavior * The server stops listening and `http.listen` returns when `true` is returned from the callback or a `server_stop` event is queued. ### Events * `server_stop`: Queue this event within the callback to stop the listener. ### Request Example ```lua http.listen(8080, function(req, res) print("Request URL: " .. req.getURL()) print("Request Method: " .. req.getMethod()) local headers = req.getRequestHeaders() for key, value in pairs(headers) do print(key .. ": " .. value) end res.setStatusCode(200) res.setResponseHeader("Content-Type", "text/plain") res.write("Hello, CraftOS-PC!") res.close() end) ``` ### Response #### Success Response (200) * The response is determined by the `res` handle's methods and the `res.close()` call within the callback. #### Response Example ``` Hello, CraftOS-PC! ``` ``` -------------------------------- ### Ubuntu PPA CLI Support Fix in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This entry notes a fix for Command-Line Interface (CLI) support specifically for the Ubuntu PPA (Personal Package Archive) of CraftOS-PC. This ensures CLI functionality works correctly when installed via the PPA. ```bash # Fixed CLI support for the Ubuntu PPA installation of CraftOS-PC. ``` -------------------------------- ### CraftOS-PC Plugin API Initialization Source: https://www.craftos-pc.cc/docs/changelog This section details the new plugin API for CraftOS-PC introduced in v2.2. Plugins must implement a `plugin_info` function that returns API version and requested capabilities. Capabilities are registered via callback functions, which receive the requested function as Lua userdata. ```lua -- Example plugin_info function function plugin_info() return { api_version = "2.2", capabilities = { register_getLibrary = function(getLibrary_func) print("getLibrary address received") end, register_registerPeripheral = function(registerPeripheral_func) print("registerPeripheral address received") end, register_addMount = function(addMount_func) print("addMount address received") end } } end ``` -------------------------------- ### Computer Peripheral Creation in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This code shows how to create a new computer peripheral in CraftOS-PC. This can be done programmatically using `periphemu.create` or from the shell using the `attach` command. ```lua -- Create a computer peripheral with ID 2 periphemu.create(2, "computer") -- Alternatively, from the shell: -- attach 2 computer ``` -------------------------------- ### Get Configuration Variable Type (Lua) Source: https://www.craftos-pc.cc/docs/config Determines the expected data type of a configuration variable using the CraftOS-PC Lua API. It takes the variable name as input and returns a number representing the type (0: boolean, 1: string, 2: number, 3: table). ```lua config.getType(name) ``` -------------------------------- ### New Plugin API Initialization and Deinitialization Functions Source: https://www.craftos-pc.cc/docs/changelog Demonstrates the new C++ functions for initializing and deinitializing plugins in CraftOS-PC. These functions are part of the new plugin API introduced in version 2.5, allowing for more advanced plugin development. ```cpp PluginInfo * plugin_init(const PluginFunctions * functions, const path_t& path); void plugin_deinit(PluginInfo * info); ``` -------------------------------- ### Get Pixel Dimensions in CraftOS-PC Graphics Mode (Lua) Source: https://www.craftos-pc.cc/docs/gfxmode This Lua function retrieves the pixel dimensions of the screen in CraftOS-PC's graphics mode. It intelligently queries the terminal size based on the current graphics mode, ensuring compatibility with future changes. It relies on the `term.getSize` and `term.getGraphicsMode` functions. ```lua local function pixelDimensions() return term.getSize(term.getGraphicsMode() or 1) end ``` -------------------------------- ### Implement Music Disc Domain for Drives Source: https://www.craftos-pc.cc/docs/changelog Adds a `record` domain for drives, allowing music discs to be inserted from `minecraft:music_disc.*` sound files. Inserting a disk like `record:cat` plays the corresponding music disc. ```lua disk.insertDisk("left", "record:cat") -- Inserts the 'cat' music disc ``` -------------------------------- ### Set a Single Pixel using term.setPixel Source: https://www.craftos-pc.cc/docs/gfxmode The `term.setPixel(x, y, color)` function allows you to set the color of a single pixel on the screen. Coordinates are zero-based, starting from (0, 0) at the top-left. The `color` argument depends on the current terminal mode: a `colors` constant in mode 1, or a number between 0-255 in mode 2. ```lua term.setPixel(0, 0, colors.white) -- Sets the top-left pixel to white in 16-color mode term.setPixel(10, 20, 128) -- Sets pixel at (10, 20) to color index 128 in 256-color mode ``` -------------------------------- ### Configure WebP for Screenshots and Recordings in CraftOS-PC Source: https://www.craftos-pc.cc/docs/screenshot Controls the image format for screenshots and recordings in CraftOS-PC. When set to true, WebP format is used, offering significant file size reduction. If false, screenshots are PNG and recordings are GIF. WebP offers better compression but may have compatibility issues with some platforms. ```lua -- To enable WebP format for screenshots and recordings: fs.write("config", "useWebP=true") -- To disable WebP format (default): fs.write("config", "useWebP=false") ``` -------------------------------- ### Queue Lua Event to Computer Source: https://www.craftos-pc.cc/docs/plugins Queues a Lua event to be sent to a specified computer. It takes a pointer to the Computer object, an event provider, and user data. The event provider is a function that supplies the event details. ```cpp void queueEvent(Computer * comp, const event_provider & event, void * userdata) ``` -------------------------------- ### Lua API for File System Mounting in CraftOS-PC Source: https://www.craftos-pc.cc/docs/mounter Demonstrates the use of the 'mounter' Lua API in CraftOS-PC for programmatic file system mounting. Functions include mounting, unmounting, listing mounts, and checking read-only status. ```lua -- Mount a directory mounter.mount(name, path, readOnly) -- Unmount a directory mounter.unmount(name) -- List all mounts mounter.list() -- Check if a mount is read-only mounter.isReadOnly(name) ``` -------------------------------- ### File System and Drive Operations in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This snippet focuses on file system operations and drive peripheral management in CraftOS-PC. It includes details on the `file.seek` method, the `io` library with filename redirects, and how to mount folders or audio files using the `drive` peripheral. ```lua -- Seek to a specific position in a file file.seek(fileHandle, "set", offset) -- Mount a folder or audio file using the drive peripheral disk.insertDisk("/path/to/folder_or_audio.wav") -- Mount a floppy disk from the default directory disk.insertDisk(1) -- Mounts disk with id 1 from ~/.craftos/computer/disk/1 ``` -------------------------------- ### Fix `io.open` Not Creating Parent Directories Source: https://www.craftos-pc.cc/docs/changelog Ensures that `io.open` now creates all necessary parent directories if they are missing when a file path is specified. This simplifies file path management. ```lua -- Before fix: io.open("path/to/new/file.txt", "w") would fail if 'path/to/new' didn't exist -- After fix: io.open("path/to/new/file.txt", "w") now creates 'path', 'to', and 'new' directories if they are missing ``` -------------------------------- ### IO Library and Filename Redirects in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This entry details the addition of the `io` library in CraftOS-PC, which includes proper filename redirects. This enhances file handling capabilities. ```lua -- The 'io' library has been added with proper filename redirects. -- This improves the way file operations handle different filenames and paths. ``` -------------------------------- ### Merge Mounts Source: https://www.craftos-pc.cc/docs/mounter Explains how to create and manage merge mounts, which allow multiple real directories to be mounted to a single CraftOS-PC mount point. It details file reading and writing behavior with merge mounts, including priority rules. ```APIDOC ## Merge Mounts CraftOS-PC allows mounting multiple real directories to a single CraftOS-PC mount point using the "merge mount" feature. This is achieved by mounting two or more directories to the same path using the `mount` command or `mounter.mount` function. ### File Access with Merge Mounts - **Reading Files**: The system searches for the requested file in the mounted directories in the order they were mounted. The first existing file found is used. - Example: Requesting `/mnt/file.txt` checks `a/file.txt` first, then `b/file.txt`. - **Writing Files**: - If the file exists, it's treated like a read operation to determine the target mount. - If the file does not exist, it's written to the first mount that contains the necessary subdirectories. Writing to the root of the mount always targets the first mount. - Example: Writing a non-existent `/mnt/file.txt` goes to `a/file.txt`. - Example: Writing a non-existent `/mnt/dir/file.txt` attempts to write to `a/dir/file.txt` if `a/dir` exists, otherwise it tries `b/dir/file.txt` if `b/dir` exists. If neither `a/dir` nor `b/dir` exists and subdirectory creation is enabled, it will create `a/dir` and write the file there. ``` -------------------------------- ### Command-Line Flags for Mounting in CraftOS-PC Source: https://www.craftos-pc.cc/docs/mounter Explains the command-line flags used to inject directory mounts into CraftOS-PC on startup. These flags allow specifying read-write or read-only mounts directly. ```bash # Mount with default mount_mode craftos-pc --mount = # Force read-write mount craftos-pc --mount-rw = # Force read-only mount craftos-pc --mount-ro = ``` -------------------------------- ### Fix `fs.find("/")` Returning Empty Table Source: https://www.craftos-pc.cc/docs/changelog Corrects an issue where `fs.find("/")` incorrectly returned an empty table. It should now return a table containing the root directory's contents. ```lua -- Before fix: fs.find("/") returned {} -- After fix: fs.find("/") now returns a table with entries for the root directory ``` -------------------------------- ### Run CraftOS-PC Test Script Source: https://www.craftos-pc.cc/docs/changelog This command executes a test script to evaluate the performance of different rendering methods in CraftOS-PC. The script is available via a gist URL and helps determine the optimal rendering configuration for your system. ```bash gist run 802f64508a1f51b3244f5bcc0414ca22 ``` -------------------------------- ### HTTP Methods and WebSocket Support in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This snippet details the addition of new HTTP methods and WebSocket support in CraftOS-PC. It covers how to initiate client and server WebSockets and notes the removal of some dependencies for HTTP code. ```lua -- Opens a client WebSocket connection http.websocket("ws://example.com") -- Opens a server WebSocket http.websocket() -- Note: HTTP client/server code was redone in v2.0p1, removing some dependencies. ``` -------------------------------- ### HTTP Server Listen Function in CraftOS-PC Source: https://www.craftos-pc.cc/docs/http-server The `http.listen` function in CraftOS-PC allows for synchronous HTTP listening on a specified port. It takes a port number and a callback function that handles incoming requests and outgoing responses. The callback receives request and response handles with methods for URL, method, headers, status codes, and response headers. It's crucial to call `response.close()` to send the response. ```lua http.listen(port, function(req, res) local url = req.getURL() local method = req.getMethod() local headers = req.getRequestHeaders() res.setStatusCode(200) res.setResponseHeader("Content-Type", "text/plain") res.write("Hello, World!") res.close() end) ``` -------------------------------- ### GIF Recording and Screenshot Functionality in CraftOS-PC Source: https://www.craftos-pc.cc/docs/changelog This snippet explains how to use the GIF recording feature in CraftOS-PC, including the hotkey to toggle recording and the file save location. It also mentions a 15-second recording limit for performance reasons. ```bash # Press F3 to toggle GIF recording. # A red circle will appear in the corner while recording. # Recording is limited to 15 seconds. # Files are saved to ~/.craftos/screenshots/