本文整理匯總了Golang中github.com/aarzilli/golua/lua.State.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.Close方法的具體用法?Golang State.Close怎麽用?Golang State.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aarzilli/golua/lua.State
的用法示例。
在下文中一共展示了State.Close方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (p ProbeRunner) Run() {
var err error
var state *lua.State
var fun *luar.LuaObject
var res interface{}
r := p.Error
args := make(map[string]interface{})
if err = json.Unmarshal([]byte(p.Probe.Arguments), &args); err != nil {
goto out
}
state = mkstate()
defer state.Close()
err = state.DoString(fmt.Sprintf("fun = function(args) %s end", p.Script.Code))
if err != nil {
goto out
}
state.GetGlobal("fun")
fun = luar.NewLuaObject(state, -1)
if res, err = fun.Call(args); err != nil {
goto out
} else if res == nil {
// if nil, that means no error. just go to out.
goto out
} else if status, ok := res.(string); !ok {
// if it's not a string, that's bad. luar seems to convert go errors to strings..
err = fmt.Errorf("script resulted in non-string return value %q", res)
} else if status != "" {
// if the string is not empty that's an error.
err = fmt.Errorf("probe error: %s", status)
}
out:
r <- err
close(r)
}