Skip to content

Commit

Permalink
more modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tacheraSasi committed Dec 6, 2024
1 parent e8f552b commit 5e43145
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.7.1
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/lrstanley/bubblezone v0.0.0-20230303230241-08f906ff62a9
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lrstanley/bubblezone v0.0.0-20230303230241-08f906ff62a9 h1:w7W7F0EBRNTRRy+MFNLGrhJLn2Ldzl8Ms2AtHtgFtuw=
Expand Down
23 changes: 23 additions & 0 deletions module/colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package module

import (
"fmt"

"github.com/ekilie/vint-lang/object"
)

var ColorsFunctions = map[string]object.ModuleFunction{}

func init() {
ColorsFunctions["rgbToHex"] = rgbToHex
}

func rgbToHex(args []object.Object, defs map[string]object.Object) object.Object {
if len(args) != 3 {
return &object.Error{Message: "rgbToHex requires three arguments: R, G, B values"}
}

r, g, b := args[0].Inspect(), args[1].Inspect(), args[2].Inspect()
hex := fmt.Sprintf("#%02x%02x%02x", r, g, b)
return &object.String{Value: hex}
}
Empty file removed module/conc.go
Empty file.
4 changes: 2 additions & 2 deletions module/dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var DotenvFunctions = map[string]object.ModuleFunction{}

func init() {
DotenvFunctions["load"] = loadEnv
DotenvFunctions["get"] = getEnv
DotenvFunctions["get"] = getDotenvValue
}

func loadEnv(args []object.Object, defs map[string]object.Object) object.Object {
Expand All @@ -33,7 +33,7 @@ func loadEnv(args []object.Object, defs map[string]object.Object) object.Object
return &object.Boolean{Value: true}
}

func getEnv(args []object.Object, defs map[string]object.Object) object.Object {
func getDotenvValue(args []object.Object, defs map[string]object.Object) object.Object {
if len(args) != 1 || len(defs) != 0 {
return &object.Error{Message: "get requires exactly one argument: the key name"}
}
Expand Down
38 changes: 38 additions & 0 deletions module/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package module

import (
"encoding/base64"

"github.com/ekilie/vint-lang/object"
)

var EncodingFunctions = map[string]object.ModuleFunction{}

func init() {
EncodingFunctions["base64Encode"] = base64Encode
EncodingFunctions["base64Decode"] = base64Decode
}

func base64Encode(args []object.Object, defs map[string]object.Object) object.Object {
if len(args) != 1 {
return &object.Error{Message: "base64Encode requires one argument: the string to encode"}
}

input := args[0].Inspect()
encoded := base64.StdEncoding.EncodeToString([]byte(input))
return &object.String{Value: encoded}
}

func base64Decode(args []object.Object, defs map[string]object.Object) object.Object {
if len(args) != 1 {
return &object.Error{Message: "base64Decode requires one argument: the string to decode"}
}

input := args[0].Inspect()
decoded, err := base64.StdEncoding.DecodeString(input)
if err != nil {
return &object.Error{Message: "Invalid base64 string"}
}

return &object.String{Value: string(decoded)}
}
5 changes: 5 additions & 0 deletions module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ func init() {
Mapper["string"] = &object.Module{Name: "string", Functions: StringFunctions}
Mapper["crypto"] = &object.Module{Name: "crypto", Functions: CryptoFunctions}
Mapper["regex"] = &object.Module{Name: "regex", Functions: RegexFunctions}
Mapper["shell"] = &object.Module{Name: "shell", Functions: RegexFunctions}
Mapper["dotenv"] = &object.Module{Name: "dotenv", Functions: RegexFunctions}
Mapper["sysinfo"] = &object.Module{Name: "sysinfo", Functions: RegexFunctions}
Mapper["encoding"] = &object.Module{Name: "encoding", Functions: RegexFunctions}
Mapper["colors"] = &object.Module{Name: "colors", Functions: RegexFunctions}

}
4 changes: 4 additions & 0 deletions vintLang/colors.vint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import colors

hex = colors.rgbToHex(255, 255, 255)
print(hex) // Outputs "#ffffff"
7 changes: 7 additions & 0 deletions vintLang/encoding.vint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import encoding

encoded = encoding.base64Encode("Hello, World!")
print(encoded) // Outputs "SGVsbG8sIFdvcmxkIQ=="

decoded = encoding.base64Decode(encoded)
print(decoded) // Outputs "Hello, World!"

0 comments on commit 5e43145

Please sign in to comment.