LuaScriptModule.cpp 1.5 KB

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