-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8f552b
commit 5e43145
Showing
9 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |