Wednesday, January 12, 2022

New feature: Export BASIC programs (three options)

 Today's new version of BASIC Anywhere Machine adds the "Export" button to the File menu.



This export button is the standard TiddlyWiki export button.  Upon clicking it, the button presents a pop-up menu which will offer you options to export the tiddler in multiple formats.

To the standard formats, BASIC Anywhere Machine adds these three new options:
  • ".bas" file
  • ".bas.html" file
  • ".bas.json" file


".bas" file

This will take the tiddler for the BASIC program, resolve all transclusions (via "wikification") and export the program to a plain text file.

The usefulness of this: take a program that you've created and tested, and use the source code with other BASIC implementations (QB64, Qbasic, FREEBasic, PureBASIC, Gambas, etc. etc.)  So BASIC Anywhere Machine as portable and run anywhere generic BASIC programming (and testing, and source code manager), feeding projects using other BASIC implementations.  Cool.

".bas.html" file

This will do the same as export to ".bas" file, but wrap the basic program with all of the html and javascript needed to have a legit single-file web page (fully self-contained) for running the BASIC program.  

  • BASIC Anywhere Machine uses a custom version of wwwBASIC.js and embeds the javascript directly in the HTML file (i.e. does not use "include" of any external files).  The resulting file will otherwise be very similar to the file described on the wwwBASIC github page.

The usefulness of this: deploy/share a BASIC program as a self-contained HTML file.  (i.e. just the necessaries for the BASIC program to run.   Anybody can run the BASIC program anywhere: the only thing needed is a web browser.

".bas.json" file

Partially complete !!!  Currently only works for BASIC programs that do not have any TiddlyWiki  transclusions of source code.  For information about the source code transclusion feature in BASIC Anywhere Machine, please read about that further below.

This is an enhanced version of the native TiddlyWiki single-tiddler JSON file export option, but adds to the export the bare minimum number of tiddlers needed to run the BASIC program in another TiddlyWiki.

The usefulness of this: take a program created and tested in BASIC Anywhere Machine, and export just what is needed for the BASIC program to run in any other TiddlyWiki instance.  The tiddlers in the JSON file created by BASIC Anywhere Machine can be imported into another TiddlyWiki instance.


Man, all of this gets my geek mojo going.

Cheers !


BASIC Anywhere Machine's "Code Transclusion" Feature

BASIC Anywhere Machine enhances BASIC programming by taking advantage of TiddlyWiki's "Transclusion in Wikitext" feature.

Upon start (aka RUN) of a BASIC program in BASIC Anywhere Machine, the program is pre-processed before getting handed over to the interpreter.  Pre-processing resolves all transclusion instances.

In the following program,  the "{{Conversion Functions}}" transclusion reference will get replaced during pre-processing by the content of the tiddler called "Conversion Functions".


' πŸ“š libraries
{{Conversion Functions}}
'
' 🏁 start
'
print "The number of kilometers in 2 miles = "; MilesToKms!(2)
print "The number of miles in 2 kilometers = "; KmsToMiles!(2)
'
end
' 🏁

The "Conversion Functions" program:

function MilesToKms!(Miles!)
MilesToKms! = Miles! * 1.609345
end function
function KmsToMiles!(Kms!)
KmsToMiles! = Kms! / 1.609345
end function

The result of pre-processing, the code that will be passed to the interpreter:

' πŸ“š libraries
function MilesToKms!(Miles!)
MilesToKms! = Miles! * 1.609345
end function
function KmsToMiles!(Kms!)
KmsToMiles! = Kms! / 1.609345
end function
'
' 🏁 start
'
print "The number of kilometers in 2 miles = "; MilesToKms!(2)
print "The number of miles in 2 kilometers = "; KmsToMiles!(2)
'
end
' 🏁

Aside: in the sample programming code above, single-quotes are alternatives to the "REM" statements (used for comments in BASIC programs.)  Also, for a bit of experimentation with code readability, I've added emoji's.  I think it is something which should be used sparingly.  


No comments:

Post a Comment

πŸ–₯ Pongy game

This program is a port (and slight mod) of the QB64pe program by SierraKen.  (SierraKen's program shared with the QB64pe community in th...