Is there an easy way to convert Inline::C code to XS?If you run with the Inline::C Config option 'CLEAN_AFTER_BUILD => 0', then after compilation you can go into the build directory and grab the actual XS file that Inline::C auto-generated. You can then package that with an appropriate Makefile.PL, test suite, etc. into a normal cpan-type distro. You'll need to edit the 'MODULE' and 'PACKAGE' entries in the auto-generated XS file but, iirc, that's the only change you'll have to make.
Alternatively, you could try Inline::C2XS (which I wrote and put on CPAN). It works ok for me - but it's not exactly a great piece of work, and ymmv :-) The
correct thing for Inline::C2XS would be to tap into the XS-generating code that Inline::C uses - but it doesn't do that. Anyway, here's the IdleTime.xs file that Inline::C2XS produces for me. (I believe it's correct.)
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/scrnsaver.h>
int GetIdleTime () {
time_t idle_time;
static XScreenSaverInfo *mit_info;
Display *display;
int screen;
mit_info = XScreenSaverAllocInfo();
if((display=XOpenDisplay(NULL)) == NULL) { return(-1); }
screen = DefaultScreen(display);
XScreenSaverQueryInfo(display, RootWindow(display,screen), mit
+_info);
XFree(mit_info);
XCloseDisplay(display);
idle_time = (mit_info->idle) / 1000;
return idle_time;
}
MODULE = X11::IdleTime PACKAGE = X11::IdleTime
PROTOTYPES: DISABLE
int
GetIdleTime ()
I couldn't quite make sense of the errors you reported - and don't have time to investigate. In the past I have used Inline::C and PAR. The Inline::C binaries need to be placed in a specifically-named location, and PAR mangles that location so that the files can't be found. The only way I ever got it to work was to include that "specifically-named" location as a separate folder alongside the PAR executable. I forget the details - it was something I did only as a "proof-of-concept" exercise. (There might well be a better solution.)
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.