1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-25 09:36:24 -07:00

Update gcplugin package for new API, use luar to pass zerolog logs to VM

This commit is contained in:
Eggbertx 2022-12-30 15:27:19 -08:00
parent c38816b5df
commit d0e59b4580
2 changed files with 16 additions and 16 deletions

View file

@ -1,10 +1,13 @@
package gcplugin
import (
"errors"
"github.com/gochan-org/gochan/pkg/config"
"github.com/gochan-org/gochan/pkg/gcutil"
lua "github.com/yuin/gopher-lua"
luar "layeh.com/gopher-luar"
)
var (
@ -27,22 +30,20 @@ func ClosePlugins() {
func createLuaLogFunc(which string) lua.LGFunction {
return func(l *lua.LState) int {
args := []interface{}{}
for v := 1; v <= l.GetTop(); v++ {
args = append(args, l.Get(v))
}
switch which {
case "info":
gcutil.LogInfo().
Interface("pluginInfo", args)
l.Push(luar.New(l, gcutil.LogInfo()))
case "warn":
gcutil.LogWarning().
Interface("pluginWarning", args)
l.Push(luar.New(l, gcutil.LogWarning()))
case "error":
gcutil.LogError(nil).
Interface("pluginError", args)
numArgs := l.GetTop()
if numArgs == 0 {
l.Push(luar.New(l, gcutil.LogError(nil)))
} else {
l.Push(luar.New(l, gcutil.LogError(errors.New(l.CheckString(-1)))))
}
}
return 0
return 1
}
}

View file

@ -13,11 +13,10 @@ const (
versionStr = `return _GOCHAN_VERSION
`
structPassingStr = `print(string.format("Receiving post from %q", post.Name))
print(string.format("Message before changing: %q", post.MessageText))
post.MessageText = "Message modified by a plugin\n"
post.MessageHTML = "Message modified by a plugin<br />"
print(string.format("Modified message text: %q", post.MessageText))
`
print(string.format("Message before changing: %q", post.MessageRaw))
post.MessageRaw = "Message modified by a plugin\n"
post.Message = "Message modified by a plugin<br />"
print(string.format("Modified message text: %q", post.MessageText))`
)
func initPluginTests() {