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

feat(Lua): add event scripting via Lua #239

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

ShadowApex
Copy link
Contributor

@ShadowApex ShadowApex commented Nov 27, 2024

This change adds Lua scripting support for custom input routing. Users can now write Lua scripts to add custom input routing and translation logic that can be executed on every input event in the input pipeline.

Whenever a new composite device is initialized, each composite device instantiates its own Lua runtime instance and will load any lua scripts from the following directories:

  • /etc/inputplumber/scripts.d
  • /usr/share/inputplumber/scripts

Each script should return a lua table containing function(s) that will get executed by the composite device at certain stages of the input processing pipeline. This can allow users to easily implement their own custom input routing logic.

It can also be used as a pretty nice debugging tool. For example, this script will print whenever certain input events are emitted:

-- preprocess_event is called on every input event -before- capability mapping
-- and input profile translation.
local preprocess_event = function(event)
  if event.capability == "Gamepad:Button:Guide" then
    print("Guide button event:", event.value)
  end
  
  return true
end

return {
  preprocess_event = preprocess_event,
}

Fixes #238

@ShadowApex ShadowApex requested a review from pastaq November 27, 2024 05:21
@ShadowApex ShadowApex force-pushed the shadowapex/lua branch 2 times, most recently from cc917f7 to db07126 Compare November 27, 2024 05:37
@pastaq
Copy link
Contributor

pastaq commented Nov 27, 2024

Neat

@R1kaB3rN
Copy link

Question: Why did you decide to make the event scripting feature required and not optional instead?

As an enhancement, if the feature is intended to be included by default, I think it would be a plus to allow it be disabled when compiling Input Plumber.

@ShadowApex
Copy link
Contributor Author

Question: Why did you decide to make the event scripting feature required and not optional instead?

As an enhancement, if the feature is intended to be included by default, I think it would be a plus to allow it be disabled when compiling Input Plumber.

We can make this feature optional via a compilation flag. It does not need to be required.

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.

[Feature] Add Lua scripting support
3 participants