ERMScriptModule.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * ERMScriptModule.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "ERMScriptModule.h"
  12. #include "ERMInterpreter.h"
  13. #ifdef __GNUC__
  14. #define strcpy_s(a, b, c) strncpy(a, c, b)
  15. #endif
  16. const char *g_cszAiName = "(V)ERM interpreter";
  17. extern "C" DLL_EXPORT void GetAiName(char* name)
  18. {
  19. strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName);
  20. }
  21. extern "C" DLL_EXPORT void GetNewModule(std::shared_ptr<scripting::Module> &out)
  22. {
  23. out = std::make_shared<ERMScriptModule>();
  24. }
  25. ERMScriptModule::ERMScriptModule()
  26. {
  27. }
  28. std::string ERMScriptModule::compile(const std::string & name, const std::string & source, vstd::CLoggerBase * logger) const
  29. {
  30. std::shared_ptr<ERMInterpreter> interp = std::make_shared<ERMInterpreter>(logger);
  31. try
  32. {
  33. return interp->loadScript(name, source);
  34. }
  35. catch(const std::exception & ex)
  36. {
  37. logger->error(ex.what());
  38. }
  39. catch(const std::string & ex)
  40. {
  41. logger->error(ex);
  42. }
  43. catch(...)
  44. {
  45. logger->error("Sorry, caught unknown exception type. No more info available.");
  46. }
  47. return "";
  48. }
  49. std::shared_ptr<scripting::ContextBase> ERMScriptModule::createContextFor(const scripting::Script * source, const Environment * env) const
  50. {
  51. throw std::runtime_error("ERM context creation is not possible");
  52. }
  53. void ERMScriptModule::registerSpellEffect(spells::effects::Registry * registry, const scripting::Script * source) const
  54. {
  55. throw std::runtime_error("ERM spell effect registration is not possible");
  56. }