Jump to content

Static & Global


DXRW4E
 Share

Recommended Posts

Guys are not talking about radical changes or to add a feature or other, we are talking about a small modification or improvement in Au3Check, that would actually help a lot UDF maker, nothing else

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Guys are not talking about radical changes or to add a feature or other, we are talking about a small modification or improvement in Au3Check, that would actually help a lot UDF maker, nothing else

Ciao.

What you're suggesting is that Au3Check looks for a directive #Au3CheckLock or whatever, if that's found, then the variables WITHIN that include file CANNOT be re-assigned by the file which it's included by?

Link to comment
Share on other sites

What you're suggesting is that Au3Check looks for a directive #Au3CheckLock or whatever, if that's found, then the variables WITHIN that include file CANNOT be re-assigned by the file which it's included by?

but according to my suggestion, a certain thing you can do perfectly in AutoIt, need just that when Au3Check load a file, take all the names of the functions in that file, and then see if there are Gobal Static, and get to know them only in those functions that file, or add a directive, where to put the names of the functions where seeuseedit that Global Static, nothing else

Ciao.

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Is possible to add a (Optional) directive or something like that, in order to indicate to Au3Check the names of the functions where Global Static variable will be visible

Did I misrepresent your request?

BTW that would need to get beyond Au3Check, since the interpretor needs to be aware of your specifications too.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Did I misrepresent your request?

There are many ways to do it, I think Jos & Developer or others will know better how to do it better, however the easiest way and the logical way is what i said in post before

 

BTW that would need to get beyond Au3Check, since the interpretor needs to be aware of your specifications too.

certainly AutoIt itself will know (in all parts of the script) the same as the history of the ByRefAutoItAu3Check, but to add a control in Au3Check to help udf makers to be more save that their Global Static variable is not usedchangeedit outside the basic function of the udf

it would have been nice if the Au3Check try to check this too, I know that in the end everything will never be 100% save, but at least it would help a lot

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

As I said, that requires to pass this information to the compiler and after forces the interpretor to lookup, for every variable access, whether it is a local, global or global static and then in the latter case check in some new table that if we are inside a function, then this function is actually allowed to access that variable.

That doesn't look like a small change to me and a significative slow down of critical runtime code.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

If he knows even the AutoIt itself during the execution would be really nice, I suggested at least to know the Au3Check to alert the user ect ect, as it does with the ByRef or when used in the wrong way the Const variable ect ect

as mentioned above, a certain thing you can do perfectly in AutoIt, need just that when Au3Check load a file, take all the names of the functions in that file, and then see if there are Gobal Static, and get to know them only in those functions that file

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Wouldn't you want a Local Static in a function? Why would you want it to be Global?

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

DXRW4E,

Then it would certainly be easier and much more powerful to introduce Blocks. The only requirement is that the interpretor knows where it is, just like it currently does with local vars inside functions. That's exactly the same technique, just one level higher.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi jchd, compiler does not center, which serves only Au3Check inform user when using the Global Static out of the functions of the UDF where it was declare that Global Static variable, as it does with the ByRef or when used in the wrong way the Const variable ect ect, nothing else

@BrewManNH

concrete example see my INI File Processing Functions '?do=embed' frameborder='0' data-embedContent>> I have a handle them

I do not want users to accidentally change the $_HINI OK

There are lots and lots of other scenarios that require or need to use a Global Static, or better to say when a Global Static solves many situations, and since autoit does not support pointers, is very useful to have at least the Global Static

as I said this will help a lot only udf maker, because as already mentioned

because in personal script does not need not have to do it does not make sense to do it

in personal script simply use a different name for the variable ehhhh

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Here is one current method to privatize variables that can be shared between functions. You can get the value, work with it and then save it. You can use just 1 or more functions to handle just the local static variables that are used for the share.

_Test_a()
_Test_b()
_Test_array()

If IsDeclared('a') Or IsDeclared('b') Or IsDeclared('array') Then
    ConsoleWrite('found static' & @CRLF)
EndIf

Func _Test_a()
    Local $result
    ; get value of static variable
    $result = _Static('a')
    ConsoleWrite($result & @CRLF)
    ; add 1 and save static variable
    $result += 1
    $result = _Static('a', $result)
    ConsoleWrite($result & @CRLF & @CRLF)
EndFunc

Func _Test_b()
    Local $result
    $result = _Static('b')
    ConsoleWrite($result & @CRLF)
    $result = _Static('b', $result * 10)
    ConsoleWrite($result & @CRLF & @CRLF)
EndFunc

Func _Test_array()
    Local $result
    $result = _Static('array')
    For $1 In $result
        ConsoleWrite($1 & @CRLF)
    Next
    ConsoleWrite(@CRLF)
    $result[0] = 50
    $result = _Static('array', $result)
    For $1 In $result
        ConsoleWrite($1 & @CRLF)
    Next
    ; and here is $a to finish
    $result = _Static('a')
    ConsoleWrite(@CRLF & $result & @CRLF)
EndFunc

Func _Static($variable, $value = '*')
    ; store static variables for use in other functions
    Switch $variable
        Case 'a'
            Static $a = 5
            If String($value) <> '*' Then $a = $value
            Return $a
        Case 'b'
            Static $b = 6
            If String($value) <> '*' Then $b = $value
            Return $b
        Case 'array'
            Static $array[5] = [1,2,3,4,5]
            If IsArray($value) Then $array = $value
            Return $array
    EndSwitch
EndFunc

Perhaps not great but it works. :)

Link to comment
Share on other sites

Hi MHz, Thank you, to do one thing there always a way ehhh (almost even from a cmd file do all ehhh), but have a Global Static is more safer and faster, it helps a lot also the performance, if so i use function & ByRef and Local Static Variable so everything is Ok ;)

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

; Interpretor need s to know about that!
#AutoIt3Check $xxx=_prot,protinc        ; list on functions allowed to access global static $xxx

_prot()
ConsoleWrite($xxx & @LF)    ; 5
_protinc()
ConsoleWrite($xxx & @LF)    ; 6
ConsoleWrite(_pirate() & @LF)   ; 6, could access it, or not?
_hacker()
ConsoleWrite($xxx & @LF)    ; not 6, could access it, or not?

Func _prot()
    Global Static $xxx = 5  ; legal
EndFunc

Func _protinc()
    $xxx += 1   ; legal too
EndFunc

Func _pirate()
    Return Eval("x" & "x" & "x")
EndFunc

Func _hacker()
    Assign("x" & "x" & "x", "Gotcha!")
EndFunc

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

As said if he also knows AutoIt itself during the execution would be very nice, for the moment it would be useful to add it only in Au3Check, AutoIt itself will behave as usual, will know Global Static in all the scripts, in poor words will behave as it already does with Global Static
 

Au3Check do exactly what he does here, nothing else

Global $sGlobal = "Global text"
Global Static $sStatic = "Global Static text"

Global $sGlobal = "new text"
Global $sStatic = "new text2"
MsgBox(0,0,$sStatic)

;~ >Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script (2).au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script (2).au3" (5) : ==> Cannot make static variables into regular variables.:
;~ Global $sStatic = "new text2"
;~ Global ^ ERROR
;~ ->11:10:36 AutoIt3.exe ended.rc:1
;~ >Exit code: 1    Time: 0.42

or as it does with byref, which Autoit knows them and Au3Check No

#AutoIt3Wrapper_If_Run
    #AutoIt3Wrapper_Run_AU3Check=N
#Autoit3Wrapper_If_Compile
    #AutoIt3Wrapper_Run_AU3Check=N
#AutoIt3Wrapper_EndIf
MsgBox(0, "Test", _FuncName(111))
Func _FuncName(ByRef $a)
    $a = 222
    Return $a
EndFunc

so if it will be used

#AutoIt3Wrapper_If_Run
    #AutoIt3Wrapper_Run_AU3Check=N
#Autoit3Wrapper_If_Compile
    #AutoIt3Wrapper_Run_AU3Check=N
#AutoIt3Wrapper_EndIf

the script will be OK for Autoit, only Au3Check will alert the user for the problem, if are problems with use of Global Static ect ect

Sorry for my English

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

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...