#ifndef _H_SCRIPT_H
#define _H_SCRIPT_H

#define SOL_ALL_SAFETIES_ON 1

#include <chrono>
#include <memory>
#include <sol/sol.hpp>

class Script {
public:
  sol::state lua;
  Script(const std::string &str);
  ~Script();

private:
  bool loadScript(const std::string &str) {
    auto result = lua.script(str);
    if (!result.valid()) {
      sol::error err = result;
      std::cerr << "Failed to load script. Error: " << err.what() << std::endl;
    }
    return result.valid();
  }
  void registerGlobalUserTypes();
};

class AIScript : public Script {
public:
  AIScript(const std::string &str) : Script(str) { registerUserTypes(); }

  ~AIScript();

private:
  void registerUserTypes();
};

class WeaponScript : public Script {
public:
  WeaponScript(const std::string &str) : Script(str) { registerUserTypes(); }
  ~WeaponScript();

private:
  void registerUserTypes();
};

#endif // _H_SCRIPT_H
