User:Crowley666/Run locally

From Wiktionary, the free dictionary
Jump to navigation Jump to search

To run some scripts locally with Lua 5.4.3:

unpack = unpack or table.unpack
mw = { ustring = require("ustring/ustring"), html = require("html"), text = {} }
tr = require('Module:th-translit').tr
function mw.text.gsplit( text, pattern, plain )
	local s, l = 1, mw.ustring.len( text )
	return function ()
		if s then
			local e, n = mw.ustring.find( text, pattern, s, plain )
			local ret
			if not e then
				ret = mw.ustring.sub( text, s )
				s = nil
			elseif n < e then
				-- Empty separator!
				ret = mw.ustring.sub( text, s, e )
				if e < l then
					s = e + 1
				else
					s = nil
				end
			else
				ret = e > s and mw.ustring.sub( text, s, e - 1 ) or ''
				s = n + 1
			end
			return ret
		end
	end, nil, nil
end
  • Result:
tr("เฮิ็้ย")
́i
  • As a result, some functions in Module:th-pron are not supported.
  • mwtext.JSON_PRESERVE_KEYS(1) will effect iff:
    • '[]' table
    • '{"0":?,"1":?,"2":?}' table, with 0...#t-1 all present.
  • bliki: [1]