From 9935442085ab163e9424dd367fd79335fa43c93c Mon Sep 17 00:00:00 2001 From: crazyRBLX11 <165557662+crazyRBLX11@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:43:41 +0000 Subject: [PATCH] Selene Error fixes --- .../AtomModuleContents/AtomClient_OOP.lua | 9 +- .../Core/MemoryStoreOperations.lua | 21 +- .../AtomModuleContents/Core/Serializer.lua | 2 +- src/Atom/AtomModuleContents/Utils/Signal.lua | 180 ------------------ src/Atom/Packages/GoodSignal.lua | 8 +- 5 files changed, 26 insertions(+), 194 deletions(-) delete mode 100644 src/Atom/AtomModuleContents/Utils/Signal.lua diff --git a/src/Atom/AtomModuleContents/AtomClient_OOP.lua b/src/Atom/AtomModuleContents/AtomClient_OOP.lua index 6f9873a..be62ad7 100644 --- a/src/Atom/AtomModuleContents/AtomClient_OOP.lua +++ b/src/Atom/AtomModuleContents/AtomClient_OOP.lua @@ -69,9 +69,12 @@ end ]] function Clean(WorkingJanitor) WorkingJanitor:Cleanup() - print("Memory Usage: "..collectgarbage('count').."kb") - print("Memory Usage: "..collectgarbage('count') * 1024, "B") - return "Cleaned" + return "Cleaned." +end + +function AtomMain.Clean(WorkingJanitor) + WorkingJanitor:Cleanup() + return "Cleaned." end --[[ diff --git a/src/Atom/AtomModuleContents/Core/MemoryStoreOperations.lua b/src/Atom/AtomModuleContents/Core/MemoryStoreOperations.lua index f2e6d65..e956c02 100644 --- a/src/Atom/AtomModuleContents/Core/MemoryStoreOperations.lua +++ b/src/Atom/AtomModuleContents/Core/MemoryStoreOperations.lua @@ -26,7 +26,11 @@ end function MemoryStoreOperations:GetMemoryIdentifier(Queue:MemoryStoreQueue, count:number, allOrNothing:boolean, waitTimeout:number) local results, identifier = Queue:ReadAsync(count, allOrNothing, waitTimeout) - return identifier + if not results then + return nil + else + return identifier + end end function MemoryStoreOperations:RemoveFromMemoryStoreQueue(Queue:MemoryStoreQueue, Identifier:string) @@ -41,27 +45,32 @@ end function MemoryStoreOperations:ReadFromMemoryStoreQueue(Queue:MemoryStoreQueue, count:number, allOrNothing:boolean, waitTimeout:number) local results = nil local success, errormessage = pcall(function() - local results, identifier = Queue:ReadAsync(count, allOrNothing, waitTimeout) + results = Queue:ReadAsync(count, allOrNothing, waitTimeout) end) if success then return results elseif not success then - return "Error reading MemoryStoreQueue. "..errormessage + warn("Error reading MemoryStoreQueue. "..errormessage) + return nil else - return "Error with function. "..errormessage + warn("Error with function "..errormessage) + return nil end end function MemoryStoreOperations:ReadFromSortedMap(SortedMap:MemoryStoreSortedMap, Key:string) + local SortedMapData = nil local success, errormessage = pcall(function() - SortedMap:GetAsync(Key) + SortedMapData = SortedMap:GetAsync(Key) end) if success then - return SortedMap:GetAsync(Key) + return SortedMapData elseif not success then warn("Error getting Value! "..errormessage) + return nil else warn("Error with function! "..errormessage) + return nil end end diff --git a/src/Atom/AtomModuleContents/Core/Serializer.lua b/src/Atom/AtomModuleContents/Core/Serializer.lua index 240e856..f9e9589 100644 --- a/src/Atom/AtomModuleContents/Core/Serializer.lua +++ b/src/Atom/AtomModuleContents/Core/Serializer.lua @@ -4,7 +4,7 @@ local Serializer = {} function Serializer.serialize(Buffer: buffer, offset: number, DataType: string, Data) local dataType = string.lower(DataType) - + print(dataType) Switch(Data)({ case("number")(function() buffer.writef64(Buffer, offset * math.random(1, 34), Data) diff --git a/src/Atom/AtomModuleContents/Utils/Signal.lua b/src/Atom/AtomModuleContents/Utils/Signal.lua deleted file mode 100644 index e3a1129..0000000 --- a/src/Atom/AtomModuleContents/Utils/Signal.lua +++ /dev/null @@ -1,180 +0,0 @@ --------------------------------------------------------------------------------- --- Batched Yield-Safe Signal Implementation -- --- This is a Signal class which has effectively identical behavior to a -- --- normal RBXScriptSignal, with the only difference being a couple extra -- --- stack frames at the bottom of the stack trace when an error is thrown. -- --- This implementation caches runner coroutines, so the ability to yield in -- --- the signal handlers comes at minimal extra cost over a naive signal -- --- implementation that either always or never spawns a thread. -- --- -- --- API: -- --- local Signal = require(THIS MODULE) -- --- local sig = Signal.new() -- --- local connection = sig:Connect(function(arg1, arg2, ...) ... end) -- --- sig:Fire(arg1, arg2, ...) -- --- connection:Disconnect() -- --- sig:DisconnectAll() -- --- local arg1, arg2, ... = sig:Wait() -- --- -- --- Licence: -- --- Licenced under the MIT licence. -- --- -- --- Authors: -- --- stravant - July 31st, 2021 - Created the file. -- --------------------------------------------------------------------------------- - --- The currently idle thread to run the next handler on -local freeRunnerThread = nil - --- Function which acquires the currently idle handler runner thread, runs the --- function fn on it, and then releases the thread, returning it to being the --- currently idle one. --- If there was a currently idle runner thread already, that's okay, that old --- one will just get thrown and eventually GCed. -local function acquireRunnerThreadAndCallEventHandler(fn, ...) - local acquiredRunnerThread = freeRunnerThread - freeRunnerThread = nil - fn(...) - -- The handler finished running, this runner thread is free again. - freeRunnerThread = acquiredRunnerThread -end - --- Coroutine runner that we create coroutines of. The coroutine can be --- repeatedly resumed with functions to run followed by the argument to run --- them with. -local function runEventHandlerInFreeThread() - -- Note: We cannot use the initial set of arguments passed to - -- runEventHandlerInFreeThread for a call to the handler, because those - -- arguments would stay on the stack for the duration of the thread's - -- existence, temporarily leaking references. Without access to raw bytecode - -- there's no way for us to clear the "..." references from the stack. - while true do - acquireRunnerThreadAndCallEventHandler(coroutine.yield()) - end -end - --- Connection class -local Connection = {} -Connection.__index = Connection - -function Connection.new(signal, fn) - return setmetatable({ - _connected = true, - _signal = signal, - _fn = fn, - _next = false, - }, Connection) -end - -function Connection:Disconnect() - self._connected = false - - -- Unhook the node, but DON'T clear it. That way any fire calls that are - -- currently sitting on this node will be able to iterate forwards off of - -- it, but any subsequent fire calls will not hit it, and it will be GCed - -- when no more fire calls are sitting on it. - if self._signal._handlerListHead == self then - self._signal._handlerListHead = self._next - else - local prev = self._signal._handlerListHead - while prev and prev._next ~= self do - prev = prev._next - end - if prev then - prev._next = self._next - end - end -end - --- Make Connection strict -setmetatable(Connection, { - __index = function(tb, key) - error(("Attempt to get Connection::%s (not a valid member)"):format(tostring(key)), 2) - end, - __newindex = function(tb, key, value) - error(("Attempt to set Connection::%s (not a valid member)"):format(tostring(key)), 2) - end -}) - --- Signal class -local Signal = {} -Signal.__index = Signal - -function Signal.new() - return setmetatable({ - _handlerListHead = false, - }, Signal) -end - -function Signal:Connect(fn) - local connection = Connection.new(self, fn) - if self._handlerListHead then - connection._next = self._handlerListHead - self._handlerListHead = connection - else - self._handlerListHead = connection - end - return connection -end - --- Disconnect all handlers. Since we use a linked list it suffices to clear the --- reference to the head handler. -function Signal:DisconnectAll() - self._handlerListHead = false -end - --- Signal:Fire(...) implemented by running the handler functions on the --- coRunnerThread, and any time the resulting thread yielded without returning --- to us, that means that it yielded to the Roblox scheduler and has been taken --- over by Roblox scheduling, meaning we have to make a new coroutine runner. -function Signal:Fire(...) - local item = self._handlerListHead - while item do - if item._connected then - if not freeRunnerThread then - freeRunnerThread = coroutine.create(runEventHandlerInFreeThread) - -- Get the freeRunnerThread to the first yield - coroutine.resume(freeRunnerThread) - end - task.spawn(freeRunnerThread, item._fn, ...) - end - item = item._next - end -end - --- Implement Signal:Wait() in terms of a temporary connection using --- a Signal:Connect() which disconnects itself. -function Signal:Wait() - local waitingCoroutine = coroutine.running() - local cn; - cn = self:Connect(function(...) - cn:Disconnect() - task.spawn(waitingCoroutine, ...) - end) - return coroutine.yield() -end - --- Implement Signal:Once() in terms of a connection which disconnects --- itself before running the handler. -function Signal:Once(fn) - local cn; - cn = self:Connect(function(...) - if cn._connected then - cn:Disconnect() - end - fn(...) - end) - return cn -end - --- Make signal strict -setmetatable(Signal, { - __index = function(tb, key) - error(("Attempt to get Signal::%s (not a valid member)"):format(tostring(key)), 2) - end, - __newindex = function(tb, key, value) - error(("Attempt to set Signal::%s (not a valid member)"):format(tostring(key)), 2) - end -}) - -return Signal diff --git a/src/Atom/Packages/GoodSignal.lua b/src/Atom/Packages/GoodSignal.lua index e3a1129..4090e39 100644 --- a/src/Atom/Packages/GoodSignal.lua +++ b/src/Atom/Packages/GoodSignal.lua @@ -88,10 +88,10 @@ end -- Make Connection strict setmetatable(Connection, { - __index = function(tb, key) + __index = function(key) error(("Attempt to get Connection::%s (not a valid member)"):format(tostring(key)), 2) end, - __newindex = function(tb, key, value) + __newindex = function(key) error(("Attempt to set Connection::%s (not a valid member)"):format(tostring(key)), 2) end }) @@ -169,10 +169,10 @@ end -- Make signal strict setmetatable(Signal, { - __index = function(tb, key) + __index = function(key) error(("Attempt to get Signal::%s (not a valid member)"):format(tostring(key)), 2) end, - __newindex = function(tb, key, value) + __newindex = function(key) error(("Attempt to set Signal::%s (not a valid member)"):format(tostring(key)), 2) end })