|
Post by bigbass on May 12, 2014 15:15:13 GMT 1
Here is something that jumped out of nowhere I was wondering if we could link to other *.so libraries directly and yes we can here is a working example just wanted to document this it may be useful for some other libs too also a nice test of the shared fix for the beta 3.0.1 ' Needed to connect signals libgobject-2.0 ' Needed for gtk2 libgtk-x11-2.0 using shared lib instead of the usual pragma include or headers ! we may have some special libs that we need to link directly and if the lib was built correctly it should work UPDATED to use LDFLAGS this way we compile as usual no options -l needed PRAGMA LDFLAGS gobject-2.0 PRAGMA LDFLAGS gtk-x11-2.0 Joe button.bac
'--- using shared lib instead of the usual pragma include '--- bacon -l gobject-2.0 -l gtk-x11-2.0 button.bac
PRAGMA LDFLAGS gobject-2.0 PRAGMA LDFLAGS gtk-x11-2.0 PROTO gtk_init,gtk_main_quit,gtk_window_new, gtk_window_set_default_size PROTO gtk_window_set_title,gtk_table_new,gtk_container_add PROTO gtk_table_attach_defaultsgtk_button_new_from_stock, gtk_table_attach_defaults PROTO g_signal_connect_data, gtk_widget_show_all, gtk_main
SUB exit_prog gtk_main_quit END SUB
gtk_init(0, 0)
window = gtk_window_new() gtk_window_set_default_size(window, 200, 200) gtk_window_set_title(window, "Hello world ")
table = gtk_table_new(15, 15, 1) gtk_container_add(window, table) label = gtk_label_new("Bacon and GTK shared lib example!") gtk_table_attach_defaults(table, label, 1, 8, 3, 7)
button = gtk_button_new_from_stock("gtk-quit") gtk_table_attach_defaults(table, button, 10, 14, 12, 14)
g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) g_signal_connect_data(button, "clicked", exit_prog, 0, 0, 0)
gtk_widget_show_all(window) gtk_main
|
|
|
Post by bigbass on May 12, 2014 17:20:22 GMT 1
Would this method work for other libs lets give it a try lets link the libcurl.so directly and see what happens There is a complete include.bac called curl.bac www.basic-converter.org/curl.bac.htmlhowever it is not used here except three constants were used from curl.bac bacon -l curl curl-dowloader.bac Working example code just provided to show another method of shared linking with PROTO or use PRAGMA LDFLAGS curl curl-dowloader.bac' ' Download a binary file example over HTTP using CURL - PvE december 2010 ' '--- dynamically linked doesn't use the IMPORTS curl.bac -bigbass May 12 2014 '--- bacon -l curl curl-dowloader.bac
PRAGMA LDFLAGS curl
'--- we pull these out of the library directly PROTO curl_easy_init PROTO curl_easy_setopt PROTO url_easy_perform PROTO curl_easy_cleanup PROTO curl_version_info
'--- http://www.basic-converter.org/curl.bac.html '--- borrowed/stole from the curl.bac the const '--- somethings are not defined inside the lib CONST CURLOPT_URL = 10002 CONST CURLOPT_WRITEDATA = CURLOPT_FILE CONST CURLOPT_FILE = 10001
CONST filename$ = "documentation.pdf"
' File where we store the download OPEN filename$ FOR WRITING AS download
' Create the handle easyhandle = curl_easy_init()
' Set the options curl_easy_setopt(easyhandle, CURLOPT_URL, CONCAT$("http://www.basic-converter.org/", filename$)) curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, download)
' Perform the GET success = curl_easy_perform(easyhandle)
' Cleanup curl_easy_cleanup(easyhandle)
' Close filehandle CLOSE FILE download
'--- fix for getting the version as a string using PROTO CURLV$=(char *)curl_version()
' Print Curl version PRINT NL$, "Downloaded '", filename$, "' using CURL version: ",CURLV$ , NL$
|
|
|
Post by bigbass on May 26, 2014 15:04:20 GMT 1
Hey to get functions from the libraries directly and easily without headers the syntax lets you see exactly what you are doing pulling the functions from the libraries making this stand alone codeWhat does this mean we can reduce the syntax even more and depending on the libraries used we can even not includeheaders the headers can be ugly in gtk forcing you to use ugly casting all the way though the code In the above examples I did it like this adding the libs on the command line bacon -l gobject-2.0 -l gtk-x11-2.0 button.bac but after seeing tha vovchik used just PRAGMA LDFLAGS I converted the examples this way we dont need the command line options adding the libs '--- using shared lib *.so directly instead of the usual pragma include PRAGMA LDFLAGS gobject-2.0 PRAGMA LDFLAGS gtk-x11-2.0 they are the same =================================== another example using curl as a shared lib from command line bacon -l curl curl-dowloader.bac or you can avoid the command line and add it to the file with just PRAGMA LDFLAGS curl they are the same
|
|
|
Post by vovchik on May 26, 2014 15:35:46 GMT 1
Dear Joe, Thanks for that curl code...it's nice and terse, and free of distractions. Very nice job. With kind regards, vovchik
|
|
|
Post by SunBurnt on May 27, 2014 19:38:25 GMT 1
Perhaps use XCB to write a new Tool Kit and dump GTK+ ?
GTK`s been griped about so many times that more griping`s not needed.
High quality widgets and new window graphics would be most welcome.
M$ windows boxes looked great at first, but after 20 years it`s a cluttered eye sore now.
|
|
|
Post by bigbass on May 28, 2014 5:18:08 GMT 1
Hey SunBurnt
Enlightenment has all the stuff needed to make quality work all widgets libraries that we can use with bacon need to be in C code so that the compiler will do its job
This makes for whatever library you choose you are stuck with porting C code to BaCon at some time if you want to do anything out side the scope of generic widgets you would be forced to know how things work under the hood [period]
Its not because we like C code if that was the case we could just use C code and be done with it The real problem lies in the low level stuff it is always in C this is the ugly part that we all wish wasn't there but is and isn't going away
We try many procedures to ALIAS ,PROTO and convert what we can to BASIC for the end result of having some more digestible code to read and use
Will programming ever be very easy and foolproof?
probably not but we are trying every possible way to ease the job for the next guy with some working examples that can be used as a starting point
And a widget library is in the making but that is also just a starting point to make things easier to work with
Joe
|
|
|
Post by bigbass on Jun 16, 2021 5:51:01 GMT 1
I am updating a post from 2014 to simplify it more and get it to compile and run again in 2021
still usable after many years
note you need the headers '---sudo apt-get install libcurl4-gnutls-dev
Joe
' ' Download a binary file example over HTTP using CURL - PvE december 2010 ' '--- dynamically linked doesn't use the IMPORTS curl.bac -bigbass May 12 2014 '--- bacon curl-downloader.bac
'---shortened code and added headers June 15 2021 bigbass '---sudo apt-get install libcurl4-gnutls-dev
PRAGMA LDFLAGS curl PRAGMA OPTIONS -Wno-implicit -Wno-deprecated-declarations PRAGMA INCLUDE <curl/curl.h> PRAGMA INCLUDE <curl/typecheck-gcc.h> PRAGMA INCLUDE <curl/easy.h>
OPTION PARSE FALSE CONST filename$ = "documentation.pdf"
' File where we store the download OPEN filename$ FOR WRITING AS download
' Create the handle DECLARE easyhandle TYPE void* easyhandle = curl_easy_init()
' Set the options curl_easy_setopt(easyhandle, CURLOPT_URL, CONCAT$("http://www.basic-converter.org/", filename$)) curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, download)
' Perform the GET success = curl_easy_perform(easyhandle)
' Cleanup curl_easy_cleanup(easyhandle)
' Close filehandle CLOSE FILE download
'--- fix for getting the version as a string CURLV$=(char*)curl_version()
' Print Curl version PRINT NL$, "Downloaded '", filename$, "' using CURL version: ",CURLV$ , NL$
|
|
|
Post by vovchik on Jun 16, 2021 10:17:18 GMT 1
Dear Joe, Thanks. I did the apt-get on Mint and Pi Buster/testing and everything worked fine - got the pdf intact using the code you posted above. With kind regards, vovchik
|
|
|
Post by bigbass on Jun 18, 2021 1:26:12 GMT 1
Thanks vovchik
for giving it a try and the feedback
I see things differently after trying many different ways to port code to bacon
and many of those older bac include files could be shortened dramatically by using the official headers in the same way that was done with the curl.bac port
I guess the key here is bacon has evolved to be more powerful and we have more options that were not available 10 years ago it is much easier now to get something working quickly
Joe
|
|
|
Post by bigbass on Jul 16, 2021 19:03:14 GMT 1
hello everyone
I had an example for downloads above but here is for uploads on your localhost
good for testing and all is bacon compatible use any bac file call it a.bac for testing
Joe
'--- Upload a binary file over HTTP using CURL on your localhost
'---shortened code and added headers July 14 2021 bigbass '---sudo apt-get install libcurl4-gnutls-dev
'---short description of how to use run this in /home/pi/ '--- it will upload a.bac to /home/pi/UPLOAD/ it makes the folder for you
PRAGMA LDFLAGS curl PRAGMA OPTIONS -Wno-implicit -Wno-deprecated-declarations PRAGMA INCLUDE <curl/curl.h> PRAGMA INCLUDE <curl/typecheck-gcc.h> PRAGMA INCLUDE <curl/easy.h>
OPTION PARSE FALSE CONST filename$ = "a.bac"
' File we will upload OPEN filename$ FOR READING AS uploadme
' Create the handle DECLARE easyhandle TYPE void* easyhandle = curl_easy_init()
MAKEDIR "/home/pi/UPLOAD/"
'---tell it to "upload" to the URL curl_easy_setopt(easyhandle, CURLOPT_UPLOAD, 1L)
' upload to this place curl_easy_setopt(easyhandle, CURLOPT_URL, CONCAT$( "file:///home/pi/UPLOAD/", filename$))
'---set where to read the file from curl_easy_setopt(easyhandle, CURLOPT_READDATA, uploadme)
' Perform the GET success = curl_easy_perform(easyhandle)
' Cleanup curl_easy_cleanup(easyhandle)
' Close filehandle CLOSE FILE uploadme
'--- fix for getting the version as a string CURLV$=(char*)curl_version()
' Print Curl version PRINT NL$, "Downloaded '", filename$, "' using CURL version: ",CURLV$ , NL$
|
|
|
Post by vovchik on Jul 25, 2021 23:41:19 GMT 1
Dear Joe (and all),
Here is a little demo, using the same method, that loads and runs the python interpreter.
With kind regards, vovchik
' change next two lines to reflect your python version ' you need to have the python development headers installed ' for this to work
PRAGMA LDFLAGS python2.7 PRAGMA INCLUDE <python2.7/Python.h> OPTION PARSE FALSE
' ------------------ SUB PYINFO() ' ------------------ LOCAL st$[11] TYPE STRING st$[9] = "--------------------------" st$[10] = "---" PRINT st$[9] PRINT "Getting Python information", NL$, st$[9] Py_Initialize() IF NOT(Py_IsInitialized()) THEN PRINT "Unable to initialize Python interpreter" END IF st$[0] = Py_GetPrefix() st$[1] = Py_GetExecPrefix() st$[2] = Py_GetProgramFullPath() st$[3] = Py_GetPath() st$[4] = Py_GetVersion() st$[5] = Py_GetPlatform() st$[6] = Py_GetCopyright() st$[7] = Py_GetCompiler() st$[8] = Py_GetBuildInfo() PRINT "Prefix: ", st$[0], NL$, st$[10] PRINT "Exec Prefix: ", st$[1], NL$, st$[10] PRINT "Python path: ", st$[2], NL$, st$[10] PRINT "Module Path: ", st$[3], NL$, st$[10] PRINT "Version: ", st$[4], NL$, st$[10] PRINT "Platform: ", st$[5], NL$, st$[10] PRINT "Copyright: ", st$[6], NL$, st$[10] PRINT "Compiler String: ", st$[7], NL$, st$[10] PRINT "Build Info:", st$[8] PRINT st$[9] Py_Finalize() END SUB
PYINFO()
|
|