You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A library-companion to register custom data types that can be encoded and decoded for json.lua.
How to use:
Require it as such: local arson = require("arson")
or if it is nested in a directory: local arson = require("folder.folder.arson")
You can check the main.lua as an example. It has descriptive comments.
Custom Data/Class Prerequisite
Your class or object must have the public field type. This will be used by Arson to determine whether a table stored in the data is to be encoded/decoded
--(t : table)--returns custom_encoded_table : tablelocaldata= {
1, 2, 3, custom_vec2_class(1, 1),
foo= { 4, 5, 6 },
bar=custom_vec2_class(2, 2),
}
localcustom_data=arson.encode(data)
--[[returned table:{1, 2, 3, { x = 1, y = 1, type = "custom_vec2_class" },foo = { 4, 5, 6 },bar = { x = 1, y = 1, type = "custom_vec2_class" }}--]]--the custom_data table can now be used with json.lualocalstr_json=json.encode(custom_data)
Arson.decode - decode a table. It will modify the table passed as it will replace custom data with the decoded one
Example:
--(t : table)--returns nothing--first let us decode the str_jsonlocaljson_decoded=json.decode(str_json)
--then finally decode custom data/classarson.decode(json_decoded)
Why Arson?
It is from RSON, which is derived from Register-JSON. I know it does not make any sense. But is sounds cool.