From 979676be219b83c7295409824ee8280a3335cc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 6 Dec 2018 18:07:10 +0800 Subject: =?UTF-8?q?=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/json/init.lua | 1 - server/src/json/table.lua | 62 ----------------------------------------------- 2 files changed, 63 deletions(-) delete mode 100644 server/src/json/table.lua (limited to 'server/src/json') diff --git a/server/src/json/init.lua b/server/src/json/init.lua index db513678..c28e7aed 100644 --- a/server/src/json/init.lua +++ b/server/src/json/init.lua @@ -1,7 +1,6 @@ local api = { decode = require 'json.decode', encode = require 'json.encode', - table = require 'json.table', } return api diff --git a/server/src/json/table.lua b/server/src/json/table.lua deleted file mode 100644 index 351bfe07..00000000 --- a/server/src/json/table.lua +++ /dev/null @@ -1,62 +0,0 @@ - -local pairs = pairs -local next = next -local sort = table.sort -local type = type -local rawset = rawset -local move = table.move -local setmetatable = setmetatable - -local function sort_table(tbl) - if not tbl then - tbl = {} - end - local mt = {} - local keys = {} - local mark = {} - local n = 0 - for key in next, tbl do - n=n+1;keys[n] = key - mark[key] = true - end - sort(keys) - function mt:__newindex(key, value) - rawset(self, key, value) - n=n+1;keys[n] = key - mark[key] = true - if type(value) == 'table' then - sort_table(value) - end - end - function mt:__pairs() - local list = {} - local m = 0 - for key in next, self do - if not mark[key] then - m=m+1;list[m] = key - end - end - if m > 0 then - move(keys, 1, n, m+1) - sort(list) - for i = 1, m do - local key = list[i] - keys[i] = key - mark[key] = true - end - n = n + m - end - local i = 0 - return function () - i = i + 1 - local key = keys[i] - return key, self[key] - end - end - - return setmetatable(tbl, mt) -end - -return function (tbl) - return sort_table(tbl) -end -- cgit v1.2.3