From 10731c43e388de38e783b4c14107519ef495cf69 Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Sun, 12 Nov 2023 00:11:53 -0500 Subject: [PATCH] Add selfaware functions for E2 extensions (#2823) * Add selfaware functions for E2 extensions * Optimize * Lessons in futility --- .../gmod_wire_expression2/core/selfaware.lua | 54 +++++++++++++++++++ lua/wire/client/e2descriptions.lua | 3 ++ 2 files changed, 57 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/selfaware.lua b/lua/entities/gmod_wire_expression2/core/selfaware.lua index de3cee296c..c6b54431e7 100644 --- a/lua/entities/gmod_wire_expression2/core/selfaware.lua +++ b/lua/entities/gmod_wire_expression2/core/selfaware.lua @@ -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 + --[[******************************************************************************]]-- @@ -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) --[[******************************************************************************]]-- diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 39e9b1646e..268d4856f7 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -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"