Towards an IMPORT module command for Harbour

177 views
Skip to first unread message

antonio....@gmail.com

unread,
Nov 15, 2025, 12:10:06 PM (8 days ago) Nov 15
to Harbour Users
The idea is to implement a (somehow similar Python`s)  import module command for Harbour. 

We may have an official repo of HRB modules for Harbour and basically IMPORT module downloads the HRB file and loads the HRB at runtime:

I appreciate if you comment, elaborate, modify, etc. about this idea that hopefully may become an official supported command for Harbour:

#include "hbcurl.ch"  

#define HB_CURLSSLOPT_NATIVE_CA   hb_bitShift( 1, 4 )

#xcommand IMPORT <module> => static <module> ;;
          init procedure <module> ;;
             <module> := Import( <(module)> );;
          return

IMPORT ai

function Main()

return nil

FUNCTION Import( cModuleName, nMode )  

   LOCAL pHrbBody, cFileName := cModuleName + ".hrb"  
     
   hb_default( @nMode, HB_HRB_BIND_DEFAULT )  

   UrlDownload( "https://harbour.github.io/modules/" + cModuleName + ".hrb", cFileName )

return pHrbBody := hb_hrbLoad( nMode, cFileName )  

FUNCTION UrlDownload( cUrl, cDestFile )

   LOCAL hCurl
   LOCAL nResult  
     
   curl_global_init()  
     
   hCurl := curl_easy_init()  
   IF hCurl != NIL  
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )  
      curl_easy_setopt( hCurl, HB_CURLOPT_DOWNLOAD )  
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, cDestFile )  
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_OPTIONS, HB_CURLSSLOPT_NATIVE_CA )  
       
      nResult := curl_easy_perform( hCurl )  
       
      curl_easy_cleanup( hCurl )  
   ENDIF  
     
   curl_global_cleanup()  
     
RETURN nResult == HB_CURLE_OK


thank you

Antonio

alex;

unread,
Nov 16, 2025, 2:17:29 AM (8 days ago) Nov 16
to Harbour Users
Hello, Antonio. It looks good.
But the import command in Python is designed to connect modules that have already been downloaded. That is, as a REQUEST in Harbour. In fact, it is now important to create a workspace in the cloud for connecting models, connecting your repositories via VPN, and running code analysis of projects using GPU resources from the same cloud. I think so.

WBR, alex;
суббота, 15 ноября 2025 г. в 20:10:06 UTC+3, antonio....@gmail.com:

Eric Lendvai

unread,
Nov 16, 2025, 8:04:29 AM (8 days ago) Nov 16
to Harbour Users
The idea of having packages for Harbour would be wonderful!
Alex is correct that the IMPORT command in Python does not download. This can open the doors for hackers.
Python is a non compiled language (At least the CPython implementation) and behaves differently internally. For Harbour we probably need to support hrb and regular libs (C compiled). Python packages can be pure Python or C libraries.
If having an IMPORT command, could be used to make it easier to bring it packages into Harbour it could help many new developers.
What about even allowing to IMPORT Python Packages into Harbour. I already link CPython in all my builds now.
Package managers for Python, JavaScript, .Net are great to attract new developers but they can be a nightmare do deal with dependencies. 
hbmk2 is an extremely powerful tool, but it is not easy for new developers. VFP used to have a project manager which helped to specify what was needed to build an EXE or DLL. 
Another idea would be to find out how we could have Harbour packages to be imported into Python. This could help provide name recognition of Harbour to a large number of Python developers, and for some of us who run Python code in Harbour, this would allow us to call back into Harbour functions from Python.

Keeping the doors open to new ideas is what is needed to help Harbour. Thanks Antonio!

alex;

unread,
Nov 16, 2025, 9:39:14 AM (7 days ago) Nov 16
to Harbour Users
Eric,  idea to create template of Harbour project for creating modules for Python is very very good. 
It seems to me that there are many variations here like JNI or FFI for callbacks and some thing else.

WBR, alex;
воскресенье, 16 ноября 2025 г. в 16:04:29 UTC+3, Eric Lendvai:
Reply all
Reply to author
Forward
0 new messages