mirror of https://github.com/Hilbis/Hilbish
Compare commits
4 Commits
b39083fe32
...
50f703d9b3
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 50f703d9b3 | |
TorchedSammy | f94d7ac81f | |
TorchedSammy | 48ab7c13ac | |
TorchedSammy | e91cf98634 |
1
lua.go
1
lua.go
|
@ -61,7 +61,6 @@ 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,6 +10,7 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
|
||||
"hilbish/util"
|
||||
"hilbish/golibs/bait"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
|
@ -151,17 +152,17 @@ func main() {
|
|||
}
|
||||
|
||||
if getopt.NArgs() > 0 {
|
||||
/*luaArgs := l.NewTable()
|
||||
for _, arg := range getopt.Args() {
|
||||
luaArgs.Append(lua.LString(arg))
|
||||
luaArgs := rt.NewTable()
|
||||
for i, arg := range getopt.Args() {
|
||||
luaArgs.Set(rt.IntValue(int64(i + 1)), rt.StringValue(arg))
|
||||
}
|
||||
|
||||
l.SetGlobal("args", luaArgs)
|
||||
err := l.DoFile(getopt.Arg(0))
|
||||
l.GlobalEnv().Set(rt.StringValue("args"), rt.TableValue(luaArgs))
|
||||
err := util.DoFile(l, 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,6 +1,8 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
|
@ -49,13 +51,48 @@ func DoString(rtm *rt.Runtime, code string) error {
|
|||
}
|
||||
|
||||
// DoFile runs the contents of the file in the Lua runtime.
|
||||
func DoFile(rtm *rt.Runtime, filename string) error {
|
||||
data, err := os.ReadFile(filename)
|
||||
func DoFile(rtm *rt.Runtime, path string) error {
|
||||
f, err := os.Open(path)
|
||||
defer f.Close()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return DoString(rtm, string(data))
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
|
||||
// HandleStrCallback handles function parameters for Go functions which take
|
||||
|
|
Loading…
Reference in New Issue