Template:O/doc: Difference between revisions

Template page
(→‎Usage: fix require() call)
 
(3 intermediate revisions by one other user not shown)
Line 2: Line 2:


This template encodes its arguments into JSON and then hex encodes the JSON. These arguments can then later be decoded by [[Module:O]]. This allows templates to use more complicated data structures for their arguments with ordinary wikitext syntax.
This template encodes its arguments into JSON and then hex encodes the JSON. These arguments can then later be decoded by [[Module:O]]. This allows templates to use more complicated data structures for their arguments with ordinary wikitext syntax.
The name of this module is short for Object, which is what JSON calls its key-value pair data structure.


== Usage ==
== Usage ==
Line 21: Line 23:


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local O = require("O")
local O = require("Module:O")


p.main = function(frame) do
p.main = function(frame) do
   local standing = O.decode( frame.args.standing )
   local standing = O.decode( frame:getParent().args.standing )
   for k,v in pairs(standing)
   for k,v in pairs(standing)
     standing[k] = O.decode(v)
     standing[k] = O.decode(v)

Latest revision as of 10:12, 8 September 2023

This template encodes its arguments into JSON and then hex encodes the JSON. These arguments can then later be decoded by Module:O. This allows templates to use more complicated data structures for their arguments with ordinary wikitext syntax.

The name of this module is short for Object, which is what JSON calls its key-value pair data structure.

Usage

{{PunisherTable
  |standing={{o
    |{{o|frames=-10|id=Bryan-2,3}}
    |{{o|frames=-10|id=Bryan-1,4}}
  }}
  |crouching={{o
    |{{o|frames=-11|id=ws4}}
    |{{o|frames=-15|id=ws1|combo=?}}
  }}
}}

Later, in a Lua module called by {{PunisherTable}}:

local O = require("Module:O")

p.main = function(frame) do
  local standing = O.decode( frame:getParent().args.standing )
  for k,v in pairs(standing)
    standing[k] = O.decode(v)
  end
end

Example

5b223762323236363732363136643635373332323361323232643331333032323263323236393634323233613232343237323739363136653264333232633333323237645c6e2020222c223762323236363732363136643635373332323361323232643331333032323263323236393634323233613232343237323739363136653264333132633334323237645c6e225d