Skip to content

Commit

Permalink
Fix overwriting required parameter types table
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Oct 23, 2023
1 parent 75897f4 commit cb09747
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Pronghorn/Remotes/TypeChecker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,34 @@ end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

return function(remote: any, requiredParameterTypes: {string}, ...: any)
local requiredParameterTypesTemp = table.clone(requiredParameterTypes)
local parameters = {...}
local numRequiredParameterTypes = #requiredParameterTypes
local numRequiredParameterTypes = #requiredParameterTypesTemp

if numRequiredParameterTypes > 0 and requiredParameterTypes[numRequiredParameterTypes]:sub(1, 3) == "..." then
local variadicRequiredParameterType = requiredParameterTypes[numRequiredParameterTypes]:sub(4)
if numRequiredParameterTypes > 0 and requiredParameterTypesTemp[numRequiredParameterTypes]:sub(1, 3) == "..." then
local variadicRequiredParameterType = requiredParameterTypesTemp[numRequiredParameterTypes]:sub(4)

for index = 1, #parameters do
if index >= numRequiredParameterTypes then
requiredParameterTypes[index] = variadicRequiredParameterType
requiredParameterTypesTemp[index] = variadicRequiredParameterType
end
end
end

for index = 1, math.max(numRequiredParameterTypes, #parameters) do
requiredParameterTypes[index] = requiredParameterTypes[index] or "nil"
requiredParameterTypesTemp[index] = requiredParameterTypesTemp[index] or "nil"

local parameter = parameters[index]
local parameterType = typeof(parameter)
local requiredParameterType = requiredParameterTypes[index]:gsub(" ", ""):gsub("?", "")
local requiredParameterType = requiredParameterTypesTemp[index]:gsub(" ", ""):gsub("?", "")

if requiredParameterType == "..." then break end

local requiredParameterTypeOptions = requiredParameterType:split("|")
local pass = false

if
requiredParameterTypes[index]:find("?", 1, true) and parameter == nil
requiredParameterTypesTemp[index]:find("?", 1, true) and parameter == nil
or requiredParameterType == "any" and parameter ~= nil
then
pass = true
Expand Down
2 changes: 1 addition & 1 deletion Pronghorn/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
║ ██████▀██▓▌▀▌ ▄ ▄▓▌▐▓█▌ ║
║ ║
║ ║
║ Pronghorn Framework Rev. B45
║ Pronghorn Framework Rev. B46
║ https://github.com/Iron-Stag-Games/Pronghorn ║
║ GNU Lesser General Public License v2.1 ║
║ ║
Expand Down

0 comments on commit cb09747

Please sign in to comment.