Skip to content

chore: Add Lua sample scripts and sync fixes with Python variants#141

Open
hanatyan128 wants to merge 10 commits intodevfrom
chore-add-lua-sample-codes
Open

chore: Add Lua sample scripts and sync fixes with Python variants#141
hanatyan128 wants to merge 10 commits intodevfrom
chore-add-lua-sample-codes

Conversation

@hanatyan128
Copy link
Copy Markdown
Member

Summary

  • Add Lua sample scripts for recording-filename-from-text and replay-buffer-filename-from-text, mirroring the existing Python variants.
  • Enhance API.md / API_ja.md with a "Threading and Call Context" section, an "Obtaining the Filter Source" walkthrough, and notes on osi_branch_output_get_filter_list (private source exclusion, obs_module_post_load() timing, snapshot semantics).
  • Sync robustness fixes between the Lua and Python variants so both share: override_cleared flag, enhanced sanitize_filename (control chars / trailing dots/spaces / Windows reserved names), UTF-8/UTF-16 BOM handling with 4KB read limit, old-filter override clearing on selection change, filter ID validation with proc return-value logging, and a defensive timer_remove in script_load.

Test plan

  • Load each Lua sample script in OBS, verify the filename override updates as the text source changes
  • Load each Python sample script in OBS, verify the same behavior for parity
  • Switch the selected filter in the script properties and confirm the previous filter's override is cleared
  • Point the text source at a file with a UTF-8 BOM and confirm it is stripped; point it at a UTF-16 file and confirm the warning is logged
  • Unload/reload the script and confirm no duplicate timers via timer_remove + timer_add
  • Verify the API.md / API_ja.md rendering looks correct (new sections, notes)

🤖 Generated with Claude Code

@hanatyan128 hanatyan128 mentioned this pull request Apr 12, 2026
@hanatyan128 hanatyan128 added this to the 1.1.0 milestone Apr 12, 2026
@hanatyan128 hanatyan128 self-assigned this Apr 12, 2026
@tonywingmah
Copy link
Copy Markdown

I have tested the script and it seems to work very well.

  • Load each Lua sample script in OBS, verify the filename override updates as the text source changes
  • Load each Python sample script in OBS, verify the same behavior for parity
  • Switch the selected filter in the script properties and confirm the previous filter's override is cleared

My works flow is
4 x Google Sheets > Companion to scroll athletes > 4 x OBS Text Box > 4x Branch Output Lua Rename script > Record / Stop toggle.

I have modified the script for 4 simultaneous streams to be easier for volunteers.

@hanatyan128 hanatyan128 force-pushed the chore-add-lua-sample-codes branch 9 times, most recently from f9a2238 to 90cd399 Compare April 26, 2026 04:04
@hanatyan128 hanatyan128 force-pushed the chore-add-lua-sample-codes branch from 90cd399 to 288b272 Compare May 4, 2026 04:44
hanatyan128 and others added 10 commits May 4, 2026 13:48
Add Lua variants of recording-filename-from-text and
replay-buffer-filename-from-text sample scripts. Both include:
- Robust filename sanitization (control chars, trailing dots/spaces,
  Windows reserved names)
- UTF-8 BOM stripping and UTF-16 detection
- 4 KB read size limit for safety
- Filter id verification before proc calls
- Proper cleanup on filter selection change and script reload

Enhance API.md and API_ja.md with:
- Threading and call context requirements
- Filter source acquisition guide
- osi_branch_output_get_filter_list notes (post_load timing,
  private source exclusion)
- Sample scripts section covering both Python and Lua variants

Update README TIPS sections to mention both Python and Lua variants.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Align recording/replay-buffer filename-from-text sample scripts so the
Lua and Python variants share the same robustness fixes: version note
corrected to v1.0.9+, override_cleared flag to suppress redundant proc
calls, enhanced sanitize_filename (control chars, trailing dots/spaces,
Windows reserved names), BOM handling with 4KB read limit, old-filter
override clearing on selection change, filter ID validation with proc
return-value logging, and defensive timer_remove in script_load.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- onGetFilterList: dispatch to UI thread via QMetaObject::invokeMethod,
  with same-thread direct-call fallback to avoid BlockingQueuedConnection
  self-deadlock; null-out statusDock on module unload
- Sample scripts: reset last_text (and throttle state) on clear_override,
  warn on empty file path, extend Windows reserved-name check to cover
  base names with extensions (e.g. CON.txt)
- API docs: revise threading notes and add call-context guidance for
  osi_branch_output_get_filter_list

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…etime

Round 1-3 review findings across sample scripts and related native code:
- Lua sanitize_filename now normalizes NBSP/U+3000/ZWSP/U+2028/U+2029/BOM
- Document Windows ANSI code page limitation of Lua io.open
- statusDock promoted to std::atomic and unpublished before dock teardown
- Clarify callback safety and hotkey context in API docs
- Document lock ordering and proc_handler lifetime in native code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the per-byte-sequence gsub chain in sanitize_filename() with a
utf8.codes() walk driven by a strip/space lookup. Also folds the en/em
space family (U+2000–200A) for parity with the Python variant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Lua: replace Lua 5.3 utf8 library with LuaJIT-compatible manual
  UTF-8 decoder/encoder (utf8_codepoints, cp_to_utf8), removing
  dead code and misleading pcall warning
- C++: change JSON fallback from empty string to '{}' for safer
  downstream parsing
- Python: wrap calldata_create/calldata_free in try/finally to
  prevent leaks on exception
- Python: add MAX_SANITIZED_LENGTH=128 to sanitize_filename to
  avoid exceeding Windows MAX_PATH
Lua/Python scripts:
- Truncate sanitized filenames to 200 bytes with UTF-8 boundary respect
- Call clear_override() when text source is deselected in script_update()
- Validate empty base_format to prevent ambiguous empty overrides (Lua)
- Add group source limitation note to script_description()

C++:
- Use statusDock.store() instead of implicit operator= for consistency
- Fix comment: 'acquire/release semantics' -> 'sequential consistency'
- Clarify Q_DECLARE_METATYPE comment as qRegisterMetaType safety net
Trim review-round artifacts where long justification comments were
added to defend design choices. Replace prose with concise FIXMEs
where the root-cause fix is deferred. Drop internal-implementation
details from API.md / API_ja.md that callers do not need.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Defer last_text update to proc call success to prevent failed calls
  from being silently swallowed on subsequent ticks
- Fix 4-branch new_format logic in Python to match Lua (trailing space,
  unintended clear when base_format is empty)
- Add UTF-8 validation for non-UTF-8 file content (CP932 etc.)
- Add cp_to_utf8 surrogate-half guard
- Detect and warn on file truncation at MAX_READ_SIZE
- Unify sanitize_filename step order with Python variant
- Move MAX_FILENAME_BYTES to module-level constants
- Log warning on JSON parse failure
- Remove redundant state resets after clear_override()
@hanatyan128 hanatyan128 force-pushed the chore-add-lua-sample-codes branch from 288b272 to 40ec4c4 Compare May 4, 2026 16:59
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.

2 participants