mirror of https://github.com/Hilbis/Hilbish
Compare commits
1 Commits
ff6e08902f
...
63359cdb1e
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 63359cdb1e |
|
@ -2,13 +2,13 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"go/ast"
|
||||
"go/doc"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"strings"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EmmyPiece struct {
|
||||
|
@ -17,9 +17,9 @@ type EmmyPiece struct {
|
|||
Params []string // we only need to know param name to put in function
|
||||
}
|
||||
type DocPiece struct {
|
||||
Doc []string
|
||||
FuncSig string
|
||||
FuncSig string
|
||||
FuncName string
|
||||
Doc []string
|
||||
}
|
||||
|
||||
// feel free to clean this up
|
||||
|
@ -29,9 +29,8 @@ func main() {
|
|||
os.Mkdir("docs", 0777)
|
||||
os.Mkdir("emmyLuaDocs", 0777)
|
||||
|
||||
|
||||
dirs := []string{"./"}
|
||||
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
|
||||
filepath.Walk("golibs/", func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
@ -65,8 +64,12 @@ func main() {
|
|||
p := doc.New(f, "./", doc.AllDecls)
|
||||
for _, t := range p.Funcs {
|
||||
mod := l
|
||||
if strings.HasPrefix(t.Name, "hl") { mod = "hilbish" }
|
||||
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" { continue }
|
||||
if strings.HasPrefix(t.Name, "hl") {
|
||||
mod = "hilbish"
|
||||
}
|
||||
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(strings.TrimSpace(t.Doc), "\n")
|
||||
funcsig := parts[0]
|
||||
doc := parts[1:]
|
||||
|
@ -90,8 +93,8 @@ func main() {
|
|||
}
|
||||
|
||||
dps := DocPiece{
|
||||
Doc: funcdoc,
|
||||
FuncSig: funcsig,
|
||||
Doc: funcdoc,
|
||||
FuncSig: funcsig,
|
||||
FuncName: strings.TrimPrefix(t.Name, prefix[mod]),
|
||||
}
|
||||
|
||||
|
@ -100,7 +103,9 @@ func main() {
|
|||
}
|
||||
for _, t := range p.Types {
|
||||
for _, m := range t.Methods {
|
||||
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue }
|
||||
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(strings.TrimSpace(m.Doc), "\n")
|
||||
funcsig := parts[0]
|
||||
doc := parts[1:]
|
||||
|
@ -135,7 +140,9 @@ func main() {
|
|||
}
|
||||
|
||||
for mod, v := range docs {
|
||||
if mod == "main" { continue }
|
||||
if mod == "main" {
|
||||
continue
|
||||
}
|
||||
f, _ := os.Create("docs/" + mod + ".txt")
|
||||
for _, dps := range v {
|
||||
f.WriteString(dps.FuncSig + " > ")
|
||||
|
@ -149,7 +156,9 @@ func main() {
|
|||
}
|
||||
|
||||
for mod, v := range emmyDocs {
|
||||
if mod == "main" { continue }
|
||||
if mod == "main" {
|
||||
continue
|
||||
}
|
||||
f, _ := os.Create("emmyLuaDocs/" + mod + ".lua")
|
||||
f.WriteString("--- @meta\n\nlocal " + mod + " = {}\n\n")
|
||||
for _, em := range v {
|
||||
|
|
8
exec.go
8
exec.go
|
@ -4,10 +4,10 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -19,21 +19,21 @@ import (
|
|||
rt "github.com/arnodel/golua/runtime"
|
||||
"mvdan.cc/sh/v3/shell"
|
||||
//"github.com/yuin/gopher-lua/parse"
|
||||
"mvdan.cc/sh/v3/expand"
|
||||
"mvdan.cc/sh/v3/interp"
|
||||
"mvdan.cc/sh/v3/syntax"
|
||||
"mvdan.cc/sh/v3/expand"
|
||||
)
|
||||
|
||||
var errNotExec = errors.New("not executable")
|
||||
var errNotFound = errors.New("not found")
|
||||
var runnerMode rt.Value = rt.StringValue("hybrid")
|
||||
|
||||
type execError struct{
|
||||
type execError struct {
|
||||
err error
|
||||
typ string
|
||||
cmd string
|
||||
code int
|
||||
colon bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (e execError) Error() string {
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
|
||||
"hilbish/util"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
"github.com/arnodel/golua/lib/packagelib"
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
)
|
||||
|
||||
type listenerType int
|
||||
|
||||
const (
|
||||
goListener listenerType = iota
|
||||
luaListener
|
||||
|
@ -19,18 +20,18 @@ const (
|
|||
type Recoverer func(event string, handler *Listener, err interface{})
|
||||
|
||||
// Listener is a struct that holds the handler for an event.
|
||||
type Listener struct{
|
||||
typ listenerType
|
||||
once bool
|
||||
type Listener struct {
|
||||
caller func(...interface{})
|
||||
luaCaller *rt.Closure
|
||||
typ listenerType
|
||||
once bool
|
||||
}
|
||||
|
||||
type Bait struct{
|
||||
Loader packagelib.Loader
|
||||
type Bait struct {
|
||||
recoverer Recoverer
|
||||
handlers map[string][]*Listener
|
||||
handlers map[string][]*Listener
|
||||
rtm *rt.Runtime
|
||||
Loader packagelib.Loader
|
||||
}
|
||||
|
||||
// New creates a new Bait instance.
|
||||
|
@ -316,8 +317,10 @@ func (b *Bait) bhooks(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
|
||||
luaHandlers := rt.NewTable()
|
||||
for _, handler := range handlers {
|
||||
if handler.typ != luaListener { continue }
|
||||
luaHandlers.Set(rt.IntValue(luaHandlers.Len() + 1), rt.FunctionValue(handler.luaCaller))
|
||||
if handler.typ != luaListener {
|
||||
continue
|
||||
}
|
||||
luaHandlers.Set(rt.IntValue(luaHandlers.Len()+1), rt.FunctionValue(handler.luaCaller))
|
||||
}
|
||||
|
||||
if luaHandlers.Len() == 0 {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
rt "github.com/arnodel/golua/runtime"
|
||||
)
|
||||
|
||||
type luaHistory struct {}
|
||||
type luaHistory struct{}
|
||||
|
||||
func (h *luaHistory) Write(line string) (int, error) {
|
||||
histWrite := hshMod.Get(rt.StringValue("history")).AsTable().Get(rt.StringValue("add"))
|
||||
|
@ -54,8 +54,8 @@ func (h *luaHistory) Dump() interface{} {
|
|||
}
|
||||
|
||||
type fileHistory struct {
|
||||
f *os.File
|
||||
items []string
|
||||
f *os.File
|
||||
}
|
||||
|
||||
func newFileHistory(path string) *fileHistory {
|
||||
|
|
30
job.go
30
job.go
|
@ -19,22 +19,20 @@ var jobs *jobHandler
|
|||
var jobMetaKey = rt.StringValue("hshjob")
|
||||
|
||||
type job struct {
|
||||
cmd string
|
||||
running bool
|
||||
id int
|
||||
pid int
|
||||
exitCode int
|
||||
once bool
|
||||
args []string
|
||||
// save path for a few reasons, one being security (lmao) while the other
|
||||
// would just be so itll be the same binary command always (path changes)
|
||||
path string
|
||||
handle *exec.Cmd
|
||||
cmdout io.Writer
|
||||
cmderr io.Writer
|
||||
stdout *bytes.Buffer
|
||||
stderr *bytes.Buffer
|
||||
cmdout io.Writer
|
||||
ud *rt.UserData
|
||||
stderr *bytes.Buffer
|
||||
stdout *bytes.Buffer
|
||||
handle *exec.Cmd
|
||||
path string
|
||||
cmd string
|
||||
args []string
|
||||
exitCode int
|
||||
pid int
|
||||
id int
|
||||
once bool
|
||||
running bool
|
||||
}
|
||||
|
||||
func (j *job) start() error {
|
||||
|
@ -204,9 +202,9 @@ func luaBackgroundJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
|
||||
type jobHandler struct {
|
||||
jobs map[int]*job
|
||||
latestID int
|
||||
foreground bool // if job currently in the foreground
|
||||
mu *sync.RWMutex
|
||||
latestID int
|
||||
foreground bool
|
||||
}
|
||||
|
||||
func newJobHandler() *jobHandler {
|
||||
|
|
15
timer.go
15
timer.go
|
@ -10,21 +10,22 @@ import (
|
|||
)
|
||||
|
||||
type timerType int64
|
||||
|
||||
const (
|
||||
timerInterval timerType = iota
|
||||
timerTimeout
|
||||
)
|
||||
|
||||
type timer struct{
|
||||
type timer struct {
|
||||
ticker *time.Ticker
|
||||
ud *rt.UserData
|
||||
channel chan struct{}
|
||||
fun *rt.Closure
|
||||
th *timerHandler
|
||||
dur time.Duration
|
||||
id int
|
||||
typ timerType
|
||||
running bool
|
||||
dur time.Duration
|
||||
fun *rt.Closure
|
||||
th *timerHandler
|
||||
ticker *time.Ticker
|
||||
ud *rt.UserData
|
||||
channel chan struct{}
|
||||
}
|
||||
|
||||
func (t *timer) start() error {
|
||||
|
|
Loading…
Reference in New Issue