Jump to content

Recommended Posts

Posted (edited)

From the user's perspective, yes, this is function pointers. I'm invoking built-in and user-defined functions indirectly through a variable. Don't let the missing $ confuse you, Writer (in the first example) is a variable. The $ is now optional in the language. The following code is equally valid and functionally equivalent:

ConsoleWrite("AutoIt version: " & @AutoItVersion & @CRLF)

Local $Writer = ConsoleWrite
$Writer("What the hell, this works?" & @CRLF)

$Writer = MyConsoleWrite
$Writer("This works, too!?" & @CRLF)


Func MyConsoleWrite($sText)
    ConsoleWrite("MyConsoleWrite(): " & sText)
EndFunc

Note that MyConsoleWrite() uses mixed $ and $-less variables. While this is possible and supported it's obviously stylistically undesirable and inconsistent. You should always use $ or never use $, not mixed.

Edited by Valik
Posted

The $ is now optional in the language.

I was about to ask this. Thanks.

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

Posted (edited)

The $ is now optional in the language.

This will break scripts if someone uses a variable called "$output" in a function called "output", right? Why don't you include the $ in the actual name of the variable, so that $var <> var? This would prevent breaking scripts and in my opinion this it would be a logical choice. Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

I would have thought that internally autoit could distinguish between a function and a type variable.

Hmmm, saying that, if a variable can be a pointer to a function, then a variable of type pointer might collide.

But then a variable of typr pointer can only be created in a DllStruct as far as I know.

I'm just confusing myself now.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted (edited)

This will break scripts if someone uses a variable called "$output" in a function called "output", right? Why don't you include the $ in the actual name of the variable, so that $var <> var? This would prevent breaking scripts and in my opinion this it would be a logical choice.

We will see how severe an impact this has. Right now my argument is you should have used better variable names including but not limited to some sort of type prefix.

I would have thought that internally autoit could distinguish between a function and a type variable.

Hmmm, saying that, if a variable can be a pointer to a function, then a variable of type pointer might collide.

But then a variable of typr pointer can only be created in a DllStruct as far as I know.

I'm just confusing myself now.

The implementation for functions as first-class objects does not involve pointers. It only provides pointer-to-function like semantics from the language side. Internally it's implemented completely differently. Do not concern yourself with implementation details. What matters is that the feature works sensibly and how people expect. Which it does, barring a bug or two. Edited by Valik
Posted

Very cool features! I always missed something like that!

But what about highlighting variables in editor? Editor can not know what it is, or am i wrong.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Posted

One thing that I'd like to throw out there...

Has anyone considered making it so that the autoit syntax would be like php? I mean wouldn't it be cool if we were able to create script's in one whole damn line?

That would be a trip...

Posted

This will break scripts if someone uses a variable called "$output" in a function called "output", right? Why don't you include the $ in the actual name of the variable, so that $var <> var? This would prevent breaking scripts and in my opinion this it would be a logical choice.

Actually no, you are not correct. I think. Variables with $ are not ambiguous. We know they are variables so AutoIt should only look in the variable table for it. It's only ambiguous when you use $-less names in which case AutoIt has to figure out if it's a variable or a function. I actually didn't look to see how trancexx handled this situation because obviously the situation produces a name conflict.

Also as an aside, in theory $ variables will be faster (or functions will be slower) under the new system due to the ambiguity in $-less lookups requiring more work to resolve.

So yeah, making $ optional should be fully backwards compatible.

Posted (edited)

I'm assuming that assigning a function name to a variable will also work for array elements. That is going to be something.pretty awesome. ;)

Maybe I worded that wong but the idea rocks.

Edited by czardas
Posted (edited)

I'm assuming that assigning a function name to a variable will also work for array elements. That is going to be something.pretty awesome. ;)

Wow. Two steps away from objects. I don't think it is going to happen, but let me dream :)

Step 1: Associative Arrays with dot-access (arrya.key)

Step 2: Something like Javascripts bind to preset parameters

Result:

Global $array[Assoc]
$array.func = Bind(objectfunc, $array)
$array.func("hello")

Func objectfunc($self, $param)
    ConsoleWrite($param & @LF)
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

That's opening a new range of programming styles and constructs. I wouldn't say "paradigm" but this is great.

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)

Posted

Will it be possible to pass these function pointers to *Register functions instead of strings?

Ideally we'd never have to pass function names as strings.

Eventually we can modify the functions to accept the reference, yes. Right now, no, it's not implemented.

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
  • Recently Browsing   0 members

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