Created
March 26, 2018 07:37
-
-
Save mfelsche/6b377d9aa83eb45c1307a5ecec37447f to your computer and use it in GitHub Desktop.
Code to reproduce weird `String.cstring()` behaviour in ponyc
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
use "net" | |
use "cli" | |
use "debug" | |
actor Main | |
new create(env: Env) => | |
try | |
let spec = CommandSpec.leaf("damn", "", [ | |
OptionSpec.string("addr", | |
"The host:port:name to be advertised to other clustering nodes." | |
where short' = 'a', default' = "127.0.0.1:9999:") | |
], [ | |
ArgSpec.string_seq("", "") | |
])?.>add_help()? | |
let cmd = | |
match CommandParser(spec).parse(env.args, env.vars()) | |
| let c: Command => c | |
| let c: CommandHelp => | |
c.print_help(env.out) | |
env.exitcode(0) | |
error | |
| let err: SyntaxError => | |
env.out.print(err.string()) | |
env.exitcode(1) | |
error | |
end | |
let s = cmd.option("addr").string() | |
let i1 = s.find(":")? | |
let i2 = s.find(":", (i1 + 1).isize())? | |
let s2 = s.trim(i1.usize() + 1, i2.usize()) | |
TCPListener( | |
env.root as AmbientAuth, | |
object iso is TCPListenNotify | |
fun ref listening(listen: TCPListener ref) => | |
env.out.write(".") | |
listen.close() | |
fun ref not_listening(listen: TCPListener ref) => | |
env.out.write("E") | |
fun ref connected(listen: TCPListener ref): TCPConnectionNotify iso^ ? => | |
error | |
end, | |
"", | |
s2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment