I'm 24 years old and started using PureBasic as I was 12 (I guess )
Came across a lot of other programming languages, as I made my
way to become a sofware engineer. All the other languages in my mind -
I still often use PureBasic, because it is ... well.. just beautiful and handy
Now back to topic
My harddrive was a mess, that's why I decided to clean it up and found
some codes. Maybe this one is usefull for anyone out there
I needed some code to communicate with JS, so I came across this
simple solution: On a hidden window, WebGadgets are created and run
my own 'Scripts'. I can put in parameters and get parameters out, all of them
in JSON-Format. The code itself injects return/update-functions, so it's simple
to use.
It should (hopefully) be clear what the code does, but let's take a look on this function:
Code: Select all
JSc_Script(Name$, Script$, ParamIn$, RunOnce.l=1, jq.b=0)
01: Code runs once and is 'Ready'
00: Code runs unlimited
-1: Code restarts (untested)
-2: Code restarts, output becomes input (untested)
JQ:
00: Nothing
01: Inject JQuery
Download: http://www.mediafire.com/file/uzls8jpyn ... mpiler.zip (Includes + Example)
Here's an example-code:
Code: Select all
; Library for simple usage of JS-Scripts in PureBasic
IncludeFile "_Init.pb"
IncludeFile "_IDLE.pb"
;::::::::::::::::::::::::::::::::::::::::::::::::::::
;ScriptA with JQuery in it
ScriptA$ = "var x=$('body');"
ScriptA$ + "x.addClass('testClass');"
ScriptA$ + "jsc_return(x.attr('class'));"
;ScriptB with simple use of arguments, Math and Strings
ScriptB$ = "var x= args.name + 5*3*213*5.4+'_2secondscript_test2';"
ScriptB$ + "jsc_return(x);"
;ScriptC with counter
ScriptC$ = "window.setInterval('args.count++;" ;Every 0.300 secs new Output
ScriptC$ + "jsc_return(args.count)',300);"
;ScriptD with Prompt and User-Data
ScriptD$ = "jsc_return(prompt('Get from User','Default'));"
;Register Scripts
JSc_Script("script_a", ScriptA$, "{'name':'test'}",1,1)
JSc_Script("script_b", ScriptB$, "{'name':'test'}")
JSc_Script("script_c", ScriptC$, "{'count':0}", 0)
JSc_Script("script_d", ScriptD$, "{}")
;Run Scripts
OpenConsole("JSC")
While JSc_Script_Ready("script_a") <> 1 Or JSc_Script_Ready("script_b") <> 1 Or Val(JSc_Script_Out("script_c")) < 5
JSc_IDLE()
Delay(1)
PrintN("a: "+JSc_Script_Out("script_a"))
PrintN("b: "+JSc_Script_Out("script_b"))
PrintN("c: "+JSc_Script_Out("script_c"))
PrintN("d: "+JSc_Script_Out("script_d"))
PrintN("======")
Wend
;Get Final-Results
MessageRequester("Out", JSc_Script_Out("script_a")) ;Returns are in JSON_Format
MessageRequester("Out", JSc_Script_Out("script_b"))
MessageRequester("Out", JSc_Script_Out("script_c"))
MessageRequester("Out", JSc_Script_Out("script_d"))
; =======================================
Maybe it helps someone to build there own way to use JS in PureBasic.
That said: I'm not going to update this code anymore, but if you want
feel free to develop it further
Have a nice day,
Kirito