Page 1 of 1
HRB curiosities...
Posted: Tue Jul 23, 2019 7:25 am
by Antonio Linares
This works:
Code: Select all
function Main()
local o := AddFunc( "function Orm()" + CRLF + "return nil" )
? HB_ISFUNCTION( "ORM" )
return nil
function AddFunc( cCode )
return hb_HrbLoad( 1, hb_CompileFromBuf( cCode, .T., "-n" ) )
and this doesn't:
Code: Select all
function Main()
AddFunc( "function Orm()" + CRLF + "return nil" )
? HB_ISFUNCTION( "ORM" )
return nil
function AddFunc( cCode )
return hb_HrbLoad( 1, hb_CompileFromBuf( cCode, .T., "-n" ) )
Re: HRB curiosities...
Posted: Tue Jul 23, 2019 7:32 am
by Antonio Linares
HRBs implement a garbage collector that unloads them, thats the reason for it:
Code: Select all
/* HRB module destructor */
static HB_GARBAGE_FUNC( hb_hrb_Destructor )
{
PHRB_BODY * pHrbPtr = ( PHRB_BODY * ) Cargo;
if( *pHrbPtr )
{
hb_hrbUnLoad( *pHrbPtr );
*pHrbPtr = NULL;
}
}
Re: HRB curiosities...
Posted: Tue Jul 23, 2019 8:54 pm
by Antonio Linares
Code: Select all
function Main()
local o := AddFunc( "function Orm()" + CRLF + "AP_RPuts( 'yes' )" + CRLF + "return nil" )
Execute( "function test()" + CRLF + "Orm()" + CRLF + "return nil" )
return nil
function AddFunc( cCode )
return hb_HrbLoad( 0, hb_CompileFromBuf( cCode, .T., "-n" ) )
Re: HRB curiosities...
Posted: Tue Jul 23, 2019 9:18 pm
by Antonio Linares
Code: Select all
function Another()
local o := hb_HrbLoad( 1, MemoRead( hb_GetEnv( "PRGPATH" ) + "/testhrb.hrb" ) )
Execute( "function test()" + CRLF + "Main()" + CRLF + "return nil" )
return nil
Re: HRB curiosities...
Posted: Wed Jul 24, 2019 5:56 am
by Antonio Linares
This is specifically for mod_harbour:
Code: Select all
// {% AAdd( getList, hb_HrbLoad( 0, hb_CompileFromBuf( "function Orm()" + Chr( 13 ) + Chr( 10 ) + "AP_RPuts( 'yes' )" + Chr( 13 ) + Chr( 10 ) + "return nil", .T., "-n" ) ) ) %}
function Main()
Orm()
return nil
Re: HRB curiosities...
Posted: Wed Jul 24, 2019 7:20 am
by Antonio Linares
mod_harbour final version:
Code: Select all
// {% LoadHRB( "testhrb.hrb" ) %}
function Another()
Test()
return nil