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

Call SB Procedure with JavaScript

by falsam Fri Nov 04, 2016 10:40 am

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 10 - JDK 1.8 - SB 2.20 - Android 5.5
Mood ☀️
http://falsam.com

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

Re: Call SB Procedure with JavaScript

by Fred Fri Nov 04, 2016 10:40 am

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

Re: Call SB Procedure with JavaScript

by falsam Fri Nov 04, 2016 10:48 am

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 10 - JDK 1.8 - SB 2.20 - Android 5.5
Mood ☀️
http://falsam.com

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

Re: Call SB Procedure with JavaScript

by Peter Fri Nov 04, 2016 10:48 am

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

by mdp Tue Oct 10, 2017 8:23 am

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".
Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests