feat: args variable (resolves #49)

anytime hilbish is ran as shebang or given a script to run,
itll provide an `args` variable which will be the args a user
provides to the script.
it includes the execute path, as most argv's do
pull/59/head
sammy 2021-05-11 19:37:00 -04:00
parent 0f9d3732fb
commit fd478e883f
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 2 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/pborman/getopt" "github.com/pborman/getopt"
"github.com/bobappleyard/readline" "github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"layeh.com/gopher-luar"
"golang.org/x/term" "golang.org/x/term"
) )
@ -118,6 +119,7 @@ func main() {
RunInput(*cmdflag) RunInput(*cmdflag)
if getopt.NArgs() > 0 { if getopt.NArgs() > 0 {
l.SetGlobal("args", luar.New(l, getopt.Args()))
err := l.DoFile(getopt.Arg(0)) err := l.DoFile(getopt.Arg(0))
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)