GLON: Garry's Mod Lua Object Notation

This is for developers, you cannot shoot babies with it.

GLON (An extension of LON (Lua Object Notation (Also made by me))) is a serialisation module for Garry’s Mod Lua to create very compact storable strings. Unfortunately, that means non-human readable.
These are the types it can serialise:

	-- 2: table
	-- 3: array
	-- 4: fasle boolean
	-- 5: true boolean
	-- 6: number (NOT COMPRESSED, it isn't worth it)
	-- 7: string
	---- non-LON types start here!
	-- 8: Vector (NOT COMPRESSED, it isn't worth it)
	-- 9: Angle (NOT COMPRESSED, it isn't worth it)
	-- 10: Entity (Can do players, vehicles, npcs, weapons and any other type of entity (-1 for null entity))
	-- 11: Player (By UserID)
	-- 12: CEffectData
	-- 13: ConVar (Not ClientConVar)
	-- 15: Color
	-- 255: reference (Sends the ID of the table to use (for "local t = {} t.a=t"))

It can even serialise this:
local t = {}
t.a = t
whatever = glon.encode(t)
And do this when decoding it:
local t = glon.decode(whatever)
t.a.b = 5
print(t.b) – prints 5!
Because the encoder realises that t and t.a are the same table, so it writes t as a table, and writes t.a as a reference to t. When the decoder unserialises it, it makes a new table for t, then makes t.a the same table!

You can send any imaginable combination of data, as long as it keeps to the types listed above. You can even do things such as tables as keys.

Arrays (tables with only numerical keys) don’t worry about sending their keys.

Deco (Da Man) (Me) - Making the LON and GLON.
LuaBanana - Using it in his datastream module, and fixing GLON in the process.

Online Viewable Source:

Place in lua/includes/modules/.

Downloadable Source:
(Probably not coming (no need))

Example Output
local t = {
[“zomg\1!”] = LocalPlayer(),
[666] = GetConVar(“something”),
local s, sa, c, b = glon.encode(t), “”
for i = 1,s:len() do
c = string.sub(s, i, i)
b = string.byte©
if b < 33 or b > 125 then
sa = sa…"[\"…b…"]"
sa = sa…c
– Output:
– ([\NUMBER] means the char with NUMBER’s ID (will make sense to coders))
– [\2][\7]zomg[\1][\11]2[\1][\6]1[\1][\3][\7]An[\1][\7]Array![\1][\1][\6]666[\1][\13]something[\1][\1]
– Dissection:
– \2 Start of table
– \7 Start of string (key)
– z
– o
– m
– g
– \2
– \1
– !
– \1 End of string
– \11 Start of player (value)
– 2 My Entity Index
– \1 End of player
– \6 Start of number (key)
– 1
– \1 End of number
– \3 Start of array (value)
– \7 Start of string
– A
– n
– \1 End of string
– \7 Start of string
– A
– r
– r
– a
– y
– !
– \1 End of string
– \1 End of array
– \6 Start of number (key)
– 6
– 6
– 6
– \1
– \13 Start of ConVar
– s
– o
– m
– e
– t
– h
– i
– n
– g
– \1 End on ConVar
– \1 End of table

(Sorry for double post)

I request a Developer Releases subforum!

No, I think keeping the developer tools in the normal Lua forum is good enough.

Though many get lost and burried. Since a developer kit is not somthing where people will keep it on the first few pages with “OMG This looks, AWESOME, it’s on my server now and having great fun”.
A nice sticky for developers or a wiki page with nice layout and recomended addons/apps/plugins for us to use would be good.

How can I remove the hidden characters and replace them with another character?
I need this script for a special way of saving which doesn’t seem to work with those chars around.


Damn the chars don’t work on this forum.

That would remove the point of GLON…

If you only need to replace
, you can use what I gave LuaBanana for Datastream:
encoded = string.gsub(string.gsub(glon.encode(data),"\","\\"),"
local reptab = {[”\"]="\",[“n”]="
decoded = glon.decode(string.gsub(encoded,”\(.)",reptab))

You really should pcall the GLON functions, though, like so:
local b,err = pcall(glon.decode,encdat)
if b then decdat=err else error(“DataStreamServer Decoding Error: “…err…” (operation “…id…”)”) end
– do stuff with decdat

Hah great.

It looks like the saving supports utf character perfectly. It was just the
that was breaking things.


GLON doesn’t accept Vehicles, Weapons or NPCs, at least on the server side.

Here are 2 patches that both fix this problem. only one of them needs to be applied to glon.lua: - simply copy-pasted from the part for “Entity” - this one adds a small for loop that copies the handler for “Entity” to Vehicles, Weapons and NPCs.

I hope you can get this into the GLON version that comes with gmod :slight_smile:

can some one tell me how i use this GLON to do same as util.TableToKeyValues(my_Table)?

From the example, glon.encode(my_table)

oh ok sounds simple

i tought it would need something that tells to it what to do with the table


another problem how i can make file.Write(“my_Table.txt”,glon.encode(my_table)) back to table with file.Read(“my_Table.txt”) ?

Read the gmod wiki entry about GLON. It’s all described there.

how can i edit .txt econded with that? i see some characters and when i save it itcrashes the addon