RosettaCodeData/Task/Reflection-Get-source/Lingo/reflection-get-source-1.lingo

26 lines
946 B
Plaintext

----------------------------------------
-- 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