Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/lua #42 #52

Merged
merged 3 commits into from
Apr 9, 2024
Merged

Feature/lua #42 #52

merged 3 commits into from
Apr 9, 2024

Conversation

sillydan1
Copy link
Owner

This PR adds Lua as an editor scripting language, enabling you to write plugins and edit keybinds from an init.lua file instead of through Java and GUIs. This is all possible due to gudzpoz's fantastic LuaJava project.

Notes

  • The init.lua file must be located in EditorActions.getConfigDir() + "/lua"
    • On MacOS: ~/Library/Application Support/Graphedit/lua
    • On Linux: ~/.local/graphedit/lua
    • On Windows: %APPDATA%\graphedit\lua (untested for now)
  • Take a look at the lua bindings types repository to get an idea of what is possible

Minimal Example

ge.log:info("Hello " .. ge.info.name .. " " .. ge.info.version .. "!")

-- Get stuff from the Dependency Injection container
-- TODO: manually importing like this may become a bit cumbersome, maybe we should add a helper function for this
local IBufferContainer = java.import("dk.gtz.graphedit.viewmodel.IBufferContainer")
ge.api.dep:get(IBufferContainer)

-- Add plugins
ge.api.add_plugin({
    name = "Example",
    description = "Example plugin",
    on_start = function()
        ge.log:info("Hello from the Example lua plugin!")
    end,
    on_destroy = function()
        ge.log:info("Goodbye from the Example lua plugin!")
    end,
    -- TODO: These are not supported yet, but I will add them if interest shows.
    -- syntax_factories = {},
    -- panels = {},
    -- importer = function(paths) end,
    -- exporter = function(resource, new_path) end,
})

-- This will overwrite the default keymap if you add a keymap with the same key combination
ge.api.keymap.set("Shortcut+K", function() ge.api.toast:success("Hello from the keymap!") end, "Greeter")
ge.api.keymap.set_in_category("Shortcut+Shift+L", function() ge.api.action:openKeybinds() end, "Open Keybinds", "help")

This is almost too easy...

wip: add todos

wip

wip
@sillydan1 sillydan1 self-assigned this Apr 9, 2024
@sillydan1 sillydan1 changed the base branch from main to dev April 9, 2024 05:32
@sillydan1
Copy link
Owner Author

This PR fixes #42

@sillydan1 sillydan1 force-pushed the feature/lua-#42 branch 2 times, most recently from d2f2dcf to a05302d Compare April 9, 2024 05:41
@sillydan1 sillydan1 merged commit bc86aed into dev Apr 9, 2024
3 checks passed
@sillydan1 sillydan1 deleted the feature/lua-#42 branch April 9, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant