Scripting brief specification

Started by alex, September 12, 2009, 01:54:49 PM

Previous topic - Next topic

alex

Hi All,

I have done some analysis, and I think we can already discuss here some architectural basis of new scripting engine for HippoEDIT.

Which functionality is planned:


  • Simple script execution. It would be possible to select some file and execute it as script or, just execute text from current editor window (unsaved). Mixed script would not be supported (in one scriptlet), but it should be possible to execute scripts in different languages (vb and js) as separated scripts.

  • Background script execution. Because of support for script event handlers, listening for some application or editor events, it would be possible to have background scripts (basically event handlers), running in parallel to main thread and reacting on some actions. Such actions can be Indent, Code Completion, Command Execution etc. Using such functionality user can implement simple plug-ins in any supported scripting language. User would be able to see running background scripts, pause/stop, change auto start properties.


  • Registration on HippoEDIT events from script. It should be possible to register for some event from script and have script called, when this event would be triggered. It should be possible to register more then one handle to event, called one by one, but from different scripts. After long investigation I have decided to move for so called callback events (dynamic). Such events can be:
       function OnFileOpen(string sFileName){ .... }
       function OnCommand(ecCommand command){ .... }
      function OnCompletion(Document doc) { ... }

    and registration would look like this:
       var langPHP = GetLanguage("php");
       langPHP.onCompletion = OnCompletion;

  • Simple registration. It should be possible to register script. This should be some function from script, which called only once, and inside of it script can associate a name with itself, icon,menu entry etc. And maybe also for registering events. Using of some predefined script preprocessor commands like #title = "some script title" I think is wrong, and correct way would be to use native way for current script language to define specific function with reserved name, which would be called. And inside this function would call some methods of Application on script language. For example:
       function __he_init()
       {
          addMenuEntry("Some script");
          addShortcut("Ctrl + Shift + F1");
       }

  • Script includes. Its should be possible to include another scripts in the current script. There are no standard Windows Scripting ways for it (except one used in WSH with special, xml like wsh files), so I am forced to introduce special, preprocessing directive for this #__he_include "some_include". Directive can be processed in any line, but should be done inside of language specific comment, to not disturb script engine. Directive is not scope relative, and static (executed in preprocessing time). You can use more then one include, include one include inside another, use duplicates. Preprocessor would skip duplicates, collect all includes and execute them before main script, taking into account inclusion sequence.
    You can use as relative as absolute include paths.
    You can call as same language includes as other languages (for example Java Script function in VB script).
    Following regular expression is used for extracting include name: #__he_include\s+"([\w_\/:*?"<>|: .]+)".
    If you want to comment include, just remove leading # from include definition.

Objects:

  • Application. Main object with system and global functionality.

    • Methods:

      • alert( strMessage). Displays a message in a simple dialog box with the OK button.
      • bAnswer = confirm( strQuestion );. Displays a message in a simple dialog box with the OK button and the Cancel button.
      • status( strMessage, eStatusType = none|info|warning|error). Displays a status message (in status bar) with specific style.
      • sleep( nMilliseconds ). Pauses the script execution for the specified time in milliseconds.
      • execute( ecCommand ). Executes on of the registered commands.
      • fileLoad( string sFileName ). Opens/Loads existing document or ask for file name if sFileName is empty.
    • Events:

      • onSessionStart. Called after application start.
      • onSessionEnd. Called before application close.
      • onCommand. Called when some editor command is executed and give possibility to allow continue processing or replace action by own.
      • onIdle. Called when application is in Idle state.
  • Documents. Collection of open documents.
  • Document. Object responsible to document methods and events.
  • View. Object responsible for presentation. Contains methods and events connected to cursor movements, selection etc

Rest would come later, based on your suggestions and my investigations.
That would be very useful to get a proposal of built-in objects architecture (object names, methods etc). Also please comment on method/event names because it would not be possible to change this after implementation.

From scripting models, as far as I have checked them, best is which used in emeditor (also done with Windows Scripting) but some parts, I think, can be designed better.

I would extend this post with details, as far some part would became clear.

Best regards,
Alex.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Stefan

Looks good, as far as i understand.


>Rest would come later, based on your suggestions
I don't know what you wanna hear or need, so here just some thought:

Methods:
bAnswer = Yes/No
bConfirm = OK/Cancel
get/set HE Settings like HE.Setting.Get(SelectionMode), HE.Settings.Set(LineNumbers=0),
            HE.Settings.Set(colorscheme=blue)
HTMLDialog as extension for simple MsgBox and for complex UI (comes later, i know)
fileSave( string sFileName ). Save document as sFileName or ask for file name if sFileName is empty.
FileDelete( string sFileName )
execute( CleanUp.vbs ), execute( comspec /c delete  string sFileName)
runTool( compiler )
TabNew/TabClose
TabSetAsCurrentActive

Events:
onFileLoad/close (or is this part of onCommand ?)
onFocus/Focus loose (tab and/or app)
onKey (key is pressed)
onMouse move / click


>to get a proposal of built-in objects architecture (object names, methods etc).
You ask for an collection of commands needed?
Like that  we would need things like 'GetLineCount' or 'get/set Pos of Line/Column' ?

.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

alex

FileDelete, and execute I think this is part of scripting engine functionality and should not be done in HE (FSO maybe).  Not sure.

onCommand is event before executing command. So you can cancel standard processing and replace it by your own.
So onFileLoad is Ok.

When I ask about objects methods, I mean object oriented architecture of HE.
So, you have Application object - it has onFileLoad event, OpenFile method etc...
You have a Document object - it has onFileSave (maybe can be also done as Application event), InsertText, GetText etc...

So to not have a global list of everything but separated by objects. Like here. But maybe it is too early to talk about this :)
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]