Scripting library for B4ppc

agraham

Expert
Licensed User
Longtime User
can i addevent from all basic script objects to one sub
I don't see why not if that's what you need to do but I wouldn't recommend it. If that event code manipulates GUI elements or calls DoEvents there might be a risk of re-entry. Even then it might be OK as long as your event code is threadsafe.
all scripts run in threads.what happend,if 2 or more scripts fired CallHost at ONE moment?
I think all the code involved is threadsafe so it should work as you would expect. CallHost runs on the script thread and behaves just like thread events in the Threading library. It posts a message to the main window thread message loop to run the event code in Basic4ppc on the main thread and waits until the event code finishes then returns. Normally an event cannot interrupt another event, although if you do DoEvents or manipulate GUI elements in your event code that might not be a good idea as that might run the main window message loop and let a second event re-enter your event code before the first has finished.
and when event fired,it performed in thread or main thread?
All Basic4ppc events run on the main thread so they are allowed to manipulate GUI elements without risk.
 

Byak@

Active Member
Licensed User
big thanks Agraham...it is not good.
and nevertheless maybe you right simple sample with 2(or more) scripts at one time?please =)
 

Byak@

Active Member
Licensed User
2Agraham I try to creates plugins for my program.every plagin must create panel and add webbrowser to it.and every x seconds every plugin add some info to his webbrowser.

thanks for sample=)
 

agraham

Expert
Licensed User
Longtime User
Version 3.1 posted which has a new Keyword, CallHostSub, that can be used both as a statement and a function. This is available only to scripts running in optimised compiled applications. In a legacy environment the script will error and halt.

CallHostSub allows a B4Script to directly execute Basic4ppc host program Subs and, as the Sub executes directly rather than going via an event, it has much, much higher performance than CallHost. It provides a much easier and more direct way of allowing a script access to host program functionality, particularly for anyone writing a plug-in.

The downside is that, like a Thread Sub, a Sub called by CallHostSub must not touch GUI elements if it is not running on the main thread. For this you must use CallHost, Print or Msgbox events.

Note that BasicLib.New1 now requires "B4PObject(1)" as a parameter.
 
Last edited:

Byak@

Active Member
Licensed User
big thanks agraham!it's very well!
i have problem...can i get variable from main code to script when it doing not in start!for example i'm use callhost for do some operations in main cose.and can i get result to script? mya be it ias real with GetGlobal or GetLocal?

 

agraham

Expert
Licensed User
Longtime User
Version 3.2 posted which has a new Keyword, CallHostGuiSub, that can be used both as a statement and a function and allows scripts to safely call Subs that manipulate GUI elements. This is available only to scripts running in optimised compiled applications. I should have thought to include this in v3.1 as it makes CallHost obsolete for optimised compiled apps and lets scripts easily manipulate GUI elements. Plugins should be easier as now you just put all the Subs that interface to your plugin in a module, document them, and let your user scripts call them.

As scripts might be interested in color I have included RGB, GetR, GetG and GetB functions and all the Basic4ppc colour constants.

A notable oversight of mine was not to include CallSub, it is now implemented.

Step and break now stop before the line is executed rather than after. This is to match the behaviour of the IDE and my forthcoming debugger for optimised compiled apps which will require the next version of Basic4ppc.
 

Byak@

Active Member
Licensed User
Agraham you are superman!!!big thanks)))
 

Byak@

Active Member
Licensed User
:-[ may be sample for new function?and i not fint her in manual...
 

Byak@

Active Member
Licensed User
CallHostGuiSub! i don't found it in manual and don't found script with it
 

agraham

Expert
Licensed User
Longtime User
CallHostGuiSub is in B4Script help->Keywords->General between the topics CallHostSub and CallSub, a bit out of alphabetical order I'm afraid.

It is described in BasicLib help in Overview at the ninth paragraph of "Limitations and differences".

I didn't bother with a demo as it is so simple. To check it works edit "CallHostSub" to "CallHostGuiSub" in CallHostSub.src.
 

Byak@

Active Member
Licensed User
Hello Agraham!
i have problem when use Scripting lib in thread. when i'm use "callhostguisub" i want see sender (Scripting object) but... Please see my sample.
I think this is because i'm use Formex...
:sign0085:

p.s. and i'm found bug- rnd(min,max) doesn't work
 

Attachments

  • getREALsender.sbp
    1.9 KB · Views: 13
Last edited:

agraham

Expert
Licensed User
Longtime User
i want see sender (Scripting object)
Read the third paragraph of the Threading topic of the FormExDesktop help and see the FormExDesktop.Sender property.

Sorry about Rnd()! I missed a line of code out that effectively disables it. I'll fix it soon.
 

Byak@

Active Member
Licensed User
Agraham,
for events Message,Ended and any i'm use EnableThreadEvent and formex.sender return real sender...BUT how can i'm use this with callhostgui ?it is not event!
and if i do
B4X:
Sub test
Msgbox(formex.sender)
i=StrReplace(Sender,"script","")
'why sender is not a 'script'???
i=1
AddObject("formex"&i,"Formex")
Control("formex"&i,"Formex").new2("formm"&i,i,200,200)
Control("formex"&i,"Formex").showmodal
End Sub
msgbox(formex.sender) return ERROR "Object reference not set to instance of an object" :confused:
 

agraham

Expert
Licensed User
Longtime User
As you haven't posted your script I have no idea what your script is trying to do. CallHostGuiSub has nothing to do with Sender because, like you said, it does not cause an event. 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.

Remember you only need to use CallHostGuiSub if you want to access GUI elements, otherwise CallHostSub is a LOT faster but may raise threading issues as it runs on the calling thread and not the GUI thread.
 
Top