/* This plugin allows you to run any code written in Scol to OpenSpace3D Copyright (C) 2011, Stephane Bisaro, aka iri OpenSpace3d is a software made by I-maginer. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ typeof channels = [Chn r1];; // misclleanous functions fun getLastPosChar (s, char)= let 0 -> i in let (strfind char s 0) + 1 -> npos in while npos != nil do ( set i = npos; set npos = (strfind char s npos) + 1; i );; // run the code - fun [PInstance [S S] S] I fun run (inst, datas, arg)= let datas -> [code funmain] in let _envchannel _channel -> env in let _openchannel nil strcatn "_loadS \"" :: (addSlashes code) :: "\"" :: nil env -> ch in if ch == nil then ( _DLGMessageBox _channel DMSwin "AddSourceCode Plugit !!" "Error : unable to load this code !" 0; SendPluginEvent inst "Error" "unable to load this code" nil; 1 ) else let if arg == nil then funmain else strcatn funmain :: " \"" :: arg :: "\"" :: nil -> script in ( _scriptc ch script; set channels = ch :: channels; SendPluginEvent inst "Done" nil nil; 0 );; /* kill the last channel */ fun stop (inst)= if channels == nil then 1 else ( _killchannel hd channels; set channels = tl channels; SendPluginEvent inst "Stopped" nil nil; 0 );; fun getCount (inst)= SendPluginEvent inst "GetCount" itoa sizelist channels nil; 0;; /*! \brief Callback on "Run" dms action * * Call the program function to run a source code * * Prototype: fun [PInstance DMI S S I u0] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param u0 : user parameter, the type is not defined here because it is not used in this template * * \return I : 0 **/ fun cbRun (inst, from, action, param, rep, user_param)= run inst user_param param; 0;; /*! \brief Callback on "Stop" dms action * * Call the program function to stop a channel * * Prototype: fun [PInstance DMI S S I u0] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param u0 : user parameter, the type is not defined here because it is not used in this template * * \return I : 0 **/ fun cbStop (inst, from, action, param, rep, user_param)= stop inst; 0;; /*! \brief Callback on "GetCount" dms action * * Call the program function to get the number of active channels * * Prototype: fun [PInstance DMI S S I u0] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param u0 : user parameter, the type is not defined here because it is not used in this template * * \return I : 0 **/ fun cbGetCount (inst, from, action, param, rep, user_param)= getCount inst; 0;; /*! \brief Callback on instance destruction * Callback called when a plugIT instance is destroyed * * Prototype: fun [PInstance u0] I * * \param PInstance : destroyed plugIT instance * \param u0 : user parameter, the type is not defined here because it is not used in this template * * \return I : 0 **/ fun deleteOb(inst, uparam)= while channels != nil do ( _killchannel hd channels; set channels = tl channels ); 0;; /*! \brief Callback on new plugIT instance * * Read the parameters from editor values and initialise the plugIT * * Prototype: fun [PInstance] I * * \param PInstance : plugIT instance * * \return I : 0 **/ fun newOb (inst)= // retrieve the params values let getPluginInstanceParam inst "code" -> code in let getPluginInstanceParam inst "function" -> main in ( // define the function to call when we receive the Run action PluginRegisterAction inst "Run" mkfun6 @cbRun [code main]; // define the function to call when we receive the Stop action PluginRegisterAction inst "Stop" mkfun6 @cbStop nil; // define the function to call when we receive the Stop action PluginRegisterAction inst "GetCount" mkfun6 @cbGetCount nil; // define the function to call when the plugIT instance is destroyed setPluginInstanceCbDel inst mkfun2 @deleteOb nil; ); 0;; /*! \brief Global plugIT function to initialize the plugIT callbacks * * called on plugIT load, here define the functions to use for a new instance and the editor * * Prototype: fun [s] I * * \param S : plugIT file path * * \return I : 0 **/ fun IniPlug (file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;