Template:O/doc: Difference between revisions

Template page
(Created page with "== Example == {{o |foo=42 |bar=''Bold'' |baz=Acid Rain |quux={{o|foo|bar|baz}} }}")
 
Line 1: Line 1:
{{Lua|Module:O}}
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.
== Usage ==
<syntaxhighlight lang="html">
{{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=?}}
  }}
}}
</syntaxhighlight>
Later, in a Lua module:
<syntaxhighlight lang="lua">
local O = require("O")
p.main = function(frame) do
  local standing = O.decode( frame.args.standing )
  for k,v in pairs(standing)
    standing[k] = O.decode(v)
  end
end
</syntaxhighlight>
== Example ==
== Example ==


{{o
{{o
   |foo=42
   |{{o|frames=-10|id=Bryan-2,3}}
  |bar=''Bold''
   |{{o|frames=-10|id=Bryan-1,4}}
  |baz=[[Acid Rain]]
   |quux={{o|foo|bar|baz}}
}}
}}

Revision as of 09:54, 5 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.

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:

local O = require("O")

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

Example

5b223762323236363732363136643635373332323361323232643331333032323263323236393634323233613232343237323739363136653264333232633333323237645c6e2020222c223762323236363732363136643635373332323361323232643331333032323263323236393634323233613232343237323739363136653264333132633334323237645c6e225d