Scripting library for B4ppc

agraham

Expert
Licensed User
Longtime User
This is a library for executing scripts written in a syntax that is as close to that of Basic4ppc as I could implement. I've been working on this library on and off for a few months now and have finally done the documentation for release. I wrote this library more out of a personal interest and challenge rather than having a real use in mind, but now I've done it I might as well release it in case it is of some use to somebody. A programmable calculator is an obvious use.

The library will work on all versions of .NET and on the desktop and device. As it is interpreted and written for convenience of implementation rather than efficiency it is rather slow (EDIT:- Not any more as of version 1.2) on the device compared to B4ppc. This time I've remembered that not everybody is running the next release beta so the demo source is compatible with B4ppc version 6.30.

I am sure that there will be some bugs in this library as I have not done production quality checking of it.

I should also mention, in case you haven't noticed, that by some strange coincidence maXim has also been working on a script library and released it here a few days ago http://www.b4x.com/forum/italian-forum/2875-db2000-functions-library.html

EDIT:- Version 1.2 posted. See post #6 for details.

EDIT:- Version 2.0 posted.See post #7 for details.

EDIT:- Version 2.1 posted.See post #8 for details.

EDIT:- Script help 1.0 posted.See post #9 for details.

EDIT:- Version 2.2 posted, including B4Script help. See post #10 for details.

EDIT:- Version 2.3 posted, including better B4Script help. See post #11 for details.

EDIT:- Version 2.4 posted, bug fixed and including even better B4Script help. See post #16 for details.

EDIT:- Version 3.0 posted. See post #17 for details.

EDIT:- Version 3.1 posted. See post #28 for details.

EDIT:- Version 3.2 posted. See post #31 for details.

EDIT:- Version 3.3 posted. See post #43 for details.

EDIT:- Version 3.4 posted. See post #44 for details.

EDIT:- Version 3.5 posted. See post #46 for details.

EDIT :- Version 4.0 for use with Basic4ppc v6.90 or later posted. See post #50 for details.

EDIT :- Version 4.1 for use with Basic4ppc v6.90 or later posted. See post #52 for details.

EDIT :- Version 4.2 for use with Basic4ppc v6.90 or later posted. See post #59 for details.
 

Attachments

  • BasicLib3.5.zip
    123.1 KB · Views: 192
  • BasicLib4.2.zip
    124.5 KB · Views: 166
Last edited:

specci48

Well-Known Member
Licensed User
Longtime User
EDIT:- I've just noticed that a line in the locals.bas example is not correct. It should be "Sub test2(a#, b#)".
It would be nice if you could correct your upload so we won't need to save this post separately to the .zip file. It's hard to remember such a correction if someone saves your great dll for later use... :)


specci48
 

agraham

Expert
Licensed User
Longtime User
Having got a fairly robust working program in the initial release I have done some performance optimising and version 1.2, now posted, runs between 10 and 20 times faster than previously depending upon what it is actually doing.

This version now copes with Return within If, For or Do loops and implements Else If.

The treament of args() is changed to set individual variables with argument items rather than setting A as the args() array. This gives a cleaner way of pre-loading variables. A Starting event and GetArray and SetArray methods are added. Whereas the args() mechanism allows non-array variables to be preset the Starting event, together with SetArray allows arrays to be pre-initialised.

A few small bugs were also fixed
 
Last edited:

agraham

Expert
Licensed User
Longtime User
After optimising the library for performance I realised that I now had a good structure that would let me implement proper variable names without performance penalties. This version now programs identically to Basic4ppc - as long as you use its subset of Basic4ppc facilities. Check out the Base64vnames.bas program.

Arguments are now handled as in Basic4ppc by a predefined args() array. An extra event, CallHost, is provided - see the help for why.

In the end I am very pleased with this library, even though it is pretty useless except for a few specialist applications that require runtime scripting. The performance now is very close to that of a legacy compiled Basic4ppc application which I think is pretty good going :)
 

agraham

Expert
Licensed User
Longtime User
:signOops: The addition of proper variable names broke Rem and all the Date and Time functions. Version 2.1 fixes them together with various other small performance and bug fixes.

Goto and labels added and also the traditional ? as a synonym for Print.

This is now feature complete (I think!). Just bug fixes from now on!

The zip includes a desktop IDE for the library that can watch a couple of variables during step and break. This is in the code format for version 6.42 and later but you can get it to run on 6.30 by saving a minimal 6.30 sbp file, opening both that file and the 6.42 file in Notepad or Wordpad and cutting and pasting the form.control/generation statements and the code from the 6.42 version into the appropriate positions in the 6.30 file - or you could wait for the release of 6.50 :)
 

agraham

Expert
Licensed User
Longtime User
Thanks to Erel allowing me to use the Basic4ppc help file as a base I have now posted help for the language elements implemented in the BasicLib script engine. With a total lack of originality (and imagination) I have named this script language B4Script. If you wrote an app that implemented scripting you could pass this help file to your users as part of the documentation on how to use scripting in your app.
 

agraham

Expert
Licensed User
Longtime User
Version 2.2 now posted. The main reason for this was to correct the same oversight I had made with GPSSerial where problems arose with OS culture settings that did not use full stop as the decimal separator. Hopefully this library is now robust in this regard.

I took the opportunity to makes some other changes -

Sleep(mSecs) is added to the language as it may be useful if a script is running on a separate thread.

Version is added which returns the same version number to a script as DllVersion returns to the library host program.

An updated B4Script help file for the script language is included which may be provided to a user if you implement a scripting facility in your app.

Script source files in the demos are now *.src to avoid confusion with Basic4ppc modules which are *.bas
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Version 2.3 posted. This is a bug-fix version with several bug fixes. Most of them are somewhat arcane and deal with incorrect syntax scenarios.

The B4Script help file has been further edited and improved.

Anyone who has previously downloaded this library should update to this new version.
 
Last edited:

Byak@

Active Member
Licensed User
very big thanks Agraham!it is super lib!
 

Byak@

Active Member
Licensed User
I have some questions:
1) can i run some scripts at one time? Or only using threading.dll?
2) can i load any library from script?
 

agraham

Expert
Licensed User
Longtime User
1) can i run some scripts at one time? Or only using threading.dll?
If you mean can you run more than one script at once then yes, but only with the Threading library and you will need a different BasicLib object for each script. That way you could run several scripts on threads and one on your main thread simultaneously. Why you would want to is a different matter!
2) can i load any library from script?
I am not sure what you mean by "load". The main Basic4ppc program cannot load libraries at runtime and neither can a script. Remember this is only a runtime scripting language, why would you want to use a library? If you want to use some result produced by a library then you can code it into the main program and the script can ask for it. There is an example of script communication with a host application here http://www.b4x.com/forum/share-your-creations/3705-creating-plugins-demonstration.html
 
Last edited:

Byak@

Active Member
Licensed User
thanks Agraham
 

agraham

Expert
Licensed User
Longtime User
Version 2.4 now posted that fixes the break to the MOD operator in version 2.3. It also includes a couple more bug fixes, for the interested there is a list of the changes for each version in the BasicLib.cs source file at the beginning - but it may not mean much to you!.

I realised while fixing the latest bugs (and causing an endless loop) that I had made a glaring oversight :( in not providing a way of stopping a script caught in an endless loop. I have remedied that by providing a new Halt method that will unconditionally stop script execution and cause it to terminate.

Anyone who has downloaded a previous release should upgrade to this one.
 

agraham

Expert
Licensed User
Longtime User
Version 3.0 now posted with another obscure bug fixed.

The reason for the major version jump is that internally the library has been restuctured to calculate as much invariant stuff, like jump destinations for looping, as possible in a pre-pass through the program before executing it rather than doing the calculations at run time. This was done for performance reasons. Code now executes appreciably faster (depending on the actual code) than the same code running in a legacy compiled Basic4ppc app.
 

agraham

Expert
Licensed User
Longtime User
I like your math implementation. It is cleaner and as we see runs faster.
Thanks Erel :sign0188: Yes, it is quite clean isn't it! I was quite pleased when I realised that I could add all the conditional as well as the numeric stuff in a single recursive descent parser. I did think that the performance might suffer compared to a "flat" implementation but all the function calls are probably less expensive than I feared. The cost of them is probably offset against the conditional evaluations that would otherwise be needed.
 
Last edited:

Byak@

Active Member
Licensed User
hello Agraham!
If you mean can you run more than one script at once then yes, but only with the Threading library and you will need a different BasicLib object for each script. That way you could run several scripts on threads and one on your main thread simultaneously. Why you would want to is a different matter!
can your give a simple example with it?i'm try to do it and have problem.i'm create all objects with runtime and i'm don't understand-can i addevent from all basic script objects to one sub?for example
B4X:
addevent("script1",CallHost,"scripts_callhost")
addevent("script2",CallHost,"scripts_callhost")
addevent("script3",CallHost,"scripts_callhost")
all scripts run in threads.what happend,if 2 or more scripts fired CallHost at ONE moment?
and when event fired,it performed in thread or main thread?
 
Top