LuaScriptModule.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * LuaScriptModule.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 "LuaScriptModule.h"
  12. #include "LuaScriptingContext.h"
  13. #include "LuaSpellEffect.h"
  14. #ifdef __GNUC__
  15. #define strcpy_s(a, b, c) strncpy(a, c, b)
  16. #endif
  17. static const char * const g_cszAiName = "Lua interpreter";
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. extern "C" DLL_EXPORT void GetAiName(char * name)
  20. {
  21. strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName);
  22. }
  23. extern "C" DLL_EXPORT void GetNewModule(std::shared_ptr<scripting::Module> & out)
  24. {
  25. out = std::make_shared<scripting::LuaScriptModule>();
  26. }
  27. namespace scripting
  28. {
  29. LuaScriptModule::LuaScriptModule() = default;
  30. LuaScriptModule::~LuaScriptModule() = default;
  31. std::string LuaScriptModule::compile(const std::string & name, const std::string & source, vstd::CLoggerBase * logger) const
  32. {
  33. //TODO: pre-compile to byte code
  34. //LuaJit bytecode in architecture agnostic, but is not backward compatible and completely incompatible with Lua
  35. return source;
  36. }
  37. std::shared_ptr<ContextBase> LuaScriptModule::createContextFor(const Script * source, const Environment * env) const
  38. {
  39. return std::make_shared<LuaContext>(source, env);
  40. }
  41. void LuaScriptModule::registerSpellEffect(spells::effects::Registry * registry, const Script * source) const
  42. {
  43. registry->add(source->getName(), std::make_shared<spells::effects::LuaSpellEffectFactory>(source));
  44. }
  45. }
  46. VCMI_LIB_NAMESPACE_END