Skip to content

chadhyatt/LuaEncode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LuaEncode

Fast table serialization library for pure Luau/Lua 5.1+

Latest Release Last Modified License Wally

Roblox Marketplace


πŸŽ‰ About

LuaEncode is a simple library for serialization of Lua tables and basic data types, along with support for all of Roblox's engine data types. LuaEncode supports both Luau and Lua 5.1+

🌟 Features

  • Serialization and output of basic types number, string, table, boolean, and nil for key/values
  • Pretty-printing and custom indentation configuration
  • Compatible with Roblox's engine data types (Instance, UDim2, Vector3, DateTime, etc..) - See Roblox Engine Data Type Coverage for more info
  • Secure table iteration and value reading, with potentially untrusted inputs in-mind
  • Manual cycle inserts in serialized codegen with InsertCycles
  • Extended raw key/value inserts with FunctionsReturnRaw

βš™οΈ Installation

  • Rojo/Wally

    If you're using Rojo and Wally, you can import the package in your wally.toml:

    LuaEncode = "chadhyatt/luaencode@1.4.4"
  • Roblox Marketplace

    You can also grab the LuaEncode module from the Roblox Marketplace: https://roblox.com/library/12791121865


πŸš€ Basic Usage

local LuaEncode = require("path/to/LuaEncode")

local Table = {
    foo = "bar",
    baz = {
        1,
        2,
        3,
        [5] = 5,
    },
    qux = function()
        return "\"hi!\"" -- With `FunctionsReturnRaw` set as true in options, this will output as 'qux = "hi!"'
    end,
}

local Encoded = LuaEncode(Table, {
    Prettify = true,
    FunctionsReturnRaw = true,
})

print(Encoded)
Output
    {
        qux = "hi!",
        baz = {
            1,
            2,
            3,
            [5] = 5
        },
        foo = "bar"
    }

πŸ”¨ API

LuaEncode(inputTable: {[any]: any}, options: {[string]: any}): string

Options

Argument Type Description
Prettify <boolean:false> Whether or not the output should be pretty printed
IndentCount <number:0> The amount of characters that should be used for indents (Note: If Prettify is set to true and this is unspecified, it will default to 4)
InsertCycles <boolean:false> If there are cyclic references in your table, the output will be wrapped in an anonymous function that manually sets paths to those references. (NOTE: If a key in the index path to the cycle is a reference type (e.g. table, function), the codegen can't externally set that path, and the value will have to be ignored)
OutputWarnings <boolean:true> If "warnings" should be placed into the output as comment blocks
FunctionsReturnRaw <boolean:false> If function values should be treated as callbacks that return a string to be inserted directly into the serialized output as the key/value
UseInstancePaths <boolean:true> If Roblox Instance values should return their Lua-accessable path for serialization. If the instance is parented under nil or isn't under game/workspace, it'll always fall back to Instance.new(ClassName)
UseFindFirstChild <boolean:true> When options.UseInstancePaths is true, whether or not instance paths should use FindFirstChild instead of direct indexes
SerializeMathHuge <boolean:true> If "infinite" (or negative-infinite) numbers should be serialized as math.huge. (uses the math global, as opposed to just a direct data type) If false, "1/0" or "-1/0" will be serialized, which is supported on all target Lua environments

Roblox Engine Data Type Coverage

(See AllRobloxTypes.server.lua for example input and output of supported Roblox data types.)

βœ” Implemented | βž– Partially Implemented | ❌ Unimplemented | β›” Never

DataType Serialized As Implemented
buffer buffer.fromstring() βœ”
SharedTable SharedTable.new() βœ”
Axes Axes.new() βœ”
BrickColor BrickColor.new() βœ”
CFrame CFrame.new() βœ”
CatalogSearchParams CatalogSearchParams.new() βœ”
Color3 Color3.new() βœ”
ColorSequence ColorSequence.new(<ColorSequenceKeypoints>) βœ”
ColorSequenceKeypoint ColorSequenceKeypoint.new() βœ”
DateTime DateTime.fromUnixTimestamp() βœ”
DockWidgetPluginGuiInfo DockWidgetPluginGuiInfo.new() βœ”
Enum Enum.<EnumType> βœ”
EnumItem Enum.<EnumType>.<EnumItem> βœ”
Enums Enum βœ”
Faces Faces.new() βœ”
FloatCurveKey FloatCurveKey.new() βœ”
Font Font.new() βœ”
Instance Instance.new() βœ”
NumberRange NumberRange.new() βœ”
NumberSequence NumberSequence.new(<NumberSequenceKeypoints>) βœ”
NumberSequenceKeypoint NumberSequenceKeypoint.new() βœ”
OverlapParams OverlapParams.new() βœ”
Path2DControlPoint Path2DControlPoint.new() βœ”
PathWaypoint PathWaypoint.new() βœ”
PhysicalProperties PhysicalProperties.new() βœ”
RBXScriptConnection N/A β›”
RBXScriptSignal N/A β›”
Random Random.new() βœ”
Ray Ray.new() βœ”
RaycastParams RaycastParams.new() βœ”
RaycastResult N/A β›”
Rect Rect.new() βœ”
Region3 Region3.new() βœ”
Region3int16 Region3int16.new() βœ”
TweenInfo TweenInfo.new() βœ”
RotationCurveKey RotationCurveKey.new() βœ”
Secret N/A β›”
UDim UDim.new() βœ”
UDim2 UDim2.new() βœ”
Vector2 Vector2.new() βœ”
Vector2int16 Vector2int16.new() βœ”
Vector3 Vector3.new() βœ”
Vector3int16 Vector3int16.new() βœ”

(See official Roblox data type documentation here)


πŸ›οΈ License

MIT License

Copyright (c) 2022-2025 Chad Hyatt <chad@hyatt.page>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Fast table serialization library for pure Luau/Lua 5.1+

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 5