Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

...and whether this is worth pursuing further

hmm, I'll take that as a resounding "No!". Fair enough.

For completeness, heres what worked/sucked:

  • on Linux, only the original code worked - all other calls into the API seg faulted. Just dont know enough C/Perl/Linux to continue with this...
  • on Windows, I had reached scalar/array creation and manipulation, call_argv and eval_pv - tested and working. Using only the base SV type and a couple of #defines seemed to provide most of what youd likely need in terms of variable manipulation from C; assuming your not diotalevi ;-)
  • Getting DynaLoader working this way remains a mystery...
  • no stack manipulation...

Ive included the basic source that compiled on both platforms, as I will be removing the link in the OP. Maybe at least, this will be of some use to windows users that dont have MSVC... you may also be interested in these:

275516 - BrowserUks results compiling perl with bcc32
sieperl - binary perl builds with GPL/Artistic licensing.

#ifndef perlembed_h #define perlembed_h /* ** compilation examples for bcc32 and gcc linux ** bcc32 -DEMBED_WIN32 ** gcc -ldl -lpthread -DEMBED_LINUX ** ** int main(int argc, char** argv, char** env) ** { ** perlembed_setup("/path/to/libperl.so/or/perl58.dll"); ** perlembed_main(argc, argv, env); ** perlembed_teardown(); ** return 0; ** } **/ #ifdef EMBED_WIN32 #define WIN32_LEAN_AND_MEAN #include <windows.h> #endif #ifdef EMBED_LINUX #include <dlfcn.h> #endif int perlembed_setup(char* DllPath); void perlembed_main(int argc, char** argv, char** env); void perlembed_teardown(); void* perlembed_loadLibrary(char* DllPath); void* perlembed_getProcAddress(char* symbol); void perlembed_freeLibrary(void* perlDll); static struct { void* interpreter ; void* dll ; int loadedOK ; void* (*alloc) (); void (*construct) (void*); void (*parse) (void*, void*, int, char**, char**); void (*destruct) (void*); void (*free) (void*); void (*run) (void*); } perlembed; /* ** dynamically links to the appropriate perl library */ int perlembed_setup( char* DllPath ) { if(perlembed.loadedOK ) return 1; perlembed.dll = perlembed_loadLibrary(DllPath); if(perlembed.dll) { perlembed.alloc = perlembed_getProcAddress("perl_alloc"); perlembed.construct = perlembed_getProcAddress("perl_construct"); perlembed.parse = perlembed_getProcAddress("perl_parse"); perlembed.destruct = perlembed_getProcAddress("perl_destruct"); perlembed.free = perlembed_getProcAddress("perl_free"); perlembed.run = perlembed_getProcAddress("perl_run"); perlembed.interpreter= perlembed.alloc(); perlembed.construct( perlembed.interpreter ); perlembed.loadedOK = 1; return 0; } return 1; } /* ** frees the interpreter */ void perlembed_teardown() { if( !perlembed.loadedOK ) return; perlembed.free(perlembed.interpreter); perlembed.destruct(perlembed.interpreter); perlembed.loadedOK = 0; perlembed_freeLibrary( perlembed.dll ); } /* ** runs as perl with the given commandline */ void perlembed_main(int argc, char** argv, char** env) { if( !perlembed.loadedOK ) return; perlembed.parse(perlembed.interpreter, 0, argc, argv, env); perlembed.run(perlembed.interpreter); } void* perlembed_getProcAddress(char* symbol) { #ifdef EMBED_WIN32 return GetProcAddress( perlembed.dll, symbol ); #endif #ifdef EMBED_LINUX return dlsym(perlembed.dll, symbol); #endif } void* perlembed_loadLibrary(char* DllPath) { #ifdef EMBED_WIN32 return LoadLibrary(DllPath); #endif #ifdef EMBED_LINUX return dlopen(DllPath, RTLD_LAZY|RTLD_GLOBAL); #endif } void perlembed_freeLibrary(void* perlDll) { #ifdef EMBED_WIN32 FreeLibrary( perlDll ); #endif #ifdef EMBED_LINUX dlclose(perlDll); #endif } #endif



time was, I could move my arms like a bird and...

In reply to Re: poor mans embedding by Ctrl-z
in thread poor mans embedding by Ctrl-z

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found