Debug.getinfo(1) not returning the current function

debug.getinfo(1) does not seem to return the current function name when called from an engine callback , there’s plenty of other stuff, see below

{
  linedefined = 3,
  currentline = 6,
  func = function: 0x174fb6e0,
  isvararg = false,
  namewhat = ,
  lastlinedefined = 12,
  source = =/main/main.script,
  nups = 1,
  what = Lua,
  nparams = 1,
  short_src = /main/main.script,
}

Calling getinfo from a regular function down the stack return the name as expected

{
  linedefined = 15,
  currentline = 17,
  func = function: 0x0a1c2830,
  isvararg = false,
  namewhat = global,
  lastlinedefined = 19,
  source = =/main/main.script,
  nups = 0,
  what = Lua,
  nparams = 0,
  name = someFunction,
  short_src = /main/main.script,
}

The callback function isn’t anonymous? Can you show the code?

1 Like

By callback I meant something that the engine calls like init(), this is running from the main.script, see below for code and output. Also, at a breakpoint in init() the debugger Call Stack shows “Unknown” for the init() and the correct name for someFunction(), this may be related.

   function init(self)
    	pprint(debug.getinfo(1))
    	someFunction()
    end

    function someFunction() 
    	pprint(debug.getinfo(1))
    end

Outputs this in the console

     DEBUG:SCRIPT: 
     {
       linedefined = 3,
       currentline = 4,
       func = function: 0x0d884610,
       isvararg = false,
       namewhat = ,
       lastlinedefined = 6,
       source = =/main/main.script,
       nups = 0,
       what = Lua,
       nparams = 1,
       short_src = /main/main.script,
     }

  DEBUG:SCRIPT: 
     {
       linedefined = 8,
       currentline = 9,
       func = function: 0x0d884630,
       isvararg = false,
       namewhat = global,
       lastlinedefined = 10,
       source = =/main/main.script,
       nups = 0,
       what = Lua,
       nparams = 0,
       name = someFunction,
       short_src = /main/main.script,
     }

Ah, I see. Yeah, those lifecycle functions are treated a bit differently. I’m not sure if we’ll be able to get the function name back in that case. You’ll at least still get line number and source.