A Ring language extension/library for UUID (Universally Unique Identifier) generation and validation, providing a simple and efficient API for working with UUIDs in Ring applications built on top of the stduuid C++ library.
- Generate random UUIDs (version 4)
- Validate UUID strings
- Create nil (all-zero) UUIDs
- Cross-platform support (Windows, Linux, macOS, FreeBSD)
- Multiple architecture support (x64/amd64, arm64, x86/i386/i686)
This package can be installed using the Ring Package Manager (RingPM):
ringpm install uuid from ysdragon
First, load the library in your Ring script:
load "uuid.ring"To generate a random UUID:
cUUID = uuid_generate()
see "Generated UUID: " + cUUID + nlTo validate if a string is a valid UUID:
cUUID = "550e8400-e29b-41d4-a716-446655440000"
if uuid_isvalid(cUUID)
? "Valid UUID!"
else
? "Invalid UUID!"
okTo create a nil UUID (all zeros):
cNilUUID = uuid_nil()
? "Nil UUID: " + cNilUUIDTo convert a UUID to a byte array:
cUUID = "550e8400-e29b-41d4-a716-446655440000"
try
aBytes = uuid_tobytes(cUUID)
? "Byte array length: " + len(aBytes)
catch
? "Error: Invalid UUID format"
enduuid_generate()- Generates a random UUID (version 4) and returns it as a stringuuid_isvalid(uuid_string)- Validates if the provided string is a valid UUID format- Parameters:
uuid_string(string): The UUID string to validate
- Returns: 1 (true) if valid, 0 (false) if invalid
- Parameters:
uuid_nil()- Returns a nil UUID (all zeros) as a stringuuid_tobytes(uuid_string)- Converts a UUID string to a 16-byte array- Parameters:
uuid_string(string): The UUID string to convert
- Returns: 16-byte array containing the UUID bytes
- Throws: Error if the UUID string is invalid
- Parameters:
If you wish to contribute to the development of Ring UUID or build it from the source, follow these steps.
- CMake: Version 3.16 or higher.
- C++ Compiler: A C++ compiler compatible with your platform (e.g., GCC, Clang, MSVC).
- Ring Source Code: You will need to have the Ring language source code available on your machine.
-
Clone the Repository:
git clone https://github.com/ysdragon/uuid.git --recursive
Note: If you installed the library via RingPM, you can skip this step.
-
Set the
RINGEnvironment Variable: This variable must point to the root directory of the Ring language source code.- Windows (Command Prompt):
set RING=X:\path\to\ring
- Windows (PowerShell):
$env:RING = "X:\path\to\ring"
- Unix-like Systems (Linux, macOS or FreeBSD):
export RING=/path/to/ring
- Windows (Command Prompt):
-
Configure with CMake: Create a build directory and run CMake from within it.
mkdir build cd build cmake .. -
Build the Project: Compile the source code using the build toolchain configured by CMake.
cmake --build .The compiled library will be available in the
lib/<os>/<arch>directory.
Contributions are always welcome! If you have suggestions for improvements or have identified a bug, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.