Jump to content

Shoud I be calling Execute() rather than Eval() ?


Recommended Posts

A user of my cDebug.au3 (in Example scripts) can code;

Global $g=123
_GuiDebug('test','$g',$g)

(This is a trivial example: the second argument is usually much longer, and there are more value arguments.)

My script runs _GuiDebug, which calls  _cDebug_EvaluateGlobalVar() to get the value of $g:

This function now is:

Func _cDebug_EvaluateGlobalVar($cDebug_param)
Local $___cDebug_ret
    If StringLeft($cDebug_param,1)='$' Then
        $cDebug_param =  StringTrimLeft($cDebug_param,1)
    EndIf
    If IsDeclared($cDebug_param)=$DECLARED_GLOBAL Then
        Local $___cDebug_ret = Eval($cDebug_param)
    Else
        SetError(1)     ; the Help implies that @error from Eval() may not be reliable!
    EndIf
    Return $___cDebug_ret
EndFunc

The older version did not call IsDeclared(), depending on Eval() to set @error if $g was not declared by the user as a global. My thinking was that Eval() did not reliably set @error. Hence the new version. (The casue might have been a bug somewhere else.)

But, thinking some more, I remember the Help for Eval():

Quote

If there is a need to use Eval() to read a variable, then in most situations Assign() should be used to create/write to the variable

In my script, Assign() is never called.

So should I be calling Execute() rather than Eval()?

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

If you're just trying to get the value of the variable, then all you need is this

Local $___cDebug_ret = $cDebug_param
; OR
Return $cDebug_param

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Just now, c.haslam said:

Don't think so: the value of parameter $cDebug_param is '$g'

That's not the way to do it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The situation is much more complicated. The second parameter has to be parsed. An example from the user manual:

#AutoIt3Wrapper_Version=B
#include "CDebug.au3"
Global $g=4,$h=2
foo()

Func foo()
    Local $ar =[[0,1,2,3],[10,11,12,13], [20,21,22,23], [30,31,32,33], [40,41,42,43], [50,51,52,53]]
    Local $kk=3,$m=6.73
    _GuiDebug('test','$kk,$ar[$kk..,$g][$h..],$m',$kk,$ar,$m)
EndFunc

In this case, the user could hard-code $h:

_GuiDebug('test','$kk,$ar[$kk..,$g][4..],$m',$kk,$ar,$m)

but $h can be set at run time. (The same is true of global $g and locals $kk.)

If you are interested, this feature is described in the cDebug user manual, pages 5 and 6.

Do you mean that I should be using Exeecute(), not Eval() ?

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...