lua_api.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include "lumacs/editor_core.hpp"
  3. #include "lumacs/theme.hpp"
  4. #include <sol/sol.hpp>
  5. #include <functional>
  6. #include <map>
  7. #include <string>
  8. namespace lumacs {
  9. /// Lua scripting API for Lumacs
  10. class LuaApi {
  11. public:
  12. explicit LuaApi(EditorCore& core);
  13. ~LuaApi() = default;
  14. /// Get the Lua state
  15. [[nodiscard]] sol::state& state() { return lua_; }
  16. /// Load and execute a Lua file
  17. bool load_file(const std::filesystem::path& path);
  18. /// Execute Lua code
  19. bool execute(std::string_view code);
  20. /// Load init.lua from standard locations
  21. bool load_init_file();
  22. /// Bind a key to a Lua function
  23. void bind_key(std::string key, sol::function callback);
  24. /// Check if a key has a binding
  25. [[nodiscard]] bool has_key_binding(const std::string& key) const;
  26. /// Execute key binding if it exists
  27. bool execute_key_binding(const std::string& key);
  28. /// Get all key bindings (for debugging)
  29. [[nodiscard]] std::map<std::string, sol::function> key_bindings() const {
  30. return key_bindings_;
  31. }
  32. private:
  33. sol::state lua_;
  34. EditorCore& core_;
  35. std::map<std::string, sol::function> key_bindings_;
  36. void setup_api();
  37. void register_types();
  38. void register_functions();
  39. };
  40. } // namespace lumacs