B4J Library jBasicLib embedded Basic interpreter library

Nearly six years ago I posted the original B4A version of this library that was in fact a port to Java from the original Basic4ppc .Net C# version that I wrote even earlier. Shortly after that I gave up Android development out of disgust with Google and returned to playing with Basic4ppc and C# under Windows.

I now find myself back having to use Android for mobile work and have already posted an updated, polished and reasonably documented version for B4A. I now post here a version that will work with B4J.

Download the zip and before extracting it unblock it by right clicking on it in File Explorer, selecting Properties and checking Unblock at the lower right of the General tab otherwise the CHM help files will need to be individually unblocked.

The zip file contains the library jar and xml files and a relatively trivial demo program that does however show how to load, run and monitor a program. At the top level of the zip you will find a Readme.txt file, you know what to do with it (No! Not that! :)).

EDIT: V2.2 includes a very minor change allowing space characters between the Sub name and the left parenthesis of the parameter list.
Another very minor change allows Resumable Subs to be invoked on the host without error.

EDIT: In light of the slightly renewed interest I've noticed that the B4Script help file is that for the original Basic4ppc version. B4AScript help file now attached is for the BA/B4J versions. The main difference is the Date and Time formatting functions that match Java rather than the .NET original version. Right click and unblock it after downloading it.
 

Attachments

  • jBasicLib_v2.2.zip
    133.5 KB · Views: 270
  • B4AScript.zip
    70.5 KB · Views: 116
Last edited:

wl

Well-Known Member
Licensed User
Longtime User
Seems great !

One question though: is there some possibility to blend the code more in its host application ? It would be nice if the Basic script could use call a method defined in the host B4J application by its name instead of by calling it through CallHostSub ?

Thanks!
 

wl

Well-Known Member
Licensed User
Longtime User
I'm planning to use the library as a simple scripting mechanism in a jServer handler. Is the library threadsafe ?

Thanks
 

agraham

Expert
Licensed User
Longtime User
Note that if you want to call back to the main GUI thread of your app each instance must be initialized on that thread, although it can run programs on any other thread. This is because this B4J version of the library uses the thread on which it was initialized to determined the thread to call in CallGuiSub/SysGui. However a side effect of this will be that all the other events, like Break and Ended, will be called on the main thread as well.

If you initialize the instances on the thread they are to run on then all the events will run on that thread but CallGuiSub/SysGui will also run on that thread and so cannot touch any UI elements.
 

wl

Well-Known Member
Licensed User
Longtime User
Thanks. I'll use it for server side scripting (website), so I guess that won't pose a problem. Thanks !
 

wl

Well-Known Member
Licensed User
Longtime User
Hi,

Looking to passing a key-value pair from the script to B4J with AddSysCalls, but it seems these kind of methods only support a single string as a parameter.

Any possibility to pass 2 string values as parameters ?

I know I can use CallSubHost for multiple parameters.

Thanks!
 
Last edited:

wl

Well-Known Member
Licensed User
Longtime User
It seems I was wrong: I thought I read it somewhere in the help files and had an error while trying multiple parameters, but I tried it again and it seems to work.

Great ! Thanks!
 

wl

Well-Known Member
Licensed User
Longtime User
Hi,

I'm finally using your library in a server side scripting server. It works fine... except: the library does not support a space between the name of the sub and the opening brackets.

CORRECT: sub foo(someparm)
INCORRECT: sub foo<space>(someparam)

Note: I'm calling into this procedure "foo" from within B4J code.

Is there any way to correct this somehow ?

Thanks
 
Last edited:

agraham

Expert
Licensed User
Longtime User
You know, in all the years I've used this library I've never noticed this 'feature' before because by habit I would never insert a space between a Sub or method name and the opening parenthesis of its parameter list no matter what language I am using, be it C#, Java Python or Basic-derived language variants.

I haven't been able to fully characterise this behaviour and don't expect to fix it any time soon. I haven't looked at the innermost strucutre of the interpreter for several years, it's a bit complicated in there! I'm afraid that you will have to live with this.
 

wl

Well-Known Member
Licensed User
Longtime User
Hi,

Thanks for your answer though. I already looked at the code (by decompiling it :) and indeed it seems difficult, but I guess I can have a look at it and maybe, just maybe I can change it myself: if you would permit me to do so :)


Although the original java files could be easier ... Thanks

Thanks
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I'm not currently capable of properly investigating anything this complicated as I was recently diagnosed with advanced prostate cancer and am recovering from a failed attempt at chemotherapy that had to be stopped early because I reacted very badly to it. Now, coronavirus limiting measures permitting they are about to try burning out my insides for the next few weeks with External Beam Radiotherapy to try to slow things down :(

So here is the library source for you to look at. It's not very pretty as it started out about 12 years ago as a C# library for Erel's earlier product - Basic4ppc on which the syntax is modeled. It has evolved over the years and some of the later code optimisations for performance are not very readable. This library is a direct port from C# to Java so the code is not always as it would be if originally written in Java. If you find and change anything then please let me know.
 

Attachments

  • Libraries.zip
    185.8 KB · Views: 304

Peter Simpson

Expert
Licensed User
Longtime User
I'm not currently capable of properly investigating anything this complicated as I was recently diagnosed with advanced prostate cancer and am recovering from a failed attempt at chemotherapy that had to be stopped early because I reacted very badly to it. Now, coronavirus limiting measures permitting they are about to try burning out my insides for the next few weeks with External Beam Radiotherapy to try to slow things down :(

S.................................. I have a family member that had to go through that. I really hope that it goes well for you and not too painful either. Just do whatever you have to do to get through it all.

Good luck, Peter...
 

stevel05

Expert
Licensed User
Longtime User
Sorry to hear about you health problems Andrew, I hope all goes well.
 
Top