Skip to content

Commit

Permalink
shallow copy parameter array to avoid undesired behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
tremwil committed Aug 2, 2024
1 parent 16e7b26 commit 412c0fc
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ if symbols == nil then
end

function executeEzStateEvent(id, parameterArray);
parameterArray = parameterArray or {}
table.insert(parameterArray, 1, id)
local args = allocateMemory(16 * #parameterArray)
local allParams = { id }
if parameterArray ~= nil then
for i, v in ipairs(parameterArray) do
allParams[i+1] = v
end
end

local args = allocateMemory(16 * #allParams)
local encoderMap = {
integer = { n = 2, fun = writeInteger },
number = { n = 1, fun = writeFloat }
}

for i, param in ipairs(parameterArray) do
for i, param in ipairs(allParams) do
local encoder = encoderMap[math.type(param)]
if encoder == nil then
deAlloc(args)
Expand All @@ -30,7 +35,7 @@ function executeEzStateEvent(id, parameterArray);
writeInteger(args + 0x10 * (i - 1) + 8, encoder.n)
end

executeCodeEx(0, nil, symbols.ezstate_execute_event, args, 1 + #parameterArray);
executeCodeEx(0, nil, symbols.ezstate_execute_event, args, #allParams);
deAlloc(args)
end

Expand Down

0 comments on commit 412c0fc

Please sign in to comment.