Академический Документы
Профессиональный Документы
Культура Документы
Preface:
This document intends to show methods and source code for developing a completely dynamic plug-in
system in Scripting applications. This will also show how easy it is to implement.
Plug-in syntax:
Because I will be using a method of calling all the functions from *.code which were loaded into memory
it will have to follow the syntax of my Script Engine although this can be changed to have its own special
handler.
/DevelopPlugin/plugin.name
DevelopPlugin
1
1
/DevelopPlugin/plugin.code
dbgprint DevelopementPlugin called
As you can see in the above files I have a definition file (*.name) and the function file (*.code). The first
line in the definition file is for the name to be called (plugin DevelopPlugin), the second is for the
beginning line and the third is for the ending line of the function file (the code to be called). Thus the code
one line one is called (dbgprint DevelopmentPlugin called).
/PluginSystem.cs
namespace ScriptMin
{
class Plugin
{
public string CallName;
private int[] Lines;
public string[] Code;
try
{
CallName = s.ReadLine();
}
catch {
MessageBox.Show("Could not read plugin name in: "+directory);
}
try
{
Lines = new int[] { Convert.ToInt32(s.ReadLine()), Convert.ToInt32(s.ReadLine()) };
}
catch {
MessageBox.Show("Could not read plugin lines in: " + directory);
}
s.Close();
try
{
Code = new string[Lines[1] - Lines [0]];
for (int i = 0; i < Lines[1]; i++)
{
Code[i] = s.ReadLine();
}
}
catch
{
}
else
{
MessageBox.Show("Required plug-in files in: "+directory+" could not be located");
}
}
}
Creating a “plug-in interface” for scripting programs
By: Turpentine Page 3
/Main.cs
Plugins win = new Plugins();
if (win.ShowDialog() == DialogResult.OK)
{
Plugin test = new Plugin(win.PluginName);
MessageBox.Show(test.Code[0]);
}
/Plugins.cs
PluginName = textBox1.Text;
DialogResult = DialogResult.OK;
this.Close();