People have been asking for a way to create code libraries in Liberty BASIC for some time. I have thinking about how to do this using an in-memory model. Over the weekend Scott and I worked on adding some modularity to the Run/Liberty BASIC language. Here's how it works so far. We are open to suggestions.
The RUN statement has a new form. If I want to use mymodule.bas as a module in a program I am writing I would code it like this:
run "mymodule.bas", #myModule
This causes mymodule.bas to be compiled into memory. It will execute code up to the first wait statement. This is how values will be initialized. The program then becomes an object assigned to the #myModule handle.
Then you can call any function on that program from within the calling program, like so:
#myModule myFunction(myParameter)
or even use the invokation in a more complex expression:
print "digits: "; len(#myModule myFunction(myParameter))
You may recognize this syntax as being the same as for controlling widgets. It relies on the same underlying mechanisms to do its work.
When we're done with this, modular programs loaded this way will be cached in memory and will only recompile when the source file changes.
Wednesday, May 30, 2007
Subscribe to:
Posts (Atom)