I have an applet which I’m trying to restructure (main.scpt is large and is slow to edit in Script Debugger, which sometimes crashes). I have lifted some handlers from “main.scpt” and placed them in another script in the bundle “loaded_script.scpt”. I have then loaded the loaded_script.scpt file. So, instead of going to one of its own handlers, execution in main.scpt goes to the relevant handler in loaded_script.scpt. That works well. This is a prototype of what is working:
Applets’ main.scpt:
get_the_data()
on get_the_data()
set folder_path to path to me as string
set path_to_script to (folder_path & "Contents:Resources:Scripts:loaded_script.scpt") as string
set theScriptInside to path_to_script as alias
set run_this to load script file theScriptInside
set data_returned to run_this's run_this_handler(folder_path)
display dialog data_returned
end get_the_data
and in loaded_script.scpt I have:
on run_this_handler(folder_path)
set data_to_be_returned to "This has been returned " & folder_path
end run_this_handler
But, for my applet to work, I need execution to return to a different handler. So, the prototype main.scpt has this:
get_the_data()
on get_the_data()
set folder_path to path to me as string
set path_to_script to (folder_path & "Contents:Resources:Scripts:loaded_script.scpt") as string
set theScriptInside to path_to_script as alias
set run_this to load script file theScriptInside
set data_returned to run_this's run_this_handler(folder_path)
end get_the_data
on return_to_this_handler()
display dialog "Called by theScriptInside"
end return_to_this_handler
I have got that to work by loading main.scpt into loaded_script.scpt. So loaded_script.scpt has:
on run_this_handler(folder_path)
set data_to_be_returned to "This has been returned " & folder_path
set return_to_different_handler to load script file folder_path
return_to_different_handler's return_to_this_handler()
end run_this_handler
This redirection works. But it’s at the expense of loading all of main.scpt into loaded_script.scpt. main.scpt in my applet is over 3,200 lines. Is there another way to redirect execution to a handler different to that which called the loaded script ?
I have looked at specifying a parent-child relationship between the two scripts but all my attempts at that have failed. For example, I can’t figure out how to make a parent-child relationship between two script files. Even if that worked, I don’t know if it will do what I need without effectively loading all 3,200 lines of the parent’s code into the child so it can call a handler in the parent.
Thanks.
Garry
Model: iMac (late 2009) Core i5, macOS X 10.15.7
Browser: Safari 14.0.2
Operating System: Other