diff options
| author | mryouse | 2022-05-13 03:14:57 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-13 03:14:57 +0000 |
| commit | e9459b2104b56618b678404e52a2daeabc1cef61 (patch) | |
| tree | a30bc439e7ffddda22548cb932192950e1d7df35 | |
| parent | 0ad764d450d8c477c375c2608eaa479c2106253a (diff) | |
type conversion ->string functions
| -rw-r--r-- | std.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -114,6 +114,13 @@ def std_is_bool(arg): else: return NebBool(False) +# type conversion +def std_literal_to_string(arg): + if isinstance(arg, NebString): + return arg + else: + return NebString(f"{arg.value}".lower()) + # shell def std_shell(arg): assert isinstance(arg, NebString) @@ -195,6 +202,18 @@ def build_std(): is_bool = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_bool) STD["bool?"] = [is_bool] + # type conversion + int_to_string = FuncImpl(NebFunction("int->string", [NebInt], NebString), std_literal_to_string) + STD["int->string"] = [int_to_string] + float_to_string = FuncImpl(NebFunction("float->string", [NebFloat], NebString), std_literal_to_string) + STD["float->string"] = [float_to_string] + number_to_string = FuncImpl(NebFunction("number->string", [NebNumber], NebString), std_literal_to_string) + STD["number->string"] = [number_to_string] + bool_to_string = FuncImpl(NebFunction("bool->string", [NebBool], NebString), std_literal_to_string) + STD["bool->string"] = [bool_to_string] + to_string = FuncImpl(NebFunction("->string", [NebLiteral], NebString), std_literal_to_string) + STD["->string"] = [to_string] + # shell shell_string = FuncImpl(NebFunction("$", [NebString], NebBool), std_shell) STD["$"] = [shell_string] |
