### Install Blink using Rokit Source: https://1axen.github.io/blink/getting-started/1-installation Installs the Blink package using the Rokit package manager. This is the recommended method for installation. ```bash rokit add 1Axen/blink ``` -------------------------------- ### Blink Installation Alternatives Source: https://1axen.github.io/blink/getting-started/1-installation Lists alternative methods for obtaining Blink, including downloading pre-built binaries from GitHub Releases and using the Roblox Studio plugin. ```plaintext GitHub Releases: Download pre-built binaries. Roblox Studio Plugin: Install from Creator Store or GitHub Releases. ``` -------------------------------- ### Install Lune Runtime Source: https://1axen.github.io/blink/getting-started/1-installation Installs Lune, the runtime environment for Blink, using Rokit. This is a necessary step for running Blink bytecode. ```bash rokit add lune ``` -------------------------------- ### Run Blink Bytecode Source: https://1axen.github.io/blink/getting-started/1-installation Executes Blink bytecode using the `lune run` command. Replace `[INPUT]` with the path to your bytecode file and `[ARGS]` with any arguments for your script. ```bash lune run init [INPUT] -- [ARGS] ``` -------------------------------- ### Install Blink using pesde Source: https://1axen.github.io/blink/getting-started/1-installation Installs Blink as a development dependency using pesde. This method is available for pesde version 0.15.0 and later. ```bash pesde add --dev pesde/blink pesde install ``` -------------------------------- ### Blink Network Description Example Source: https://1axen.github.io/blink/getting-started/2-introduction An example of a Blink network description file, defining options for output paths and an event with specified data types and communication patterns. ```blink -- these can be ignored if you are using the studio plugin option ClientOutput ="path/to/client.luau" option ServerOutput ="path/to/server.luau" event MyFirstEvent { from: Server, type: Reliable, call: SingleSync, data: string } ``` -------------------------------- ### Update Blink using Rokit Source: https://1axen.github.io/blink/getting-started/1-installation Updates the Blink package to the latest version using the Rokit package manager. This command should be run in your project directory. ```bash rokit update 1Axen/blink ``` -------------------------------- ### Using Generated Blink Code (Client) Source: https://1axen.github.io/blink/getting-started/2-introduction Example of how to use the generated Luau code on the client-side to listen for an event. It shows requiring the client module and setting up an event listener. ```luau local Net =require(Path.To.Client) Net.MyFirstEvent.On(function(Text) print(Text) end) ``` -------------------------------- ### Using Generated Blink Code (Server) Source: https://1axen.github.io/blink/getting-started/2-introduction Example of how to use the generated Luau code on the server-side to fire an event. It demonstrates requiring the server module and invoking the 'MyFirstEvent'. ```luau local Net =require(Path.To.Server) Net.MyFirstEvent.FireAll("Hello World") ``` -------------------------------- ### Struct Merging Example Source: https://1axen.github.io/blink/language/4-types Shows how structs can merge other structs, demonstrating a table union equivalent in Luau. ```blink struct foo { foo: u8 } struct bar { bar: string } struct foo_bar { ..foo, ..bar } ``` ```luau type foo_bar = { foo: number, bar: string } ``` -------------------------------- ### Map Type Alias Example Source: https://1axen.github.io/blink/language/4-types Provides an example of creating a type alias for a map where the keys are 64-bit floating-point numbers and the values are strings. ```blink map UserIdToUsername ={ [f64]:string } ``` -------------------------------- ### Array Type Alias Example Source: https://1axen.github.io/blink/language/4-types Provides an example of creating a type alias for an array of 64-bit floating-point numbers with a bounded length between 1 and 50 elements. ```blink type UserIds = f64[1..50] ``` -------------------------------- ### Generic Struct Definition Source: https://1axen.github.io/blink/language/4-types Illustrates the use of generics with structs to create flexible type definitions, using a packet fragment example. ```blink struct Fragment{ Index: u8, Sequence: u16, Fragments: u8, Data: T } type EntitiesFragment = Fragment ``` -------------------------------- ### Invoke Blink Function (Luau) Source: https://1axen.github.io/blink/language/6-functions Demonstrates how to invoke a Blink function from Luau. Examples are provided for different yielding mechanisms (Coroutine, Future, Promise). ```Luau local Value = blink.MyFunction.Invoke(5) ``` ```Luau local Future = blink.MyFunction.Invoke(5) local Value =Future:Await() ``` ```Luau local Promise = blink.MyFunction.Invoke(5) local Value =Promise:await() ``` -------------------------------- ### Listening to Blink Events Source: https://1axen.github.io/blink/language/5-events Demonstrates how to subscribe to events using the `.On()` method in Blink. This includes events with single values and events with multiple values (type packs). The examples show client-side and server-side event listening. ```luau client.luau ```lua blink.MyEvent.On(function(Value) -- ... end) blink.MyTypePackEvent.On(function(Foo,Bar,FooBar) -- ... end) ``` ``` ```luau server.luau ```lua blink.MyEvent.On(function(Player,Value) -- ... end) blink.MyTypePackEvent.On(function(Player,Foo,Bar,FooBar) -- ... end) ``` ``` ```luau disconnect.luau ```lua local Disconnect = blink.MyEvent.On(...) Disconnect() ``` ``` -------------------------------- ### Buffer Type Aliases Source: https://1axen.github.io/blink/language/4-types Provides examples of creating type aliases for buffer types, including a standard binary blob and a bounded buffer for unreliable events. ```blink type BinaryBlob = buffer type UnreliableEventBuffer = buffer(..950) ``` -------------------------------- ### Fire Blink Events in Luau Source: https://1axen.github.io/blink/language/5-events Demonstrates how to fire events from Luau scripts, targeting specific players or all players. Includes examples for single data and type packs. ```luau blink.MyEvent.Fire(5) blink.MyTypePackEvent.Fire(2^8-1, 2^16-1, 2^32-1) ``` ```luau blink.MyEvent.Fire(Player, 5) blink.MyEvent.FireAll(Player, 5) blink.MyEvent.FireList((Player), 5) blink.MyEvent.FireExcept(Player, 5) ``` -------------------------------- ### Tagged Enum Union Example Source: https://1axen.github.io/blink/language/4-types Illustrates how tagged enums can substitute for union types, showing the Blink definition and the resulting Luau type. ```blink enum Union = "Type" { Number { Value: f64 }, String { Value: string } } ``` ```luau type Union = | {Type: "Number", Value: number} | {Type: "String", Value: string} ``` -------------------------------- ### Map Declaration Source: https://1axen.github.io/blink/language/4-types Shows the syntax for defining a map type in Blink, which consists of key-value pairs. The example defines a map with string keys and 64-bit float values. ```blink map StringToNumber ={ [string]:f64 } ``` -------------------------------- ### Iterating (Polling) Blink Events Source: https://1axen.github.io/blink/language/5-events Shows how to iterate over events using the `.Iter()` method in Blink, which allows for polling event data. This covers events with single values and type-packed events, with examples for both client and server contexts. ```luau client.luau ```lua for Index, Value in MyEvent.Iter() do -- ... end for Index, Foo, Bar, FooBar in MyTypePackEvent.Iter() do -- ... end ``` ``` ```luau server.luau ```lua for Index, Player, Value in MyEvent.Iter() do -- ... end for Index, Player, Foo, Bar, FooBar in MyTypePackEvent.Iter() do -- ... end ``` ``` -------------------------------- ### RemoteScope Option Configuration Source: https://1axen.github.io/blink/language/1-options Configures a prefix for events generated by a Blink instance. This is useful for isolating Blink events when used within packages to avoid conflicts with other Blink setups. If not specified, default event names are used. ```APIDOC RemoteScope: Default: "" Description: Adds a prefix to the events generated by this Blink instance. For example, a value of "PACKAGE" creates events "PACKAGE_BLINK_RELIABLE_REMOTE" and "PACKAGE_BLINK_UNRELIABLE_REMOTE". If the option is not specified, they will just be "BLINK_RELIABLE_REMOTE" and "BLINK_UNRELIABLE_REMOTE". This is particularly useful if you're using Blink inside of a package, and don't want to interfere with a game's own Blink setup. ``` -------------------------------- ### Generic Tagged Enum Definition Source: https://1axen.github.io/blink/language/4-types Demonstrates the use of generics with tagged enums to create reusable type templates, shown with a union example. ```blink enum Union="Type"{ A { Value: A }, B { Value: B }, } enum NumberStringUnion = Union ``` -------------------------------- ### Set Declaration Source: https://1axen.github.io/blink/language/4-types Shows the syntax for defining a set type in Blink, which is a map of static string keys to the boolean value `true`. The example defines a set for feature flags. ```blink set Flags ={ FeatureA, FeatureB, FeatureC } ``` -------------------------------- ### Luau Facing API for Blink Exports Source: https://1axen.github.io/blink/language/4-types Shows the Luau-facing API generated for Blink exports, including 'Read' and 'Write' functions. It also provides an example of how a game script can utilize these functions to serialize and deserialize Blink types. ```luau type MyInterfaceExport = { Read: (buffer) -> MyInterface, Write: (MyInterface) -> buffer } local Serialized = blink.MyInterface.Write(MyInterface) local Deserialized = blink.MyInterface.Read(Serialized) ``` -------------------------------- ### Unit Enum Declaration Source: https://1axen.github.io/blink/language/4-types Demonstrates how to define a unit enum in Blink, representing a set of possible distinct values. The example defines an enum for character status states. ```blink enum CharacterStatus ={ Idling, Walking, Running, Jumping, Falling } ``` -------------------------------- ### Blink Type System Overview Source: https://1axen.github.io/blink/language/4-types This section provides an overview of the Blink programming language's type system. It covers fundamental types such as numbers (integers, floats), strings, booleans, and buffers, along with more complex types like vectors, arrays, maps, and sets. It also delves into advanced concepts like optionals, generics, enums (unit and tagged), structs, unknowns, instances, and CFrames. The documentation highlights how to specify encoding for certain types and provides usage examples for various constructs, including how to use Blink types within Luau. ```Blink // Blink Type System Documentation // Ranges // Full Ranges, Half Ranges, Exact Ranges // Example: let range = 1..5; // Numbers // Unsigned Integers, Signed Integers, Floating points // Bounding Numbers // Example: let count: u32 = 10; // Example: let price: f64 = 99.99; // Strings // Bounding Strings // Example: let name: string = "Blink"; // Booleans // Example: let isActive: bool = true; // Buffers // Bounding Buffers // Example: let data: buffer = buffer.from([1, 2, 3]); // Vectors // Bounding Vectors // Specifying Encoding // Example: let vec: vector = [1, 2, 3]; // Optionals // Example: let optionalValue: ?i32 = null; // Arrays // Bounding Arrays // Example: let arr: array = ["a", "b", "c"]; // Maps // Bounding Maps // Example: let map: map = {"key": 1}; // Generics // Example: function identity(value: T): T { return value; } // Sets // Example: let set: set = {1, 2, 3}; // Enums // Unit Enums, Tagged Enums // Example: enum Color { Red, Green, Blue }; // Example: enum Result { Ok(i32), Err(string) }; // Structs // Merging // Example: struct Point { x: f64, y: f64 }; // Unknowns // Example: let unknown: unknown = 5; // Instances // Specifying Class // Example: let instance: Instance; // CFrames // Specifying Encoding // Other Roblox Types // Exports // Usage in Luau ``` -------------------------------- ### Roblox Studio Plugin Usage Source: https://1axen.github.io/blink/getting-started/4-plugin Instructions on how to use the Blink Roblox Studio Plugin, including locating it, granting script access, managing files via the side menu, saving, and generating networking modules. ```markdown # Studio Plugin ## Navigating After installing the plugin locate it within your plugin tab in Studio. After opening the plugin you will be prompted to give it access to inject scripts, this is needed to be able to generate output files. ## Side Menu You can open the side menu using the sandwich button on the left hand side. Within the side menu you can manage your network description files. ## Saving To save a network description simply press the save button at the bottom of the side menu. This will prompt you to save whatever is currently in the editor. You can save to already existing files by simply inputting their name. ## Generating To generate your networking modules simply press the "Generate" button on your desired file. This will open a prompt asking you to select your desired output destination within the game explorer. ⚠️ Make sure to select a location that is accessible to both the client and server, otherwise you won't be able to require the generated files. Once you've selected your desired output destination simply press "Generate" and your files will be ready. If no issues arise Blink will generate the following Folder containing your networking modules: ## Editor The editor is the center piece of the plugin, it has various rudimentary intellisense features built-in to help with your writing speed, and analysis to correct any mistakes. ## Errors Upon generating output files, Blink will parse the source contents and inform you of any errors within your files that are blocking generation. ``` -------------------------------- ### Blink Compilation Command Source: https://1axen.github.io/blink/getting-started/2-introduction The command-line instruction to compile a Blink network description file. This process generates Luau files for client and server integration. ```bash blink FILE_NAME ``` -------------------------------- ### Compile Blink Description File Source: https://1axen.github.io/blink/getting-started/3-cli Compiles a Blink description file. The command looks for a file with the specified name and a .blink or .txt extension in the current directory. ```bash blink file-name ``` -------------------------------- ### Importing Blink Files Source: https://1axen.github.io/blink/language/3-imports Demonstrates how to import other Blink configuration files using the 'import' keyword. It shows importing a file directly and aliasing it using the 'as' keyword, along with type definitions for imported modules. ```blink import"./external" import"./external"as"Common" type ExternType = external.Type type CommonType = Common.Type ``` -------------------------------- ### Watch Blink Description Files for Changes Source: https://1axen.github.io/blink/getting-started/3-cli Compiles a Blink description file and automatically recompiles it, along with its imports, whenever changes are detected. This is useful for rapid development. ```bash blink file-name --watch ``` -------------------------------- ### Listen to Blink Function (Luau) Source: https://1axen.github.io/blink/language/6-functions Shows how to set up a listener for a Blink function on the server side using Luau. The listener receives player data and input value, and returns a value. ```Luau blink.MyFunction.On(function(Player,Value) return Value *2 end) ``` -------------------------------- ### Blink Function Yielding Options Source: https://1axen.github.io/blink/language/6-functions Explains the different libraries that can be used for handling yielding in Blink functions. Recommended libraries are provided for Future and Promise. ```APIDOC Yield Options: - Coroutine: Uses the built-in Luau coroutine library. - Future: Uses a user-provided future library (redblox's future library recommended). - Promise: Uses a user-provided promise library (evaera's promise library recommended). ``` -------------------------------- ### Blink Configuration Options Source: https://1axen.github.io/blink/language/1-options This section covers various configuration options for the Blink language, controlling aspects like casing, output file generation, TypeScript support, polling, and validation. ```blink option Casing =Camel ``` ```blink option TypesOutput ="../Network/Types.luau" option ServerOutput ="../Network/Server.luau" option ClientOutput ="../Network/Client.luau" ``` ```blink option Typescript =true ``` ```blink option UsePolling =true ``` ```blink option FutureLibrary ="ReplicatedStorage.Packages.Future" option PromiseLibrary ="ReplicatedStorage.Packages.Promise" ``` -------------------------------- ### Defining Scopes in Blink Source: https://1axen.github.io/blink/language/2-scopes Demonstrates how to define a scope using the 'scope' keyword, including nested types and events. It also shows how scopes capture definitions from their parent scopes. ```Blink scope ExampleScope { type InScopeType = u8 event InScopeEvent { From: Server, Type: Reliable, Call: SingleSync, Data: u8 } } struct Example { Reference = ExampleScope.InScopeType } ``` ```Blink type Outer = u8 scope CaptureExample { type Inner = Outer } ``` -------------------------------- ### Specifying Instance Class Source: https://1axen.github.io/blink/language/4-types Demonstrates how to narrow down the 'Instance' type by specifying a class, allowing for subclass acceptance. ```blink type Player =Instance(Player) ``` -------------------------------- ### Blink Language Features Source: https://1axen.github.io/blink/index The Blink language supports several key features for defining data structures and communication protocols. These include options for configuration, scopes for organizing code, imports for modularity, explicit type definitions, event handling, and function declarations. ```APIDOC Blink Language Specification: 1. Options: - Description: Define configuration settings for the compiler or generated code. - Usage: `option = ` 2. Scopes: - Description: Organize definitions into logical groups. - Usage: `scope { ... }` 3. Imports: - Description: Include definitions from other Blink files. - Usage: `import ` 4. Types: - Description: Define custom data types for fields and variables. - Supported Types: `int`, `float`, `string`, `bool`, `array`, `map`, custom types. - Usage: `type = { field1: Type1, field2: Type2 }` 5. Events: - Description: Define communication events between client and server. - Usage: `event (param1: Type1, param2: Type2)` 6. Functions: - Description: Define reusable code blocks or procedures. - Usage: `function (param1: Type1): ReturnType { ... }` Example Blink File (Conceptual): ```blink import "./common.blink" option networkVersion = 1 type PlayerData { name: string, score: int } scope GameEvents { event PlayerJoined(playerData: PlayerData) event PlayerLeft(playerId: string) } function calculateBonus(base: int, multiplier: float): float { return base * multiplier; } ``` ``` -------------------------------- ### Instance Type Definition Source: https://1axen.github.io/blink/language/4-types Defines how to use the 'Instance' type for Roblox instances in Blink. ```blink type AnInstance =Instance ``` -------------------------------- ### Map Generics Source: https://1axen.github.io/blink/language/4-types Illustrates the use of generics in Blink maps for creating reusable map templates. It shows defining a generic map and then instantiating it with specific types. ```blink map Map={[K]: V} map StringToNumber = Map ``` -------------------------------- ### Using Imported Modules in Luau Source: https://1axen.github.io/blink/language/3-imports Illustrates how to interact with imported Blink modules within Luau code. It shows requiring the Blink module and accessing events and types from the imported scopes. ```luau local Blink =require(PATH_TO_BLINK) Blink.external.Event.FireAll(0) localNumber: Blink.Common_Type =0 ``` -------------------------------- ### Blink Range Definitions Source: https://1axen.github.io/blink/language/4-types Demonstrates how to define full, half, and exact ranges for bounding values in Blink. Ranges specify the minimum and maximum limits for data types. ```blink type Health =u8(0..100) type UserId =f64 ``` ```blink type UUID =string(36) type Username =string(3..20) ``` ```blink type Success =boolean ``` -------------------------------- ### Blink Compiler Overview Source: https://1axen.github.io/blink/index Blink is an IDL compiler written in Luau for Roblox buffer networking. It focuses on generating performant and bandwidth-efficient code, leading to lower ping and CPU usage for players. It also enhances security by validating client data and making network traffic harder to snoop. ```Luau --- Blink Compiler --- -- Purpose: Compiles IDL definitions into efficient Luau code for Roblox networking. -- Features: -- - Performance optimization for bandwidth and CPU usage. -- - Enhanced security through data validation and obfuscation. -- - Supports various language features like options, scopes, imports, types, events, and functions. -- Example Usage (Conceptual): -- local blink = require(game.ServerStorage.Blink) -- local compiledModule = blink.compile("path/to/your/idl.blink") -- compiledModule.sendDataToClient(player, data) ``` -------------------------------- ### Using Scopes in Luau Code Source: https://1axen.github.io/blink/language/2-scopes Illustrates how to access definitions within a Blink scope from Luau code. It shows how exported types and events are nested within the scope's table and how Luau types are prefixed. ```Luau local Blink = require(PATH_TO_BLINK) Blink.ExampleScope.InScopeEvent.FireAll(0) local Number: Blink.ExampleScope_InScopeType = 0 ``` -------------------------------- ### Vector Type Aliases Source: https://1axen.github.io/blink/language/4-types Demonstrates creating type aliases for vector types, including a basic position vector, a unit vector, and a vector with a specified unsigned 8-bit integer encoding. ```blink type Position = vector type UnitVector = vector(0..1) type VectorU8 = vector ``` -------------------------------- ### Blink Export Definition Source: https://1axen.github.io/blink/language/4-types Demonstrates how to define an export for a Blink struct by prefixing the 'export' keyword. This allows for read and write functions to be generated for the type, useful for automatic ECS replication. ```blink exportstruct MyInterface ={ field: u8, } ``` -------------------------------- ### Bounding Array Length Source: https://1axen.github.io/blink/language/4-types Demonstrates how to bound the length of an array in Blink by specifying a range within the square brackets. This limits the number of elements the array can hold. ```blink string[25..50] ``` -------------------------------- ### Bounding Map Size Source: https://1axen.github.io/blink/language/4-types Explains and demonstrates how to bound the number of elements in a map in Blink by placing a range in parentheses after the map definition. This limits the map's capacity. ```blink map StringToNumber ={ [string]:f64 }(1..100) ``` -------------------------------- ### Array Declaration Source: https://1axen.github.io/blink/language/4-types Illustrates the basic syntax for declaring an array type in Blink, which is a list of homogeneous types, by appending square brackets to the element type. ```blink string[] ``` -------------------------------- ### Bounding Vectors Source: https://1axen.github.io/blink/language/4-types Illustrates how to bound the magnitude (length) of vector types in Blink using a range within parentheses. This is useful for enforcing constraints like unit vectors. ```blink vector(0..1) ``` -------------------------------- ### Struct Definition Source: https://1axen.github.io/blink/language/4-types Defines a struct named 'Entity' with various fields including nested structs and optional values, showcasing static typing. ```blink struct Entity { Health: u8(0..100), Position: vector, Rotation: u8, Animations: struct { First: u8?, Second: u8, Third: u8 } } ``` -------------------------------- ### Bounding Buffers Source: https://1axen.github.io/blink/language/4-types Defines how to bound the length of buffer types in Blink using a range within parentheses. This limits the buffer size to a specified minimum and maximum number of bytes. ```blink buffer(..900) ``` -------------------------------- ### Define Blink Event Source: https://1axen.github.io/blink/language/5-events Defines an event in Blink, specifying its origin, reliability, calling convention, and data payload. Supports various data types and type packs. ```blink event MyEvent { From: Server, Type: Reliable, Call: SingleAsync, Data: f64 } event MyTypePackEvent { From: Server, Type: Reliable, Call: SingleAsync, Data: (u8, u16, u32) } ``` -------------------------------- ### Define Blink Function Source: https://1axen.github.io/blink/language/6-functions Defines a function in Blink, specifying its yielding mechanism, input data type, and return data type. This is analogous to Roblox's RemoteFunction. ```Blink function MyFunction { Yield: Coroutine, Data: f64, Return: f64 } ``` -------------------------------- ### Optional Type Declaration Source: https://1axen.github.io/blink/language/4-types Explains and shows how to make a type optional in Blink by appending a question mark (?) after the entire type definition. This indicates that a value of this type may be absent. ```blink type Username = string(3..20)? ``` -------------------------------- ### Vector Encoding Specification Source: https://1axen.github.io/blink/language/4-types Shows how to specify the number type used for encoding vector components using angular brackets. Note that using types larger than f32 may not improve precision due to internal storage. ```blink type VectorI16 = vector ``` -------------------------------- ### CFrame Type Definition Source: https://1axen.github.io/blink/language/4-types Shows the definition of the 'CFrame' type for representing 3D points and rotations in Blink. ```blink type Location =CFrame ``` -------------------------------- ### CFrame Encoding Specification Source: https://1axen.github.io/blink/language/4-types Defines how to specify positional and rotational encoding for CFrames using number types within angular brackets. It highlights precision limitations and the effect of using integer types for rotational encoding. ```blink type MyCFrame =CFrame ``` -------------------------------- ### Tagged Enums Definition Source: https://1axen.github.io/blink/language/4-types Defines tagged enums with variants and associated data, demonstrating their structure and usage for representing different data types. ```blink enum MouseEvent ="Type"{ Move { Delta: vector, Position: vector, }, Drag { Delta: vector, Position: vector, }, Click { Button: enum { Left, Right, Middle }, Position: vector } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.