mirror of
https://github.com/gmod-integration/lua.git
synced 2025-08-02 10:12:56 +00:00
fix: enhance serialization in console live exporter for better data handling
This commit is contained in:
parent
90e5f48f20
commit
9245625326
|
@ -1,10 +1,46 @@
|
||||||
local oldPrint = print
|
local oldPrint = print
|
||||||
function print(...)
|
|
||||||
local msg = table.concat({...}, " ")
|
local function serialize(val)
|
||||||
if gmInte.enableConsoleLiveExporter then
|
local ok, result = pcall(function()
|
||||||
gmInte.websocket:send("console_live_exporter", {
|
local t = type(val)
|
||||||
data = msg
|
if t == "string" or t == "number" then
|
||||||
}, nil, true)
|
return tostring(val)
|
||||||
|
elseif t == "Vector" or t == "Angle" then
|
||||||
|
return tostring(val)
|
||||||
|
elseif t == "Entity" then
|
||||||
|
return IsValid(val) and "Entity[" .. val:EntIndex() .. "]" or "Entity[NULL]"
|
||||||
|
elseif t == "table" then
|
||||||
|
local parts = {}
|
||||||
|
for k, v in pairs(val) do
|
||||||
|
parts[#parts+1] = "[" .. serialize(k) .. "]=" .. serialize(v)
|
||||||
|
end
|
||||||
|
return "{ " .. table.concat(parts, ", ") .. " }"
|
||||||
|
else
|
||||||
|
return "<" .. t .. ">"
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
if ok then
|
||||||
|
return result
|
||||||
|
else
|
||||||
|
return "<serialization error>"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function print(...)
|
||||||
|
if gmInte.enableConsoleLiveExporter then
|
||||||
|
local parts = {}
|
||||||
|
for i = 1, select("#", ...) do
|
||||||
|
parts[i] = serialize(select(i, ...))
|
||||||
|
end
|
||||||
|
|
||||||
|
local msg = table.concat(parts, " ")
|
||||||
|
local ok, err = pcall(function()
|
||||||
|
gmInte.websocket:send("console_live_exporter", { data = msg }, nil, true)
|
||||||
|
end)
|
||||||
|
if not ok then
|
||||||
|
oldPrint("ConsoleLiveExporter send error:", err)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
oldPrint(...)
|
oldPrint(...)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user