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:
|
||||
- go build -tags midnight,{{.LUA}} {{.GOFLAGS}}
|
||||
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:
|
||||
cmds:
|
||||
|
|
3
api.go
3
api.go
|
@ -61,6 +61,7 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||
*/
|
||||
}
|
||||
hshMod = moonlight.NewTable()
|
||||
hshMod.SetRuntime(mlr)
|
||||
mlr.SetExports(hshMod, exports)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
println("setting ver field")
|
||||
hshMod.SetField("ver", moonlight.StringValue(getVersion()))
|
||||
println("setting goversion field")
|
||||
hshMod.SetField("goVersion", moonlight.StringValue(runtime.Version()))
|
||||
hshMod.SetField("user", moonlight.StringValue(username))
|
||||
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
|
||||
//_, 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 {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
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.PushGoClosure(cluaLoader)
|
||||
mlr.state.SetField(-2, name)
|
||||
mlr.state.Pop(1)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (mlr *Runtime) pushToState(v Value) {
|
|||
case TableType:
|
||||
tbl := v.AsTable()
|
||||
tbl.SetRuntime(mlr)
|
||||
mlr.state.RawGeti(lua.LUA_REGISTRYINDEX, tbl.refIdx)
|
||||
tbl.Push()
|
||||
default: mlr.state.PushNil()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
//go:build midnight
|
||||
|
||||
package moonlight
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aarzilli/golua/lua"
|
||||
)
|
||||
|
||||
type Table struct{
|
||||
type Table struct {
|
||||
refIdx int
|
||||
mlr *Runtime
|
||||
nativeFields map[Value]Value
|
||||
|
@ -26,6 +25,8 @@ func (t *Table) SetRuntime(mlr *Runtime) {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
@ -39,20 +40,35 @@ func (t *Table) Push() {
|
|||
}
|
||||
|
||||
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()
|
||||
defer t.mlr.state.Pop(1)
|
||||
|
||||
t.mlr.pushToState(value)
|
||||
t.mlr.state.SetField(-1, key)
|
||||
t.mlr.state.Pop(1)
|
||||
println("what")
|
||||
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) {
|
||||
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)) {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue