run script fails to execute handler
run script fails to execute handler
The following ASObjC delegate code fails with:
-[ASObjcCAppDelegate applicationWillFinishLaunching:]: «class ocid» id «data kptr40903301» doesn’t understand the test message. (error -1708)
A similar vanilla AS version (further below) works as expected in AS Editor.
The intention is to evaluate a script object function.
In the actual application of this code the script whose function is to be evaluated is loaded from disk with load script.
But the issue is well illustrated in this example.
I understand the need to coerce «class ocid» but I am not quite sure what to do in this instance.
Is there a way to coerce the script object so that it behaves as in vanilla AS?
script ASObjcCAppDelegate
property parent : class "NSObject"
on applicationWillFinishLaunching_(aNotification)
tell me
test()
end tell
evaluateScriptFunction(me, "test", {})
end applicationWillFinishLaunching_
--
-- evaluateScriptFunction
--
on evaluateScriptFunction(theScript, theFunc, theArgs)
-- generate on run {x} tell x return test() end tell end
set i to 1
set expr to "on run {x} " & linefeed
set expr to expr & "tell x " & linefeed
set expr to expr & "return " & theFunc & "("
repeat (count of theArgs) times
if i = 2 then
set expr to expr & ", "
end if
set expr to expr & "item " & i & " of theArgs "
end repeat
set expr to expr & ")" & linefeed
set expr to expr & "end tell" & linefeed
set expr to expr & "end" & linefeed
log expr
return run script expr with parameters {theScript}
end evaluateScriptFunction
to test()
say "test called"
end test
end script
========
This similar script functions as expected in vanilla AS
========
script ASObjcCAppDelegate
on applicationWillFinishLaunching_(aNotification)
tell me
test()
end tell
return evaluateScriptFunction(me, "test", {})
end applicationWillFinishLaunching_
--
-- evaluateScriptFunction
--
on evaluateScriptFunction(theScript, theFunc, theArgs)
set i to 1
set expr to "on run {x} " & linefeed
set expr to expr & "tell x " & linefeed
set expr to expr & "return " & theFunc & "("
repeat (count of theArgs) times
if i = 2 then
set expr to expr & ", "
end if
set expr to expr & "item " & i & " of theArgs "
end repeat
set expr to expr & ")" & linefeed
set expr to expr & "end tell" & linefeed
set expr to expr & "end" & linefeed
return run script expr with parameters {theScript}
end evaluateScriptFunction
on test()
return "test called"
end test
end script
tell ASObjcCAppDelegate
say applicationWillFinishLaunching_("")
end tell
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden