Jump to content
Sign in to follow this  
Viktor1703

Namespaces in AutoIt

Recommended Posts

Viktor1703

Hi, in AutoIt will be support namespace?

Example:

Module MyUDF1
    Global $iSeq

    Declare Wind()
    Declare Show()

    ; Private Func Test()
    ;    Return 1
    ; EndFunc

    Func Test()
        Return 1
    EndFunc

    Func Wind()
        $iSeq += Test()
    EndFunc

    Func Show()
        ConsoleWrite('counter 1: ' & $iSeq)
    EndFunc
EndModule

Module MyUDF2
    Global $iSeq

    Declare Wind()
    Declare Show()
    Declare $iSeq

    Func Wind()
        $iSeq += 1
    EndFunc

    Func Show()
        ConsoleWrite('counter 2: ' & $iSeq)
    EndFunc
EndModule

MyUDF1.Test()       ;~ Error, access to this function is not possible outside of the module
MyUDF1.Wind()
MyUDF1.Wind()
MyUDF1.Show()      ;~ output "counter 1: 2"

MyUDF2.Wind()
MyUDF2.Show()      ;~ output "counter 2: 1"
MyUDF2.$iSeq        ;~ Access to a variable outside the module
Edited by Viktor1703

Share this post


Link to post
Share on other sites
guinness

Namespaces don't exist in AutoIt.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
guinness

and aren't planned?

AutoIt isn't Object Orientated. You have to rename the functions maybe to _String_Strip() and then _StringDebug_Strip()?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Viktor1703

Thanks

Edited by Viktor1703

Share this post


Link to post
Share on other sites
Viktor1703

I guess you could use AutoItObject.  I use it constantly.

 

No, OOP isn't necessary to me, I would like to use only namespaces (Modules)

Share this post


Link to post
Share on other sites
jaberwacky

Yes, so encapsulation.  Object orientation is not encapsulation.  Or rather I meant to say information hiding.  ::hurrhurrhurr::

Edited by jaberwacky

Share this post


Link to post
Share on other sites
jaberwacky

Untested:

Func MyUDF1()
  Local $this = _AutoItObject_Class()
 
  $this.AddMethod("Wind", "MyUDF1_Wind")
  $this.AddMethod("Show", "MyUDF1_Show")
 
  $this.AddProperty("iSeq", $elscope_private, 0)
 
  $this.AddMethod("Test", "MyUDF1_Test", True)
 
  Return $this.Object
Endfunc

Func MyUDF1_Wind($this)
  $this.iSeq += Test()
Endfunc

Func MyUDF1_Show($this)
  ConsoleWrite('counter 1: ' & $this.iSeq)
Endfunc

Func MyUDF1_Test($this)
  Return 1
Endfunc

Func MyUDF2()
  Local $this = _AutoItObject_Class()

  $this.AddMethod("Wind", "MyUDF2_Wind")
  $this.AddMethod("Show", "MyUDF2_Show")

  $this.AddProperty("iSeq", $elscope_public, 0)

  $this.AddMethod("", "", True)

  Return $this.Object
Endfunc

Func MyUDF2_Wind($this)
  $this.iSeq += 1
Endfunc

Func MyUDF2_Show($this)
  ConsoleWrite('counter 2: ' & $iSeq)
Endfunc

#include "AutoItObject.au3"

_AutoItObject_Startup()

Global $oMyUDF1 = MyUDF1()
Global $oMyUDF2 = MyUDF2()

$oMyUDF1.Test()       ;~ Error, access to this function is not possible outside of the module
$oMyUDF1.Wind()
$oMyUDF1.Wind()
$oMyUDF1.Show()      ;~ output "counter 1: 2"

$oMyUDF2.Wind()
$oMyUDF2.Show()      ;~ output "counter 2: 1"
$oMyUDF2.iSeq        ;~ Access to a variable outside the module

_AutoItObject_Shutdown()
Edited by jaberwacky

Share this post


Link to post
Share on other sites
Viktor1703

No, I didn't make, but there is a wish for normal support of namespaces, there is no wish to extend with the AutoItObject.dll program, I simply wanted to learn, whether there will be a support of namespaces in future AutoIt versions?!

Edited by Viktor1703

Share this post


Link to post
Share on other sites
JLogan3o13

So you received your answer, it is not on the roadmap.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Viktor1703

AutoIt isn't Object Orientated.

 

Yes, but it is possible to do this

 

;~ Interface

Global Const $IAutoItFunc = 'MsgBox int(uint;wstr;wstr);' & _
                            'ToolTip void(wstr;int;int);'

;~ Methods

Global $Methods[2] = [DllCallbackRegister('ObjFunc__MsgBox', 'int', 'ptr;uint;wstr;wstr'), _
                      DllCallbackRegister('ObjFunc__ToolTip', 'none', 'ptr;wstr;int;int')]

Func ObjFuncConstructor()
    Local $tTable, $oObj

    $tTable = DllStructCreate('ptr VTable;ulong_ptr Number;ptr Method[2]')
    DllStructSetData($tTable, 'VTable', DllStructGetPtr($tTable, 'Method'))
    DllStructSetData($tTable, 'Number', 2)
    DllStructSetData($tTable, 'Method', DllCallbackGetPtr($Methods[0]), 1)
    DllStructSetData($tTable, 'Method', DllCallbackGetPtr($Methods[1]), 2)
    $oObj = ObjCreateInterface(DllStructGetPtr($tTable), DllStructGetPtr($tTable), $IAutoItFunc, False)
    If IsObj($oObj) Then
        ConsoleWrite(ObjName($oObj) & @CRLF)
        Return $oObj
    EndIf

    Return 0
EndFunc

Func ObjFuncDestructor($oObj)

    Local $i

    If IsObj($oObj) Then
        $oObj = Null

        For $i = 0 To UBound($Methods) - 1
            DllCallbackFree($Methods[$i])
        Next

        $Methods = 0
    EndIf
EndFunc

Func ObjFunc__MsgBox($pThis, $iFlag, $sTitle, $sText)
    Return MsgBox($iFlag, $sTitle, $sText)
EndFunc

Func ObjFunc__ToolTip($pThis, $sText, $iLeft, $iTop)
    ToolTip($sText, $iLeft, $iTop)
EndFunc


$oFunc = ObjFuncConstructor()

If IsObj($oFunc) Then

    $oFunc.MsgBox(32, 'Title', 'Text')

    ObjFuncDestructor($oFunc)
EndIf

Exit

but often there is an error  :(

Edited by Viktor1703

Share this post


Link to post
Share on other sites
guinness

Some would argue you're incorrectly using the Dll functions.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
KaFu
guinness

Those functions should only be used for interacting with the Win32 API.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
trancexx

Those functions should only be used for interacting with the Win32 API.

Not only that API, rather all APIs that require the "bridge".

@Viktor1703, your struct for object is local and therefore destroyed before you even get to use the object. See


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Viktor1703

Those functions should only be used for interacting with the Win32 API.

 

Not only that API, rather all APIs that require the "bridge".

@Viktor1703, your struct for object is local and therefore destroyed before you even get to use the object. See

 

Thank you very much

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.