Hello fellow Perl fans, I'm currently working on a Lua-Perl bridge, and I'm implementing a function perl.require that loads a Perl module from Lua, in the same manner as CORE::require. The usage is as follows:
require 'perl' perl.require 'Scalar::Util'
This works fine, but if I'm missing a module...
require 'perl' perl.require 'Doesnt::Exist::Yet'
In this case, Perl dies with a module not found error and calls exit(). Here's my implementation of perl.require:
static int perl_interp_require(lua_State *L) { size_t len; const char *modname; SV *modnameSv; modname = luaL_checklstring(L, 1, &len); modnameSv = newSVpvn(modname, len); /* Exits on failure */ load_module(PERL_LOADMOD_NOIMPORT, modnameSv, NULL); check_perl_error(L, 1); // left out for brevity; checks $@ return 0; }
Is there a way to catch any errors that load_module may throw? I did a quick search for "perl xs load_module catch die", but it yielded nothing useful. Thanks for any and all help! -Rob

In reply to Catching a die in Perl XS by robhoelz

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.