MCPcopy Create free account
hub / github.com/yuin/gopher-lua / PCall

Method PCall

state.go:2029–2095  ·  view source on GitHub ↗
(nargs, nret int, errfunc *LFunction)

Source from the content-addressed store, hash-verified

2027}
2028
2029func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) {
2030 err = nil
2031 sp := ls.stack.Sp()
2032 base := ls.reg.Top() - nargs - 1
2033 oldpanic := ls.Panic
2034 ls.Panic = panicWithoutTraceback
2035 if errfunc != nil {
2036 ls.hasErrorFunc = true
2037 }
2038 defer func() {
2039 ls.Panic = oldpanic
2040 ls.hasErrorFunc = false
2041 rcv := recover()
2042 if rcv != nil {
2043 if _, ok := rcv.(*ApiError); !ok {
2044 err = newApiErrorS(ApiErrorPanic, fmt.Sprint(rcv))
2045 if ls.Options.IncludeGoStackTrace {
2046 buf := make([]byte, 4096)
2047 runtime.Stack(buf, false)
2048 err.(*ApiError).StackTrace = strings.Trim(string(buf), "\000") + "\n" + ls.stackTrace(0)
2049 }
2050 } else {
2051 err = rcv.(*ApiError)
2052 }
2053 if errfunc != nil {
2054 ls.Push(errfunc)
2055 ls.Push(err.(*ApiError).Object)
2056 ls.Panic = panicWithoutTraceback
2057 defer func() {
2058 ls.Panic = oldpanic
2059 rcv := recover()
2060 if rcv != nil {
2061 if _, ok := rcv.(*ApiError); !ok {
2062 err = newApiErrorS(ApiErrorPanic, fmt.Sprint(rcv))
2063 if ls.Options.IncludeGoStackTrace {
2064 buf := make([]byte, 4096)
2065 runtime.Stack(buf, false)
2066 err.(*ApiError).StackTrace = strings.Trim(string(buf), "\000") + ls.stackTrace(0)
2067 }
2068 } else {
2069 err = rcv.(*ApiError)
2070 err.(*ApiError).StackTrace = ls.stackTrace(0)
2071 }
2072 ls.stack.SetSp(sp)
2073 ls.currentFrame = ls.stack.Last()
2074 ls.reg.SetTop(base)
2075 }
2076 }()
2077 ls.Call(1, 1)
2078 err = newApiError(ApiErrorError, ls.Get(-1))
2079 } else if len(err.(*ApiError).StackTrace) == 0 {
2080 err.(*ApiError).StackTrace = ls.stackTrace(0)
2081 }
2082 ls.stack.SetSp(sp)
2083 ls.currentFrame = ls.stack.Last()
2084 ls.reg.SetTop(base)
2085 }
2086 ls.stack.SetSp(sp)

Callers 8

DoFileMethod · 0.95
DoStringMethod · 0.95
GPCallMethod · 0.95
CallByParamMethod · 0.95
basePCallFunction · 0.45
baseXPCallFunction · 0.45
TestPCallFunction · 0.45
TestPCallAfterFailFunction · 0.45

Calls 11

stackTraceMethod · 0.95
PushMethod · 0.95
CallMethod · 0.95
GetMethod · 0.95
newApiErrorSFunction · 0.70
newApiErrorFunction · 0.70
SpMethod · 0.65
SetSpMethod · 0.65
LastMethod · 0.65
TopMethod · 0.45
SetTopMethod · 0.45

Tested by 2

TestPCallFunction · 0.36
TestPCallAfterFailFunction · 0.36