Task

The goal is to get the source code or file path and line number where a programming object (e.g. module, class, function, method) is defined.




----------------------------------------
-- Returns source code either for a class (parent script) or a class instance (object)
-- @param {script|instance} class
-- @return {string}
----------------------------------------
on getClassCode (class)
  if ilk(class)=#instance then class=class.script
  return class.text
end
 
----------------------------------------
-- Returns the source code of the movie script that defines the specified global function
-- @param {symbol} func - function specified as symbol
-- @return {string|VOID}
----------------------------------------
on getGlobalFunctionCode (func)
  -- iterate over all members in all castlibs
  repeat with i = 1 to _movie.castlib.count
    repeat with j = 1 to _movie.castlib[i].member.count
      m = _movie.castlib[i].member[j]
      if m.type<>#script then next repeat
      if m.scriptType=#movie and m.script.handler(func) then return m.script.text
    end repeat
  end repeat
end