Skip to content

Conversation

@narknon
Copy link
Collaborator

@narknon narknon commented Oct 23, 2025

Description

Adds early termination support to ForEach loops for all container types (TArray, TMap, TSet, UDataTable).

Previously, ForEach implementations called lua.call_function() with 0 expected return values, meaning callbacks could not signal early termination. This forced users to iterate through entire collections even when they found their target element.

This PR updates all ForEach implementations to:

  1. Expect 1 return value from callbacks: lua.call_function(params, 1)
  2. Check if the return value is boolean true to break the loop
  3. Properly clean up the Lua stack for non-breaking iterations

The implementation follows the pattern already established by UEnum::ForEachName.

Example usage:

-- Stop iterating as soon as target is found
dataTable:ForEachRow(function(rowName, rowData)
    if rowName == "TargetRow" then
        -- Process the target
        targetData = rowData
        return true  -- Break out of the loop
    end
end)

Fixes # (issue) (if applicable)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Is/requires documentation update

How has this been tested?

Checklist

  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • I have added the necessary description of this PR to the changelog, and I have followed the same format as other entries.
  • Any dependent changes have been merged and published in downstream modules.

Screenshots

Additional context

@narknon narknon marked this pull request as ready for review October 23, 2025 21:44
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

MSVC-Game__Debug__Win64 Download Logs
Build Details
Name Information
PR Commit bdf44e5
Merge Commit 43510de
Size 54.21 MB
Last Updated Oct 25, 25, 7:38:29 AM UTC
Expires At Nov 8, 25, 7:38:22 AM UTC

MSVC-Game__Shipping__Win64 Download Logs
Build Details
Name Information
PR Commit bdf44e5
Merge Commit 43510de
Size 45.06 MB
Last Updated Oct 25, 25, 7:42:28 AM UTC
Expires At Nov 8, 25, 7:42:24 AM UTC

Changes the UDataTable Lua API to return UScriptStruct wrappers instead of copies, providing reference-based access to row data.
This allows direct modification of DataTable entries from Lua.
The AddRow function now also accepts UScriptStructs for cloning.

This approach aligns with C++ behavior and improves data manipulation efficiency.

BREAKING CHANGE: I think might be breaking? though I left table support in
@narknon narknon merged commit ad8a297 into main Oct 25, 2025
1 check passed
@narknon narknon deleted the luatypefixes branch October 25, 2025 07:19
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