Variable typing

Dick Kriesel dick.kriesel at mail.com
Tue Apr 4 15:10:02 EDT 2006


On 4/4/06 9:30 AM, "Alex Tweedly" <alex at tweedly.net> wrote:

> Of course, you still can't distinguish between a variable which is
> undefined and one which has been deliberately set to empty :-(

Here's a technique based on what revvariablewatcher.rev does:

Step 1: create a stack
Step 2: create a field
Step 3: paste the following handlers into the stack script
Step 4: click the stack

on mouseUp
  put 1 into t
  a
end mouseUp

on a
  answer callerVariableExists("t") & cr & callerVariableValue("t")
end a

function callerVariableExists pVariableName
  put empty into fld 1 of me
  set the debugContext to line -3 of the executionContexts
  debugDo "put the variableNames into fld 1 of me"
  set the debugContext to empty
  return pVariableName is among the items of line 2 of fld 1 of me
end callerVariableExists

function callerVariableValue pVariableName
  put empty into fld 1 of me
  set the debugContext to line -3 of the executionContexts
  debugDo "put the variableNames into fld 1 of me"
  if pVariableName is among the items of line 2 of fld 1 of me then
    debugDo "put" && pVariableName && "into fld 1 of me"
  else
    put empty into fld 1 of me
  end if
  set the debugContext to empty
  return fld 1 of me
end callerVariableValue

-- Dick






More information about the use-livecode mailing list