mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Update all code styles
This commit is contained in:
@@ -6,72 +6,72 @@ local type = type
|
||||
local concat = table.concat
|
||||
local inspect = table.inspect
|
||||
local pcall = pcall
|
||||
local loadstring = loadstring ---@diagnostic disable-line
|
||||
local loadstring = loadstring --- @diagnostic disable-line
|
||||
local rawset = rawset
|
||||
|
||||
local Public = {}
|
||||
|
||||
local luaObject = {'{', nil, ", name = '", nil, "'}"}
|
||||
local luaPlayer = {"{LuaPlayer, name = '", nil, "', index = ", nil, '}'}
|
||||
local luaEntity = {"{LuaEntity, name = '", nil, "', unit_number = ", nil, '}'}
|
||||
local luaGuiElement = {"{LuaGuiElement, name = '", nil, "'}"}
|
||||
local luaObject = { "{", nil, ", name = '", nil, "'}" }
|
||||
local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" }
|
||||
local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" }
|
||||
local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
|
||||
|
||||
local function get(obj, prop)
|
||||
return obj[prop]
|
||||
end
|
||||
|
||||
local function get_name_safe(obj)
|
||||
local s, r = pcall(get, obj, 'name')
|
||||
local s, r = pcall(get, obj, "name")
|
||||
if not s then
|
||||
return 'nil'
|
||||
return "nil"
|
||||
else
|
||||
return r or 'nil'
|
||||
return r or "nil"
|
||||
end
|
||||
end
|
||||
|
||||
local function get_lua_object_type_safe(obj)
|
||||
local s, r = pcall(get, obj, 'help')
|
||||
local s, r = pcall(get, obj, "help")
|
||||
|
||||
if not s then
|
||||
return
|
||||
end
|
||||
|
||||
return r():match('Lua%a+')
|
||||
return r():match("Lua%a+")
|
||||
end
|
||||
|
||||
local function inspect_process(item)
|
||||
if type(item) ~= 'table' or type(item.__self) ~= 'userdata' then
|
||||
if type(item) ~= "table" or type(item.__self) ~= "userdata" then
|
||||
return item
|
||||
end
|
||||
|
||||
local suc, valid = pcall(get, item, 'valid')
|
||||
local suc, valid = pcall(get, item, "valid")
|
||||
if not suc then
|
||||
-- no 'valid' property
|
||||
return get_lua_object_type_safe(item) or '{NoHelp LuaObject}'
|
||||
return get_lua_object_type_safe(item) or "{NoHelp LuaObject}"
|
||||
end
|
||||
|
||||
if not valid then
|
||||
return '{Invalid LuaObject}'
|
||||
return "{Invalid LuaObject}"
|
||||
end
|
||||
|
||||
local obj_type = get_lua_object_type_safe(item)
|
||||
if not obj_type then
|
||||
return '{NoHelp LuaObject}'
|
||||
return "{NoHelp LuaObject}"
|
||||
end
|
||||
|
||||
if obj_type == 'LuaPlayer' then
|
||||
luaPlayer[2] = item.name or 'nil'
|
||||
luaPlayer[4] = item.index or 'nil'
|
||||
if obj_type == "LuaPlayer" then
|
||||
luaPlayer[2] = item.name or "nil"
|
||||
luaPlayer[4] = item.index or "nil"
|
||||
|
||||
return concat(luaPlayer)
|
||||
elseif obj_type == 'LuaEntity' then
|
||||
luaEntity[2] = item.name or 'nil'
|
||||
luaEntity[4] = item.unit_number or 'nil'
|
||||
elseif obj_type == "LuaEntity" then
|
||||
luaEntity[2] = item.name or "nil"
|
||||
luaEntity[4] = item.unit_number or "nil"
|
||||
|
||||
return concat(luaEntity)
|
||||
elseif obj_type == 'LuaGuiElement' then
|
||||
elseif obj_type == "LuaGuiElement" then
|
||||
local name = item.name
|
||||
luaGuiElement[2] = gui_names and gui_names[name] or name or 'nil'
|
||||
luaGuiElement[2] = gui_names and gui_names[name] or name or "nil"
|
||||
|
||||
return concat(luaGuiElement)
|
||||
else
|
||||
@@ -82,10 +82,11 @@ local function inspect_process(item)
|
||||
end
|
||||
end
|
||||
|
||||
local inspect_options = {process = inspect_process}
|
||||
local inspect_options = { process = inspect_process }
|
||||
function Public.dump(data)
|
||||
return inspect(data, inspect_options)
|
||||
end
|
||||
|
||||
local dump = Public.dump
|
||||
|
||||
function Public.dump_ignore_builder(ignore)
|
||||
@@ -97,14 +98,14 @@ function Public.dump_ignore_builder(ignore)
|
||||
return inspect_process(item)
|
||||
end
|
||||
|
||||
local options = {process = process}
|
||||
local options = { process = process }
|
||||
return function(data)
|
||||
return inspect(data, options)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.dump_function(func)
|
||||
local res = {'upvalues:\n'}
|
||||
local res = { "upvalues:\n" }
|
||||
|
||||
local i = 1
|
||||
while true do
|
||||
@@ -112,11 +113,11 @@ function Public.dump_function(func)
|
||||
|
||||
if n == nil then
|
||||
break
|
||||
elseif n ~= '_ENV' then
|
||||
elseif n ~= "_ENV" then
|
||||
res[#res + 1] = n
|
||||
res[#res + 1] = ' = '
|
||||
res[#res + 1] = " = "
|
||||
res[#res + 1] = dump(v)
|
||||
res[#res + 1] = '\n'
|
||||
res[#res + 1] = "\n"
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
@@ -126,16 +127,16 @@ function Public.dump_function(func)
|
||||
end
|
||||
|
||||
function Public.dump_text(text, player)
|
||||
local func = loadstring('return ' .. text)
|
||||
local func = loadstring("return " .. text)
|
||||
if not func then
|
||||
return false
|
||||
end
|
||||
|
||||
rawset(game, 'player', player)
|
||||
rawset(game, "player", player)
|
||||
|
||||
local suc, var = pcall(func)
|
||||
|
||||
rawset(game, 'player', nil)
|
||||
rawset(game, "player", nil)
|
||||
|
||||
if not suc then
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user