lua_api.hpp 1.2 KB

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