robhoelz has asked for the wisdom of the Perl Monks concerning the following question:
This works fine, but if I'm missing a module...require 'perl' perl.require 'Scalar::Util'
In this case, Perl dies with a module not found error and calls exit(). Here's my implementation of perl.require:require 'perl' perl.require 'Doesnt::Exist::Yet'
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! -Robstatic 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Catching a die in Perl XS
by ikegami (Patriarch) on Jun 02, 2010 at 19:44 UTC |