📄 compat.lua
字号:
--------------------------------------------------------------------- Real globals-- _ALERT-- _ERRORMESSAGE-- _VERSION-- _G-- assert-- error-- metatable-- next-- print-- require-- tonumber-- tostring-- type-- unpack--------------------------------------------------------------------- collectgarbage-- gcinfo-- globals-- call -> protect(f, err)-- loadfile-- loadstring-- rawget-- rawset-- getargs = Main.getargs ??rawtype = typefunction do_ (f, err) if not f then print(err); return end local a,b = pcall(f) if not a then print(b); return nil else return b or true endendfunction dostring(s) return do_(loadstring(s)) end-- function dofile(s) return do_(loadfile(s)) end--------------------------------------------------------------------- Table librarylocal tab = tableforeach = tab.foreachforeachi = tab.foreachigetn = tab.getntinsert = tab.inserttremove = tab.removesort = tab.sort--------------------------------------------------------------------- Debug librarylocal dbg = debuggetinfo = dbg.getinfogetlocal = dbg.getlocalsetcallhook = function () error"`setcallhook' is deprecated" endsetlinehook = function () error"`setlinehook' is deprecated" endsetlocal = dbg.setlocal--------------------------------------------------------------------- math librarylocal math = mathabs = math.absacos = function (x) return math.deg(math.acos(x)) endasin = function (x) return math.deg(math.asin(x)) endatan = function (x) return math.deg(math.atan(x)) endatan2 = function (x,y) return math.deg(math.atan2(x,y)) endceil = math.ceilcos = function (x) return math.cos(math.rad(x)) enddeg = math.degexp = math.expfloor = math.floorfrexp = math.frexpldexp = math.ldexplog = math.loglog10 = math.log10max = math.maxmin = math.minmod = math.modPI = math.pi--??? pow = math.pow rad = math.radrandom = math.randomrandomseed = math.randomseedsin = function (x) return math.sin(math.rad(x)) endsqrt = math.sqrttan = function (x) return math.tan(math.rad(x)) end--------------------------------------------------------------------- string librarylocal str = stringstrbyte = str.bytestrchar = str.charstrfind = str.findformat = str.formatgsub = str.gsubstrlen = str.lenstrlower = str.lowerstrrep = str.repstrsub = str.substrupper = str.upper--------------------------------------------------------------------- os libraryclock = os.clockdate = os.datedifftime = os.difftimeexecute = os.execute --?exit = os.exitgetenv = os.getenvremove = os.removerename = os.renamesetlocale = os.setlocaletime = os.timetmpname = os.tmpname--------------------------------------------------------------------- compatibility onlygetglobal = function (n) return _G[n] endsetglobal = function (n,v) _G[n] = v end-------------------------------------------------------------------local io, tab = io, table-- IO library (files)_STDIN = io.stdin_STDERR = io.stderr_STDOUT = io.stdout_INPUT = io.stdin_OUTPUT = io.stdoutseek = io.stdin.seek -- sick ;-)tmpfile = io.tmpfileclosefile = io.closeopenfile = io.openfunction flush (f) if f then f:flush() else _OUTPUT:flush() endendfunction readfrom (name) if name == nil then local f, err, cod = io.close(_INPUT) _INPUT = io.stdin return f, err, cod else local f, err, cod = io.open(name, "r") _INPUT = f or _INPUT return f, err, cod endendfunction writeto (name) if name == nil then local f, err, cod = io.close(_OUTPUT) _OUTPUT = io.stdout return f, err, cod else local f, err, cod = io.open(name, "w") _OUTPUT = f or _OUTPUT return f, err, cod endendfunction appendto (name) local f, err, cod = io.open(name, "a") _OUTPUT = f or _OUTPUT return f, err, codendfunction read (...) local f = _INPUT if rawtype(arg[1]) == 'userdata' then f = tab.remove(arg, 1) end return f:read(unpack(arg))endfunction write (...) local f = _OUTPUT if rawtype(arg[1]) == 'userdata' then f = tab.remove(arg, 1) end return f:write(unpack(arg))end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -