Compare commits

..

No commits in common. "50f703d9b3ca940aa8068ba92696a7fc97ea0467" and "b39083fe3265ee998867d5f4b3afa61e4748d5db" have entirely different histories.

3 changed files with 10 additions and 47 deletions

1
lua.go
View File

@ -61,6 +61,7 @@ func luaInit() {
fmt.Fprintln(os.Stderr, "Missing preload file, builtins may be missing.") fmt.Fprintln(os.Stderr, "Missing preload file, builtins may be missing.")
} }
} }
fmt.Println(err)
} }
func runConfig(confpath string) { func runConfig(confpath string) {

13
main.go
View File

@ -10,7 +10,6 @@ import (
"runtime" "runtime"
"strings" "strings"
"hilbish/util"
"hilbish/golibs/bait" "hilbish/golibs/bait"
rt "github.com/arnodel/golua/runtime" rt "github.com/arnodel/golua/runtime"
@ -152,17 +151,17 @@ func main() {
} }
if getopt.NArgs() > 0 { if getopt.NArgs() > 0 {
luaArgs := rt.NewTable() /*luaArgs := l.NewTable()
for i, arg := range getopt.Args() { for _, arg := range getopt.Args() {
luaArgs.Set(rt.IntValue(int64(i + 1)), rt.StringValue(arg)) luaArgs.Append(lua.LString(arg))
} }
l.GlobalEnv().Set(rt.StringValue("args"), rt.TableValue(luaArgs)) l.SetGlobal("args", luaArgs)
err := util.DoFile(l, 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)
os.Exit(1) os.Exit(1)
} }*/
os.Exit(0) os.Exit(0)
} }

View File

@ -1,8 +1,6 @@
package util package util
import ( import (
"bufio"
"io"
"os" "os"
rt "github.com/arnodel/golua/runtime" rt "github.com/arnodel/golua/runtime"
@ -51,48 +49,13 @@ func DoString(rtm *rt.Runtime, code string) error {
} }
// DoFile runs the contents of the file in the Lua runtime. // DoFile runs the contents of the file in the Lua runtime.
func DoFile(rtm *rt.Runtime, path string) error { func DoFile(rtm *rt.Runtime, filename string) error {
f, err := os.Open(path) data, err := os.ReadFile(filename)
defer f.Close()
if err != nil {
return err
}
reader := bufio.NewReader(f)
c, err := reader.ReadByte()
if err != nil && err != io.EOF {
return err
}
// unread so a char won't be missing
err = reader.UnreadByte()
if err != nil { if err != nil {
return err return err
} }
if c == byte('#') { return DoString(rtm, string(data))
// shebang - skip that line
_, err := reader.ReadBytes('\n')
if err != nil && err != io.EOF {
return err
}
}
var buf []byte
for {
line, err := reader.ReadBytes('\n')
if err != nil {
if err == io.EOF {
break
}
return err
}
buf = append(buf, line...)
}
return DoString(rtm, string(buf))
} }
// HandleStrCallback handles function parameters for Go functions which take // HandleStrCallback handles function parameters for Go functions which take