Example #1
0
void ATemplateNodeHandler_LUA::Node::process(ATemplateContext& context, AOutputBuffer& output)
{
  AAutoPtr<AEventVisitor::ScopedEvent> scoped;
  if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) 
  {
    scoped.reset(new AEventVisitor::ScopedEvent(context.useEventVisitor(), ASW("ATemplateNodeHandler_LUA",24), m_BlockData, AEventVisitor::EL_DEBUG));
  }

  if (m_BlockData.isEmpty())
    return;

  ALuaTemplateContext *pLuaTemplateContext = dynamic_cast<ALuaTemplateContext *>(&context);
  if (pLuaTemplateContext)
  {
    //a_Have a Lua context with its own interpreter
    if (!pLuaTemplateContext->useLua().execute(m_BlockData, context, output))
    {
      output.append(" block(context)={{{\r\n",21);
      output.append(m_BlockData);
      output.append("}}}\r\n",5);
      context.useEventVisitor().addEvent(output, AEventVisitor::EL_ERROR);
    }
  }
  else
  {
    //a_Create a temporary interpreter, this is the less efficient way of doing it
    ALuaEmbed lua;
    if (!lua.execute(m_BlockData, context, output))
    {
      output.append(" block(local)={{{\r\n",19);
      output.append(m_BlockData);
      output.append("}}}\r\n",5);
      context.useEventVisitor().addEvent(output, AEventVisitor::EL_ERROR);
    }
  }
}