Skip to content

Commit

Permalink
Prettify function tostring (#2870)
Browse files Browse the repository at this point in the history
* Prettify function tostring

* E2Descriptions

* Change definition style

* Change

* Add function to table print
  • Loading branch information
Denneisk authored Nov 22, 2023
1 parent ed5908d commit f2f87c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
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 @@ end
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
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 @@ local tostring_typeid = {
xm2 = tostrings.table,
a = tostrings.Vector,
xv4 = tostrings.Vector4,
f = tostring
}

local function checkAbort( ret, cost, abortafter )
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"

0 comments on commit f2f87c5

Please sign in to comment.