google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.27k stars 204 forks source link

System calls #378

Closed brunomiranda-hotmart closed 3 years ago

brunomiranda-hotmart commented 3 years ago

Is it possible to use system call with starlark?

Couldn't find it in the docs (either saying it is doable, or not doble)

I would like to do something like:

def fizz_buzz(n):
  """Print Fizz Buzz numbers from 1 to n."""
  for i in range(1, n + 1):
    result = subprocess.run(["ls", "-l"])
    s = ""
    if i % 3 == 0:
      s += "Fizz"
    if i % 5 == 0:
      s += "Buzz"
    print(s if s else i)

fizz_buzz(20)
adonovan commented 3 years ago

No, by design core Starlark does not expose any system calls, but you can add your own built-in functions to the environment that do whatever you like.

That said, an a-la-carte menu of standard packages that provide operations like HTTP requests, file read/write, and subprocess execution would be useful additions for applications that choose to expose them.