lua_api.hpp 1.5 KB

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