Scripting library for B4ppc

Byak@

Active Member
Licensed User
ooops i'm sorry.
this is my test script

please Agraham correct my source with
You will have to pass a script identifier to the Sub you are calling and you can pass that identifier to a script in its args() when it starts.
I am confused:sign0013:
 

agraham

Expert
Licensed User
Longtime User
Look at the attachments. You are trying to use FormExDesktop with Threading in ways that I didn't intend, I can already see that Showmodal doesn't work as I would expect and I don't understand why. Please understand that you are on your own using them this way. I probably won't be willing to spend much time if you have problems as it will not be of much benefit to anyone else.
 

Attachments

  • script.txt
    52 bytes · Views: 16

agraham

Expert
Licensed User
Longtime User
Version 3.3 posted in post #1. This fixes a bug that hid the B4Script Rnd(min, max) function and also adds a ShareArray() method to BasicLib that lets an array be shared between the script and its' host so that changes made by one are visible to the other.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
As BasicLib is probably best used with the Threading library BasicLib version 3.4, now posted, has improved CallHostSub and CallGUISub so they can now run host Subs in the IDE and not just when optimised compiled like earlier versions. There is also a bug fix asoociated with CallHostGUISub (but no-one seems to have found the bug so far!) so if you have downloaded a previous version you should probably update to this version
 

Byak@

Active Member
Licensed User
Thanks)
 

agraham

Expert
Licensed User
Longtime User
I've been playing with and extending this library for own interest recently and have come across a couple of bugs so I thought I would post an updated version.

Bug fixes
---------
CallSub used to error when calling a Sub with no parameters - fixed.
ArrayCopy source and destination were interchanged - fixed.

Improvements
-------------
Even higher performance due to optimising string literals and Sub name handling.

Multidimensional arrays with up to three dimenions now implemented. ArrayRank and ArrayTotalLen added.

Structures added although the indexers behave slightly differently to Basic4ppc. In Basic4ppc they are constants unique to each structure, in B4Script they are global variables. a side effect of this is that you can "dot" access any array with any variable.

Indirect array access implemented to simulate passing arrays as parameters using GetItem, SetItem, GetRank and GetTotalLen.

The BasicLib object has some additional decompiler methods and properties all prefixed "dec" that I implemented for debugging the compiler. They are briefly documented in the help but will be of no use in Basic4ppc applications.
 

Byak@

Active Member
Licensed User
Anrew, is it real for you to add a Dispose method? (i know, BasicLib isn't a REAL object but maybe you can do it?)
 

Byak@

Active Member
Licensed User
ooops :-[
i don't in AutoComplete,only in help :-[
 

agraham

Expert
Licensed User
Longtime User
Owing to internal changes in Basic4ppc v6.90 BasicLib needed changing to match in order for CallHostSub to work.

Version 4.0 of BasicLib will work with Basic4ppc v6.90 or later but I have left BasicLib version 3.5 vailable for Basic4ppc version 6.80 or earlier.

Version 4.0 removes the need for B4PObject(1) in BasicLib.New1.
 

aroom

Member
Licensed User
B4X:
sum = 0
Do while fun = true
   print sum
Loop 

sub fun
  sum = sum + 1
  if sum < 10 then
     return true
  else
     return false
  end if
end sub

Run this script, Prompt message:
Error at line 9
Code - return true
Error - Return: stack empty

Where is my mistake? thanks.
 

aroom

Member
Licensed User
B4X:
sqlstr = "update set a = 'hello' from table1"
Run this script, Prompt message:
Error - Assign: expected CR, found VARIABLE
 

agraham

Expert
Licensed User
Longtime User
From the B4Script help
Strings can be either single or double quotes delimited.
var = "a string"
var = 'a string'
This makes it easier to dynamically handle scripts within Basic4ppc programs using single quotes as delimiters but means that the string you are using is not legal. At the moment, to keep things simple the string handling doesn't care whether the closing delimiter matches the opening delimiter - I might take a look at that. Meanwhile use something like this

B4X:
sqlstr = "update set a = " & Chr(39) & "hello" & Chr(39) & " from table1"
 

aroom

Member
Licensed User
agraham, could you expose BasicLib object property Name: CodeStyle. Boolean value, default is true, script code only use "" as string delimiter, string can include ' , single ' as comment, is the same as traditional Basic4ppc code style;
otherwise is flase, new style.
user select code style, Facilitate migration between BasicLib and Basic4ppc.
thanks.
 

mjcoon

Well-Known Member
Licensed User
... At the moment, to keep things simple the string handling doesn't care whether the closing delimiter matches the opening delimiter - I might take a look at that.

Cableguy should not have written, in his list of libraries:
BasicLib 4.0 - A runtime scripting language that employs identical syntax to Basic4ppc.

But rather the qualified similarity that AGraham expressed in his introduction to this library.

Using a choice of delimiter (and dropping the use of apostrophe to start a comment) and requiring a match at start and end, could make it possible to include an apostrophe in a string delimited by quotes and v.v.

Mike.
 

agraham

Expert
Licensed User
Longtime User
I've already done the match start and end delimiters mod which makes it possible to include an apostrophe in a string delimited by quotes and v.v. - it was already implicit in the code and so simple I don't know why I didn't do it originally but there you go, mind on other things at the time probably.
dropping the use of apostrophe to start a comment
You can't start a comment with an apostrophe in B4Script. It must start with REM and be on a separate line. This is because a comment is treated as a statement and each line can contain one, and only one, statement.
 
Top