Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettify function tostring #2870

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/entities/gmod_wire_expression2/core/e2lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
---@field ret string
local Function = {}
Function.__index = Function
Function.__tostring = function(self)
Denneisk marked this conversation as resolved.
Show resolved Hide resolved
return "function(" .. self.arg_sig .. ")" .. (self.ret and ": " .. self.ret or "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "function(" .. self.arg_sig .. ")" .. (self.ret and ": " .. self.ret or "")
return "function(" .. self.arg_sig .. ")" .. (self.ret and (": " .. self.ret)) or ""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the LuaLS upset

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need another set of parens wrapping or "" I assume

end

function Function.new(args, ret, fn)
return setmetatable({ arg_sig = args, ret = ret, fn = fn }, Function)
Expand Down Expand Up @@ -216,7 +219,7 @@
local new_signature = string.format("%s(%s)", funcname, table.concat(args, ","))
if thistype then new_signature = thistype .. ":" .. new_signature end

return (not rets or rets == "") and (new_signature) or (E2Lib.typeName(rets) .. "=" .. new_signature)

Check warning on line 222 in lua/entities/gmod_wire_expression2/core/e2lib.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
end

-- ------------------------ various entity checkers ----------------------------
Expand Down Expand Up @@ -1203,7 +1206,7 @@
local status, tree, dvars = E2Lib.Parser.Execute(tokens)
if not status then return false, tree end

local status, script, inst = E2Lib.Compiler.Execute(tree, directives, dvars, {})

Check warning on line 1209 in lua/entities/gmod_wire_expression2/core/e2lib.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: inst
if not status then return false, script end

local ctx = RuntimeContext.builder()
Expand Down
8 changes: 7 additions & 1 deletion lua/entities/gmod_wire_expression2/core/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ __e2setcost(1)

e2function string function:getReturnType()
return this.ret or ""
end
end

e2function string toString(function func)
return tostring(func)
end

e2function string function:toString() = e2function string toString(function func)
Loading