|
Post by Pjot on Nov 19, 2022 11:45:07 GMT 1
All, As most of you know, I am the creator of the GTK-server, which enables GTK programming for interpreted code. One of the things on my bucket list was to redo this GTK-server in BaCon, but in a more general and multi-purpose manner. This has resulted in a new small project called 'PSALM' (Plain Shell Access to Library Modules), a small tool to enable the invocation of functions in external libraries. It is implemented in only approx. 400 lines of BaCon code! It not only is capable to access external functions; it can even build a complete GUI with GTK. I have created a simple page here: www.basic-converter.org/psalm/psalm.htmlBest regards Peter EDIT: updated the page further.
|
|
|
Post by rikky on Nov 19, 2022 15:10:16 GMT 1
Tsjeeses ... I thought I was retired .. And then some psalm wakes me up and it starts all over again. Well, it will keep me off the streets, I suppose.. Super, Thanks. Rik.
|
|
|
Post by rikky on Nov 19, 2022 16:43:00 GMT 1
And it works. coproc psalm [1] 15745 $ echo "DEF libm.so double cos double" >&"${COPROC[1]}" $ read variable <&"${COPROC[0]}" $ echo $variable ok $ echo "EXE cos 0.8" >&"${COPROC[1]}" $ read variable <&"${COPROC[0]}" $ echo $variable 0.696707 $ echo "EXIT" >&"${COPROC[1]}" $ read variable <&"${COPROC[0]}" [1]+ Done coproc COPROC psalm $ echo $variable Goodbye!
Next step is putting this into a script, that can talk to itself.
|
|
|
Post by Pjot on Nov 19, 2022 17:24:50 GMT 1
Hey rikky,
You could do it like this.
#!/usr/bin/env bash
function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc ./psalm comm "DEF libm.so double cos double" comm "EXE cos 0.8"; result=${answer} comm "EXIT"
echo ${result}
BR Peter
|
|
|
Post by rikky on Nov 19, 2022 18:03:40 GMT 1
The result is : 0.696707. Should be : Goodbye!
|
|
|
Post by Pjot on Nov 19, 2022 19:01:47 GMT 1
Yes, the result is 0.696707 because the variable 'result' is assigned right after the function where the cosine is invoked. If you would like to see "Goodbye!" as a result, then the script looks like this: #!/usr/bin/env bash
function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc ./psalm comm "DEF libm.so double cos double" comm "EXE cos 0.8" comm "EXIT"; result=${answer}
echo ${result}
But then again, this is not of much use, as the idea is to obtain the result from the cosine, and not from the EXIT... HTH Peter
|
|
|
Post by rikky on Nov 20, 2022 14:27:03 GMT 1
Ah ja, I see. The advanced demo programs they all give a signal for SEGMENTATION FAULT received, or "${COPROC[0]}": Bad file descriptor "${COPROC[1]}": Bad file descriptor Pff .. I m not going there. That something for Vovchik or Bigbass or Alexfish .. Too difficult. I managed to get 3 'simple' programs working: function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc psalm
comm "DEF libc.so int strlen char*" comm "EXE strlen hallo"; result=${answer} comm "EXIT"
echo $result
result : 5 function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc psalm
comm "DEF libc.so char* basename char*" comm "EXE basename bla/blabla"; result=${answer} comm "EXIT"
echo $result
result : blabla function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc psalm
comm "DEF libc.so int abs float" comm "EXE abs 1.234"; result=${answer} comm "EXIT"
echo $result result : 1096905796 The last result is obviously not the result that is desired. That"s because I do not have a clou about ints floats chars or char*s. I'm obviously missing certain knowledge that isn't 123 available. So I'll leave it to that. I can confirm that it works, But I do not always know howto. Maybe when I'm older. Rik.
|
|
|
Post by Pjot on Nov 20, 2022 15:14:36 GMT 1
Ah ja, I see. The advanced demo programs they all give a signal for SEGMENTATION FAULT received, or "${COPROC[0]}": Bad file descriptor "${COPROC[1]}": Bad file descriptor You have to make sure that the program actually points to the 'psalmĀ“ binary. Some demo programs start 'psalm', some './psalm', the first indicating that the binary is in your general system path, the latter indicating that the binary is in your current path. So if the Psalm binary is in the same directory as the scripts, then just change 'psalm' to './psalm' in the advanced demo programs to make it work. Also, please check if the mentioned library 'libgtk-3.so' exists on your system. Some systems use 'libgtk-3.so.0' for example. function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc psalm
comm "DEF libc.so int abs float" comm "EXE abs 1.234"; result=${answer} comm "EXIT"
echo $result result : 1096905796 The last result is obviously not the result that is desired. You're right, the ABS function in C doesn't work that way. You seem to be looking for a function which can round a float value towards an integer? If so, you have to use LRINT instead. So the following will work: #!/usr/bin/env bash
function comm { echo "${@}" >&"${COPROC[1]}" read answer <&"${COPROC[0]}" }
coproc ./psalm comm "DEF libm.so long lrint double" comm "EXE lrint 1.234"; result=${answer} comm "EXIT"
echo ${result}
The result of this is '1' as expected. HTH Peter
|
|
|
Post by Pjot on Nov 20, 2022 16:14:26 GMT 1
Hi rikky,
Looking further, I eventually found an issue when using Psalm in CentOS 7 with GTK2. This is fixed in 1.0.1 (site updated).
Hope updated version works for you,
Thanks, Peter
|
|
|
Post by rikky on Nov 21, 2022 7:36:20 GMT 1
Ja, now its working. That means that I have to do something like 'cd $(dirname $0)' first, for on my system such a script starts always in the 'home' working directory. I get a nice calendar, and If I 'press me' AND echo $cb then I get a number. This is supposedly a pointer to the response. By now I should be able to figure out how to get this response if I research the other gtk programs that are already somewhere. Thanks Rik.
|
|
|
Post by alexfish on Nov 21, 2022 14:00:53 GMT 1
Hi Peter Tested gtk demo1 on pi4 Ubuntu 20.10 = OK thought about using BaCon gtk ui to get scripts to load rename say demobash1.bac UI , load / demobash1.bac the from terminal : | { ./psalm | ./demobash1.bac; } > /dev/fd/0 ADDED: just a thought Sometime ago I did a BaCon SEDIT editor with a terminal (gtk2) if can resurrect it will post in due course ... BR Alex Attachments:
|
|
|
Post by alexfish on Nov 21, 2022 14:15:48 GMT 1
Hi All Original SEDIT1 HEREif find updated will post further on Ubuntu 20.10 ADDED : vte9 parsing ';}' problems maybe to old Sedit sourceview2 not avalable substitute SEDIT for EDIT Bigbass did a HUG3 , will see if can convert to HUG3 the problem there is the realize vte command, it is different & what can I say , 7years I did a vte3 sometime ago, not sure if it was posted, doing a search on both BR Alex
|
|
|
Post by alexfish on Nov 21, 2022 16:15:51 GMT 1
Agh. BaCon Scratch Pad
CHANGEDIR "bacon" SYSTEM (": | { ./psalm | ./demobash.bac; } > /dev/fd/0 &")
BR Alex
|
|
|
Post by Pjot on Nov 22, 2022 6:43:52 GMT 1
Thanks rikky and alexfish for checking out the 'psalm' tool. Glad to see things have worked out well.
In the upcoming days, I will add more demonstration scripts in other languages, to demonstrate how it works there (Expect and LUA already added).
BR Peter
|
|
|
Post by alexfish on Nov 23, 2022 1:22:51 GMT 1
Hi Peter
would be possible to have text only so I can wget it
BR Alex
|
|