Info gets information about a specific function or function invocation. To get information about a function invocation, the parameter where must be a valid activation record that was filled by a previous call to Stack or given as an argument to a hook (see Hook). To get information about a functio
(l *State, what string, where Frame)
| 311 | // |
| 312 | // This function returns false on error (for instance, an invalid option in what). |
| 313 | func Info(l *State, what string, where Frame) (d Debug, ok bool) { |
| 314 | var f closure |
| 315 | var fun value |
| 316 | if what[0] == '>' { |
| 317 | where = nil |
| 318 | fun = l.stack[l.top-1] |
| 319 | switch fun := fun.(type) { |
| 320 | case closure: |
| 321 | f = fun |
| 322 | case *goFunction: |
| 323 | default: |
| 324 | panic("function expected") |
| 325 | } |
| 326 | what = what[1:] // skip the '>' |
| 327 | l.top-- // pop function |
| 328 | } else { |
| 329 | fun = l.stack[where.function] |
| 330 | switch fun := fun.(type) { |
| 331 | case closure: |
| 332 | f = fun |
| 333 | case *goFunction: |
| 334 | default: |
| 335 | l.assert(false) |
| 336 | } |
| 337 | } |
| 338 | ok, hasL, hasF := true, false, false |
| 339 | d.callInfo = where |
| 340 | ci := d.callInfo |
| 341 | for _, r := range what { |
| 342 | switch r { |
| 343 | case 'S': |
| 344 | d = functionInfo(d, f) |
| 345 | case 'l': |
| 346 | d.CurrentLine = -1 |
| 347 | if where != nil && ci.isLua() { |
| 348 | d.CurrentLine = l.currentLine(where) |
| 349 | } |
| 350 | case 'u': |
| 351 | if f == nil { |
| 352 | d.UpValueCount = 0 |
| 353 | } else { |
| 354 | d.UpValueCount = f.upValueCount() |
| 355 | } |
| 356 | if lf, ok := f.(*luaClosure); !ok { |
| 357 | d.IsVarArg = true |
| 358 | d.ParameterCount = 0 |
| 359 | } else { |
| 360 | d.IsVarArg = lf.prototype.isVarArg |
| 361 | d.ParameterCount = lf.prototype.parameterCount |
| 362 | } |
| 363 | case 't': |
| 364 | d.IsTailCall = where != nil && ci.isCallStatus(callStatusTail) |
| 365 | case 'n': |
| 366 | // calling function is a known Lua function? |
| 367 | if where != nil && !ci.isCallStatus(callStatusTail) && where.previous.isLua() { |
| 368 | d.Name, d.NameKind = l.functionName(where.previous) |
| 369 | } else { |
| 370 | d.NameKind = "" |
no test coverage detected