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

Add basic lua scripting capabilities #4341

Merged
merged 157 commits into from
Apr 2, 2023
Merged

Add basic lua scripting capabilities #4341

merged 157 commits into from
Apr 2, 2023

Conversation

Mm2PL
Copy link
Collaborator

@Mm2PL Mm2PL commented Jan 29, 2023

Pull request checklist:

  • CHANGELOG.md was updated, if applicable

Description

Aware chatterino getting plugins
Example plugin: https://github.com/mm2pl/chatterino-test-plugin
Place in: Chatterino app directory -> Plugins -> test_plugin, then type testing into any chat and notice a bunch of text pop up in the channel. Use /eval to evaluate lua code in the context of the test plugin.
Tree should look like this:

chatterino/Plugins/
└── test_plugin
    ├── index.lua
    ├── info.json
    └── LICENSE

TODO:

  • Add reloading
  • Add some kind of settings thing and an info json or something
  • rebuild settings UI on reload of plugin
  • add lua license to settings
  • finalize most basic apis and document them, http (another PR) -- will not touch APIs in this PR
  • Add a Enable this functionality switch because plugins can probably lead to executing binaries (which is probably
    not desired xd)
    it's probably not that easy anymore, as direct bytecode execution and dedicated functions for this are blocked
  • replace print with a qCInfo call ended up doing qCDebug equivalent + apis to do proper logging
  • add a description on what lua plugins can do
  • add an option to disable any plugins wanting to use dangerous apis, check it by default permission system material
  • Assess the sandboxing of lua, what it could do, how the user's system could be attacked. Plugins can use io, package and os libraries to read/write files, and execute binaries (most notable functions are io.popen, os.execute) Plugins can only use the safe part of the stdlib
  • future PR material: Make a version of package that does not have the ability to load native shared libraries, it's nice to have multi-file plugins, you can use loadfile instead i guess
  • make the chatterino lua api be in a lua namespace
  • check when lua's shared library loading is enabled it's impossible to load native code without require() or package.loadlib, both of which are blocked
  • add tests?

Later plans/ideas:

  • plugin settings api, each plugin would get a file it gets to save stuff in
  • custom completion api, i have this basically ready

Unrelated changes:

  • fixes prettier CI to make it print a diff as it should.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/controllers/plugins/PluginController.cpp Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/controllers/plugins/PluginController.cpp Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.hpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.hpp Outdated Show resolved Hide resolved
@Mm2PL Mm2PL marked this pull request as ready for review February 2, 2023 13:37
@Mm2PL Mm2PL requested a review from pajlada February 2, 2023 18:26
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some really minor stuff I found when trying this PR.

CMakeLists.txt Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/PluginController.hpp Outdated Show resolved Hide resolved
docs/wip-plugins.md Outdated Show resolved Hide resolved
docs/wip-plugins.md Show resolved Hide resolved
src/controllers/plugins/PluginController.cpp Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
docs/wip-plugins.md Show resolved Hide resolved
docs/wip-plugins.md Outdated Show resolved Hide resolved
docs/wip-plugins.md Outdated Show resolved Hide resolved
lib/lua/CMakeLists.txt Show resolved Hide resolved
src/controllers/plugins/Plugin.hpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.hpp Outdated Show resolved Hide resolved
src/controllers/plugins/LuaApi.hpp Outdated Show resolved Hide resolved
src/controllers/plugins/LuaApi.hpp Outdated Show resolved Hide resolved
src/controllers/plugins/LuaApi.cpp Outdated Show resolved Hide resolved
@Mm2PL Mm2PL requested a review from pajlada February 14, 2023 19:38
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/common/QLogging.cpp Show resolved Hide resolved
src/common/QLogging.cpp Show resolved Hide resolved
src/common/QLogging.hpp Show resolved Hide resolved
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 83. Check the log or trigger a new build to see more.

src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 58. Check the log or trigger a new build to see more.

src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
src/controllers/plugins/LuaAPI.cpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.cpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.cpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.cpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.cpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.hpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.hpp Show resolved Hide resolved
src/controllers/plugins/LuaUtilities.hpp Show resolved Hide resolved
src/controllers/plugins/Plugin.cpp Show resolved Hide resolved
@pajlada pajlada merged commit 5ba8098 into master Apr 2, 2023
@pajlada pajlada deleted the feature/lua_scripting branch April 2, 2023 13:31
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.

3 participants