Jump to content

Dynamic include


kiboost
 Share

Recommended Posts

Hi,

I would clear up some of my understanding about include.

The standard include (guiconstants.au3, etc etc), when I compile the script to exe, are 'included' into the exe, so I don't need the au3 files anymore, right ? I can put my exe anywhere and execute it alone. That's ok, and I need it to work like this.

But, I also need some dynamic include :

I need my exe to read an external file which got some infos I need, and these infos are updated time to time, without having to recompile the script. Actually, no problem, it is a flat txt file, so my exe read the file, and parse it to define some variable accordingly to what is in the file.

But, now I would insert some variables into this file ! I need to updates these variables in the file, without recompile my exe, but having this exe taking them as variables. Just like in php, you can put some functions and define tons of variables, and a main script php file will include and load all variables and use all functions defined. Put it isn't a compiled language, yes.

I don't need it for this, but it could server for an ini file for example. You change some ini value in the config.ini, and when the exe start, it read the ini, get its variables, and use it.

Is there such a way to 'externalise' some variables and functions like this ? To have a .exe and a few child files with variables and functions ?

Cheers,

Kib

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Link to comment
Share on other sites

This is what AutoIT does every day! If you read a file or list the contents of a directory, you've done just that! The text that is read or the contents of a directory can be variables. You can have your script do different things based on those results. The trick is to define what to do given the different scenarios (content of a text or ini file, existence of a file or folder, etc.) That's where intelligent planning and testing come in.

Link to comment
Share on other sites

So I can just put a fileread(myinifile.ini) into my main.exe

in myinifile.ini put

$bibi = 2

func bobo()

do anything

endfunc

And my main.exe will be able to use $bibi and run bobo()without any more step ?

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Link to comment
Share on other sites

Yes you can..this script creates a file on the root of the C drive, reads the contents of that file, and then calls a function that displays the results.

RunWait(@Comspec & ' /c dir /b/ad C:\> C:\tList.txt')

$File = FileOpen('C:\tList.txt', 0)
If $File = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $Line = FileReadLine($File)
    If @error = -1 Then ExitLoop
    _Splash($Line)
    Sleep(200)
WEnd

FileClose($File)

Func _Splash($Text) ;Shows a small borderless splash message.
    SplashTextOn('', $Text, @DesktopWidth, 25, -1, 5, 33, '', 14)
EndFunc   ;==>_Splash

Link to comment
Share on other sites

I'm getting the impressions that you are looking for a function that is in a file other than the main script, but that can be used by the main script as if it was a normal function. Php can do such things, but autoit can't.

It is possible to simulate the behavior executing an external au3, or a3x file, using the /AutoIt3ExecuteScript command line parameter. (look up "command line parameters" in the help file).

Another way to execute external code is by using Execute().

Both ways are limited in their ability to exchange variables with the main script and I wouldn't reccomend using them in this way.

If you are just trying to reduce the size of the updates for your program you can use the command line approach, but instead of splitting your script into seperate file for each function, you use two files:

1. An a3x that Checks, downloads and applies updates for both a3x files and if needed downloads resources like icons.

2. An a3x that contains the entire functional script, eliminating the need to exchange variables between different scripts.

As the exe only has about two lines of code it is easy to write it in such a way, that it will never need to be updated, and because the interpeter is in the exe, you can keep the size of the script files low.

If you realy want to keep your script in different files you can still use the above approach, but instead of having the entire script in one a3x file, you use an au3 file with multiple #includes, however your code will be there for everyone to see and change. (as I assume obfuscating defies your purpose)

Link to comment
Share on other sites

Ok thanks everyone for the feedback about this, nice to at least understand how it works and can or can not, work.

I have no way to avoid handling external files, so I will continue to parse them with the main exe to read it and attribute variables inside the main script. I'm playing with regions and such, but approaching 1000lines of code become a bit tricky to navigate inside the code. The php approach is indeed for that, externalising functions and big arrays of datas so your main code is easier to change, and datas are easily accessible also without recompiling main code. But that's life ;-)

Again, thanks ;-) I'm at home and don't have time to test this, was just thinking about some ideas to implement additional features and clean code, now I know how it works. Will have a look at command line anyway. At least one big data file would help, and nothing secret there (and read only for users on the network).

Cheers,

Kib

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

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