wren-cli
wren-cli copied to clipboard
CLI Eval
This is a quite small thing, but most interpreters have it.
$ wren -e 'System.print("Hello, world!")'
It seems simple enough (famous last words, right?) to add in basic support for it by breaking the runFile function into the part that actually loads the file and the part that runs the VM (probably in a new function called runVM), and then looking for the flag on the commandline (maybe just seeing if argc == 3 and taking argv[2] for now and not worrying about a full commandline parser).
If this sounds like something you want I can probably do this myself and submit a pull request.
that sound nice, but I would go with solid foundations (like using getopt) and not quickly hacking a non-scalable dirty thing.
I'm ambivalent to the commandline option solution really.
Likely, getopt (or equivalent) could be added with a simple --help and --version flags, because right now wren can't do either of those. But that's beyond the scope of this issue imho.
Yeah, this sounds reasonable to me too. Figuring out how to actually parse the command line options is a tricky one. My hunch is that getopt() is a little too primitive. getopt_long() may not be portable enough.
Right now, the command line options are simple enough that we could probably just hand code them in C like we do for --help and --version.
My hunch is that getopt() is a little too primitive. getopt_long() may not be portable enough.
Is there a reason we can't have a small class in Wren to handle this? It has the advantage of being 100% portable (because Wren is)... The main runfile vs repl branching can also be moved inside Wren (vs C) and then Wren can parse the arguments however it desires. So we'd be running a CLI class instead of Repl... if runFile and runRepl are still needed for some reason they can be foreign.
Is there any guidance or thought on how much of the CLI must be C code vs Wren? I'd think more Wren (where possible) would encourage more contribution since Wren is so much more accessible than C to many people.
Right now, the command line options are simple enough that we could probably just hand code them in C
Also doable.
@acook Not sure if you'd be interested but I just implemented this in my Pure Wren branch of the CLI just to see how easy it would be to add something like this in Wren vs C:
https://github.com/joshgoebel/wren-cli/commit/78b05e53f5d146e7bf95bcc6ab64142739c92594
No, it doesn't use any opt parsing library (yet), but it works.