Author Topic: Scripting brief specification  (Read 4614 times)

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2162
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Scripting brief specification
« on: September 12, 2009, 12:54:49 pm »
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.
« Last Edit: September 27, 2009, 02:14:02 pm by alex »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Scripting brief specification
« Reply #1 on: October 07, 2009, 10:51:10 am »
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' ?

.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2162
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Scripting brief specification
« Reply #2 on: October 07, 2009, 01:50:53 pm »
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 :)

 

Related Topics

  Subject / Started by Replies Last post
39 Replies
14768 Views
Last post April 22, 2010, 06:40:49 pm
by alex
18 Replies
7961 Views
Last post June 17, 2016, 11:09:59 pm
by alex
28 Replies
8463 Views
Last post September 11, 2011, 04:23:33 am
by alex
3 Replies
2337 Views
Last post November 30, 2011, 12:20:59 am
by alex
2 Replies
1870 Views
Last post July 07, 2013, 03:09:16 pm
by RJP74