shagu / pfUI

A User Interface Replacement for World of Warcraft: Vanilla & TBC
https://shagu.org/pfUI
MIT License
339 stars 117 forks source link

please rename your custom print function #1239

Closed Artur91425 closed 5 months ago

Artur91425 commented 8 months ago

Please rename the print function to some other name. As a developer, it is important for me to display the values of variables in the chat and I use the original Blizzard code for this function, but your addon overwrites it... The functionality of your implementation is the simplest and it is not able to display several variables, and also an unnecessary postscript [INFO] is added... Please rename your function or modify it to the original Blizzard functionality. I attach the original code below:

local LOCAL_ToStringAllTemp = {}
function tostringall(...)
  local n = getn(arg)
  -- Simple versions for common argument counts
  if (n == 1) then
    return tostring(arg[1])
    elseif (n == 2) then
    return tostring(arg[1]), tostring(arg[2])
    elseif (n == 3) then
    return tostring(arg[1]), tostring(arg[2]), tostring(arg[3])
    elseif (n == 0) then
    return
  end

  local needfix
  for i = 1, n do
    local v = arg[i]
    if (type(v) ~= "string") then
      needfix = i
      break
    end
  end
  if (not needfix) then return unpack(arg) end

  wipe(LOCAL_ToStringAllTemp)
  for i = 1, needfix - 1 do
    LOCAL_ToStringAllTemp[i] = arg[i]
  end
  for i = needfix, n do
    LOCAL_ToStringAllTemp[i] = tostring(arg[i])
  end
  return unpack(LOCAL_ToStringAllTemp)
end

local LOCAL_PrintHandler = function(...)
  DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(unpack(arg))))
end

function setprinthandler(func)
  if (type(func) ~= "function") then
    error("Invalid print handler")
    else
    LOCAL_PrintHandler = func
  end
end

function getprinthandler() return LOCAL_PrintHandler end

local function print_inner(...)
  local ok, err = pcall(LOCAL_PrintHandler, unpack(arg))
  if (not ok) then
    local func = geterrorhandler()
    func(err)
  end
end

function print(...)
  pcall(print_inner, unpack(arg))
end

SLASH_PRINT1 = "/print"
SlashCmdList["PRINT"] = print
github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 30 days with no activity.

shagu commented 5 months ago

Oops, Sorry! It now only sets it if there is no other: https://github.com/shagu/pfUI/commit/b37e8bdc5593afc28f8d73a405a5bfcd1b14db7f