Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

stealFunc - steal only the needed functions from a script


  • Please log in to reply
4 replies to this topic
A v i
  • Members
  • 1323 posts
  • Last active: Nov 14 2015 06:56 PM
  • Joined: 30 Jan 2013

stealFunc v0.12
 
stealFunc is a function-oriented script (tool) to extract only the required functions from an ahk library .
It recursively processes the library file to only extract functions that are minimally needed. 

From v0.1 , it has feature to scan a autohotkey script snippet and extract the foreign functions that are used in that script from another given script.
 
EXAMPLE USE -
The following function is based on the gdip library


SetImagetoClipboard( pImage ){
    ;Sets some Image file to Clipboard
    PToken := Gdip_Startup()
    pBitmap := Gdip_CreateBitmapFromFile(pImage)
    Gdip_SetBitmaptoClipboard(pBitmap)
    Gdip_DisposeImage( pBitmap )
    Gdip_Shutdown( PToken)
}

As you see it uses the following functions from Gdip lib-

Gdip_Startup
Gdip_CreateBitmapFromFile
Gdip_DisposeImage
Gdip_shutdown
gdip_setbitmaptoclipboard

 

These functions in the lib may be dependent on other functions in the lib which in turn may be dependent on more functions and so on...
Extracting only the needed functions manually can get tedious.
So to shorten the process, I made this script which is presented as function .
 

return_script := stealFunc(function_list, function_file) 
;EXAMPLE
Clipboard := stealFunc("Gdip_Startup`nGdip_SetBitmaptoClipboard`nGdip_CreateBitmapFromFile`nGdip_DisposeImage`nGdip_Shutdown", "<path_to_gdip_lib>")

 
The script also has a gui added for user convenience and can be commented out anytime.  [  SCREENSHOT of Gui ]


Tip - To check if the extracted file is OK and doesn't contain bugs, run it as a separate script. If everything is OK , you will not see an error.


DOWNLOAD Script

Documentation (see for examples)


Now a CS Undergrad. | My WebsiteAutohotkey Scripts | Softwares

Telegram me : @aviaryan


A v i
  • Members
  • 1323 posts
  • Last active: Nov 14 2015 06:56 PM
  • Joined: 30 Jan 2013

v0.1

  • Added feature to extract used functions from an ahk script (snippet) in addition to listing them manually. This should make the process a lot faster. SeeDocumentation for more info

Now a CS Undergrad. | My WebsiteAutohotkey Scripts | Softwares

Telegram me : @aviaryan


A v i
  • Members
  • 1323 posts
  • Last active: Nov 14 2015 06:56 PM
  • Joined: 30 Jan 2013

v0.12

* added `r to the output
* little bug fix with block comments
* fixed bugs with nested functions

Now a CS Undergrad. | My WebsiteAutohotkey Scripts | Softwares

Telegram me : @aviaryan


Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013
The function @ stealFuncfromLib.ahk:57 can be replaced with this:
MsgBox % stealFunc_IsDefault("Asc")

stealFunc_IsDefault(func){
	oFunc := Func(func)
	return oFunc.isBuiltin
}
that is ofcourse, if that function does what i think it does: Return if the function is built in or not. :)

A v i
  • Members
  • 1323 posts
  • Last active: Nov 14 2015 06:56 PM
  • Joined: 30 Jan 2013

Thanks Menixator, I didn't know about that feature. I will use this from the next time.


Now a CS Undergrad. | My WebsiteAutohotkey Scripts | Softwares

Telegram me : @aviaryan