Batch Simple Plugin System Concept

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#31 Post by penpen » 10 Jan 2014 15:22

:oops: Upps :oops: !!!
A big SORRY to you... the post including "Regards," should have been a PM and no post... :
I have noticed that ... when typing in my mobile phone :oops: .
Please forgive me for that.

Adrianvdh wrote:So the "batch-dll" stores all the public functions OF 'main.bat'.
No:The batch-dll contains the services of the application (the application is both: SampleMain.bat, and Sample.dll.bat).

Adrianvdh wrote:So a plugin can replace a function within the "batch-dll"?
No, you are allowed to call the functions of the batch-dll from within the plugin:
The replaceable functions are all located in the SampleMain.bat.
And if you use the word "replace" in the sense of "the Samplemain.bat source is changes", then again: No.
The SampleMain.bat just doesn't call them, if "replaced" by a plugin: The plugin is called instead.

Adrianvdh wrote:In your system, what does this main exactly?:

Code: Select all

call :callfunction :Pluginable2, default 2 n

The "default 2 n" because I don't know.
The "default 2 n" are just 3 command line arguments: "default", "2", and "n".
There is no deeper sense; it is just used to see from where they are called, but you may use any other parameters.

Adrianvdh wrote:And does the 'main.bat' have to be aware of the plugin? Because it seem to only support 3 plugins "Pluginable1, Pluginable2, Pluginable3"
How do you mean this?
It should be aware of the plugins, as it calls them, if present.
You could add more plugins to this example system, but then it may be unpredictable which one will be executed for the specifiied pluginable functions.

You could also build another application, that does not "replace" function calls, but
creates an array of functions like Aacini Main1.bat (that type of organization is much more common to plugins), or
you may organize them in any way you think of.

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#32 Post by Adrianvdh » 11 Jan 2014 03:32

penpen wrote:No:The batch-dll contains the services of the application (the application is both: SampleMain.bat, and Sample.dll.bat).


What do you mean by services? What are services in a batch file?

penpen wrote:No, you are allowed to call the functions of the batch-dll from within the plugin:
The replaceable functions are all located in the SampleMain.bat.


So "batch-dll" would act as a read only class, if I could say that, that stores "services" not functions.
And 'main.bat' stores functions that stay in 'main.bat' but can be called from a different locations i.e. 'plugin.bat'?

":Pluginable1"

What does that do, I don't know but it is confusing me a lot.

penpen wrote:The "default 2 n" are just 3 command line arguments: "default", "2", and "n".
There is no deeper sense; it is just used to see from where they are called, but you may use any other parameters.


So "default", is a legit argument? and "2" and "n" are just something the author of the plugin would make? i.e. they don't do anything?

The ":Pluginable1" is very off putting, I still am deeply confused. Sorry for that :)

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#33 Post by penpen » 11 Jan 2014 16:45

Adrianvdh wrote:What do you mean by services? What are services in a batch file?
services == extern callable/exported/public functions

Adrianvdh wrote:So "batch-dll" would act as a read only class, if I could say that,
Yes.
Adrianvdh wrote:that stores "services" not functions.
?!? I think you've misunderstood this:
penpen wrote:
Adrianvdh wrote:Adrianvdh wrote:
So the "batch-dll" stores all the public functions OF 'main.bat'.
No:The batch-dll contains the services of the application (the application is both: SampleMain.bat, and Sample.dll.bat).
This should NOT express: "The batch-dll contains no functions but services."
It should mean: application != main.bat.

Adrianvdh wrote:And 'main.bat' stores functions that stay in 'main.bat' but can be called from a different locations i.e. 'plugin.bat'?
No: The main.bat functions cannot be accessed from the plugin.
In its header a plugin defines a pluginable main.bat function.
The main.bat reads the header, and understands: Call the plugin instead of this specific pluginable function.


Adrianvdh wrote:What does that do, I don't know but it is confusing me a lot.
penpen wrote:The "default 2 n" are just 3 command line arguments: "default", "2", and "n".
There is no deeper sense; it is just used to see from where they are called, but you may use any other parameters.

So "default", is a legit argument? and "2" and "n" are just something the author of the plugin would make?
These are only some example parameters, to show, that they aren't forbidden.
In the above example all parameters were printed to screen via "echo %*"
These parameters weren't defined, and cannot be changed (in this example), by any plugin.
The author of the main.bat has defined them.
Instead of "default" "2" and "n", i could have used "param1", "param2", and "param3".

Adrianvdh wrote:i.e. they don't do anything?
I haven't simulated this good in this example, but you should always assume that all parameters are needed by the program, that defined these:
If they don't do anything, then the author wouldn't have used them.

Maybe this picture shows it better how the main.bat manages the plugins:
The pluginable functions are 3: :pluginable1, :pluginable2, :pluginable3
The main.batch creates 3 labeled drawer: left ('pluginable1'), middle ('pluginable2'), right ('pluginable3').
It also creates their content: a note (left to right): "call pluginable1", "call pluginable2", "call pluginable3"
The main then searches for all valid plugin and finds this one:
A plugin neamed "Plugin1.bat" that wants the main.bat to be executed instead of the function :pluginable2.
Then the main.bat creates a new note: "call Plugin1.bat".
Then the main.batch opens the drawer with the label 'pluginable2', throws away the note that it finds in there, puts the new note in it, and closes it.

If the main.bat should execute the pluginable function pluginable2 with the argumens "arg1", "arg2", "arg3" it performs:
1. opens the drawer with the label 'pluginable2'
2. looks at the note: "call Plugin1.bat"
3. executes: call Plugin1.bat arg1 arg2 arg3
4. closes the drawer

If no plugin were found then the content of the drawer 'pluginable2' remains unchanged and this would be performed:
1. opens the drawer with the label 'pluginable2'
2. looks at the note: "call pluginable2"
3. executes: call :pluginable2 arg1 arg2 arg3
4. closes the drawer

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#34 Post by Adrianvdh » 12 Jan 2014 02:22

OK I think I am starting a bit to understand it,
so ":pluginable1" is created because a plugin is available i.e. 'plugin.bat'. So essentially there are 3 plugins that are being loaded? "plugin1.bat", "plugin2.bat" and "plugin3.bat", i.e. "pluginable1", "pluginable2" and "pluginable3".

OK I think I understand that a bit, I just don't know what you mean by a drawer? Does that thing set everything up?

So for example 'getWinKey' within 'batch-dll'', that function's call would be replaced by a plugin's function "function"?

I think that is what you mean, else you (please) could make a diagram in Photoshop or Word or LibOffice if you be so kind to :)

If not this is what you mean, I am so sorry, I possible you are really frustrated by now as am I.
Thank you,
Adrian

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#35 Post by penpen » 12 Jan 2014 07:11

Adrianvdh wrote:so ":pluginable1" is created because a plugin is available i.e. 'plugin.bat'. So essentially there are 3 plugins that are being loaded? "plugin1.bat", "plugin2.bat" and "plugin3.bat", i.e. "pluginable1", "pluginable2" and "pluginable3".
Nearly: The function :pluginable1 is called in a special way, to allow the main.batch, to call a plugin instead.
You may name the plugins as you want, for example "ABC.bat";
it only must contain this first line to advise the main.batch to call ABC.bat instead of the function :pluginable2:

Code: Select all

@rem MY_BATCH_FILE_NAME_TEXT :Pluginable2

Adrianvdh wrote:OK I think I understand that a bit, I just don't know what you mean by a drawer? Does that thing set everything up?
The drawer (and the notes) is an picture for the data struct "PluginFunctions" (see :: initiate ff in the main batch file).
It is needed to store the command to execute.

Adrianvdh wrote:So for example 'getWinKey' within 'batch-dll'', that function's call would be replaced by a plugin's function "function"?
No, the pluginable functions are all located in the main batch file.
The batch-dll functions could be called from every other files.

Adrianvdh wrote:I think that is what you mean, else you (please) could make a diagram in Photoshop or Word or LibOffice if you be so kind to :)

If not this is what you mean, I am so sorry, I possible you are really frustrated by now as am I.
Hmm, i have none of these tools... , and yes, it is a little bit frustrating.
I'll try it (again) text base, so copy the following to a txt file and view it with notepad if the lines were automatically word wrapped by the browser:

Code: Select all

┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Application                                                                                           │
├───────────────────────────────────────────────────────────────────────────────────────────────────────┤
│                      ╔══════════════════════════════════════════════════════════════════════════════╗ │
│                      ║ Sample.dll.bat                                                               ║ │
│                      ╠══════════════════════════════════════════════════════════════════════════════╣ │
│ Services:            ║ Service 1:                                                   :SampleFunction ║ │<── "call Sample.dll.bat /call :SampleFunction [arguments]" from anywhere
│ (batch file)         ╚══════════════════════════════════════════════════════════════════════════════╝ │                                                                   ┌──────────────────────────────────────────────────────────────────────────┐
├───────────────────────────────────────────────────────────────────────────────────────────────────────┤                                                                   │ Plugin                                                                   │
│                      ╔══════════════════════════════════════════════════════════════════════════════╗ │                                                                   ├──────────────────────────────────────────────────────────────────────────┤
│                      ║ SampleMain.bat                                                               ║ │                                                                   │               ╔════════════════════════════════════════════════════════╗ │
│                      ╠══════════════════════════════════════════════════════════════════════════════╣ │                                                                   │               ║ plugins\SamplePlugin.bat                               ║ │
│ Pluginmanager (PM):  ║                                                                              ║ │─── PM processes all plugin in "plugin\*.bat" in the same way:  ──>│               ╠════════════════════════════════════════════════════════╣ │
│ (batch variables)    ║ Accepted Plugin Id:                                "MY_BATCH_FILE_NAME_TEXT" ║ │    checks the header's Plugin Id: OK.                          ──>│ Header:       ║ Plugin Id:                   "MY_BATCH_FILE_NAME_TEXT" ║ │
│                      ║                                                                              ║ │    This plugin wants to be executed instead of: ":Pluginable2" ──>│ (batch file)  ║ Run this plugin instead of:  ":Pluginable2"            ║ │
│                      ║                                                                              ║ │    Retrieve the plugin functions number                           │               ║                                                        ║ │
│                      ║ Number of pluginable function "Pluginable1":                             "3" ║ │                                                                   │               ║                                                        ║ │
│                      ║ Number of pluginable function "Pluginable2":                             "2" ║ │<─┬        with the label ":Pluginable2":  "2"                     │ Body:         ║ <plugin code to execute>                               ║ │
│                      ║ Number of pluginable function "Pluginable3":                             "1" ║ │  │                                                                │ (batch file)  ╚════════════════════════════════════════════════════════╝ │
│                      ║                                                                              ║ │  │                                                                └──────────────────────────────────────────────────────────────────────────┘
│                      ║ Instruction to execute the pluginable function 1:         "call Pluginable3" ║ │  └──────────────────────────────────────────────────────────────────────────────────────────┐
│                      ║ Instruction to execute the pluginable function 2:         "call Pluginable2" ║ │<==        and replace the instruction command "2" with "call SamplePlugin.bat"              │
│                      ║ Instruction to execute the pluginable function 3:         "call Pluginable1" ║ │                                                                                             │
│                      ║                                                                              ║ │                                                                                             │
│                      ║                                                                              ║ │    A call to :Pluginable3 within the batch file is performed this using the :callfunction:  │
│ Internal functions:  ║                                                                              ║ │    "call :callfunction :Pluginable3 [argument(s)]", so :callfunction does this:             │
│ (batch file)         ║ Internal function 1:                                          :callfunction  ║ │    Retrieve the plugin functions number                                                     │
│                      ║ Internal function 2:                                           :Pluginable1  ║ │            with the label ":Pluginable2":  "2" ─────────────────────────────────────────────┘
│                      ║ Internal function 3:                                           :Pluginable2  ║ │<──         and execute the instruction command "2": "call SamplePlugin.bat [argument(s)]"
│                      ║ Internal function 4:                                           :Pluginable3  ║ │
│                      ║                                                                              ║ │
│                      ╚══════════════════════════════════════════════════════════════════════════════╝ │
└───────────────────────────────────────────────────────────────────────────────────────────────────────┘

A reads B: A ──> B
B reads A: A <── B

A writes B: A ==> B
B writes A: A <== B
I really hope this helps you.

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#36 Post by Adrianvdh » 12 Jan 2014 16:29

Thanks you for your diagram :)

So... I understand most of your plugin system.

But, ahh, you say. What is the purpose of "Pluginable" in 'main.bat'. Is it a function like 'getWinkey'? is it being used by 'main.bat'? and does 'plugin.bat' go and interfere
with the function and may cause problems??? Please explain the relation between 'main.bat''s functions and "Pluginable" and 'plugin.bat'(s)
But my understanding says to me that the "Pluginable" is a play holder function for 'plugin.bat' within 'main.bat'

penpen wrote:The drawer (and the notes) is an picture for the data struct "PluginFunctions" (see :: initiate ff in the main batch file).
It is needed to store the command to execute.


I still don't understand this at all. Don't worry I know what structs are, but I don't understand what you mean by picture.

Sorry, this is the most someone has tried to explain to me something that I just am having difficulty understanding.
Adrian

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#37 Post by penpen » 12 Jan 2014 17:49

Adrianvdh wrote:What is the purpose of "Pluginable" in 'main.bat'. (...) is it being used by 'main.bat'? (...)
and does 'plugin.bat' go and interfere
with the function and may cause problems??? Please explain the relation between 'main.bat''s functions and "Pluginable" and 'plugin.bat'(s)
This is only a simple example, so i haven't done any important there, but it is a function that does something the author of the batch wants it to do, so: Yes it is beeing used by the 'main.bat'.
To allow any other programmer to do it in another way, the function is implemented as a plugin.

A good example were the best to explain the relation between them:
You may assume, that the main.batch collects some measured temperature data.
The function ":Pluginable" then may use an algorithm, that was up to date on creation date of the application, to predict the temperature of the next 2 days.
The author of that application knows: Maybe another scientist develops a better algorithm, so he implements the function ":Pluginable" as a plugin.
So if this descibed case happens and if you don't want to throw away the old application,
you could write a plugin that implements this algorithm, so the application now calls the new function instead of the old one.

Adrianvdh wrote:Is it a function like 'getWinkey'?
No, you wanted 'getWinkey' to be accessible from outer, so 'getWinkey' would be implemented as a service encapsulated in an batch-dll.
If you think it is usefull, that it should be implemented as a plugin function, you are free to extend the batch-dll to use plugins, too.
I didn't want to do it, to keep it simple.

Adrianvdh wrote:But my understanding says to me that the "Pluginable" is a play holder function for 'plugin.bat' within 'main.bat'
I think, this is because of my simple example, but if you use a more real-life example (see above),
then you easily can see that in most cases it is not so.

Adrianvdh wrote:
penpen wrote:The drawer (and the notes) is an picture for the data struct "PluginFunctions" (see :: initiate ff in the main batch file).
It is needed to store the command to execute.

I still don't understand this at all. Don't worry I know what structs are, but I don't understand what you mean by picture.
I oftenly translate german sentences word by word into English,
so i'm using wrong translations. I try to avoid that, but if i do this, it happens, that i didn't notice it.
So i've used the word "picture" as a special kind of metaphor:
I can't translate it better, sorry; maybe another one knows a better translation for that.

Adrianvdh wrote:Sorry, this is the most someone has tried to explain to me something that I just am having difficulty understanding.
I fear my (mis)use of ("heavily" broken) English may be also responsibile.
I try to get better, but it takes some time, i fear.
(SO if anyone thinks, my grammar (, ... ) is awfull: Feel free to send me a private message with the corrected spelling.)

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#38 Post by Adrianvdh » 12 Jan 2014 18:28

So in away my understanding was correct the whole time, but I didn't realize to state that the function 'getWinKet' would be in batch-dll' not 'main.bat'. But anyway the plugin system can really mess and interfere a lot with working functions, unless the author it no troll. :)

But why again can't all the functions for 'main.bat' be in 'main.bat'? Why do I have to include another file called "batch-dll"? Sorry I am asking this I just don't get it.
By that I mean you can it can cause dead locks, etc I don't know what those are. So ya.... (fill in the gap)

Thanks,
Adrian

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#39 Post by penpen » 12 Jan 2014 19:46

Adrianvdh wrote:But why again can't all the functions for 'main.bat' be in 'main.bat'? Why do I have to include another file called "batch-dll"? Sorry I am asking this I just don't get it.
By that I mean you can it can cause dead locks, etc I don't know what those are. So ya.... (fill in the gap)
So it suffices to explain how a batch could create a dead lock?
Dead Lock:
Lets assume:
- there are two processes (P1, P2),
- two unshareable resources (R1, R2),
- both resources must be assigned to process P1 (P2 analogous), to complete execution (P1 locks both resources, so P2 cannot access), and
- each process won't release any resources until finished.

A deadlock is created if R1 is assigned to P1, and R2 is assigned to P2:
P1 tries to get access to R2 that is locked by P2, and
P2 tries to get access to R1 that is locked by P1.

This could easily be reached by plugin functions:
The main.bat starts two parallel processes (P1, and P2) using the pipe operator:
- P1 should be the pluginable function, the resource R1 is assigned to it, and
- P2 should be a function, with R2 assigned to it, that waits until R1 has finished (because it needs R1 to complete)
No problem, if no plugin is in use: assumed main.bat is "well designed" and "deadlock free".
If a plugin is in use, it does something different, and lets assume it needs to execute the ":function" from the main.bat (the author of the plugin thought that is a good idea).
The ":function" now needs resource R2 to complete and waits until this resource was released, what never happens: Deadlock.

A deadlock could also be created with two functions (F1, F2) within one process, but this is a very special case, and not easy to see:
In this case it is P1 == P2, and the assignment (of F1, F2) is not visible to each other functions: Using batch two different setlocal blocks with overriden variables that stores the use of the resources: Deadlock.

Endless loops are created in a similar way:
The main.bat calls the plugin, this calls the ":function", that needs the plugin, ... : Endless loop.

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#40 Post by Adrianvdh » 13 Jan 2014 02:39

So with setlocal and endlocal I can prevent deadlocks?
If this is true then I would not need any use for "batch-dll"?

If not ahh I have more files that are require for 'main.bat'.

Endless loop?
Doesn't it just end when it needs to end? huh? How could I prevent this aswell?

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#41 Post by penpen » 13 Jan 2014 06:02

Adrianvdh wrote:So with setlocal and endlocal I can prevent deadlocks?
If this is true then I would not need any use for "batch-dll"?

If not ahh I have more files that are require for 'main.bat'.
I thought i've written the opposite :!:
The setlocal and endlocal blocks offers the possibility, to only need one process to create a deadlock.


Adrianvdh wrote:Endless loop?
(..) How could I prevent this aswell?
Avoid looping code, or make sure it will end.
If you don't call code from main.bat from plugin.bat, then it will produce no such complex loops.
Or if don't want to avoid it just make sure, that the program flow is organized in trees, or at minimum a loop free digraph:
But this will easily lead to a lot of work.

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#42 Post by Adrianvdh » 13 Jan 2014 13:03

So I what code can I use to avoid deadlocks? Or is it just a technique to batch file programming?

If you'd be so kind, if I may ask, how old you are and what programming languages you know?

That wraps up this post :)

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#43 Post by penpen » 13 Jan 2014 13:59

Adrianvdh wrote:So I what code can I use to avoid deadlocks? Or is it just a technique to batch file programming?
It is a common technique, not only to batch files only:
penpen wrote:Avoid looping code, or make sure it will end.
If you don't call code from main.bat from plugin.bat, then it will produce no such complex loops.
Or if don't want to avoid it just make sure, that the program flow is organized in trees, or at minimum a loop free digraph:
But this will easily lead to a lot of work.
Or in other words, you should just avoid this situation:
- 1.bat calls function(s) in 2.bat, while
- 2.bat calls function(s) in 1.bat

Although (simple) unlimited loops and (simple) deadlocks are still possible:
But you should notice them if you test your code.

Adrianvdh wrote:If you'd be so kind, if I may ask, how old you are and what programming languages you know?
That sounds familiar:
http://www.dostips.com/forum/viewtopic.php?p=28833#p28833
http://www.dostips.com/forum/viewtopic.php?p=28854#p28854

penpen

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch Simple Plugin System Concept

#44 Post by Adrianvdh » 14 Jan 2014 11:32

Oh yeah...

But those are names of languages you know right? I want to know the programming languages you can code in.

But now to break down your plugin system code, because I am ready to implement it to my batch file...

Code: Select all

:: initiate
   set "PluginFunctions.length=3"
   set "PluginFunctions[Pluginable1]=2"
   set "PluginFunctions[Pluginable2]=3"
   set "PluginFunctions[Pluginable3]=1"
   set "PluginFunctions[1]=call :Pluginable3"
   set "PluginFunctions[2]=call :Pluginable1"
   set "PluginFunctions[3]=call :Pluginable2"
   set "usePlugins=true"
   goto :processParams

:processParams
   if /I .%1 == ./noPlugins set "usePlugins=false"
   goto :pluginManager


I don't understand what these two do?

Code: Select all

:pluginManager
   if %usePlugins% == false goto :main
   for %%f in (plugins\*.bat) do (
      set "header="
      (set /P "header=" < %%f)
      for /F "tokens=1-3" %%r in ("!header!") do (
         if .%%r%%s == .@remMY_BATCH_FILE_NAME_TEXT (
            set "PluginFunction=%%~t"
            set "PluggedInFunction=%%~f"

            for /F %%p in ("!PluginFunction::=!") do (
               set "PluginFunctions[!PluginFunctions[%%~p]!]=call "!PluggedInFunction!""
            )
         )
      )
   )
   goto :main

I know this but to make sure... The plugin manager contains all the plugins batch file within the 'plugins' folder and stores the names in an array or a list I forget the differences. (I am still learning C# but I am also leaning Java at school, just starting)

Code: Select all

:main
   echo call Sample.dll.bat from main
   call Sample.dll.bat /call :SampleFunction
   goto :mainlabel

calls the services(s) used by 'main.bat'


Code: Select all

:callfunction
   set "params=%*"
   set "command=%1"
   for /F %%c in ("!PluginFunctions[%command::=%]!") do set "command=!PluginFunctions[%%~c]!"
   %command% %params:* =%
   exit /b %ErrorLevel%

The "callfunction" is used to call function(s) within plugins to be replaced by the default function(s)

Code: Select all

:Pluginable1
   echo %0 :Pluginable1
   echo params: %*
   exit /b 0

:Pluginable2
   echo %0 :Pluginable2
   echo params: %*
   exit /b 0

:Pluginable3
   echo %0 :Pluginable3
   echo params: %*
   exit /b 0

These are the functions built into the main batch file.

e.g. 'getWinkey'

Code: Select all

:mainlabel
echo =================================================================
::2
::3
::4
call :callfunction :Pluginable1, mainlabel 5 n
echo =================================================================

:default
::1
call :callfunction :Pluginable2, default 2 n
echo =================================================================

:settings
::1
::2
call :callfunction :Pluginable3, settings 2 n
::4
::5
echo =================================================================
pause
   exit /b 0

I don't understand how this works... Sorry, and the parameter (just checking) arguments are normal because some functions can have them right, like (e.g.):

Code: Select all

:header
echo %~1
pause


You need to explain this to me, the code I know the consept:

Code: Select all

:: processing parameters
@   if /I .%1 == ./list if .%2 == . goto :list
@   if /I .%1 == ./call goto :call
@   goto :help


:call
@   for /F %%e in ('call %~f0 /list') do @(
      if /I "%%~e" == "%2" goto %%~e
   )

@   echo No such exported function found: %0 %*.
@   exit /b 1

:SampleFunction
@   echo Successfully called: %0 %*
@   exit /b 0

:list
@   for %%e in (
      ":SampleFunction"
   ) do @(
      echo(%%~e
   )
@   exit /b 0

:help
@   for %%h in (
      "Sample.dll.bat [/list|/call functionName parameter(s)]"
      "  /list               returns a list of all exported functions"
      "  /call               executes a function, if it is an exported function,"
      "                      an appropriate error message is displayed else."
      "        functionName  denotes a label that defines an exported function"
      "        parameter(s)  one or more parameters."
      ""
   ) do @(
      echo(%%h
   )
@   exit /b 0


What do these mean in "SamplePlugin.bat":

Code: Select all

@rem MY_BATCH_FILE_NAME_TEXT ------> :Pluginable2 


and of course this:

Code: Select all

@echo MY_BATCH_FILE_NAME_TEXT MY_BATCH_FILE_NAME_TEXT2 MY_BATCH_FILE_NAME_TEXT3


Don't worry I understand how the system works, I just don't know bits of how the code works.
So if you'd be so kind to explain them to me :)

Adrian

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Simple Plugin System Concept

#45 Post by penpen » 14 Jan 2014 15:42

Adrianvdh wrote:Oh yeah...
But those are names of languages you know right? I want to know the programming languages you can code in.
You should reread the second link (and your post in that topic above).

Adrianvdh wrote:

Code: Select all

   set "PluginFunctions[Pluginable1]=2"
:: ...
   set "PluginFunctions[1]=call :Pluginable3"

The first line is a mapping from the pluginable functions to the indices of the next mapping.
The last line is a mapping from pluginable functions indices to the command to call them; without params, as they are added later in code.

Adrianvdh wrote:

Code: Select all

:processParams
   if /I .%1 == ./noPlugins set "usePlugins=false"
   goto :pluginManager

This is an option to not load any plugins.

Adrianvdh wrote:(... code)
I know this but to make sure... The plugin manager contains all the plugins batch file within the 'plugins' folder and stores the names in an array or a list I forget the differences. (I am still learning C# but I am also leaning Java at school, just starting)
In batch the most datatypes are all simulated, so you can see it as a list or as an array, as you want or need it.
The only datatype batch supports is a hash map on strings (key and value): The key is the name of the variabel (and the value is its value).

Adrianvdh wrote:(... code)
calls the services(s) used by 'main.bat'

(... code)
The "callfunction" is used to call function(s) within plugins to be replaced by the default function(s)

(... code)
These are the functions built into the main batch file.

e.g. 'getWinkey'
1. Yes
2. I'm sure you mean it in right way.
3. I thought this was your example of a function called from the plugin; if yes, then: No, it should be placed within the batch-dll.

Adrianvdh wrote:

Code: Select all

:mainlabel
echo =================================================================
::2
::3
::4
call :callfunction :Pluginable1, mainlabel 5 n
echo =================================================================

:default
::1
call :callfunction :Pluginable2, default 2 n
echo =================================================================

:settings
::1
::2
call :callfunction :Pluginable3, settings 2 n
::4
::5
echo =================================================================
pause
   exit /b 0

I don't understand how this works... Sorry, and the parameter (just checking) arguments are normal because some functions can have them right, like (e.g.):

Code: Select all

:header
echo %~1
pause

This should be just the simulating of a complex program, but it is much more easier:
It just processed top down.
The lines ":", "::" just don't do anything.
So it echoes "===..." lines and call the pluginable functions with some parameters.

Adrianvdh wrote:You need to explain this to me, the code I know the consept:
(... code)
What do you want to know? (The @'s are just to avoid the default command echo.)

Adrianvdh wrote:What do these mean in "SamplePlugin.bat":

Code: Select all

@rem MY_BATCH_FILE_NAME_TEXT ------> :Pluginable2 

This tells the plugin manager to call the plugin instead of the pluginable function ":Pluginable2".

Adrianvdh wrote:and of course this:

Code: Select all

@echo MY_BATCH_FILE_NAME_TEXT MY_BATCH_FILE_NAME_TEXT2 MY_BATCH_FILE_NAME_TEXT3

This is an example of a batch file in plugins folder that is not a plugin of SampleMain.bat.

penpen

Edit: Replaced "This tells the plugin manager to be called the replaceable function ":Pluginable2"" by "This tells the plugin manager to call the plugin instead of the pluginable function ":Pluginable2"."
Last edited by penpen on 15 Jan 2014 13:18, edited 1 time in total.

Post Reply