Skip to content

Commit

Permalink
Added support for string + number
Browse files Browse the repository at this point in the history
  • Loading branch information
Avril112113 committed Apr 16, 2020
1 parent 628a191 commit c729345
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions yololVM/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ function vm:eval_binary(ast, operator, leftValue, rightValue)
end
return leftValue % rightValue
elseif operator == "+" then
if type(leftValue) == "string" and type(rightValue) == "string" then
local str = leftValue .. rightValue
if type(leftValue) == "string" or type(rightValue) == "string" then
local str = tostring(leftValue) .. tostring(rightValue)
if #str > self.MAX_STR_LENGTH then
self:pushError({
level="warn",
Expand All @@ -134,12 +134,6 @@ function vm:eval_binary(ast, operator, leftValue, rightValue)
return str:sub(1, self.MAX_STR_LENGTH)
end
return str
elseif type(leftValue) == "string" or type(rightValue) == "string" then
self:pushError({
level="error",
msg="Attempt to `" .. tostring(operator) .. "` on " .. type(leftValue) .. " and " .. type(rightValue)
})
self:haltLine()
else
return leftValue + rightValue
end
Expand Down

0 comments on commit c729345

Please sign in to comment.