mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 19:52:25 +00:00
add lua engine skeleton
This commit is contained in:
1
internal/engine/lua/handler.go
Normal file
1
internal/engine/lua/handler.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package lua
|
||||||
35
internal/engine/lua/pool.go
Normal file
35
internal/engine/lua/pool.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package lua
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
lua "github.com/yuin/gopher-lua"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LuaPool struct {
|
||||||
|
pool sync.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLuaPool() *LuaPool {
|
||||||
|
return &LuaPool{
|
||||||
|
pool: sync.Pool{
|
||||||
|
New: func() any {
|
||||||
|
L := lua.NewState()
|
||||||
|
|
||||||
|
return L
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lp *LuaPool) Get() *lua.LState {
|
||||||
|
return lp.pool.Get().(*lua.LState)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lp *LuaPool) Put(L *lua.LState) {
|
||||||
|
L.Close()
|
||||||
|
|
||||||
|
newL := lua.NewState()
|
||||||
|
|
||||||
|
lp.pool.Put(newL)
|
||||||
|
}
|
||||||
26
internal/engine/lua/types.go
Normal file
26
internal/engine/lua/types.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package lua
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/akyaiy/GoSally-mvp/internal/core/corestate"
|
||||||
|
"github.com/akyaiy/GoSally-mvp/internal/engine/app"
|
||||||
|
"github.com/akyaiy/GoSally-mvp/internal/server/rpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LuaEngineDeps struct {
|
||||||
|
HttpRequest *http.Request
|
||||||
|
JSONRPCRequest *rpc.RPCRequest
|
||||||
|
SessionUUID string
|
||||||
|
ScriptPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
type LuaEngineContract interface {
|
||||||
|
Handle(deps *LuaEngineDeps) *rpc.RPCResponse
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type LuaEngine struct {
|
||||||
|
x *app.AppX
|
||||||
|
cs *corestate.CoreState
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user