seperated builtins
This commit is contained in:
29
object/builtin_assert.go
Normal file
29
object/builtin_assert.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Assert ...
|
||||
func Assert(args ...Object) Object {
|
||||
if len(args) != 2 {
|
||||
return newError("wrong number of arguments. got=%d, want=2",
|
||||
len(args))
|
||||
}
|
||||
if args[0].Type() != BOOLEAN_OBJ {
|
||||
return newError("argument #1 to `assert` must be BOOLEAN, got %s",
|
||||
args[0].Type())
|
||||
}
|
||||
if args[1].Type() != STRING_OBJ {
|
||||
return newError("argument #2 to `assert` must be STRING, got %s",
|
||||
args[0].Type())
|
||||
}
|
||||
|
||||
if !args[0].(*Boolean).Value {
|
||||
fmt.Printf("Assertion Error: %s", args[1].(*String).Value)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user