mirror of https://github.com/Hilbis/Hilbish
fix: implement go lua library loading
and remove debug symbol stripping flags when building on midnightmidnight-edition
parent
3afd1c518a
commit
0a0f2e2c38
|
@ -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:
|
||||||
|
|
3
api.go
3
api.go
|
@ -61,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()
|
||||||
|
@ -70,9 +71,7 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
||||||
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
}
|
}
|
||||||
|
|
||||||
println("setting ver field")
|
|
||||||
hshMod.SetField("ver", moonlight.StringValue(getVersion()))
|
hshMod.SetField("ver", moonlight.StringValue(getVersion()))
|
||||||
println("setting goversion field")
|
|
||||||
hshMod.SetField("goVersion", moonlight.StringValue(runtime.Version()))
|
hshMod.SetField("goVersion", moonlight.StringValue(runtime.Version()))
|
||||||
hshMod.SetField("user", moonlight.StringValue(username))
|
hshMod.SetField("user", moonlight.StringValue(username))
|
||||||
hshMod.SetField("host", moonlight.StringValue(host))
|
hshMod.SetField("host", moonlight.StringValue(host))
|
||||||
|
|
2
lua.go
2
lua.go
|
@ -53,7 +53,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("print(type(hilbish)); package.path = package.path .. " + requirePaths)
|
||||||
_, err := l.DoString("print(type(hilbish)); print(hilbish.userDir.config)")
|
_, err := l.DoString("print(type(hilbish)); print(hilbish); print(hilbish.userDir.config)")
|
||||||
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.")
|
||||||
|
|
|
@ -18,5 +18,4 @@ func (mlr *Runtime) LoadLibrary(ldr Loader, name string) {
|
||||||
mlr.state.GetField(-1, "preload")
|
mlr.state.GetField(-1, "preload")
|
||||||
mlr.state.PushGoClosure(cluaLoader)
|
mlr.state.PushGoClosure(cluaLoader)
|
||||||
mlr.state.SetField(-2, name)
|
mlr.state.SetField(-2, name)
|
||||||
mlr.state.Pop(1)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (mlr *Runtime) pushToState(v Value) {
|
||||||
case TableType:
|
case TableType:
|
||||||
tbl := v.AsTable()
|
tbl := v.AsTable()
|
||||||
tbl.SetRuntime(mlr)
|
tbl.SetRuntime(mlr)
|
||||||
mlr.state.RawGeti(lua.LUA_REGISTRYINDEX, tbl.refIdx)
|
tbl.Push()
|
||||||
default: mlr.state.PushNil()
|
default: mlr.state.PushNil()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
//go:build midnight
|
//go:build midnight
|
||||||
|
|
||||||
package moonlight
|
package moonlight
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/aarzilli/golua/lua"
|
"github.com/aarzilli/golua/lua"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Table struct{
|
type Table struct {
|
||||||
refIdx int
|
refIdx int
|
||||||
mlr *Runtime
|
mlr *Runtime
|
||||||
nativeFields map[Value]Value
|
nativeFields map[Value]Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTable() *Table {
|
func NewTable() *Table {
|
||||||
return &Table{
|
return &Table{
|
||||||
refIdx: -1,
|
refIdx: -1,
|
||||||
nativeFields: make(map[Value]Value),
|
nativeFields: make(map[Value]Value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +25,8 @@ func (t *Table) SetRuntime(mlr *Runtime) {
|
||||||
if t.refIdx == -1 {
|
if t.refIdx == -1 {
|
||||||
mlr.state.NewTable()
|
mlr.state.NewTable()
|
||||||
t.refIdx = mlr.state.Ref(lua.LUA_REGISTRYINDEX)
|
t.refIdx = mlr.state.Ref(lua.LUA_REGISTRYINDEX)
|
||||||
|
t.Push() // because Ref pops off the stack
|
||||||
|
t.syncToLua()
|
||||||
mlr.state.Pop(1)
|
mlr.state.Pop(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +40,35 @@ func (t *Table) Push() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Table) SetField(key string, value Value) {
|
func (t *Table) SetField(key string, value Value) {
|
||||||
fmt.Printf("key: %s, value: %s\n", key, value.TypeName())
|
if t.refIdx != -1 {
|
||||||
|
t.setInLua(key, value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.setInGo(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Table) setInLua(key string, value Value) {
|
||||||
t.Push()
|
t.Push()
|
||||||
defer t.mlr.state.Pop(1)
|
defer t.mlr.state.Pop(1)
|
||||||
|
|
||||||
t.mlr.pushToState(value)
|
t.mlr.pushToState(value)
|
||||||
t.mlr.state.SetField(-1, key)
|
t.mlr.state.SetField(-2, key)
|
||||||
t.mlr.state.Pop(1)
|
}
|
||||||
println("what")
|
|
||||||
|
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
|
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)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue