Forest Logo
search
package_2

luaencode

By @regginator

Roblox

Mirrored from Wally

This version ships no README. Showing the README from v1.1.6, mirrored from wally.

<h1>LuaEncode</h1>
<h4>Optimal Serialization of Lua Tables in Native Luau/Lua 5.1+</h4>
<p>
    
    
    <a href="https://github.com/regginator/LuaEncode/stargazers">
        <img src="https://img.shields.io/github/stars/regginator/LuaEncode?label=Stars&logo=GitHub" alt="Repo Stars">
    </a>
    
    <a href="https://github.com/regginator/LuaEncode/fork">
        <img src="https://img.shields.io/github/forks/regginator/LuaEncode?label=Fork&logo=GitHub" alt="Repo Forks">
    </a>
    
    <a href="https://github.com/regginator/LuaEncode/releases/latest">
        <img src="https://img.shields.io/github/v/release/regginator/LuaEncode?label=Latest%20Release" alt="Latest Release" />
    </a>
    
    <a href="https://github.com/regginator/LuaEncode/blob/master/LICENSE.txt">
        <img src="https://img.shields.io/github/license/regginator/LuaEncode?label=License" alt="License" />
    </a>
    
    <a href="https://github.com/regginator/LuaEncode/commits">
        <img src="https://img.shields.io/github/last-commit/regginator/LuaEncode?label=Last%20Modifed" alt="Last Modified" />
    </a>
    
    <a href="https://wally.run/package/regginator/luaencode">
        <img src="https://img.shields.io/badge/wally.run-regginator%2Fluaencode-%23ad4646?style=flat" alt="Package on wally.run" />
    </a>
    
    <br />
    
    
    <a href="https://latte.to/invite">
        <img src="https://img.shields.io/discord/892211155303538748?color=%235865F2&label=Latte%20Softworks&logo=Discord&logoColor=%23FFFFFF" alt="Latte Softworks Discord" />
    </a>
    
    <a href="https://twitter.com/jitlua">
        <img src="https://img.shields.io/twitter/follow/jitlua?color=1d9bf0&label=Follow%20%40jitlua&logo=Twitter&logoColor=ffffff&style=flat" alt="Follow @jitlua (Twitter)" />
    </a>
    
    <a href="https://github.com/regginator">
        <img src="https://img.shields.io/github/followers/regginator?label=Follow%20%40regginator&logo=GitHub" alt="Follow @regginator (GitHub)" />
    </a>
    
</p>

About

This is a fairly simple, user-friendly utility module developers can use for serialization of Luau/Lua tables/data structures. This natively supports both Luau (Vanilla or Roblox), and Lua 5.1+

Features

  • Full serialization and output of basic types number, string, table, boolean, and nil for keys/values.
  • Fast, optimized, and efficient!
  • Flexible and user-friendly API.
  • Pretty-printing and custom indentation.
  • type() and typeof() support for full custom Roblox DataType support (e.g. Instance, UDim2, Vector3, DateTime, etc..) - See Custom Roblox Lua DataType Coverage for more info.
  • Secure iteration and value reading, so you can also use this with something like user-generated input and "RemoteSpy" scripts.
  • Built in duplicate/cyclic detection and stack limit.
  • Raw keys/values with FunctionsReturnRaw.

Installation

  • GitHub Releases

    You can download the LuaEncode.lua or LuaEncode.rbxm module for the latest GitHub release, and immediately use the module!

  • Rojo/Wally

    If you're familiar with Rojo or Wally, you can either clone the repository and build the model yourself, or import in your Wally.toml as a dependency:

    • As a dependency in Wally.toml:

      LuaEncode = "regginator/luaencode@1.1.6"
      
    • Rojo: (Building manually)

      rojo build -o LuaEncode.rbxm
      
  • Git Submodule

    If you're familiar with Git Submodules, you can import the repo into your project as per use case.

  • Loadstring by Release URL

    If you're using a script utility with direct access to loadstring(), you can use the following line to import the module into your project:

    local LuaEncode = loadstring(game:HttpGet("https://github.com/regginator/LuaEncode/releases/latest/download/LuaEncode.lua"))()
    

    (Or with HttpService if using the Roblox API)

    local HttpService = game:GetService("HttpService")
    local LuaEncode = loadstring(HttpService:GetAsync("https://github.com/regginator/LuaEncode/releases/latest/download/LuaEncode.lua"))()
    

Basic Usage

local LuaEncode = require("src/LuaEncode")

local Table = {
    foo = "bar",
    baz = {
        1,
        "one",
        true,
        false,
        [90] = "ninety",
        ["hi mom"] = "hello world",
    },
    qux = function()
        return "\"hi!\""
    end,
}

local Encoded = LuaEncode(Table, {
    PrettyPrinting = true, -- `false` by default
    IndentCount = 4, -- `0` by default
    FunctionsReturnRaw = true, -- `false` by default
})

print(Encoded)

Expected Output:

{
    qux = "hi!",
    baz = {
        1,
        "one",
        true,
        false,
        [90] = "ninety",
        ["hi mom"] = "hello world"
    },
    foo = "bar"
}

API

<string> LuaEncode(<table> inputTable, <table?> options)

Options

ArgumentTypeDescription
PrettyPrinting<boolean?:false>Whether or not the output should use pretty printing.
IndentCount<number?:0>The amount of "spaces" that should be indented per entry.
OutputWarnings<boolean?:true>If "warnings" should be placed to the output (as comments); It's recommended to keep this enabled, however this can be disabled at ease.
StackLimit<number?:500>The limit to the stack level before recursive encoding cuts off, and stops execution. This is used to prevent stack overflow errors and such. You could use math.huge here if you really wanted.
FunctionsReturnRaw<boolean?:false>If functions in said table return back a "raw" value to place in the output as the key/value.
UseInstancePaths<boolean?:false>If Instance reference objects should return their Lua-accessable path for encoding. If the instance is parented under nil or isn't under game/workspace, it'll always fall back to Instance.new(ClassName) as before.

Custom Roblox Lua DataType Coverage

(See AllRobloxTypes.server.lua for example input and (the current expected) output of ALL Roblox DataTypes.)

✔ Implemented | ➖ Partially Implemented | ❌ Unimplemented | ⛔ Never

DataTypeSerialized AsImplemented
AxesAxes.new()✔
BrickColorBrickColor.new()✔
CFrameCFrame.new()✔
CatalogSearchParamsCatalogSearchParams.new()✔
Color3Color3.new()✔
ColorSequenceColorSequence.new(<ColorSequenceKeypoints>)✔
ColorSequenceKeypointColorSequenceKeypoint.new()✔
DateTimeDateTime.fromUnixTimestamp()✔
DockWidgetPluginGuiInfoDockWidgetPluginGuiInfo.new()✔
EnumEnum.<EnumType>✔
EnumItemEnum.<EnumType>.<EnumItem>✔
EnumsEnum✔
FacesFaces.new()✔
FloatCurveKeyFloatCurveKey.new()✔
FontFont.new()✔
InstanceInstance.new()✔
NumberRangeNumberRange.new()✔
NumberSequenceNumberSequence.new(<NumberSequenceKeypoints>)✔
NumberSequenceKeypointNumberSequenceKeypoint.new()✔
OverlapParamsOverlapParams.new()✔
PathWaypointPathWaypoint.new()✔
PhysicalPropertiesPhysicalProperties.new()✔
RBXScriptConnectionN/A⛔
RBXScriptSignalN/A⛔
RandomRandom.new()✔
RayRay.new()✔
RaycastParamsRaycastParams.new()✔
RaycastResultN/A⛔
RectRect.new()✔
Region3Region3.new()✔
Region3int16Region3int16.new()✔
TweenInfoTweenInfo.new()✔
RotationCurveKeyRotationCurveKey.new()✔
UDimUDim.new()✔
UDim2UDim2.new()✔
Vector2Vector2.new()✔
Vector2int16Vector2int16.new()✔
Vector3Vector3.new()✔
Vector3int16Vector3int16.new()✔

(Official Roblox DataType documentation here)


License

MIT License

Copyright (c) 2022 Reggie <reggie@latte.to>

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.

Package Details

Install command (Click to copy)


Version

1.4.3

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.