Skip to content

Commit

Permalink
Added concat operator eval and eval test
Browse files Browse the repository at this point in the history
  • Loading branch information
bananu7 committed Jul 18, 2018
1 parent 090caa7 commit 579750f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Test/TestEval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spec = do
describe "comparisons" $ do
it ">" $ runParse "return 1 > 2, 2 > 1, 1 > 1" `shouldBe` (map Boolean [False, True, False])
it "<" $ runParse "return 1 < 2, 2 < 1, 1 < 1" `shouldBe` (map Boolean [True, False, False])
it "concat (..)" $ runParse "return \"abc\" .. \"def\"" `shouldBe` [Str "abcdef"]

describe "equality" $ do
it "numbers" $ runParse "return 1 == 1, 1 == -1, 1 == 2, 2 == 1"
Expand Down
6 changes: 6 additions & 0 deletions src/Turnip/Eval/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ luaminus (Number a : Number b : _) = return $ [Number (a - b)]
luaminus (a : b : _) = luametaop "__sub" [a,b]
luaminus _ = throwErrorStr "Can't subtract those things"

luaconcat (Str a : Str b : _) = return [Str $ a ++ b]
luaconcat (a : b : _) = luametaop "__concat" [a,b]
luaconcat _ = throwErrorStr "Concat operator needs at least two values"

loadBaseLibrary :: LuaM ()
loadBaseLibrary = do
loadBaseLibraryGen
Expand All @@ -180,6 +184,8 @@ loadBaseLibrary = do
addNativeFunction "*" (BuiltinFunction luamult)
addNativeFunction "/" (BuiltinFunction luadiv)

addNativeFunction ".." (BuiltinFunction luaconcat)

addNativeFunction "not" (BuiltinFunction luaNot)
addNativeFunction "or" (BuiltinFunction luaOr)
addNativeFunction "and" (BuiltinFunction luaAnd)
Expand Down

0 comments on commit 579750f

Please sign in to comment.