File: inner_struct.rb

package info (click to toggle)
ruby-cstruct 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 412 kB
  • sloc: ruby: 1,008; makefile: 7
file content (28 lines) | stat: -rw-r--r-- 385 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# CStruct Examples
require 'cstruct'
# example:
# struct A in C\C++ (32-bit platform): 
# struct A{
#     struct Inner
#     {
#       int v1; 
#       int v2;
#     };
#     Inner inner;
# };

# struct A in Ruby:
class A < CStruct
  class Inner < CStruct
    int32 :v1
    int32 :v2
  end
  Inner :inner
end

a = A.new
a.inner.v1 = 1
a.inner.v2 = 2

puts a.inner.v1 
puts a.inner.v2