#pragma once #include #include #include #include #include namespace scripting { struct null {}; struct array; using script_value = std::variant; struct script_variable { std::string name; }; struct code_location { std::shared_ptr line_contents; int32_t line_number; int32_t column_number; }; struct script_error { std::shared_ptr location; std::string message; }; struct array { std::vector value; operator std::vector&() { return value; } }; using argument = std::variant; class UserScript; struct function_impl { virtual std::optional apply(UserScript* self, std::vector, std::optional&) = 0; virtual ~function_impl() = default; }; using function = std::unique_ptr; class UserScript { public: virtual std::optional> getValue(const std::string& name) = 0; virtual bool setValue(const std::string& name, script_value value) = 0; virtual void registerFunction(std::string name, function fn) = 0; virtual script_value resolve(const std::string& name) = 0; virtual std::variant> executeAtOnce(std::string code) = 0; virtual std::vector prepare(std::string code) = 0; virtual std::optional stepOnce() = 0; virtual ~UserScript() = default; }; std::unique_ptr prepare_interpreter(const std::string& code); }