You can call a handler in another class pretty easily, but there are a couple of things to be aware of. For one, you can’t pass application references. There’s also no need to make an instance of the class; AppleScript handlers are treated as both class and instance methods.
Let’s suppose you have a class called OtherScript and you want to put a handler like this in it:
on doStuff(a, b, c)
return (a + b) / c
end doStuff
First, you have to match the Cocoa naming convention. So you need to rename it something like do_some_stuff_ or even dostuff___. So let’s say you have this:
on do_some_stuff_(a, b, c)
return (a + b) / c
end do_some_stuff_
To call it from your first script, you need to refer to the relevant class, which in turn belongs to the application. So something like:
set x to current application's class "OtherScript"'s do_some_stuff_(5, 7, 2)
Because you’re calling the handler via Cocoa, x is going to be a pointer, and you’re going to have to coerce it to an integer or number before you can do anything with it.
But in fact you won’t get that far, because the same problem also happens when you pass arguments to a handler via Cocoa – so your handler will fail because a, b and c are not recognized as numbers. You need to change your handler to something like:
on do_some_stuff_(a, b, c)
set a to a as real
set b to b as real
set c to c as real
return (a + b) / c
end do_some_stuff_
Now it should work.
All that coercing is going to get tedious, especially if you have lots of parameters or handlers that return a lot of values, but in such cases you can reduce the amount you need to do. The key is to pass a single parameter as a list.
So the call becomes:
set x to current application's class "OtherScript"'s doStuff_({5, 7, 2})
And the handler becomes:
on doStuff_(d)
set {a, b, c} to d as list
return (a + b) / c
end doStuff_
end script
The important point here is that coercing the single argument to a list effectively coerces the values it contains to their respective classes.