35 lines
592 B
Go
35 lines
592 B
Go
|
package lua_speed
|
||
|
|
||
|
import (
|
||
|
_ "embed"
|
||
|
"github.com/yuin/gopher-lua"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
//go:embed speed.lua
|
||
|
var speedLuaScript string
|
||
|
|
||
|
func FibonacciLuaInit() *lua.LState {
|
||
|
L := lua.NewState()
|
||
|
L.OpenLibs()
|
||
|
|
||
|
if err := L.DoString(speedLuaScript); err != nil {
|
||
|
log.Panic("Error running Lua plugin:", err)
|
||
|
}
|
||
|
|
||
|
return L
|
||
|
}
|
||
|
|
||
|
func FibonacciLuaRun(L *lua.LState, n uint64) uint64 {
|
||
|
F := L.GetGlobal("Fibonacci")
|
||
|
err := L.CallByParam(lua.P{
|
||
|
Fn: F,
|
||
|
NRet: 1,
|
||
|
Protect: true,
|
||
|
}, lua.LNumber(n))
|
||
|
if err != nil {
|
||
|
return 0
|
||
|
}
|
||
|
return uint64(L.ToNumber(L.GetTop()))
|
||
|
}
|