Hi everyone,
A recent thread with subject "control structures (if, while, etc...)
within a pcode" discussed compiling code at runtime using codeblocks or
the hb_CompileFromBuf() function. In that thread I mentioned, based on
what I had found in the changelog and old newsgroup messages, that the
GPL license would apply on code using that function since it, in turn,
uses the compiler, which is GPL only. It seems that what I said there
needs to be slightly modified.
To begin with, this can be found in the changelog:
--------------------------
2012-10-17 09:56 UTC+0200 Viktor Szakats (harbour
syenar.net)
* utils/hbmk2/hbmk2.prg
+ added note about the requirement of GPL license next to all
hb_compile()/hb_compileFromBuf() calls.
--------------------------
And the comment in hbmk2.prg says:
--------------------------
/* We can use this function as this is a GPL licenced application */
--------------------------
It exists in several places in the hbmk2 source code where files are
read from disk and compiled with hb_CompileFromBuf()
That seems clear enough, but there is a thread about .hrb files in the
harbour-devel newsgroup where a comment from Viktor says something
slightly different:
https://groups.google.com/forum/#!searchin/harbour-devel/.HRB$20Files$20-$20Some$20Clarifications$20-$20Feature$20Requests/harbour-devel/VmzpxhA4frM/S4LPR4ThvagJ
And Viktor's comment says:
--------------------------
"Using .hrb files or including .hrb files don't have
any licensing implications. Just use them.
The only thing that's not allowed for closed source
apps, is to accept .prg and compile it to .hrb. Unless
you bundle harbour.exe with your app and make an
external call to do the compilation."
--------------------------
The important words seem to be "accept .prg and compile it". So, based
on that comment, it seems that a code snippet that is built at runtime
and compiled with hb_CompileFromBuf() should be OK in a closed source
application but not an existing code snippet in a .prg file that is read
into a buffer and compiled at runtime (but then again, if it is
precompiled to .hrb it is OK just like it would be with a dll).
If my interpretation is correct, I believe that this covers the
situation originally described by Diego Risi, where he wanted to build a
codeblock like this at runtime (although the syntax would be slightly
different):
--------------------------
bBlock := &('{ || if .t.'+chr(13)+chr(10)+;
'qout("test OK")'+chr(13)+chr(10)+'endif }')
--------------------------
Anyone with a different interpretation?
For those who have not read the harbour-devel newsgroup today: In
response to a feature request from Diego there was a post by Alexander
Kresin, who, many years ago, was involved in writing the code that runs
.hrb files. This is what he suggested, slightly modified by yours truly
for readability and to demonstrate passing arguments and returning results:
--------------------------
REQUEST QOUT
FUNCTION Main
Local cBuf, buf
cBuf := 'Function A1( nVal )' + hb_eol() +;
'if .t.' + hb_eol() +;
'qout("test > OK")' + hb_eol() +;
'endif' + hb_eol() +;
'Return nVal * 2' + hb_eol()
buf := hb_compileFromBuf( cBuf, "harbour", "/n" )
? hb_hrbRun( buf, 123 ) // Pass argument 123
RETURN nil
--------------------------
Regards,
Klas