-
Notifications
You must be signed in to change notification settings - Fork 3
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 #158 from radon-project/stdlib-io
feat: added `io` stdlib support.
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"argparser", | ||
"array", | ||
"colorlib", | ||
"io", | ||
"math", | ||
"radiation", | ||
"system", | ||
|
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,17 @@ | ||
import io | ||
|
||
var int_num = io.Input.get_int("Enter an integer number: ") | ||
print(int_num) | ||
|
||
var float_num = io.Input.get_float("Enter a float number: ") | ||
print(float_num) | ||
|
||
var str_val = io.Input.get_string("Enter a string: ") | ||
print(str_val) | ||
|
||
var password = io.Input.get_password("Enter a password: ") | ||
print(password) | ||
|
||
# issue here | ||
var val = input("Enter a value: ") | ||
io.Output.write(val) |
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,53 @@ | ||
import radiation | ||
|
||
|
||
class Input { | ||
static fun get_int(text="") { | ||
const _val = input(text) | ||
try { | ||
return int(_val) | ||
} catch as err { | ||
raise radiation.ValueError("Invalid input") | ||
} | ||
} | ||
|
||
static fun get_float(text="") { | ||
const _val = input(text) | ||
try { | ||
return float(_val) | ||
} catch as err { | ||
raise radiation.ValueError("Invalid input") | ||
} | ||
} | ||
|
||
static fun get_string(text="") { | ||
return input(text) | ||
} | ||
|
||
static fun get_bool(text="") { | ||
const _val = String(input(text)) | ||
if _val.casefold() == "true" { | ||
return true | ||
} elif _val.casefold() == "false" { | ||
return false | ||
} else { | ||
raise radiation.ValueError("Invalid input") | ||
} | ||
} | ||
|
||
static fun get_password(text="") { | ||
var ns = {"text": text} | ||
pyapi("import getpass; val = getpass.getpass(text)", ns) | ||
return ns["val"] | ||
} | ||
} | ||
|
||
class Output { | ||
static fun write(...values, sep=" ", end="\n") { | ||
var output = "" | ||
for value in values { | ||
output += str(value) + sep | ||
} | ||
print(output + end) | ||
} | ||
} |