XRtn EvalExpString()

External developers... This forum's for you!

XRtn EvalExpString()

Postby Dave_Higgins » Sun Oct 17, 2010 12:43 pm

When I run EvalExpString() using a SC base function, like date(), it works fine, but when I try to call my own function, I'm drawing error 41, Never heard of that function name. I've gone as far as placing my function in a backscript.

Code: Select all
function testMessage
    return "This is a test."
end testMessage

Str255      xResult;
short         xErr;

xErr = EvalExpString("\ptestMessage()", xResult);
// xErr = 41
------------------
xErr = EvalExpString("\pdate()", xResult);
// xErr = 0
// xResult = <today's date>

Seeing that EvalExpString() doesn't offer a destination (similar to via), like SendMessage(message, destination) does, I wonder if it's designed to only offer up functions/expressions that SC itself can answer.
Last edited by Dave_Higgins on Tue Oct 19, 2010 11:00 am, edited 1 time in total.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: Before calling it a bug... XRtn EvalExpString()

Postby codegreen » Mon Oct 18, 2010 5:41 pm

Dave Higgins wrote:When I run EvalExpString() using a SC base function, like date(), it works fine, but when I try to call my own function, I'm drawing error 41, Never heard of that function name. I've gone as far as placing my function in a backscript.

But apparently not as far as calling it from your script entry point...

When you invoke an XRtn via script it works much the same way as an XFcn, in that a reference to the current script context is passed in the parameter block and used when evaluating messages and expressions in callbacks.

When your event entry point is called though, there's no script context associated with execution (since you're not being called from a script) and thus the only expressions that can be evaluated are ones that don't depend on one (e.g. native SuperTalk functions, externals in what would be the message path if there was one, script functions called using via).

HTH,
-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

XRtn EvalExpString()

Postby Dave_Higgins » Tue Oct 19, 2010 5:59 am

mark wrote:But apparently not as far as calling it from your script entry point...

When you invoke an XRtn via script it works much the same way as an XFcn, in that a reference to the current script context is passed in the parameter block and used when evaluating messages and expressions in callbacks.

When your event entry point is called though, there's no script context associated with execution (since you're not being called from a script) and thus the only expressions that can be evaluated are ones that don't depend on one (e.g. native SuperTalk functions, externals in what would be the message path if there was one, script functions called using via).

I see... I figured it was going to end up being something I was doing wrong. Using "via" seems to be working well. I'm working into that closeBoxClick() a way for the user to return true/false to determine if the window should close.

Now I have to work out how to get the long name/id of the window in play. I can get the short name (title) easy enough, but if the actual front window is from a different project, then I need a reference to the project, as well (in order to direct the "via"). I guess the lack of a script context is also what prevents an eval of target() from working, so I'll have to take a bit more of a long route.

But, before I ask for your help on that one, I'll see if I can sort it out myself. It's more likely to stick that way. Now if I could only *choose* what to kick out in order to learn that. ;)
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

XRtn EvalExpString()

Postby Dave_Higgins » Wed Oct 20, 2010 2:32 pm

Well, I was up against getting the long name or ID of the window in question, so I could run an eval via that window, but I abandoned that for now and just decided to use GetWinPosition(), where if not zero then SetWinPosition to zero. At that point I'm OK by running the eval "via topWindow()". From there it's up to the user to return true/false to determine if it should be closed (giving a way to use or emulate 'Save Changes Yes/No/Cancel').

Learned a bit there by poking at that one. Moving on...
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: XRtn EvalExpString()

Postby Dan_Kelleher » Wed Oct 20, 2010 5:36 pm

Learned a bit there by poking at that one. Moving on...


thanks for sharing it all too...
important issues
-Dan
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest