ScriptBasic - Part 2


Author: Dave
Date: 05.30.14 - 1:21am



this is a post on some observations into embedding the ScriptBasic interpreter into your own applications. Note I have only spent about 4 days sifting through the project, so this is a pretty cursory view and I could be way off. This is just what I have seen so far.

The code base is some pretty dense C in parts. Lots of function pointers stored in structures. There are sections of code I wouldnt want to touch without a lot of study due to this complexity.

I was able to get a VS2008 project file up and compiling in an hour or two which is pretty good. There is a decent CHM for documentation. There is also a lot of sub projects for various things. Ultimately I started my own and followed along with the embedding guide to create a test application.

He did a really good job making features optional, such as not having to load a config if you didnt want to (which has to be compiled from text format to use)

Typically a config file would point to the installed directories for modules, include directories and app settings. For a standalone app embedding, I would rather do this through an API, which isnt available.

It appears that the embedding vision it was built around, was that the parent app would load a script and call defined functions based on events. The parent app can then set/retrieve global variables or function return results. Say from a web server receiving a document request. The embedding style I had in mind was similar to the MS Script control where scripts can call functions in the parent app and do processing from there. More on this latter.

I really liked that ScriptBasic has a debugger capability. Its implemented as an opcode preprocessor giving you the chance pause and inspect variables and the execution process.

Going back to the density of the code in parts, doing something like extracting the compiled config reader code is a pretty complicated ordeal. It is interleaved througout many sections of code. My first run at trying to extract it in favor of a simple struct took about 6hrs to get it to compile again, and left me with some strange crashs leading me to revert the changes. The preprocessor support and external module support is similarily complex (actually more so).

Preprocessors and extension modules are designed to be external dlls. As an extensible script intrepreter executable this is a good design. As an embedded script intrepreter in my own app, I would really prefer they were all in the same binary for development and debugging sake.

With a little copy paste, it was pretty easy to add new API allowing you to add a compiled in preprocessor to the internal structures.

In terms of a compiled in extension module, this was actually easily accomplished as well, albeit not exactly in the way I was hoping for. I wanted a way to add native functions that could be called in the script easily. Maybe even an object or namespace resolver such as calls to

scriba_AddResolver(pProgram, "myObj", &my_resolver);

then in the script

myObj.MyFunc(1,2)

would call my_resolver("myFunc", ...)

The easy way to call native functions, is by using the existing extension module capabilities. You can compile them into the embedded library, then use the declare mechanism in the script to access them because they will be exported from the parent app. (even for exes)

Originally they were designed to give the scripts access to extended functionality such as registry access on Windows systems, but this is a still the same thing, just in a slightly different light. Adding a new command to the interpreter looks a bit harder and is not that documented.

This lets you add individual C functions easily enough, but ultimately my target is going to be adding VB6 COM Objects, This will be managable as is through a single gateway function such as:

declare sub callObj alias "callObj" lib "test.exe"
a = callObj("myObj.myFunc", 1 , 2)

The VB6 CallByName function will be put to good use, but you will be limited to accessing the primary functions/properties of the object I think. (ie myObj.itsObj.someProp probably wont work at least not without some parsing and intermediate steps). Not the prettiest, but manageable.

Also, I think the way the preprocessor works..you would have to use wait loops as is to stall it. getch() does this nicely in console mode. Having the opcode processing code not be in a loop and only step when explicitly called might be a better way for a GUI app. I will have to research this more since they do have a GUI debugger and socket based listener to receive debug commands.

Code wise the quality seems very good. I havent even bothered to test its script engine capabilities yet in terms of control flow handling, operators, etc. I am just assuming those are all good at this point based on the quality of what i have seen, how well it has functioned so far, and its long dev history.

The complexity of the lexer, module manager, syntax, and external function caller, I am not sure if I dare touch those with the easy work arounds I have already identified above. Not exactly as I envisioned it, but all workable and stable.

with these hurtles overcome, next step is to slap together a quick VB6 gui to act as the debugger interface and see what it takes to get it to play nice. Not sure if I want to stick with the socket based example, or manage it through a hardcoded API of call backs.

Once I can fully flesh that out and get something I am happy with, then I will circle back and do some COM object tests. If thats successful, then I can begin work on weaving it all together using the scivb.ocx syntax highlighting control based on scintilla.

Its all within reach, were still on track and I have wanted an embeddable script control that supports single stepping, variable inspection, and general debugging for a long time!






Comments: (2)

On 01.31.20 - 4:44am Peter Verhas wrote:
Thanks for the nice article and for your candor. I only found this article now. I stopped the active development of this project 13 years ago, but it is still in use in Sarian routers, and Banner DXM controllers. Still it is nice to see that some people use the tool.

On 01.31.20 - 6:07am Dave wrote:
Hi Peter ! Thanks so much for releasing this code. It was an excellent way for me to learn about embedding a script interpreter at a low level and how to wire it up with debugging support through call backs, how to route the arbitrary script functions calls to COM objects, and to advance my GUI libraries such as integration with the scintinilla syntax highlighter ScriptBasic was a perfect 1st test at this with its ease of compilation, clean code, and architecture even though I was using it a bit outside of its original design intents.

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 72 + 84 = ? followed by the letter: C 



About Me
More Blogs
Main Site
Posts: (year)
2024 (3)
     VB6 JSON
     ffmpeg voodoo
     RegJump Vb
2023 (9)
     VB6 Virtual Files
     File handles across dlls
     python abort / script timeout
     py4vb
     VB6 Python embed w/debugger
     python embedding
     VB6 IDE Enhancements
     No Sleep
     A2W no ATL
2022 (4)
     More VB6 - C data passing
     Vb6 Asm listing
     Byte Array C to VB6
     Planet Source Code DVDs
2021 (2)
     Obscure VB
     VB6 IDE SP6
2020 (4)
     NTFileSize
     BSTR from C Dll to VB
     Cpp Memory Manipulation
     ActiveX Binary Compatability
2019 (5)
     Console tricks
     FireFox temp dir
     OCX License
     Extract substring
     VB6 Console Apps
2018 (6)
     VB6 UDTs
     VB6 Debugger View As Hex tooltips
     VB6 - C Share registry data
     VB6 Addin Missing Menus
     VB6 Class Init Params
     VB6 isIn function
2017 (6)
     Python and VB6
     Python pros and cons
     download web Dir
     vc rand in python
     VB6 Language Enhancement
     Register .NET as COM
2016 (22)
     VB6 CDECL
     UDT Tricks pt2
     Remote Data Extraction
     Collection Extender
     VB6 FindResource
     CDO.Message
     DirList Single Click
     Reset CheckPoint VPN Policy
     VB6 BSTR Oddities Explained
     SafeArrays in C
     BSTR and Variant in C++
     Property let optional args
     Misc Libs
     Enum Named Pipes
     Vb6 Collection in C++
     VB6 Overloaded Methods
     EXPORT FUNCDNAME Warning
     VB6 Syncronous Socket
     Simple IPC
     VB6 Auto Resize Form Elements
     Mach3 Automation
     Exit For in While
2015 (15)
     C# self register ocx
     VB6 Class Method Pointers
     Duktape Debug Protocol
     QtScript 4 VB
     Vb6 Named Args
     vb6 Addin Part 2
     VB6 Addin vrs Toolbars
     OpenFile Dialog MultiSelect
     Duktape Example
     DukTape JS
     VB6 Unsigned
     .Net version
     TitleBar Height
     .NET again
     VB6 Self Register OCXs
2014 (25)
     Query Last 12 Mos
     Progid from Interface ID
     VB6 to C Array Examples
     Human Readable Variant Type
     ScriptBasic COM Integration
     CodeView Addin
     ScriptBasic - Part 2
     Script Env
     MSCOMCTL Win7 Error
     printf override
     History Combo
     Disable IE
     API Hooking in VB6
     Addin Hook Events
     FastBuild Addin
     VB6 MemoryWindow
     Link C Obj Files into VB6
     Vb6 Standard Dlls
     CStr for Pascal
     Lazarus Review
     asprintf for VS
     VB6 GlobalMultiUse
     Scintilla in VB6
     Dynamic Highlight
     WinVerifyTrust, CryptMsgGetParam VB6
2013 (4)
     MS GLEE Graphing
     printf for VB6
     C# App Config
     Tero DES C# Test
2012 (10)
     VC 2008 Bit Fields
     Speed trap
     C# Db Class Generator
     VB6 vrs .NET (again)
     FireFox Whois Extension
     git and vb6
     Code Additions
     Compiled date to string
     C# ListView Sorter
     VB6 Wish List
2011 (7)
     C# Process Injection
     CAPTCHA Bots
     C# PE Offset Calculator
     VB6 Async Download
     Show Desktop
     coding philosophy
     Code release
2010 (11)
     Dll Not Found in IDE
     Advanced MSScript Control
     random tip
     Clipart / Vector Art
     VB6 Callback from C#
     Binary data from VB6 to C#
     CSharp and MsScriptControl
     HexDumper functions
     Js Beautify From VB6 or C#
     vb6 FormPos
     Inline Asm w VB6
2009 (3)
     The .NET Fiasco
     One rub on computers
     Universal extractor