mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 17:52:24 +00:00
36 lines
432 B
Go
36 lines
432 B
Go
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)
|
|
}
|