<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ACombat_Achievements_Json</id>
	<title>Module:Combat Achievements Json - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ACombat_Achievements_Json"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Combat_Achievements_Json&amp;action=history"/>
	<updated>2026-05-12T17:17:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Module:Combat_Achievements_Json&amp;diff=34450&amp;oldid=prev</id>
		<title>Alex: Created page with &quot;-- -- json.lua -- -- Copyright (c) 2020 rxi -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of -- this software and associated documentation files (the &quot;Software&quot;), to deal in -- the Software without restriction, including without limitation the rights to -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is furnished to do -- so, subject to the...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Combat_Achievements_Json&amp;diff=34450&amp;oldid=prev"/>
		<updated>2024-10-16T23:00:51Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;-- -- json.lua -- -- Copyright (c) 2020 rxi -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of -- this software and associated documentation files (the &amp;quot;Software&amp;quot;), to deal in -- the Software without restriction, including without limitation the rights to -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is furnished to do -- so, subject to the...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- json.lua&lt;br /&gt;
--&lt;br /&gt;
-- Copyright (c) 2020 rxi&lt;br /&gt;
--&lt;br /&gt;
-- Permission is hereby granted, free of charge, to any person obtaining a copy of&lt;br /&gt;
-- this software and associated documentation files (the &amp;quot;Software&amp;quot;), to deal in&lt;br /&gt;
-- the Software without restriction, including without limitation the rights to&lt;br /&gt;
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies&lt;br /&gt;
-- of the Software, and to permit persons to whom the Software is furnished to do&lt;br /&gt;
-- so, subject to the following conditions:&lt;br /&gt;
--&lt;br /&gt;
-- The above copyright notice and this permission notice shall be included in all&lt;br /&gt;
-- copies or substantial portions of the Software.&lt;br /&gt;
--&lt;br /&gt;
-- THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR&lt;br /&gt;
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,&lt;br /&gt;
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE&lt;br /&gt;
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER&lt;br /&gt;
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,&lt;br /&gt;
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE&lt;br /&gt;
-- SOFTWARE.&lt;br /&gt;
--&lt;br /&gt;
local encode&lt;br /&gt;
&lt;br /&gt;
local escape_char_map = {&lt;br /&gt;
  [ &amp;quot;\\&amp;quot; ] = &amp;quot;\\&amp;quot;,&lt;br /&gt;
  [ &amp;quot;\&amp;quot;&amp;quot; ] = &amp;quot;\&amp;quot;&amp;quot;,&lt;br /&gt;
  [ &amp;quot;\b&amp;quot; ] = &amp;quot;b&amp;quot;,&lt;br /&gt;
  [ &amp;quot;\f&amp;quot; ] = &amp;quot;f&amp;quot;,&lt;br /&gt;
  [ &amp;quot;\n&amp;quot; ] = &amp;quot;n&amp;quot;,&lt;br /&gt;
  [ &amp;quot;\r&amp;quot; ] = &amp;quot;r&amp;quot;,&lt;br /&gt;
  [ &amp;quot;\t&amp;quot; ] = &amp;quot;t&amp;quot;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local escape_char_map_inv = { [ &amp;quot;/&amp;quot; ] = &amp;quot;/&amp;quot; }&lt;br /&gt;
for k, v in pairs(escape_char_map) do&lt;br /&gt;
  escape_char_map_inv[v] = k&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function escape_char(c)&lt;br /&gt;
  return &amp;quot;\\&amp;quot; .. (escape_char_map[c] or string.format(&amp;quot;u%04x&amp;quot;, c:byte()))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function encode_nil(val)&lt;br /&gt;
  return &amp;quot;null&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function encode_table(val, stack)&lt;br /&gt;
  local res = {}&lt;br /&gt;
  stack = stack or {}&lt;br /&gt;
&lt;br /&gt;
  -- Circular reference?&lt;br /&gt;
  if stack[val] then error(&amp;quot;circular reference&amp;quot;) end&lt;br /&gt;
&lt;br /&gt;
  stack[val] = true&lt;br /&gt;
&lt;br /&gt;
  if rawget(val, 1) ~= nil or next(val) == nil then&lt;br /&gt;
    -- Treat as array -- check keys are valid and it is not sparse&lt;br /&gt;
    local n = 0&lt;br /&gt;
    for k in pairs(val) do&lt;br /&gt;
      if type(k) ~= &amp;quot;number&amp;quot; then&lt;br /&gt;
        error(&amp;quot;invalid table: mixed or invalid key types&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
      n = n + 1&lt;br /&gt;
    end&lt;br /&gt;
    if n ~= #val then&lt;br /&gt;
      error(&amp;quot;invalid table: sparse array&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    -- Encode&lt;br /&gt;
    for i, v in ipairs(val) do&lt;br /&gt;
      table.insert(res, encode(v, stack))&lt;br /&gt;
    end&lt;br /&gt;
    stack[val] = nil&lt;br /&gt;
    return &amp;quot;[&amp;quot; .. table.concat(res, &amp;quot;,&amp;quot;) .. &amp;quot;]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  else&lt;br /&gt;
    -- Treat as an object&lt;br /&gt;
    for k, v in pairs(val) do&lt;br /&gt;
      if type(k) ~= &amp;quot;string&amp;quot; then&lt;br /&gt;
        error(&amp;quot;invalid table: mixed or invalid key types&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
      table.insert(res, encode(k, stack) .. &amp;quot;:&amp;quot; .. encode(v, stack))&lt;br /&gt;
    end&lt;br /&gt;
    stack[val] = nil&lt;br /&gt;
    return &amp;quot;{&amp;quot; .. table.concat(res, &amp;quot;,&amp;quot;) .. &amp;quot;}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function encode_string(val)&lt;br /&gt;
  return &amp;#039;&amp;quot;&amp;#039; .. val:gsub(&amp;#039;[%z\1-\31\\&amp;quot;]&amp;#039;, escape_char) .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function encode_number(val)&lt;br /&gt;
  -- Check for NaN, -inf and inf&lt;br /&gt;
  if val ~= val or val &amp;lt;= -math.huge or val &amp;gt;= math.huge then&lt;br /&gt;
    error(&amp;quot;unexpected number value &amp;#039;&amp;quot; .. tostring(val) .. &amp;quot;&amp;#039;&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  return string.format(&amp;quot;%.14g&amp;quot;, val)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local type_func_map = {&lt;br /&gt;
  [ &amp;quot;nil&amp;quot;     ] = encode_nil,&lt;br /&gt;
  [ &amp;quot;table&amp;quot;   ] = encode_table,&lt;br /&gt;
  [ &amp;quot;string&amp;quot;  ] = encode_string,&lt;br /&gt;
  [ &amp;quot;number&amp;quot;  ] = encode_number,&lt;br /&gt;
  [ &amp;quot;boolean&amp;quot; ] = tostring,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
encode = function(val, stack)&lt;br /&gt;
  local t = type(val)&lt;br /&gt;
  local f = type_func_map[t]&lt;br /&gt;
  if f then&lt;br /&gt;
    return f(val, stack)&lt;br /&gt;
  end&lt;br /&gt;
  error(&amp;quot;unexpected type &amp;#039;&amp;quot; .. t .. &amp;quot;&amp;#039;&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Actual code&lt;br /&gt;
local p = {}&lt;br /&gt;
function p.json()&lt;br /&gt;
	local out = {}&lt;br /&gt;
	local params = {&lt;br /&gt;
		&amp;quot;[[Category:Combat_Achievements]]&amp;quot;,&lt;br /&gt;
		&amp;quot;?Combat Achievement JSON&amp;quot;,&lt;br /&gt;
		limit = 10000&lt;br /&gt;
	}&lt;br /&gt;
	local data = mw.smw.ask(params) or {}&lt;br /&gt;
	&lt;br /&gt;
	for _, task in ipairs(data) do&lt;br /&gt;
		local raw = task[&amp;#039;Combat Achievement JSON&amp;#039;]&lt;br /&gt;
		if raw ~= nil then&lt;br /&gt;
			local json = mw.text.jsonDecode(raw)&lt;br /&gt;
			table.insert(out, json)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return encode(out)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>