Advertisement
Guest User

Untitled

a guest
Jul 13th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const TypeId = @import("builtin").TypeId;
  2.  
  3. fn init_zeroes(comptime T: type) T {
  4. var t: T = undefined;
  5.  
  6. inline for (@typeInfo(T).Struct.fields) |field, i| {
  7. const field_type = @typeInfo(field.field_type);
  8.  
  9. if (TypeId(field_type) == TypeId.Pointer) {
  10. @field(t, field.name) = null;
  11. }
  12. if (TypeId(field_type) == TypeId.Int) {
  13. @field(t, field.name) = 0;
  14. }
  15. if (TypeId(field_type) == TypeId.Float) {
  16. @field(t, field.name) = 0;
  17. }
  18. }
  19. return t;
  20. }
  21.  
  22. fn protocol(name: [*c]const u8) lws_protocols {
  23. var p: lws_protocols = init_zeroes(lws_protocols);
  24. p.name = name;
  25. return p;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement