1 #include "yobaperl/perl_stack.hpp" 2 #include "yobaperl/perl.hpp" 4 namespace yoba {
namespace priv {
8 PerlStack::PerlStack(Perl & perl)
10 _interpreter(perl.getInterpreter()),
18 PerlStack::~PerlStack()
27 void PerlStack::extend(ssize_t size)
32 void PerlStack::pushSV(SV * sv,
bool extend)
40 SV * PerlStack::popSV()
45 void PerlStack::pushScalar(Scalar arg)
47 pushSV(arg.detachMortalSV(),
true);
50 void PerlStack::pushArray(Array args)
52 extend(args.getSize());
53 for(
int i = 0; i < args.getSize(); i++)
54 pushSV(args[i].detachMortalSV(),
false);
57 Scalar PerlStack::popScalar()
59 YOBAPERL_ASSERT(_returns_count == 1);
60 return Scalar(_perl, popSV(),
true);
63 Array PerlStack::popArray()
65 YOBAPERL_ASSERT(_returns_count != -1);
67 AV * result = av_make(_returns_count, SP - _returns_count + 1);
69 return Array(_perl, result,
false);
72 void PerlStack::call(Code code, I32 flags)
75 _returns_count = call_sv(code.detachSV(), flags);
80 if(_returns_count > 0)
83 if(_perl.isExceptionsEnabled())
84 throw PerlException(_perl.getId(), _perl.getError());
86 if(_perl.isWarningsEnabled())
87 warn(
"%s", _perl.getError().c_str());
91 void PerlStack::callMethod(Code code, I32 flags)
97 _returns_count = call_sv(code.detachSV(), flags | G_METHOD);
102 if(_returns_count > 0)
105 if(_perl.isExceptionsEnabled())
106 throw PerlException(_perl.getId(), _perl.getError());
108 if(_perl.isWarningsEnabled())
109 warn(
"%s", _perl.getError().c_str());
113 void PerlStack::eval(
const std::string & code, I32 flags)
116 #ifdef YOBAPERL_MULTIPLICITY 123 _returns_count = eval_sv(_perl.newScalar(code).detachMortalSV(), flags);
126 catch(
const PerlException & e)
129 throw PerlException(e.getPerlId(), e.getInfo(), code);
134 if(_returns_count > 0)
137 if(_perl.isExceptionsEnabled())
138 throw PerlException(_perl.getId(), _perl.getError(), code);
140 if(_perl.isWarningsEnabled())
141 warn(
"%s\nCode:\n%s", _perl.getError().c_str(), code.c_str());