diff --git a/CHANGELOG.md b/CHANGELOG.md index ccdf9c5f..5a2b948a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Add support for script context and variables on Apple platforms ([#306](https://github.com/getsentry/sentry-godot/pull/306)) + ### Dependencies - Bump Cocoa SDK from v8.54.0 to v8.55.0 ([#318](https://github.com/getsentry/sentry-godot/pull/318)) diff --git a/src/sentry/cocoa/cocoa_event.mm b/src/sentry/cocoa/cocoa_event.mm index d33c12df..c5d1ff8c 100644 --- a/src/sentry/cocoa/cocoa_event.mm +++ b/src/sentry/cocoa/cocoa_event.mm @@ -223,8 +223,21 @@ cocoa_frame.inApp = bool_to_objc(frame.in_app); cocoa_frame.platform = string_to_objc(frame.platform); - // TODO: unable to pass context_line, pre_context, post_context. - // TODO: unable to pass local/member vars. + if (!frame.context_line.is_empty()) { + cocoa_frame.contextLine = string_to_objc(frame.context_line); + cocoa_frame.preContext = string_array_to_objc(frame.pre_context); + cocoa_frame.postContext = string_array_to_objc(frame.post_context); + } + + if (!frame.vars.is_empty()) { + NSMutableDictionary *objc_vars = [NSMutableDictionary dictionaryWithCapacity:frame.vars.size()]; + for (const auto &var : frame.vars) { + NSString *key = string_to_objc(var.first); + id value = variant_to_objc(var.second); + objc_vars[key] = value; + } + cocoa_frame.vars = objc_vars; + } [mut_frames addObject:cocoa_frame]; } diff --git a/src/sentry/cocoa/cocoa_util.h b/src/sentry/cocoa/cocoa_util.h index 9b80873e..a9d215b7 100644 --- a/src/sentry/cocoa/cocoa_util.h +++ b/src/sentry/cocoa/cocoa_util.h @@ -72,6 +72,7 @@ _FORCE_INLINE_ NSNumber *double_to_objc(double p_num) { NSObject *variant_to_objc(const godot::Variant &p_value, int p_depth = 0); NSDictionary *dictionary_to_objc(const godot::Dictionary &p_dictionary); +NSArray *string_array_to_objc(const godot::PackedStringArray &p_array); } //namespace sentry::cocoa diff --git a/src/sentry/cocoa/cocoa_util.mm b/src/sentry/cocoa/cocoa_util.mm index 39f8796a..40d6c609 100644 --- a/src/sentry/cocoa/cocoa_util.mm +++ b/src/sentry/cocoa/cocoa_util.mm @@ -79,4 +79,12 @@ return (NSDictionary *)variant_to_objc(p_dictionary); } +NSArray *string_array_to_objc(const godot::PackedStringArray &p_array) { + NSMutableArray *objc_array = [NSMutableArray arrayWithCapacity:p_array.size()]; + for (int i = 0; i < p_array.size(); i++) { + [objc_array addObject:string_to_objc(p_array[i])]; + } + return objc_array; +} + } // namespace sentry::cocoa