#ifndef CAMELLYA_STATE_H #define CAMELLYA_STATE_H #include "lexer.h" #include "parser.h" #include "interpreter.h" #include "value.h" #include #include namespace camellya { // Main state class - similar to lua_State class State { public: State(); ~State() = default; // Execute script from string bool do_string(const std::string& script); // Execute script from file bool do_file(const std::string& filename); // Register native function void register_function(const std::string& name, NativeFunction func); // Get global variable ValuePtr get_global(const std::string& name); // Set global variable void set_global(const std::string& name, ValuePtr value); // Stack operations (Lua-like API) void push_number(double value); void push_string(const std::string& value); void push_bool(bool value); void push_nil(); void push_value(ValuePtr value); double to_number(int index); std::string to_string(int index); bool to_bool(int index); ValuePtr to_value(int index); int get_top() const { return static_cast(stack_.size()); } void set_top(int index); void pop(int n = 1); // Error handling const std::string& get_error() const { return last_error_; } private: std::unique_ptr interpreter_; std::vector stack_; std::string last_error_; ValuePtr get_stack_value(int index); }; } // namespace camellya #endif // CAMELLYA_STATE_H