|
Post by MrHiggins on Aug 18, 2021 2:19:56 GMT -5
Hi,
Is it possible to separate your Basic code into files and then reference them from the main one in Liberty Basic 4.5.1?
The equivalent of this in qbasic/qb64 would be
'$INCLUDE: 'foobar.bi' Thanks
|
|
|
Post by Chris Iverson on Aug 18, 2021 10:52:59 GMT -5
No, the closest you have is running another TKN file or program.
However, this is a feature being added to LB5, and in fact can be tested in LB5 today, although likely not in its final implementation.
|
|
|
Post by MrHiggins on Aug 18, 2021 11:44:58 GMT -5
Thanks for that @chris Iverson had a feeling that might have been the case.
So you could compile a bas file with list of functions to a TKN and then somehow those functions are then callable when running a bas or TKN file?
|
|
|
Post by Chris Iverson on Aug 18, 2021 12:45:47 GMT -5
Not directly, no. Essentially, running an external TKN file is like running a separate program.
To use functions in an external TKN file, just like with an external EXE, you have to do all the work marshalling whatever data has to pass yourself, as well as determine a way within the external program to "call" the function you need executed.
Whether you do this with temporary files, via the command line, whatever and however you do it, it's all gotta be done by you.
Unless you were talking about how it's going to work in LB5. Right now, it's based on direct access to the source code only; using the LIBRARY command requires access to the source code of the "module" you're trying to include. Once LB5 supports actually individually compiling a program, there will presumably be some method of using the LIBRARY command with it.
|
|
|
Post by colinmcm on Aug 18, 2021 13:06:21 GMT -5
I think Alyce Watson's Workshop editor included the facility to 'include' files.
Also it is relatively easy to make a pre-processor that adds library files to a main file. It must be easy becasue I did it, though I have lost the code many moons ago.
Essentialy the preprocessor copies the main program line by line into a temporary file ( say "temp.bas") until it comes across a line starting with 'include "myfile.lib". It then pastes into the temporary file the contents of "myfile.lib" at that point in the program, then continues with the following lines.
Finally "temp.bas" is sent to the libertybasic compiler.
note that the trigger phrase starts with a comment charecter. Also at the time I used functions much more than gosubs etc, and this worked for me, but I assume all other valid basic code would work.
|
|
rnbw
New Member
Posts: 48
|
Post by rnbw on Aug 18, 2021 13:39:14 GMT -5
I think Alyce Watson's Workshop editor included the facility to 'include' files. ............ I use Alyce Watson's Liberty Basic Workshop and I can't see any way to 'include' files.
|
|
|
Post by MrHiggins on Aug 18, 2021 14:31:11 GMT -5
I think for the time being I'll stick to copy paste code, specially as LB5 will support this eventually.
|
|
|
Post by tsh73 on Aug 18, 2021 15:32:28 GMT -5
I never tried it myself but I found two quotes that might as well work in LB Workshop
EDIT Just downloaded LB Workshop Installed on Win 10 home 32-bit It works as described (includes file contents AFTER main file end)
|
|
|
Post by colinmcm on Aug 18, 2021 17:17:10 GMT -5
I have just dug out my old copy of workshop on a windows7 machine, and 'include is in there, however there seems to be a problem. When the compiler and runtime paths(set in the editor preferences ) point to liberty.exe and the appropriate runtime, it fails. However it works if the compiler and runtime paths point to LBB.exe and LBBrun.exe. which is odd and undesirable. I will not try to set up workshop on my windows 10 machine. Oh well.
edit. tsh73 just beat me to it - oh well again
|
|
|
Post by Brandon Parker on Aug 18, 2021 20:39:56 GMT -5
|
|
rnbw
New Member
Posts: 48
|
Post by rnbw on Aug 19, 2021 3:56:37 GMT -5
I think Alyce Watson's Workshop editor included the facility to 'include' files. ............ I use Alyce Watson's Liberty Basic Workshop and I can't see any way to 'include' files. I stand corrected!
LB Workshop DOES allow Include files and this is covered in it's help file (an incomplete extract follows).
"INCLUDE FILES Liberty BASIC Workshop has the ability to allow "include" files in code. This means that a program's code may be contained on more than one module and compiled at runtime. This allows modules to be portable. Frequently used functions needn't be rewritten for each new program that uses them. The code module containing these functions can be copied to the new program's directory and simply "included" in the main code. In addition to allowing modularity and portability of code, this method allows program modules to remain smaller and easier to manage. To use "include" files in a program:
The first line of code must start with the term
'include
followed by the filename of the file to include. The file must be in the same directory as the program file, and no path information should be used. Example:
'include filename.bas
If more than one file is to be included, each file must be listed on its own line, one after the other, like this:
'include file1.bas 'include file2.bas 'include file3.bas 'include myfunctions.bas 'include subroutines.bas
and so on.
................ ................
To save a file with all of the "include" files, choose SAVE PROJECT from the file menu. The current file will be saved to disk, and all "include" files will be appended in the order they are listed at the top of the code."
I presume it works (Alyce Watson's code usually/always does), but I have never used it. I might give it a try.
I hope the above clarification is of help.
|
|
|
Post by mknarr on Aug 19, 2021 8:21:21 GMT -5
I looked at Workshop and found under File-Insert File might be just as easy since it inserts the actual code instead of "including" it at runtime.
|
|
|
Post by tsh73 on Aug 19, 2021 10:18:29 GMT -5
That kind of defies main idea of INCLUDE - to have in *separate* file reusable library of functions (write once, use many, no copy\pasting errors)
|
|