diff --git a/object/strings.go b/object/strings.go index 6cf61fa..e40c2e9 100755 --- a/object/strings.go +++ b/object/strings.go @@ -3,6 +3,7 @@ package object import ( // "fmt" "hash/fnv" + "strconv" // "strconv" "strings" ) @@ -76,6 +77,25 @@ func (s *String) len(args []Object) Object { return &Integer{Value: int64(len(s.Value))} } +// toInt converts the string to an integer +func (s *String) toInt(args []Object) Object { + // Ensure no arguments are provided + if len(args) != 0 { + return newError("toInt() expects 0 arguments, got %d", len(args)) + } + + // Try to convert the string value to an integer + numVal, err := strconv.Atoi(s.Value) + if err != nil { + // Return an error if conversion fails + return newError("Failed to convert '%s' to an integer", s.Value) + } + + // Return the integer value as an Integer object + return &Integer{Value: int64(numVal)} +} + + // upper converts the string to uppercase. func (s *String) upper(args []Object) Object { if len(args) != 0 { diff --git a/vintLang/cli.vint b/vintLang/cli.vint index bc8e195..ce923d2 100644 --- a/vintLang/cli.vint +++ b/vintLang/cli.vint @@ -1,3 +1,5 @@ +//This module is still experimental + import cli args = cli.parseArgs("arg1=val1 arg2=val2") diff --git a/vintLang/logicals.vint b/vintLang/logicals.vint index 3ac8da3..f73dece 100644 --- a/vintLang/logicals.vint +++ b/vintLang/logicals.vint @@ -3,8 +3,9 @@ // Define a function to test 'and', 'or', and 'not' let test_logical_operators = func () { // Testing 'and' operator - let result_and = and(true, false) // Should return false + let result_and = and(1+2==3, false) // Should return false print("Result of true AND false: ", result_and) + print(1+2==4) // Testing 'or' operator let result_or = or(false, true) // Should return true diff --git a/vintLang/nativeStrings.vint b/vintLang/nativeStrings.vint new file mode 100644 index 0000000..0c3fd07 --- /dev/null +++ b/vintLang/nativeStrings.vint @@ -0,0 +1,8 @@ +name = "Tachera Sasi" + +print(name.split("")) +print(name.reverse()) +print(name.len()) +print(name.upper()) +print(name.lower()) +print(name.upper()) \ No newline at end of file diff --git a/vintLang/packages.vint b/vintLang/packages.vint new file mode 100644 index 0000000..53c3ec7 --- /dev/null +++ b/vintLang/packages.vint @@ -0,0 +1,13 @@ +/** +Not working Still in development +*/ + + +package vint{ + init = func(){ + name = "vint" + a = "hiofehoi" + } + print(@.name) +} + print(@.a) \ No newline at end of file diff --git a/vintLang/strings.vint b/vintLang/strings.vint index 753efa3..c092fa7 100644 --- a/vintLang/strings.vint +++ b/vintLang/strings.vint @@ -1,5 +1,4 @@ // Sample usage of the string module - import "string" // Example 1: Trim whitespace