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 all commits
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
4 changes: 4 additions & 0 deletions lua/entities/gmod_wire_expression2/core/e2lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
local Function = {}
Function.__index = Function

function Function:__tostring()
return "function(" .. self.arg_sig .. ")" .. ((self.ret and (": " .. self.ret)) or "")
end

function Function.new(args, ret, fn)
return setmetatable({ arg_sig = args, ret = ret, fn = fn }, Function)
end
Expand Down Expand Up @@ -216,7 +220,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 223 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 +1207,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 1210 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)
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_expression2/core/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
xm2 = tostrings.table,
a = tostrings.Vector,
xv4 = tostrings.Vector4,
f = tostring
}

local function checkAbort( ret, cost, abortafter )
Expand Down Expand Up @@ -979,7 +980,7 @@
--------------------------------------------------------------------------------

registerCallback( "postinit", function()
local getf, setf

Check warning on line 983 in lua/entities/gmod_wire_expression2/core/table.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: getf

Check warning on line 983 in lua/entities/gmod_wire_expression2/core/table.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: setf
for k,v in pairs( wire_expression_types ) do
local name = k
local id = v[1]
Expand Down
5 changes: 5 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1762,3 +1762,8 @@ E2Helper.Descriptions["takeDamage(e:ne)"] = "Applies an amount of damage to the
E2Helper.Descriptions["takeDamage(e:nee)"] = "Applies an amount of damage to the player with given attacker and inflictor. Requires wire_expression2_damage_enabled to be set to 1."

E2Helper.Descriptions["blastDamage(vnn)"] = "Creates blast damage at the position provided with specified radius and damage amount. Requires wire_expression2_damage_enabled to be set to 1."

-- Functions

E2Helper.Descriptions["getParameterTypes(f:)"] = "Returns an array of the parameter typeids of the function"
E2Helper.Descriptions["getReturnType(f:)"] = "Returns the return typeid of the function"
Loading