This is actually hard to fix cleanly, so I thought I would request some ideas. Here's the problem:
Imagine the normal case:
Code: Select all
EXAMPLE 1:
(scrAddAction gScreen 'myAction 0 "My Action" (dbgOutput "Test"))
But imagine that I want a level of indirection:
Code: Select all
EXAMPLE 2:
(block (myFunc)
(setq myFunc (lambda () (dbgOutput "Test"))
(scrAddAction gScreen 'myAction 0 "My Action" myFunc)
)
The semantics of scrAddAction are:
1. Take the last argument and store it as the action code.
2. When the user invokes the action, evaluate the action code.
Importantly, step 1 does not evaluate the code at the time that you call scrAddAction. Otherwise, when you added the action, you would actually invoke it. Imagine, in EXAMPLE 1, what would happen if you evaluated the last argument when scrAddAction was called: you would output "Test" right then and there, which is something that you don't want.
But now look at EXAMPLE 2. In that case, you *want* the last argument to be evaluated. "myFunc" is just a variable (not code). What you want to do is *evaluate* myFunc and pass in the result of the evaluation (which is a function).
If evaluation is the problem, one might try this:
Code: Select all
EXAMPLE 3:
...
(scrAddAction gScreen 'myAction 0 "My Action" (eval myFunc))
...
So that's the problem.
If scrAddAction evaluates the last argument, then EXAMPLE 1 will break.
But if scrAddAction doesn't evaluate the last argument, then EXAMPLE 2 will not work.
The only hack solution that I can think of is to have two flavors of scrAddAction:
scrAddAction
scrAddActionIndirect (or something like that)
scrAddActionIndirect would evaluate the last argument.
Does anyone have any other suggestions?