Reply to thread

The question: Can be python (or lua, or ecma-script, or...) can be added to this plugins?


MP & community plugins are compiled in .NET assembly, in a language called CLR (Common Language Runtime).

See http://www.gotdotnet.com/team/clr/about_clr.aspx



MyScript uses .NET reflection to compile the script in a .NET assembly, and for this reason only language that can be compiled in CLR

(C#, VB.NET and JScript) are currenly supported.


This allow people to write script that interact with MP or other plugins, without need to change the MP core, and without need that others plugins authors know the

existence of MyScript or the language that MyScript support.


I have some esperience about integration of Python,Lua and java-script in C++ code, but every solutions require to create many wrapper class that create a 'link'

between the C++ internal code and the script.


Adding a language script that are not compiled in CLR (so, don't use reflection) need creations of class wrapper around all features in MP core that need to be exposed to script language, and is a very very big works.

Also, people that write plugin need also to create this kind of wrapper to allow people to write script that interact with the plugin.



To understand, this is a piece of code inside \WindowPlugins\GUIScript\MPScript.cs, the actual MyScript included in MP distributions:


[code]

    private void callAction(string ac)

        {

            Action act;

            switch (ac)

            {

                case "reboot" :

                    act = new Action(Action.ActionType.ACTION_REBOOT,0,0);

                    GUIGraphicsContext.OnAction(act);

                    break;

                case "shutdown" :

                    act = new Action(Action.ActionType.ACTION_SHUTDOWN,0,0);

                    GUIGraphicsContext.OnAction(act);

                    break;

                case "hibernate" :

                    WindowsController.ExitWindows(RestartOptions.Hibernate, m_bForceShutdown);

                    break;

                case "ejectcd" :

                    act = new Action(Action.ActionType.ACTION_EJECTCD,0,0);

                    GUIGraphicsContext.OnAction(act);

                    break;

                case "previous_menu" :

                    act = new Action(Action.ActionType.ACTION_PREVIOUS_MENU,0,0);

                    GUIGraphicsContext.OnAction(act);

                    break;

            }

        }

[/code]


As explained, the author need to create wrapper between script and MP core.




My question is: Why people want Python? C# Script allow people to write any kind of code.

The only problem is the complexity to write a script, for that i suggest

to create the Main class in script derived from 'Script', and add some simply methods in this class (like the 'MessageBox' or 'Trace' method already present).




Another example,


I found a topic called "Text to Speech.......Make MediaPortal Talk" here.


To allow that, can simple write a 'script' like:


[code]

using System;

using System.Windows.Forms;

using MediaPortal.GUI.Library;

using MediaPortal.Dialogs;

using MyScript;

using SpeechLib;


class Main : Script

{

    public void Start()

    {

            Say("Mediaportal starts!!");

    }


    public void Stop()

    {

    }


    public void Say(string input)

    {

        SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;

        SpVoice Voice = new SpVoice();

        Voice.Speak(input,SpFlags);

    }

}

[/code]


, and copy the dll Interop.SpeechLib.dll in MP directory.


(N.B. it's not actually possible to write this script, because in this current release we cannot add additional external assembly reference, but can be possible in the next release).


With another language not-CLR like Python, we need to create a class wrapper between Interop.SpeechLib.dll and Python.




--------------------------



I'm looking on IronPython, suggested by Smirnoff.

Can be possible to write Python scripts that use CLR-based assembly, but, if i understand correctly, the script itself is not compiled in CLR.


It's not derived from ICodeCompiler , so don't allow code compiling over reflection....


In contrast of all texts written above, i can try to integrate to check how it works.... 

I don't know the python syntax, but i don't think that python language can be more simple to write than a C# or VB.NET script (with a good 'Script' base class)


Bye!


Top Bottom