mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "50f703d9b3ca940aa8068ba92696a7fc97ea0467" and "b39083fe3265ee998867d5f4b3afa61e4748d5db" have entirely different histories.
50f703d9b3
...
b39083fe32
1
lua.go
1
lua.go
|
@ -61,6 +61,7 @@ func luaInit() {
|
|||
fmt.Fprintln(os.Stderr, "Missing preload file, builtins may be missing.")
|
||||
}
|
||||
}
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
func runConfig(confpath string) {
|
||||
|
|
13
main.go
13
main.go
|
@ -10,7 +10,6 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
|
||||
"hilbish/util"
|
||||
"hilbish/golibs/bait"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
|
@ -152,17 +151,17 @@ func main() {
|
|||
}
|
||||
|
||||
if getopt.NArgs() > 0 {
|
||||
luaArgs := rt.NewTable()
|
||||
for i, arg := range getopt.Args() {
|
||||
luaArgs.Set(rt.IntValue(int64(i + 1)), rt.StringValue(arg))
|
||||
/*luaArgs := l.NewTable()
|
||||
for _, arg := range getopt.Args() {
|
||||
luaArgs.Append(lua.LString(arg))
|
||||
}
|
||||
|
||||
l.GlobalEnv().Set(rt.StringValue("args"), rt.TableValue(luaArgs))
|
||||
err := util.DoFile(l, getopt.Arg(0))
|
||||
l.SetGlobal("args", luaArgs)
|
||||
err := l.DoFile(getopt.Arg(0))
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}*/
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
43
util/util.go
43
util/util.go
|
@ -1,8 +1,6 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
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.
|
||||
func DoFile(rtm *rt.Runtime, path string) error {
|
||||
f, err := os.Open(path)
|
||||
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()
|
||||
func DoFile(rtm *rt.Runtime, filename string) error {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c == byte('#') {
|
||||
// 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))
|
||||
return DoString(rtm, string(data))
|
||||
}
|
||||
|
||||
// HandleStrCallback handles function parameters for Go functions which take
|
||||
|
|
Loading…
Reference in New Issue