as_outputbuffer.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2012 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. andreas@angelcode.com
  22. */
  23. //
  24. // as_outputbuffer.cpp
  25. //
  26. // This class appends strings to one large buffer that can later
  27. // be sent to the real output stream
  28. //
  29. #include "as_config.h"
  30. #ifndef AS_NO_COMPILER
  31. #include "as_outputbuffer.h"
  32. #include "as_scriptengine.h"
  33. BEGIN_AS_NAMESPACE
  34. asCOutputBuffer::~asCOutputBuffer()
  35. {
  36. Clear();
  37. }
  38. void asCOutputBuffer::Clear()
  39. {
  40. for( asUINT n = 0; n < messages.GetLength(); n++ )
  41. {
  42. if( messages[n] )
  43. {
  44. asDELETE(messages[n],message_t);
  45. }
  46. }
  47. messages.SetLength(0);
  48. }
  49. void asCOutputBuffer::Callback(asSMessageInfo *msg)
  50. {
  51. message_t *msgInfo = asNEW(message_t);
  52. if( msgInfo == 0 )
  53. return;
  54. msgInfo->section = msg->section;
  55. msgInfo->row = msg->row;
  56. msgInfo->col = msg->col;
  57. msgInfo->type = msg->type;
  58. msgInfo->msg = msg->message;
  59. messages.PushLast(msgInfo);
  60. }
  61. void asCOutputBuffer::Append(asCOutputBuffer &in)
  62. {
  63. for( asUINT n = 0; n < in.messages.GetLength(); n++ )
  64. messages.PushLast(in.messages[n]);
  65. in.messages.SetLength(0);
  66. }
  67. void asCOutputBuffer::SendToCallback(asCScriptEngine *engine, asSSystemFunctionInterface *func, void *obj)
  68. {
  69. for( asUINT n = 0; n < messages.GetLength(); n++ )
  70. {
  71. asSMessageInfo msg;
  72. msg.section = messages[n]->section.AddressOf();
  73. msg.row = messages[n]->row;
  74. msg.col = messages[n]->col;
  75. msg.type = messages[n]->type;
  76. msg.message = messages[n]->msg.AddressOf();
  77. if( func->callConv < ICC_THISCALL )
  78. engine->CallGlobalFunction(&msg, obj, func, 0);
  79. else
  80. engine->CallObjectMethod(obj, &msg, func, 0);
  81. }
  82. Clear();
  83. }
  84. END_AS_NAMESPACE
  85. #endif // AS_NO_COMPILER