Skip to content

Commit

Permalink
Switch case support
Browse files Browse the repository at this point in the history
Final tweaks on switch case working. This would also resolve wiremod#2049 since operators take the actual values as arguments rather than instructions.
  • Loading branch information
Vurv78 committed Mar 21, 2023
1 parent 7e991ee commit 2021caf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lua/entities/gmod_wire_expression2/base/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,25 @@ local CompileVisitors = {
end)

local eq = self:GetOperator("eq", { expr_ty, cond_ty }, case[1].trace)
cases[i] = { eq, block }
cases[i] = {
function(state, expr)
return eq(state, cond(state), expr)
end,
block
}
end

local default = data[3] and self:Scope(function() return self:CompileStmt(data[3]) end)
return function(state) ---@param state RuntimeContext
local expr = expr(state)
for i, case in ipairs(cases) do
if case[1](state) then
if case[1](state, expr) ~= 0 then
case[2](state)
return
end
end

default(state)
end
end,

Expand Down

0 comments on commit 2021caf

Please sign in to comment.