|
Someone pointed out that there were no attachments; my mistake! Also, here is the error message I'm seeing: lua: fail.lua:2: Can't load '/usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/auto/B/B.so' for module B: /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/auto/B/B.so: undefined symbol: PL_opargs at /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/XSLoader.pm line 64. at /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/B.pm line 316 Compilation failed in require at /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/Scalar/Util/PP.pm line 15. BEGIN failed--compilation aborted at /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/Scalar/Util/PP.pm line 15. Compilation failed in require at /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/Scalar/Util.pm line 21. Compilation failed in require at (eval 1) line 1. stack traceback: [C]: in function 'assert' fail.lua:2: in main chunk [C]: ? On Wed, 28 Apr 2010 16:08:42 -0500 Rob Hoelz <rob@hoelzro.net> wrote: > Hello lua-l, > > As indicated by my e-mail this morning, I'm writing a Lua-Perl bridge. > I've run into a bit of a snag. > > I've written perl.c, which currently just allows you to evaluate > strings of Perl code from Lua. However, when I load a dynamic module > from Perl (ex. Scalar::Util), I get errors relating to undefined > symbols. This probably stems from the fact that I have a standalone > Lua interpreter loading a shared object (perl.so) that loads another > shared object (libperl.so) that uses a dynamic loader (Perl's > DynaLoader) to load another shared object (in the case of > Scalar::Util, List/Util/Util.so). I understand the basics of > linking, but this is beyond my current knowledge. > > Attached are three files: > > - perl.c, which defines the Lua bindings to my Perl bridge. > - Makefile - self explanatory > - fail.lua - After running make, run 'lua fail.lua' and you'll see the > errors. > > Note: If I compile my perl.c into standalone Lua, fail.lua passes > fine. > > I should specify that I'm on 64-bit Fedora 12. > > If anyone with a greater knowledge of linking could take a look at > this and give me any insight, I'd be very grateful. > > Thanks, > Rob Hoelz
local perl = require 'perl' assert(perl.eval [[ require Scalar::Util; ]])
Attachment:
Makefile
Description: Binary data
#include <EXTERN.h> #include <perl.h> #include <lua.h> #include <lauxlib.h> #include <lualib.h> static PerlInterpreter *my_perl; /********************************* Utilities **********************************/ void push_sv(lua_State *L, SV *sv) { if(! SvOK(sv)) { lua_pushnil(L); } else if(SvIOK(sv)) { lua_pushinteger(L, SvIV(sv)); } else if(SvNOK(sv)) { lua_pushnumber(L, SvNV(sv)); } else if(SvPOK(sv)) { lua_pushstring(L, SvPVX(sv)); } else { printf("WTF!\n"); } } /******************************** Metamethods *********************************/ static int perl_interp_gc(lua_State *L) { perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); return 0; } static perl_interp_index(lua_State *L) { lua_getfenv(L, 1); lua_pushvalue(L, 2); lua_gettable(L, -2); return 1; } static luaL_Reg perl_interpreter_mmethods[] = { { "__gc", perl_interp_gc }, { "__index", perl_interp_index }, { NULL, NULL } }; /********************************** Methods ***********************************/ static int perl_interp_eval(lua_State *L) { SV *sv, *errsv; const char *perl = luaL_checkstring(L, 1); sv = eval_pv(perl, 0); errsv = get_sv("@", GV_ADD); if(SvOK(errsv) && SvCUR(errsv)) { lua_pushnil(L); push_sv(L, errsv); return 2; } else { push_sv(L, sv); return 1; } } static luaL_Reg perl_interpreter_methods[] = { { "eval", perl_interp_eval }, { NULL, NULL } }; /*************************** Module Initialization ****************************/ EXTERN_C void boot_DynaLoader(pTHX_ CV* cv); static void xs_init(pTHX) { char *file = __FILE__; newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); } int luaopen_perl(lua_State *L) { int fake_argc = 3; char *fake_argv[] = { "", "-e", "0" }; lua_newuserdata(L, 0); PERL_SYS_INIT(&fake_argc, &fake_argv); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, xs_init, fake_argc, fake_argv, NULL); luaL_newmetatable(L, "PerlInterpreter"); luaL_register(L, NULL, perl_interpreter_mmethods); lua_setmetatable(L, -2); lua_createtable(L, 0, sizeof(perl_interpreter_methods) / sizeof(luaL_Reg) - 1); luaL_register(L, NULL, perl_interpreter_methods); lua_setfenv(L, -2); lua_pushvalue(L, -1); lua_setglobal(L, "perl"); return 1; }
Attachment:
signature.asc
Description: PGP signature