programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: EVALUATE in Callback Revisited

From: Rick VanNorman <rvn_at_forth.com>
Date: Wed, 18 Jun 2003 14:48:25 -0700

Bob,

Try this code

======================================================================
\ test evaluate in a callback
\ use a redefined wm_rbuttondown message to the console for testing

VARIABLE INFO

: INHERIT-SEARCHORDER
   OPERATOR #ORDER HIS #ORDER #VOCS 3 + CELLS CMOVE ;

: THIS-WORD-EVALUATED
   Z" Just Kidding!" INFO ! ;

: DOIT
   INHERIT-SEARCHORDER S" THIS-WORD-EVALUATED" EVALUATE ;

: DOIT-ANOTHER-WAY
   INHERIT-SEARCHORDER S" 6 5 + Z(.) INFO !" EVALUATE ;

CONSOLE-WINDOW +ORDER

: SHOW ( z -- )
   HWND INFO @ ROT MB_OK MessageBox DROP ;

[+SWITCH SF-MESSAGES
   WM_RBUTTONDOWN RUN: Z" Testing" INFO !
      Z" Before" SHOW DOIT Z" After" SHOW ;
SWITCH]

CONSOLE-WINDOW -ORDER
======================================================================

It works with either version of DOIT, showing that the evaluate was just
fine.

Hope this helps,
rick

Wednesday, June 18, 2003, 2:12:55 PM, you wrote:

BN> Some time ago (September 2001 and June 2002) there were discussions
BN> about using EVALUATE in a callback as part of a turnkeyed app.

BN> According to Rick, the problem is that internal variables and system
BN> state are not initialized during callbacks, so the search order and
BN> CONTEXT had to be set before executing EVALUATE in the callback.

BN> There were two solutions. One (from Rick) was to define the callback
BN> word something like this:

BN> : EVAL DECIMAL ONLY FORTH POSTPONE [ Buffer ZCOUNT ['] MY-EVALUATE
BN> CATCH IF 2DROP THEN ;

BN> Buffer contained the string to be evaluated and MY-EVALUATE was a
BN> version of EVALUATE that did not try to write errors to the console.

BN> Another solution (again from Rick) was to execute a special word,
BN> INHERIT-SEARCHORDER, just before executing the callback switch
BN> statements:

BN> : INHERIT-SEARCHORDER OPERATOR #ORDER HIS #ORDER #VOCS 3 + CELLS CMOVE
BN> ; \ I'll trust Rick on this one!

BN> I just tried various combos of the above with no success (mostly I got a
BN> DOS console window that persisted for a while and then went away). The
BN> evaluated words were simple stack manipulations like : test-word 5 5 +
BN> ; The word didn't seem to execute (nothing on the stack).

BN> Finally, my questions:

BN> 1. Did anyone get this to work?
BN> 2. Do you have code snippets you are willing to share?

BN> This is just for my own edification -- no immediate need. Thanks!

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Wed Jun 18 2003 - 14:56:07 PDT

This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:09 PST