Files
JiXieShi 2ce672cdde refactor: extract pkg/forward and pkg/luaplugin packages
Move ForwardManager → pkg/forward/Manager and PluginManager →
pkg/luaplugin/Manager. Move FoeWardMode (now forward.Mode) with
ParseMode/Network/String into pkg/forward. Rename constants:
NOT→None, TCPC→TCP, UDPC→UDP. Update all references in main
package.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 19:41:45 +08:00

51 lines
1.0 KiB
Go

package luaplugin
import lua "github.com/yuin/gopher-lua"
func callStringHook(L *lua.LState, name string, payload string) (*string, bool, error) {
fn := L.GetGlobal(name)
if fn.Type() == lua.LTNil {
return nil, false, nil
}
if err := L.CallByParam(lua.P{Fn: fn, NRet: 1, Protect: true}, lua.LString(payload)); err != nil {
return nil, true, err
}
ret := L.Get(-1)
L.Pop(1)
if ret.Type() == lua.LTNil {
return nil, true, nil
}
s := ret.String()
return &s, true, nil
}
func callCommandHook(L *lua.LState, name, line string) (string, bool, bool, error) {
fn := L.GetGlobal(name)
if fn.Type() == lua.LTNil {
return "", true, false, nil
}
if err := L.CallByParam(lua.P{Fn: fn, NRet: 2, Protect: true}, lua.LString(line)); err != nil {
return "", true, true, err
}
allowVal := L.Get(-1)
lineVal := L.Get(-2)
L.Pop(2)
allow := true
if allowVal.Type() == lua.LTBool {
allow = lua.LVAsBool(allowVal)
}
next := ""
if lineVal.Type() != lua.LTNil {
next = lineVal.String()
}
return next, allow, true, nil
}