Call SB Procedure with JavaScript

Everything else that doesn't fall into one of the other categories.
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Call SB Procedure with JavaScript

Post by falsam »

This example (from help) works fine.

Code: Select all

Procedure MyProcedure()
  Debug "Hello world"
EndProcedure

; Call in SpiderBasic
MyProcedure() 

; Call using Javascript
!f_myprocedure();
but not this code

Code: Select all

Procedure MyProcedure()
  Debug "Hello world"
EndProcedure

; Call using Javascript
!f_myprocedure();
Thanks for your help.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Call SB Procedure with JavaScript

Post by Fred »

You need to reference your procedure in SB code at least once or it will get removed by the code optimizer.
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: Call SB Procedure with JavaScript

Post by falsam »

Fred wrote:You need to reference your procedure in SB code at least once or it will get removed by the code optimizer.
Like the first code ? For me this is a non sense.

Code: Select all

Global dummy

Procedure MyProcedure()
  dummy + 1
EndProcedure

; Call in SpiderBasic
MyProcedure() 

; Call using Javascript
!f_myprocedure();
!alert(v_dummy)
Last edited by falsam on Fri Nov 04, 2016 10:50 am, edited 1 time in total.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Call SB Procedure with JavaScript

Post by Peter »

Fred wrote:You need to reference your procedure in SB code at least once or it will get removed by the code optimizer.
in this case:

Code: Select all

If 1=2
 MyProcedure()
EndIf
i think it's more elegant when Declare do the Job:

Code: Select all

Declare MyProcedure()
Greetings ... Peter
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

Re: Call SB Procedure with JavaScript

Post by mdp »

Peter wrote:i think it's more elegant when Declare do the Job:
Declare MyProcedure()
Absolutely, it's ok to have the optimizer working but we need a good solution to force the compilation of a procedure meant to be called with "inline JS".
Post Reply