Skip to content

Commit 8278032

Browse files
authored
feat: Add support for script context and variables on Apple platforms (#306)
1 parent 0e8b9a1 commit 8278032

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Add support for script context and variables on Apple platforms ([#306](https://github.com/getsentry/sentry-godot/pull/306))
8+
59
### Dependencies
610

711
- Bump Cocoa SDK from v8.54.0 to v8.55.0 ([#318](https://github.com/getsentry/sentry-godot/pull/318))

src/sentry/cocoa/cocoa_event.mm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,21 @@
223223
cocoa_frame.inApp = bool_to_objc(frame.in_app);
224224
cocoa_frame.platform = string_to_objc(frame.platform);
225225

226-
// TODO: unable to pass context_line, pre_context, post_context.
227-
// TODO: unable to pass local/member vars.
226+
if (!frame.context_line.is_empty()) {
227+
cocoa_frame.contextLine = string_to_objc(frame.context_line);
228+
cocoa_frame.preContext = string_array_to_objc(frame.pre_context);
229+
cocoa_frame.postContext = string_array_to_objc(frame.post_context);
230+
}
231+
232+
if (!frame.vars.is_empty()) {
233+
NSMutableDictionary *objc_vars = [NSMutableDictionary dictionaryWithCapacity:frame.vars.size()];
234+
for (const auto &var : frame.vars) {
235+
NSString *key = string_to_objc(var.first);
236+
id value = variant_to_objc(var.second);
237+
objc_vars[key] = value;
238+
}
239+
cocoa_frame.vars = objc_vars;
240+
}
228241

229242
[mut_frames addObject:cocoa_frame];
230243
}

src/sentry/cocoa/cocoa_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ _FORCE_INLINE_ NSNumber *double_to_objc(double p_num) {
7272

7373
NSObject *variant_to_objc(const godot::Variant &p_value, int p_depth = 0);
7474
NSDictionary *dictionary_to_objc(const godot::Dictionary &p_dictionary);
75+
NSArray<NSString *> *string_array_to_objc(const godot::PackedStringArray &p_array);
7576

7677
} //namespace sentry::cocoa
7778

src/sentry/cocoa/cocoa_util.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,12 @@
7979
return (NSDictionary *)variant_to_objc(p_dictionary);
8080
}
8181

82+
NSArray<NSString *> *string_array_to_objc(const godot::PackedStringArray &p_array) {
83+
NSMutableArray<NSString *> *objc_array = [NSMutableArray arrayWithCapacity:p_array.size()];
84+
for (int i = 0; i < p_array.size(); i++) {
85+
[objc_array addObject:string_to_objc(p_array[i])];
86+
}
87+
return objc_array;
88+
}
89+
8290
} // namespace sentry::cocoa

0 commit comments

Comments
 (0)