Skip to content

fix(bluetooth): keep onConnect/onDisconnect passed through the export - #304

Open
mur4i wants to merge 1 commit into
Samuels-Development:mainfrom
mri-Qbox-Brasil:fix/bluetooth-export-callbacks
Open

mur4i wants to merge 1 commit into
Samuels-Development:mainfrom
mri-Qbox-Brasil:fix/bluetooth-export-callbacks

Conversation

@mur4i

@mur4i mur4i commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A function handed to registerBluetoothDevice from another resource arrives as a function reference (a table with a __call metamethod), not a Lua function. bluetooth.validate and safely in server/bluetooth/registry.lua both checked type(fn) == 'function', so onConnect and onDisconnect were dropped and the owning script never heard about connections. The sd-phone:server:bluetooth:connected / disconnected events still fire, which is how we worked around it.

This adds bluetooth.isCallable (a function, or a table whose metatable has __call) and uses it in both places.

Type of Change

  • Bug Fix
  • New Feature
  • Improvement / Refactor
  • Performance
  • Documentation
  • Compatibility
  • Other

Related Issues

None.

Testing

On a live server, two throwaway resources: one exported a function taking a callback, the other passed a function through it. On the receiving side the value was type=table with a metatable carrying __call, and calling it returned the callback's result. That is exactly the shape the old check rejected.

The changed files were also run through a Lua parser.

  • Tested locally
  • Tested with latest sd-phone
  • Tested with latest ox_lib
  • Tested with latest ox_inventory
  • Multiplayer tested

Breaking Changes

None. Plain Lua functions pass as before; values that are neither functions nor callable tables are still ignored.


Checklist

  • My code follows the existing style of the project.
  • I have tested my changes.
  • I have updated any necessary documentation.
  • I have removed any debug code.
  • This PR does not include unrelated changes.
  • I have verified this works on the latest version of sd-phone.

A function handed to registerBluetoothDevice from another resource arrives as a function
reference (a table with __call), so the type(...) == 'function' check dropped it and the
owning script never heard about connections. Accept any callable value.
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