Skip to content

Commit

Permalink
Add selfaware functions for E2 extensions (#2823)
Browse files Browse the repository at this point in the history
* Add selfaware functions for E2 extensions

* Optimize

* Lessons in futility
  • Loading branch information
Denneisk authored Nov 12, 2023
1 parent 14d7d07 commit 10731c4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lua/entities/gmod_wire_expression2/core/selfaware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,48 @@ e2function number entity:canSetName(string name)
return IsValid(this) and isOwner(self, this) and canSetName(self, this, name) and 1 or 0
end

--[[******************************************************************************]]--
-- Extensions

local getExtensionStatus = E2Lib.GetExtensionStatus
local e2Extensions
local e2ExtensionsTable
-- See postinit for these getting initialized

__e2setcost(30)

[nodiscard]
e2function array getExtensions()
local ret = {}
for k, v in ipairs(e2Extensions) do -- Optimized copy
ret[k] = v
end
return ret
end

__e2setcost(60)

[nodiscard]
e2function table getExtensionStatus()
local ret = E2Lib.newE2Table()
local s, stypes = ret.s, ret.stypes
ret.size = e2ExtensionsTable.size

for k, v in pairs(e2ExtensionsTable.s) do
s[k] = v
stypes[k] = "n"
end

return ret
end

__e2setcost(5)

[nodiscard]
e2function number getExtensionStatus(string extension)
return getExtensionStatus(extension) and 1 or 0
end


--[[******************************************************************************]]--

Expand Down Expand Up @@ -287,6 +329,18 @@ registerCallback("postinit", function()
end
end
end

e2Extensions = E2Lib.GetExtensions()
e2ExtensionsTable = E2Lib.newE2Table()
do
local s, stypes, size = e2ExtensionsTable.s, e2ExtensionsTable.stypes, 0
for _, ext in ipairs(e2Extensions) do
s[ext] = getExtensionStatus(ext) and 1 or 0
stypes[ext] = "n"
size = size + 1
end
e2ExtensionsTable.size = size
end
end)

--[[******************************************************************************]]--
Expand Down
3 changes: 3 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ E2Helper.Descriptions["ioOutputEntities(s)"] = "Returns an array of all entities
E2Helper.Descriptions["runOnLast(n)"] = "If set to 1, the chip will run once when it is removed, setting the last() flag when it does"
E2Helper.Descriptions["selfDestruct()"] = "Removes the expression"
E2Helper.Descriptions["selfDestructAll()"] = "Removes the expression and all constrained props"
E2Helper.Descriptions["getExtensions()"] = "Returns an array of all the extensions that the server has. This includes disabled extensions!"
E2Helper.Descriptions["getExtensionStatus()"] = "Returns a table of extension names with their statuses"
E2Helper.Descriptions["getExtensionStatus(s)"] = "Returns 1 if the extension is enabled, otherwise 0"

-- Debug
E2Helper.Descriptions["playerCanPrint()"] = "Returns whether or not the next print-message will be printed or omitted by antispam"
Expand Down

0 comments on commit 10731c4

Please sign in to comment.