#include <string>
#include "Component.h"
#include <yaml-cpp/yaml.h>
#include <chrono>


extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

struct LuaCallInfo {
    std::string name;
    std::chrono::high_resolution_clock::time_point start;
};


class ScriptComponent : public Component {
public:
    ScriptComponent(Object* owner);
    ~ScriptComponent();

    void SetScriptPath(const std::string& path);
    const std::string& GetScriptPath() const;

    virtual std::string GetName() const override { return "ScriptComponent"; }
    virtual void Save(YAML::Emitter& out) const override;
    virtual void Load(const YAML::Node& node) override;

    void ReloadScript();
    void OnUpdate(float dt);

private:
    std::string scriptPath;
    lua_State* L;

    std::vector<std::string> luaCallStack;
    static void Hook(lua_State* L, lua_Debug* ar);



    void RegisterEngineBindings();
};
