| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #pragma once
- #include "lumacs/editor_core.hpp"
- #include "lumacs/theme.hpp"
- #include <sol/sol.hpp>
- #include <functional>
- #include <map>
- #include <string>
- namespace lumacs {
- /// Lua scripting API for Lumacs
- class LuaApi {
- public:
- explicit LuaApi(EditorCore& core);
- ~LuaApi() = default;
- /// 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
- void bind_key(std::string key, sol::function callback);
- /// Check if a key has a binding
- [[nodiscard]] bool has_key_binding(const std::string& key) const;
- /// Execute key binding if it exists
- bool execute_key_binding(const std::string& key);
- /// Get all key bindings (for debugging)
- [[nodiscard]] std::map<std::string, sol::function> key_bindings() const {
- return key_bindings_;
- }
- private:
- sol::state lua_;
- EditorCore& core_;
- std::map<std::string, sol::function> key_bindings_;
- void setup_api();
- void register_types();
- void register_functions();
- };
- } // namespace lumacs
|