• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
run script fails to execute handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

run script fails to execute handler


  • Subject: run script fails to execute handler
  • From: "email@hidden" <email@hidden>
  • Date: Sun, 16 May 2010 22:49:34 +0100

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

  • Prev by Date: Re: canceling a performSelector:withObject:afterDelay:
  • Next by Date: Cannot pass script object as parameter to run script
  • Previous by thread: Re: canceling a performSelector:withObject:afterDelay:
  • Next by thread: Cannot pass script object as parameter to run script
  • Index(es):
    • Date
    • Thread