LibTextFormat (0.0.10)

Change Log:
——————–
## 2025.02.05
– Fixes, added documentation

Description:
——————–
LibTextFormat

Library for Elder Scrolls Online Addons – Dynamic mail templates

Advanced Text Formatting and Parsing

This library is to add advanced text parsing and formatting, suitable for use in any precanned communication.

It allows addons to refer to variables in text, such as “{house}” which will output a formatted house link.

It also enables addons to create “protocols” in which you can encode an object into text, then decode it later to get the object back.

Reason for being

Vanilla Lua text formatting is ok in simple circumstances, but it gets hard to read and tedious sprinkling lots of”hello”..GetDisplayName()..”how are you”..punctuation everywhere.

Having filters enables much more readable text blobs, and allows you to pass around variables and adjust them as needed.

Additionally protocols enable encoding of data structures, which is helpful for use cases, such as passing data programmatically between users of the same addon.

Basic Usage

Setup

The first thing LibTextFormat requires you to do is to initialize it with a saved variables “namespace” so that it can save filters and similar objects specific to your addon.

First declare your saved varsMyAddon.savedVars = ZO_SavedVars:NewAccountWide(“MyAddon_Vars”, 1, GetWorldName(), {libNamespace = {LTF = {}}})

Then initialize LibTextFormat with the object.MyAddon.LTF = MyAddon.LTF or LibTextFormat:New(MyAddon.savedVars.libNamespace.LTF)

You can register custom filters either one by one or in bulk, with the function doing any needed processing and returning the desired substitution.Parameters are passed in sequentially and separated by a comma “,” in the filter, with the filter string being separated out by a pipe “|”.

{greeting,name|mytag}

Now you can also register “core” filters which includes the house filter, among others:MyAddon.LTF:RegisterCore()

One…

Leave a Reply

Your email address will not be published. Required fields are marked *

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.