-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from Flipez/add-os-module
move exit and raise to os module
- Loading branch information
Showing
7 changed files
with
90 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# OS | ||
|
||
|
||
|
||
|
||
## Module Function | ||
|
||
### exit(INTEGER) | ||
> Returns `` | ||
Terminates the program with the given exit code. | ||
|
||
|
||
```js | ||
🚀 > OS.exit(1) | ||
exit status 1 | ||
``` | ||
|
||
|
||
### raise(INTEGER, STRING) | ||
> Returns `` | ||
Terminates the program with the given exit code and prints the error message. | ||
|
||
|
||
```js | ||
🚀 > OS.raise(1, "broken") | ||
🔥 RocketLang raised an error: "broken" | ||
exit status 1 | ||
``` | ||
|
||
|
||
|
||
## Properties | ||
| Name | Value | | ||
| ---- | ----- | |
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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
package stdlib | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/flipez/rocket-lang/object" | ||
) | ||
|
||
var osFunctions = map[string]*object.BuiltinFunction{} | ||
var osProperties = map[string]*object.BuiltinProperty{} | ||
|
||
func init() { | ||
osFunctions["exit"] = object.NewBuiltinFunction( | ||
"exit", | ||
object.MethodLayout{ | ||
Description: "Terminates the program with the given exit code.", | ||
ArgPattern: object.Args( | ||
object.Arg(object.INTEGER_OBJ), | ||
), | ||
Example: `🚀 > OS.exit(1) | ||
exit status 1`, | ||
}, | ||
func(_ object.Environment, args ...object.Object) object.Object { | ||
os.Exit(int(args[0].(*object.Integer).Value)) | ||
|
||
return nil | ||
}) | ||
|
||
osFunctions["raise"] = object.NewBuiltinFunction( | ||
"raise", | ||
object.MethodLayout{ | ||
Description: "Terminates the program with the given exit code and prints the error message.", | ||
ArgPattern: object.Args( | ||
object.Arg(object.INTEGER_OBJ), | ||
object.Arg(object.STRING_OBJ), | ||
), | ||
Example: `🚀 > OS.raise(1, "broken") | ||
🔥 RocketLang raised an error: "broken" | ||
exit status 1`, | ||
}, | ||
func(_ object.Environment, args ...object.Object) object.Object { | ||
fmt.Printf("🔥 RocketLang raised an error: %s\n", args[1].Inspect()) | ||
os.Exit(int(args[0].(*object.Integer).Value)) | ||
|
||
return nil | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
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
604787f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rocket-lang-play – ./wasm
rocket-lang-play-git-main-flipez.vercel.app
play.rocket-lang.org
rocket-lang-play-flipez.vercel.app
rocket-lang-play.vercel.app
604787f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rocket-lang – ./docs
rocket-lang-flipez.vercel.app
rocket-lang.org
rocket-lang.vercel.app
www.rocket-lang.org
rocket-lang-git-main-flipez.vercel.app