mirror of
https://github.com/Hilbis/Hilbish
synced 2025-04-21 21:13:22 +00:00
Compare commits
8 Commits
094e795d01
...
762066022d
Author | SHA1 | Date | |
---|---|---|---|
762066022d | |||
287a983730 | |||
004615b1b2 | |||
c3025b1417 | |||
d9b177b771 | |||
4105d7d0f1 | |||
0a0f2e2c38 | |||
3afd1c518a |
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -4,6 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
- midnight-edition
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
@ -30,7 +30,7 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- go build -tags midnight,{{.LUA}} {{.GOFLAGS}}
|
- go build -tags midnight,{{.LUA}} {{.GOFLAGS}}
|
||||||
vars:
|
vars:
|
||||||
GOFLAGS: '-ldflags "-s -w -X main.dataDir={{.LIBDIR}} -X main.gitCommit=$(git rev-parse --short HEAD) -X main.gitBranch=$(git rev-parse --abbrev-ref HEAD)"'
|
GOFLAGS: '-ldflags "-X main.dataDir={{.LIBDIR}} -X main.gitCommit=$(git rev-parse --short HEAD) -X main.gitBranch=$(git rev-parse --abbrev-ref HEAD)"'
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
|
17
api.go
17
api.go
@ -39,25 +39,19 @@ var hshMod *moonlight.Table
|
|||||||
func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
||||||
println("hilbish loader called")
|
println("hilbish loader called")
|
||||||
var exports = map[string]moonlight.Export{
|
var exports = map[string]moonlight.Export{
|
||||||
|
/*
|
||||||
"alias": {hlalias, 2, false},
|
"alias": {hlalias, 2, false},
|
||||||
"appendPath": {hlappendPath, 1, false},
|
"appendPath": {hlappendPath, 1, false},
|
||||||
/*
|
|
||||||
"complete": {hlcomplete, 2, false},
|
"complete": {hlcomplete, 2, false},
|
||||||
*/
|
|
||||||
"cwd": {hlcwd, 0, false},
|
"cwd": {hlcwd, 0, false},
|
||||||
/*
|
|
||||||
"exec": {hlexec, 1, false},
|
"exec": {hlexec, 1, false},
|
||||||
*/
|
|
||||||
"runnerMode": {hlrunnerMode, 1, false},
|
"runnerMode": {hlrunnerMode, 1, false},
|
||||||
/*
|
|
||||||
"goro": {hlgoro, 1, true},
|
"goro": {hlgoro, 1, true},
|
||||||
"highlighter": {hlhighlighter, 1, false},
|
"highlighter": {hlhighlighter, 1, false},
|
||||||
"hinter": {hlhinter, 1, false},
|
"hinter": {hlhinter, 1, false},
|
||||||
"multiprompt": {hlmultiprompt, 1, false},
|
"multiprompt": {hlmultiprompt, 1, false},
|
||||||
"prependPath": {hlprependPath, 1, false},
|
"prependPath": {hlprependPath, 1, false},
|
||||||
*/
|
|
||||||
"prompt": {hlprompt, 1, true},
|
"prompt": {hlprompt, 1, true},
|
||||||
/*
|
|
||||||
"inputMode": {hlinputMode, 1, false},
|
"inputMode": {hlinputMode, 1, false},
|
||||||
"interval": {hlinterval, 2, false},
|
"interval": {hlinterval, 2, false},
|
||||||
"read": {hlread, 1, false},
|
"read": {hlread, 1, false},
|
||||||
@ -67,6 +61,7 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
hshMod = moonlight.NewTable()
|
hshMod = moonlight.NewTable()
|
||||||
|
hshMod.SetRuntime(mlr)
|
||||||
mlr.SetExports(hshMod, exports)
|
mlr.SetExports(hshMod, exports)
|
||||||
|
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
@ -111,8 +106,8 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||||||
//mod.Set(rt.StringValue("completions"), rt.TableValue(hshcomp))
|
//mod.Set(rt.StringValue("completions"), rt.TableValue(hshcomp))
|
||||||
|
|
||||||
// hilbish.runner table
|
// hilbish.runner table
|
||||||
runnerModule := runnerModeLoader(mlr)
|
//runnerModule := runnerModeLoader(mlr)
|
||||||
hshMod.SetField("runner", moonlight.TableValue(runnerModule))
|
//hshMod.SetField("runner", moonlight.TableValue(runnerModule))
|
||||||
|
|
||||||
// hilbish.jobs table
|
// hilbish.jobs table
|
||||||
jobs = newJobHandler()
|
jobs = newJobHandler()
|
||||||
@ -135,8 +130,8 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||||||
//mod.Set(rt.StringValue("version"), rt.TableValue(versionModule))
|
//mod.Set(rt.StringValue("version"), rt.TableValue(versionModule))
|
||||||
|
|
||||||
// very meta
|
// very meta
|
||||||
moduleModule := moduleLoader(mlr)
|
//moduleModule := moduleLoader(mlr)
|
||||||
hshMod.SetField("module", moonlight.TableValue(moduleModule))
|
//hshMod.SetField("module", moonlight.TableValue(moduleModule))
|
||||||
|
|
||||||
return moonlight.TableValue(hshMod)
|
return moonlight.TableValue(hshMod)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ func New(runner *interp.Runner) *fs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *fs) Loader(rtm *moonlight.Runtime) moonlight.Value {
|
func (f *fs) Loader(rtm *moonlight.Runtime) moonlight.Value {
|
||||||
|
println("fs loader called")
|
||||||
exports := map[string]moonlight.Export{
|
exports := map[string]moonlight.Export{
|
||||||
/*
|
/*
|
||||||
"cd": util.LuaExport{f.fcd, 1, false},
|
"cd": util.LuaExport{f.fcd, 1, false},
|
||||||
|
2
lua.go
2
lua.go
@ -52,7 +52,7 @@ func luaInit() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Add more paths that Lua can require from
|
// Add more paths that Lua can require from
|
||||||
_, err := l.DoString("print(type(hilbish)); package.path = package.path .. " + requirePaths)
|
_, err := l.DoString("package.path = package.path .. " + requirePaths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
fmt.Fprintln(os.Stderr, "Could not add Hilbish require paths! Libraries will be missing. This shouldn't happen.")
|
fmt.Fprintln(os.Stderr, "Could not add Hilbish require paths! Libraries will be missing. This shouldn't happen.")
|
||||||
|
@ -15,7 +15,7 @@ func (mlr *Runtime) LoadLibrary(ldr Loader, name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mlr.state.GetGlobal("package")
|
mlr.state.GetGlobal("package")
|
||||||
mlr.state.GetField(-1, "loaded")
|
mlr.state.GetField(-1, "preload")
|
||||||
mlr.state.PushGoFunction(cluaLoader)
|
mlr.state.PushGoClosure(cluaLoader)
|
||||||
mlr.state.SetField(-2, name)
|
mlr.state.SetField(-2, name)
|
||||||
}
|
}
|
||||||
|
@ -45,5 +45,10 @@ func (mlr *Runtime) pushToState(v Value) {
|
|||||||
switch v.Type() {
|
switch v.Type() {
|
||||||
case NilType: mlr.state.PushNil()
|
case NilType: mlr.state.PushNil()
|
||||||
case StringType: mlr.state.PushString(v.AsString())
|
case StringType: mlr.state.PushString(v.AsString())
|
||||||
|
case TableType:
|
||||||
|
tbl := v.AsTable()
|
||||||
|
tbl.SetRuntime(mlr)
|
||||||
|
tbl.Push()
|
||||||
|
default: mlr.state.PushNil()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,33 @@
|
|||||||
//go:build midnight
|
//go:build midnight
|
||||||
|
|
||||||
package moonlight
|
package moonlight
|
||||||
|
|
||||||
//import "github.com/aarzilli/golua/lua"
|
import (
|
||||||
|
"github.com/aarzilli/golua/lua"
|
||||||
|
)
|
||||||
|
|
||||||
type Table struct{
|
type Table struct {
|
||||||
refIdx int
|
refIdx int
|
||||||
|
mlr *Runtime
|
||||||
|
nativeFields map[Value]Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTable() *Table {
|
func NewTable() *Table {
|
||||||
return &Table{
|
return &Table{
|
||||||
refIdx: -1,
|
refIdx: -1,
|
||||||
|
nativeFields: make(map[Value]Value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Table) SetRuntime(mlr *Runtime) {
|
||||||
|
t.mlr = mlr
|
||||||
|
|
||||||
|
if t.refIdx == -1 {
|
||||||
|
mlr.state.NewTable()
|
||||||
|
t.refIdx = mlr.state.Ref(lua.LUA_REGISTRYINDEX)
|
||||||
|
t.Push() // because Ref pops off the stack
|
||||||
|
t.syncToLua()
|
||||||
|
mlr.state.Pop(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,18 +35,47 @@ func (t *Table) Get(val Value) Value {
|
|||||||
return NilValue
|
return NilValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Table) Push() {
|
||||||
|
t.mlr.state.RawGeti(lua.LUA_REGISTRYINDEX, t.refIdx)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Table) SetField(key string, value Value) {
|
func (t *Table) SetField(key string, value Value) {
|
||||||
|
if t.refIdx != -1 {
|
||||||
|
t.setInLua(key, value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.setInGo(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Table) setInLua(key string, value Value) {
|
||||||
|
t.Push()
|
||||||
|
defer t.mlr.state.Pop(1)
|
||||||
|
|
||||||
|
t.mlr.pushToState(value)
|
||||||
|
t.mlr.state.SetField(-2, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Table) setInGo(key string, value Value) {
|
||||||
|
t.nativeFields[StringValue(key)] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Table) Set(key Value, value Value) {
|
func (t *Table) Set(key Value, value Value) {
|
||||||
|
t.nativeFields[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Table) syncToLua() {
|
||||||
|
for k, v := range t.nativeFields {
|
||||||
|
t.SetField(k.AsString(), v)
|
||||||
|
}
|
||||||
|
}
|
||||||
func ForEach(tbl *Table, cb func(key Value, val Value)) {
|
func ForEach(tbl *Table, cb func(key Value, val Value)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mlr *Runtime) GlobalTable() *Table {
|
func (mlr *Runtime) GlobalTable() *Table {
|
||||||
|
mlr.state.GetGlobal("_G")
|
||||||
return &Table{
|
return &Table{
|
||||||
refIdx: -1,
|
refIdx: mlr.state.Ref(lua.LUA_REGISTRYINDEX),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ func NewTable() *Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Table) SetRuntime(mlr *Runtime) {}
|
||||||
|
|
||||||
func (t *Table) Get(val Value) Value {
|
func (t *Table) Get(val Value) Value {
|
||||||
return t.lt.Get(val)
|
return t.lt.Get(val)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@ func (mlr *Runtime) DoString(code string) (Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mlr *Runtime) DoFile(filename string) error {
|
func (mlr *Runtime) DoFile(filename string) error {
|
||||||
//return mlr.state.DoFile(filename)
|
return mlr.state.DoFile(filename)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func (v Value) Type() ValueType {
|
|||||||
|
|
||||||
switch v.iface.(type) {
|
switch v.iface.(type) {
|
||||||
case bool: return BoolType
|
case bool: return BoolType
|
||||||
case int: return IntType
|
case int64: return IntType
|
||||||
case string: return StringType
|
case string: return StringType
|
||||||
case *Table: return TableType
|
case *Table: return TableType
|
||||||
case *Closure: return FunctionType
|
case *Closure: return FunctionType
|
||||||
@ -88,7 +88,7 @@ func (v Value) AsString() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v Value) AsTable() *Table {
|
func (v Value) AsTable() *Table {
|
||||||
panic("Value.AsTable unimplemented in midnight")
|
return v.iface.(*Table)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToString(v Value) string {
|
func ToString(v Value) string {
|
||||||
@ -98,9 +98,10 @@ func ToString(v Value) string {
|
|||||||
func (v Value) TypeName() string {
|
func (v Value) TypeName() string {
|
||||||
switch v.iface.(type) {
|
switch v.iface.(type) {
|
||||||
case bool: return "bool"
|
case bool: return "bool"
|
||||||
case int: return "number"
|
case int64: return "number"
|
||||||
case string: return "string"
|
case string: return "string"
|
||||||
case *Table: return "table"
|
case *Table: return "table"
|
||||||
|
case *Closure: return "function"
|
||||||
default: return "<unknown type>"
|
default: return "<unknown type>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user