1. Automating GUI's using Euphoria
- Posted by bayes1963 Jan 20, 2013
- 1590 views
Hi,
I'm a fairly long time user of Euphoria, although still using version 3.1.1 and I would like to be able to use it for automating GUI's (mainly for the purpose creating "bots" for online games). Some of you might be aware of Autoit for windows which is a Basic-like language for doing the same. Autoit is good, but it's not as powerful as Euphoria and it's much slower, also it runs on windows only. After some searching, I came across a Python package called Autopy ( http://www.autopy.org ) which seems to meet the requirements and looks fairly simple, so I was wondering how easy it would be to "wrap" the C source code so that the functions can be used by Euphoria? Unfortunately I have no idea how to do this (I've looked at the simple examples for wrapping a C function in the docs, but I don't know C and am clueless where to start with a more ambitious project like this).
So I thought I'd post here in the hope that some more experienced/knowledgeable Euphoria user might be interested in tackling this task, or perhaps could give me a few pointers, I'm also prepared to pay someone to do the job, if necessary.
Thanks and look forward to some feedback!
2. Re: Automating GUI's using Euphoria
- Posted by bayes1963 Jan 21, 2013
- 1488 views
I'm not even sure if it's possible to create a dll from a Python package, am I completely barking up the wrong tree here? I found a similar topic on this forum and see that there's a library listed in the rapideuphoria.com archive, but it's not really sufficient for my needs.
3. Re: Automating GUI's using Euphoria
- Posted by bugmagnet Jan 21, 2013
- 1507 views
It is possible to create a (COM/ActiveX) DLL from Perl using ActiveState's PDK, and also for Tcl (when I find the link) so it should be possible to do the same for Python or any other scripting language.
4. Re: Automating GUI's using Euphoria
- Posted by bayes1963 Jan 21, 2013
- 1523 views
Thanks bugmagnet. I recall that Greg Haberek said he was going to write a tutorial on wrapping C functions, I wonder if he's got around to it yet?
5. Re: Automating GUI's using Euphoria
- Posted by ghaberek (admin) Jan 22, 2013
- 1471 views
After some searching, I came across a Python package called Autopy ( http://www.autopy.org ) which seems to meet the requirements and looks fairly simple, so I was wondering how easy it would be to "wrap" the C source code so that the functions can be used by Euphoria?
Just glancing at that library, I imagine it will be pretty difficult to wrap into Euphoria since it is written to export PyObject objects and complies with Python's external API. It would probably be easier to gut the raw C code out of the library, compile it directly, and then wrap that. In which case, you'd end up with an almost entirely different library.
Thanks bugmagnet. I recall that Greg Haberek said he was going to write a tutorial on wrapping C functions, I wonder if he's got around to it yet?
I still plan to, I just haven't had a lot of time. I'm waiting for the "right" project to come along when I have to wrap a library that is relatively straightforward yet complex enough to show most of the intricacies involved. Then I can document the process in a tutorial as I go.
-Greg
6. Re: Automating GUI's using Euphoria
- Posted by EUWX Jan 22, 2013
- 1415 views
I still plan to, I just haven't had a lot of time. I'm waiting for the "right" project to come along when I have to wrap a library that is relatively straightforward yet complex enough to show most of the intricacies involved. Then I can document the process in a tutorial as I go.
-Greg
You are already working on wxEuphoria which "is relatively straightforward" and presumably will "show most of the intricacies involved."
7. Re: Automating GUI's using Euphoria
- Posted by jimcbrown (admin) Jan 22, 2013
- 1398 views
I still plan to, I just haven't had a lot of time. I'm waiting for the "right" project to come along when I have to wrap a library that is relatively straightforward yet complex enough to show most of the intricacies involved. Then I can document the process in a tutorial as I go.
-Greg
You are already working on wxEuphoria which "is relatively straightforward"
Not really ... that wraps C++ code using a custom C shim layer that complies with Euphoria's external API (E_OBJECT, E_SEQUENCE, etc). That's vastly more complex than what's typically necessary for a C library.
8. Re: Automating GUI's using Euphoria
- Posted by ghaberek (admin) Jan 22, 2013
- 1398 views
You are already working on wxEuphoria which "is relatively straightforward" and presumably will "show most of the intricacies involved."
You would think that, but surprisingly, that is not the case. wxEuphoria is written almost entirely in C++ and it "speaks Euphoria" by passing native Euphoria objects around (a lot of C++ hackery is involved here).
This is all you see in Euphoria:
(this is strictly an example)
constant WX_SOME_FUNCTION = define_c_func( wxEuphoria_dll, "some_function", {E_OBJECT}, E_OBJECT ) public function some_function( object param ) return c_func( WX_SOME_FUNCTION, {param} ) end function
And this is what what really happens in C++:
object WXEUAPI some_function( object param ) { wxDeRefDS( param ); // de-reference the object /* do something significant here */ // create a new sequence s1_ptr result = NewS1( 2 ); // store some values result->base[1] = someIntValue1; result->base[2] = someIntValue2; // return a sequence object return MAKE_SEQ( result ); }
Conversely, when most libraries that are "wrapped" in Euphoria, we do not have the option of creating this "shim" library, and so we must "speak C" to the library by allocating memory, peeking/poking values, calling functions by name, etc. In anything but the most trivial cases, some logic is required to ensure the Euphoria code will operate correctly, especially when it comes to understanding types and moving structures around in memory.
-Greg
9. Re: Automating GUI's using Euphoria
- Posted by mattlewis (admin) Jan 22, 2013
- 1397 views
You are already working on wxEuphoria which "is relatively straightforward" and presumably will "show most of the intricacies involved."
You would think that, but surprisingly, that is not the case. wxEuphoria is written almost entirely in C++ and it "speaks Euphoria" by passing native Euphoria objects around (a lot of C++ hackery is involved here).
Yes, the problem is that a library written in C++ that only provides a C++ interface is nearly impossible to wrap with anything but C++. Originally, I did some stuff to figure out how the compiler would mangle the names, but it was very time consuming, and made updates extremely difficult. You also ended up with different source files for different compilers (including different versions of the same compiler!) / platforms.
The amount of C++ involved in wrapping new methods is typically fairly small. I created some helper routines that do things like convert a sequence into a wxString and vice versa. There are also some macros that make wrapping constructors pretty painless. Most calls involve a couple of casts and most of the wrappers are very thin. There are some places where the C++ wrappers do a bit more in order to make the euphoria interface easier.
I believe that all of the wxWidgets language bindings take a similar approach, or include wxWidgets directly into their language runtime.
Matt
10. Re: Automating GUI's using Euphoria
- Posted by EUWX Jan 22, 2013
- 1371 views
You are already working on wxEuphoria which "is relatively straightforward" and presumably will "show most of the intricacies involved."
You would think that, but surprisingly, that is not the case. wxEuphoria is written almost entirely in C++ and it "speaks Euphoria" by passing native Euphoria objects around (a lot of C++ hackery is involved here).
Yes, the problem is that a library written in C++ that only provides a C++ interface is nearly impossible to wrap with anything but C++. Originally, I did some stuff to figure out how the compiler would mangle the names, but it was very time consuming, and made updates extremely difficult. You also ended up with different source files for different compilers (including different versions of the same compiler!) / platforms.
The amount of C++ involved in wrapping new methods is typically fairly small. I created some helper routines that do things like convert a sequence into a wxString and vice versa. There are also some macros that make wrapping constructors pretty painless. Most calls involve a couple of casts and most of the wrappers are very thin. There are some places where the C++ wrappers do a bit more in order to make the euphoria interface easier.
I believe that all of the wxWidgets language bindings take a similar approach, or include wxWidgets directly into their language runtime.
Matt
Thanks both of you, for the explanation. No wonder I am a total DUD when it comes to anything
C and C plusplus
11. Re: Automating GUI's using Euphoria
- Posted by bayes1963 Jan 23, 2013
- 1431 views
Just glancing at that library, I imagine it will be pretty difficult to wrap into Euphoria since it is written to export PyObject objects and complies with Python's external API. It would probably be easier to gut the raw C code out of the library, compile it directly, and then wrap that. In which case, you'd end up with an almost entirely different library. -Greg
Thanks for the feedback, Greg. By "entirely different", do you think it would be so different that the functions wouldn't work as originally intended?
I've found a possible alternative called "Xnee" which is an X event recorder/replayer - http://xnee.wordpress.com/ It doesn't have the bitmap functions like autopy, but it's a step in the right direction. This might even be useful for you guys, because it's designed to test GUI code.
Glad to hear you're still intending to write that tutorial.
12. Re: Automating GUI's using Euphoria
- Posted by ghaberek (admin) Jan 23, 2013
- 1310 views
Thanks for the feedback, Greg. By "entirely different", do you think it would be so different that the functions wouldn't work as originally intended?
No, I'm sure it would still work the same. You'd just have to gut the Python interface and re-wrap and/or call the C functions directly. I just wouldn't call it "autopy" anymore.
-Greg
13. Re: Automating GUI's using Euphoria
- Posted by bayes1963 Jan 24, 2013
- 1237 views
Greg, is it fair to say that you need more than a passing acquaintance with C in order to write a wrapper? so when you get around to writing your tutorial, it's unlikely that a complete C noob would get much out of it. It's something I've been meaning to learn, but it's not a very user-friendly language.
14. Re: Automating GUI's using Euphoria
- Posted by jimcbrown (admin) Jan 24, 2013
- 1234 views
is it fair to say that you need more than a passing acquaintance with C in order to write a wrapper?
I don't think it is. You don't need a c compiler to write a wrapper in Euphoria for a simple C library (nb1). You don't need to write any c code to write a wrapper in Euphoria. You'd need to have a little knowledge of C (e.g. what C_INT, C_CHAR, and C_POINTER represent) but nothing that can't be presented in a short tutorial.
so when you get around to writing your tutorial, it's unlikely that a complete C noob would get much out of it. It's something I've been meaning to learn, but it's not a very user-friendly language.
I'd go as far as to argue that knowing how to code in C is not required to do this.
nb1: There's a weird exception when a structure is passed by value. The only time I've encountered this is in pthread_join(). This is not trivial to solve - the guy who hit this solved it by writing a custom C wrapper.
15. Re: Automating GUI's using Euphoria
- Posted by ghaberek (admin) Jan 24, 2013
- 1343 views
is it fair to say that you need more than a passing acquaintance with C in order to write a wrapper?
I don't think it is. You don't need a c compiler to write a wrapper in Euphoria for a simple C library (nb1). You don't need to write any c code to write a wrapper in Euphoria. You'd need to have a little knowledge of C (e.g. what C_INT, C_CHAR, and C_POINTER represent) but nothing that can't be presented in a short tutorial.
Agreed. I'll make it as Euphoria-oriented as possible. A short "primer on C types" may be in order, but any other knowledge of C will not be necessary.
so when you get around to writing your tutorial, it's unlikely that a complete C noob would get much out of it. It's something I've been meaning to learn, but it's not a very user-friendly language.
I'd go as far as to argue that knowing how to code in C is not required to do this.
nb1: There's a weird exception when a structure is passed by value. The only time I've encountered this is in pthread_join(). This is not trivial to solve - the guy who hit this solved it by writing a custom C wrapper.
I ran into this when trying to wrap Allegro5. Specifically, the ALLEGRO_COLOR structure gets passed-by-value in and out of several functions (e.g. al_map_rgb). I ended up writing a shim library, which worked, but I feel a machine code function may be better (I think Matt originally suggested it). That idea is on the back burner for now, but I haven't given up.
-Greg
16. Re: Automating GUI's using Euphoria
- Posted by bayes1963 Jan 25, 2013
- 1251 views
Ok, so not much C knowledge required, cool. Greg, will you be uploading this tutorial to rapideuphoria.com when you've done it? or do you have your own site? Edit: Just had a look at your profile and see you have your own site; I'll keep an eye on it.
17. Re: Automating GUI's using Euphoria
- Posted by ghaberek (admin) Jan 25, 2013
- 1241 views
Ok, so not much C knowledge required, cool. Greg, will you be uploading this tutorial to rapideuphoria.com when you've done it? or do you have your own site?
I was going to add it to the MiniGuides page. There is already a guide on UsingDLLs but that is more a guide on converting Euphoria code to a DLL.
Edit: Just had a look at your profile and see you have your own site; I'll keep an eye on it.
My site is currently down while I work on some changes behind the scenes. In the mean time, you can visit http://code.haberek.org/ to view my BitBucket repositories.
-Greg