Skip to content

Commit 1252bab

Browse files
committed
feat(stdlib): os.args returns the arguments passed to the program
1 parent d62e4c1 commit 1252bab

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- fix(lsp): `lithia lsp tcp` didn't work as expected
66
- fix(cli): correctly handle running script and repl
7+
- feat(stdlib): `os.args` returns the arguments passed to the program
78

89
## v0.0.18
910

external/os/external-os.go

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ func (e ExternalOS) Lookup(name string, env *Environment, decl ast.Decl) (Runtim
1616
return builtinOsExit(decl), true
1717
case "env":
1818
return builtinOsEnv(env, decl), true
19+
case "args":
20+
relevantArgs := world.Current.Args
21+
runtimeArgs := make([]RuntimeValue, len(relevantArgs))
22+
for i, arg := range relevantArgs {
23+
runtimeArgs[i] = PreludeString(arg)
24+
}
25+
list, err := env.MakeEagerList(runtimeArgs)
26+
if err != nil {
27+
return nil, false
28+
}
29+
return list, true
1930
default:
2031
return nil, false
2132
}

stdlib/os/shim.lithia

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
extern exit code
33
/// Returns an Optional value of the environment variable.
44
extern env name
5+
/// The arguments passed to the program.
6+
extern args

0 commit comments

Comments
 (0)