Converting to JS/Web Format
Converting to JS/Web Format
I have been tasked with converting a 3000 or so line graphing program from freebasic to something that can work in the web browser (preferably using javascript). I'm definitely well versed in JavaScript; however, the FreeBasic program is becoming tedious to convert by hand. It seems that all or nearly all of the FB logic has an equivalent in javascript (minus some graphing function), so I feel it should be simple to convert to JS, but I'm unsure how. Does anyone know of existing projects that can do this?
Re: Converting to JS/Web Format
Yes, Emscripten is what you are looking for. FreeBasic can use it to compile directly to a web page (you would need the FreeBasic source to compile the runtime library with Emscripten before starting)
Re: Converting to JS/Web Format
Do you happen to know the specific instructions for how that'd work? I couldn't find anything in the wiki.
Re: Converting to JS/Web Format
It is explained here:
https://freebasic.net/forum/viewtopic.php?t=24021
and here:
viewtopic.php?t=26956
Basically, you have to install and configure Emscripten, as explained here: https://emscripten.org/docs/getting_sta ... loads.html
then download the source of FreeBasic, and build the runtime libraries and the graphic library with TARGET=asmjs-unknown-emscripten
Then you can compile using "fbc -target js-asmjs file.bas"
If your program has a main loop, you might need to use the option -Wl "-s ASYNCIFY=1"
https://freebasic.net/forum/viewtopic.php?t=24021
and here:
viewtopic.php?t=26956
Basically, you have to install and configure Emscripten, as explained here: https://emscripten.org/docs/getting_sta ... loads.html
then download the source of FreeBasic, and build the runtime libraries and the graphic library with TARGET=asmjs-unknown-emscripten
Then you can compile using "fbc -target js-asmjs file.bas"
If your program has a main loop, you might need to use the option -Wl "-s ASYNCIFY=1"
Re: Converting to JS/Web Format
You can run .js files directly from freebasic.
Code: Select all
function java(message as string) as string
dim as string s
s+="WSH.Echo('"+message+"');"
s+="var console = {"+chr(10)
s+=" info: function (s){"+chr(10)
s+=" WSH.Echo(s);"+chr(10)
s+=" }"+chr(10)
s+="}"+chr(10)
s+="var document = {"+chr(10)
s+=" write : function (s){"+chr(10)
s+=" WSH.Echo(s);"+chr(10)
s+=" }"+chr(10)
s+="}"+chr(10)
s+="var alert = function (s){"+chr(10)
s+=" WSH.Echo(s);"+chr(10)
s+="}"+chr(10)
s+="console.info(""test"");"+chr(10)
s+="document.write(""test2"");"+chr(10)
s+="alert(""test3, Press any key to end . . ."");"+chr(10)
return s
end function
function savefile(filename As String,p As String) as string
Dim As long n=freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to save " + filename:sleep:end
End If
return filename
End function
Sub runscript(filename As String)
Shell "cscript.exe /Nologo "+ filename
End Sub
savefile("script.js",java("Testing .js script files"))
runscript("script.js")
kill "script.js"
sleep