| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #pragma once
- #include "lumacs/editor_core.hpp"
- #include "lumacs/theme.hpp"
- #include "lumacs/keybinding.hpp"
- #include <sol/sol.hpp>
- #include <functional>
- #include <map>
- #include <string>
- namespace lumacs {
- class EditorCore; // Forward declaration
- /// Lua scripting API for Lumacs
- class LuaApi {
- public:
- explicit LuaApi(); // Default constructor
- ~LuaApi() = default;
- /// Set the EditorCore instance after construction
- void set_core(EditorCore& core);
- /// Get the Lua state
- [[nodiscard]] sol::state& state() { return lua_; }
- /// Load and execute a Lua file
- bool load_file(const std::filesystem::path& path);
- /// Execute Lua code
- bool execute(std::string_view code);
- /// Load init.lua from standard locations
- bool load_init_file();
- /// Bind a key to a Lua function (uses new keybinding system)
- void bind_key(std::string key, sol::function callback, std::string description = "");
- /// Process key using the new keybinding system
- KeyResult process_key(const std::string& key);
- /// Get all key bindings (for debugging) - Legacy method
- [[nodiscard]] std::map<std::string, sol::function> key_bindings() const {
- return legacy_key_bindings_;
- }
- // Legacy methods for backward compatibility
- [[nodiscard]] bool has_key_binding(const std::string& key) const;
- bool execute_key_binding(const std::string& key);
- private:
- sol::state lua_;
- EditorCore* core_ = nullptr; // Changed to pointer
- std::map<std::string, sol::function> legacy_key_bindings_; // For backward compatibility
- void setup_api();
- void register_types();
- void register_functions();
- };
- } // namespace lumacs
|