cstruct 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/README.md +81 -0
  2. data/cstruct.gemspec +10 -0
  3. data/doc/examples/anonymous_struct.rb.html +94 -94
  4. data/doc/examples/anonymous_union.rb.html +93 -93
  5. data/doc/examples/array_member.rb.html +79 -79
  6. data/doc/examples/file_io.rb.html +87 -87
  7. data/doc/examples/first_example.rb.html +104 -104
  8. data/doc/examples/get_system_info.rb.html +114 -114
  9. data/doc/examples/get_versionex.rb.html +97 -97
  10. data/doc/examples/global_memory.rb.html +102 -102
  11. data/doc/examples/inner_struct.rb.html +79 -79
  12. data/doc/examples/inner_union.rb.html +77 -77
  13. data/doc/examples/namespace.rb.html +80 -80
  14. data/doc/examples/show_processes.rb.html +95 -95
  15. data/doc/examples/struct_member.rb.html +128 -128
  16. data/doc/stylesheets/ie.css +8 -8
  17. data/examples/anonymous_struct.rb +6 -6
  18. data/examples/anonymous_union.rb +5 -5
  19. data/examples/array_member.rb +1 -1
  20. data/examples/file_io.rb +22 -23
  21. data/examples/first_example.rb +4 -4
  22. data/examples/inner_struct.rb +5 -5
  23. data/examples/inner_union.rb +4 -4
  24. data/examples/namespace.rb +15 -15
  25. data/examples/win32/get_system_info.rb +31 -31
  26. data/examples/win32/get_versionex.rb +12 -12
  27. data/examples/win32/global_memory.rb +9 -9
  28. data/examples/win32/show_processes.rb +28 -28
  29. data/lib/cstruct.rb +1 -523
  30. data/lib/cstruct/cstruct.rb +457 -0
  31. data/lib/cstruct/field.rb +45 -0
  32. data/lib/cstruct/utils.rb +53 -0
  33. data/lib/cstruct/win32struct.rb +84 -0
  34. data/lib/cstruct/win64struct.rb +5 -0
  35. data/lib/win32struct.rb +3 -90
  36. data/lib/win64struct.rb +3 -13
  37. data/spec/cstruct_spec.rb +240 -0
  38. metadata +62 -73
@@ -1,95 +1,95 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
- <head profile="http://gmpg.org/xfn/11" >
4
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
- <title>CStruct:Examples:Show All Processes</title>
6
- <style type="text/css">
7
-
8
- .CodeRay {
9
- background-color: #232323;
10
- border: 1px solid black;
11
- font-family: 'Courier New', 'Terminal', monospace;
12
- color: #E6E0DB;
13
- padding: 3px 5px;
14
- overflow: auto;
15
- font-size: 12px;
16
- margin: 12px 0;
17
- }
18
- .CodeRay pre {
19
- margin: 0px;
20
- padding: 0px;
21
- }
22
-
23
- .CodeRay .an { color:#E7BE69 }
24
- .CodeRay .c { color:#BC9358; font-style: italic; }
25
- .CodeRay .ch { color:#509E4F }
26
- .CodeRay .cl { color:#FFF }
27
- .CodeRay .co { color:#FFF }
28
- .CodeRay .fl { color:#A4C260 }
29
- .CodeRay .fu { color:#FFC56D }
30
- .CodeRay .gv { color:#D0CFFE }
31
- .CodeRay .i { color:#A4C260 }
32
- .CodeRay .il { background:#151515 }
33
- .CodeRay .iv { color:#D0CFFE }
34
- .CodeRay .pp { color:#E7BE69 }
35
- .CodeRay .r { color:#CB7832 }
36
- .CodeRay .rx { color:#A4C260 }
37
- .CodeRay .s { color:#A4C260 }
38
- .CodeRay .sy { color:#6C9CBD }
39
- .CodeRay .ta { color:#E7BE69 }
40
- .CodeRay .pc { color:#6C9CBD }
41
-
42
- </style>
43
- </head>
44
- <body>
45
- <div style="margin-left:auto;margin-right:auto;width:800px;">
46
- <div class="CodeRay">
47
- <div class="code"><pre><span class="c"># CStruct Examples</span>
48
- require <span class="s"><span class="dl">'</span><span class="k">windows/tool_helper</span><span class="dl">'</span></span>
49
- require <span class="s"><span class="dl">'</span><span class="k">win32struct</span><span class="dl">'</span></span>
50
- include <span class="co">Windows</span>::<span class="co">ToolHelper</span>
51
-
52
- <span class="r">module</span> <span class="cl">Windows</span>
53
- <span class="co">MAX_PATH</span> = <span class="i">260</span>
54
- <span class="r">module</span> <span class="cl">ToolHelper</span>
55
- <span class="r">class</span> <span class="cl">PROCESSENTRY32</span> &lt; <span class="co">Win32Struct</span>
56
- <span class="co">DWORD</span> <span class="sy">:dwSize</span>
57
- <span class="co">DWORD</span> <span class="sy">:cntUsage</span>
58
- <span class="co">DWORD</span> <span class="sy">:th32ProcessID</span>
59
- <span class="co">DWORD</span> <span class="sy">:th32DefaultHeapID</span>
60
- <span class="co">DWORD</span> <span class="sy">:th32ModuleID</span>
61
- <span class="co">DWORD</span> <span class="sy">:cntThreads</span>
62
- <span class="co">DWORD</span> <span class="sy">:th32ParentProcessID</span>
63
- <span class="co">LONG</span> <span class="sy">:pcPriClassBase</span>
64
- <span class="co">DWORD</span> <span class="sy">:dwFlags</span>
65
- <span class="co">CHAR</span> <span class="sy">:szExeFile</span>,[<span class="co">MAX_PATH</span>]
66
- <span class="r">end</span>
67
- <span class="r">end</span>
68
- <span class="r">end</span>
69
-
70
- <span class="r">def</span> <span class="fu">show_all_processes</span>
71
- proc_enrty32 = <span class="co">PROCESSENTRY32</span>.new
72
- proc_enrty32.dwSize = <span class="co">PROCESSENTRY32</span>.__size__
73
- snap_handle = CreateToolhelp32Snapshot( <span class="co">TH32CS_SNAPPROCESS</span>,<span class="i">0</span>)
74
-
75
- <span class="r">if</span> Process32First(snap_handle,proc_enrty32.data)
76
- show_process proc_enrty32
77
- <span class="r">while</span> <span class="pc">true</span>
78
- <span class="r">break</span> <span class="r">if</span> !Process32Next( snap_handle,proc_enrty32.data )
79
- show_process proc_enrty32
80
- <span class="r">end</span>
81
- <span class="r">end</span>
82
-
83
- <span class="r">end</span>
84
-
85
- <span class="r">def</span> <span class="fu">show_process</span> proc_enrty32
86
- printf<span class="s"><span class="dl">&quot;</span><span class="k">%20s 0x%08X</span><span class="ch">\n</span><span class="dl">&quot;</span></span>,proc_enrty32.szExeFile.to_cstr,proc_enrty32.th32ProcessID
87
- <span class="r">end</span>
88
-
89
- printf<span class="s"><span class="dl">&quot;</span><span class="k">%20s %s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">&lt;Process Name&gt;</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">&lt;PID&gt;</span><span class="dl">&quot;</span></span>
90
- printf<span class="s"><span class="dl">&quot;</span><span class="k">%20s %s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">--------------</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">-----</span><span class="dl">&quot;</span></span>
91
- show_all_processes</pre></div>
92
- </div>
93
-
94
- </div>
95
- </body>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head profile="http://gmpg.org/xfn/11" >
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
+ <title>CStruct:Examples:Show All Processes</title>
6
+ <style type="text/css">
7
+
8
+ .CodeRay {
9
+ background-color: #232323;
10
+ border: 1px solid black;
11
+ font-family: 'Courier New', 'Terminal', monospace;
12
+ color: #E6E0DB;
13
+ padding: 3px 5px;
14
+ overflow: auto;
15
+ font-size: 12px;
16
+ margin: 12px 0;
17
+ }
18
+ .CodeRay pre {
19
+ margin: 0px;
20
+ padding: 0px;
21
+ }
22
+
23
+ .CodeRay .an { color:#E7BE69 }
24
+ .CodeRay .c { color:#BC9358; font-style: italic; }
25
+ .CodeRay .ch { color:#509E4F }
26
+ .CodeRay .cl { color:#FFF }
27
+ .CodeRay .co { color:#FFF }
28
+ .CodeRay .fl { color:#A4C260 }
29
+ .CodeRay .fu { color:#FFC56D }
30
+ .CodeRay .gv { color:#D0CFFE }
31
+ .CodeRay .i { color:#A4C260 }
32
+ .CodeRay .il { background:#151515 }
33
+ .CodeRay .iv { color:#D0CFFE }
34
+ .CodeRay .pp { color:#E7BE69 }
35
+ .CodeRay .r { color:#CB7832 }
36
+ .CodeRay .rx { color:#A4C260 }
37
+ .CodeRay .s { color:#A4C260 }
38
+ .CodeRay .sy { color:#6C9CBD }
39
+ .CodeRay .ta { color:#E7BE69 }
40
+ .CodeRay .pc { color:#6C9CBD }
41
+
42
+ </style>
43
+ </head>
44
+ <body>
45
+ <div style="margin-left:auto;margin-right:auto;width:800px;">
46
+ <div class="CodeRay">
47
+ <div class="code"><pre><span class="c"># CStruct Examples</span>
48
+ require <span class="s"><span class="dl">'</span><span class="k">windows/tool_helper</span><span class="dl">'</span></span>
49
+ require <span class="s"><span class="dl">'</span><span class="k">win32struct</span><span class="dl">'</span></span>
50
+ include <span class="co">Windows</span>::<span class="co">ToolHelper</span>
51
+
52
+ <span class="r">module</span> <span class="cl">Windows</span>
53
+ <span class="co">MAX_PATH</span> = <span class="i">260</span>
54
+ <span class="r">module</span> <span class="cl">ToolHelper</span>
55
+ <span class="r">class</span> <span class="cl">PROCESSENTRY32</span> &lt; <span class="co">Win32Struct</span>
56
+ <span class="co">DWORD</span> <span class="sy">:dwSize</span>
57
+ <span class="co">DWORD</span> <span class="sy">:cntUsage</span>
58
+ <span class="co">DWORD</span> <span class="sy">:th32ProcessID</span>
59
+ <span class="co">DWORD</span> <span class="sy">:th32DefaultHeapID</span>
60
+ <span class="co">DWORD</span> <span class="sy">:th32ModuleID</span>
61
+ <span class="co">DWORD</span> <span class="sy">:cntThreads</span>
62
+ <span class="co">DWORD</span> <span class="sy">:th32ParentProcessID</span>
63
+ <span class="co">LONG</span> <span class="sy">:pcPriClassBase</span>
64
+ <span class="co">DWORD</span> <span class="sy">:dwFlags</span>
65
+ <span class="co">CHAR</span> <span class="sy">:szExeFile</span>,[<span class="co">MAX_PATH</span>]
66
+ <span class="r">end</span>
67
+ <span class="r">end</span>
68
+ <span class="r">end</span>
69
+
70
+ <span class="r">def</span> <span class="fu">show_all_processes</span>
71
+ proc_enrty32 = <span class="co">PROCESSENTRY32</span>.new
72
+ proc_enrty32.dwSize = <span class="co">PROCESSENTRY32</span>.__size__
73
+ snap_handle = CreateToolhelp32Snapshot( <span class="co">TH32CS_SNAPPROCESS</span>,<span class="i">0</span>)
74
+
75
+ <span class="r">if</span> Process32First(snap_handle,proc_enrty32.data)
76
+ show_process proc_enrty32
77
+ <span class="r">while</span> <span class="pc">true</span>
78
+ <span class="r">break</span> <span class="r">if</span> !Process32Next( snap_handle,proc_enrty32.data )
79
+ show_process proc_enrty32
80
+ <span class="r">end</span>
81
+ <span class="r">end</span>
82
+
83
+ <span class="r">end</span>
84
+
85
+ <span class="r">def</span> <span class="fu">show_process</span> proc_enrty32
86
+ printf<span class="s"><span class="dl">&quot;</span><span class="k">%20s 0x%08X</span><span class="ch">\n</span><span class="dl">&quot;</span></span>,proc_enrty32.szExeFile.to_cstr,proc_enrty32.th32ProcessID
87
+ <span class="r">end</span>
88
+
89
+ printf<span class="s"><span class="dl">&quot;</span><span class="k">%20s %s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">&lt;Process Name&gt;</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">&lt;PID&gt;</span><span class="dl">&quot;</span></span>
90
+ printf<span class="s"><span class="dl">&quot;</span><span class="k">%20s %s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">--------------</span><span class="dl">&quot;</span></span>,<span class="s"><span class="dl">&quot;</span><span class="k">-----</span><span class="dl">&quot;</span></span>
91
+ show_all_processes</pre></div>
92
+ </div>
93
+
94
+ </div>
95
+ </body>
@@ -1,128 +1,128 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
- <head profile="http://gmpg.org/xfn/11" >
4
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
- <title>CStruct:Examples:Struct member</title>
6
- <style type="text/css">
7
-
8
- .CodeRay {
9
- background-color: #232323;
10
- border: 1px solid black;
11
- font-family: 'Courier New', 'Terminal', monospace;
12
- color: #E6E0DB;
13
- padding: 3px 5px;
14
- overflow: auto;
15
- font-size: 12px;
16
- margin: 12px 0;
17
- }
18
- .CodeRay pre {
19
- margin: 0px;
20
- padding: 0px;
21
- }
22
-
23
- .CodeRay .an { color:#E7BE69 }
24
- .CodeRay .c { color:#BC9358; font-style: italic; }
25
- .CodeRay .ch { color:#509E4F }
26
- .CodeRay .cl { color:#FFF }
27
- .CodeRay .co { color:#FFF }
28
- .CodeRay .fl { color:#A4C260 }
29
- .CodeRay .fu { color:#FFC56D }
30
- .CodeRay .gv { color:#D0CFFE }
31
- .CodeRay .i { color:#A4C260 }
32
- .CodeRay .il { background:#151515 }
33
- .CodeRay .iv { color:#D0CFFE }
34
- .CodeRay .pp { color:#E7BE69 }
35
- .CodeRay .r { color:#CB7832 }
36
- .CodeRay .rx { color:#A4C260 }
37
- .CodeRay .s { color:#A4C260 }
38
- .CodeRay .sy { color:#6C9CBD }
39
- .CodeRay .ta { color:#E7BE69 }
40
- .CodeRay .pc { color:#6C9CBD }
41
-
42
- </style>
43
- </head>
44
- <body>
45
- <div style="margin-left:auto;margin-right:auto;width:800px;">
46
- <div class="CodeRay">
47
- <div class="code"><pre><span class="c"># CStruct Examples</span>
48
- require <span class="s"><span class="dl">'</span><span class="k">cstruct</span><span class="dl">'</span></span>
49
-
50
- <span class="c"># example:</span>
51
- <span class="c"># struct Point in C\C++ (32-bit platform): </span>
52
- <span class="c">#</span>
53
- <span class="c"># struct Point</span>
54
- <span class="c"># {</span>
55
- <span class="c"># int x;</span>
56
- <span class="c"># int y;</span>
57
- <span class="c"># }; </span>
58
- <span class="c">#</span>
59
- <span class="c"># struct Line in C\C++ (32-bit platform): </span>
60
- <span class="c">#</span>
61
- <span class="c"># struct Line</span>
62
- <span class="c"># {</span>
63
- <span class="c"># Point begin_point;</span>
64
- <span class="c"># Point end_point;</span>
65
- <span class="c"># }; </span>
66
-
67
- <span class="c"># struct TwoLine in C\C++ (32-bit platform): </span>
68
- <span class="c">#</span>
69
- <span class="c"># struct TwoLine</span>
70
- <span class="c"># {</span>
71
- <span class="c"># Line lines[2];</span>
72
- <span class="c"># }; </span>
73
-
74
-
75
-
76
- <span class="c"># struct Point , Line and TwoLine in Ruby: </span>
77
- <span class="r">class</span> <span class="cl">Point</span> &lt; <span class="co">CStruct</span>
78
- int32<span class="sy">:x</span>
79
- int32<span class="sy">:y</span>
80
- <span class="r">end</span>
81
-
82
- <span class="r">class</span> <span class="cl">Line</span> &lt; <span class="co">CStruct</span>
83
- <span class="co">Point</span><span class="sy">:begin_point</span>
84
- <span class="co">Point</span><span class="sy">:end_point</span>
85
- <span class="r">end</span>
86
-
87
- <span class="r">class</span> <span class="cl">TwoLine</span> &lt; <span class="co">CStruct</span>
88
- <span class="co">Line</span><span class="sy">:lines</span>,[<span class="i">2</span>]
89
- <span class="r">end</span>
90
-
91
-
92
- line = <span class="co">Line</span>.new
93
-
94
- <span class="c"># assign like as C language</span>
95
- line.begin_point.x = <span class="i">0</span>
96
- line.begin_point.y = <span class="i">0</span>
97
- line.end_point.x = <span class="i">20</span>
98
- line.end_point.y = <span class="i">30</span>
99
-
100
-
101
- puts <span class="s"><span class="dl">&quot;</span><span class="k">sizeof(Line) = </span><span class="il"><span class="idl">#{</span><span class="co">Line</span>.__size__<span class="idl">}</span></span><span class="dl">&quot;</span></span> <span class="c"># &quot;__size__&quot; is alias of &quot;size&quot;</span>
102
- puts <span class="s"><span class="dl">&quot;</span><span class="k">line.begin_point.x = </span><span class="il"><span class="idl">#{</span>line.begin_point.x<span class="idl">}</span></span><span class="dl">&quot;</span></span>
103
- puts <span class="s"><span class="dl">&quot;</span><span class="k">line.begin_point.y = </span><span class="il"><span class="idl">#{</span>line.begin_point.y<span class="idl">}</span></span><span class="dl">&quot;</span></span>
104
- puts <span class="s"><span class="dl">&quot;</span><span class="k">line.end_point.x = </span><span class="il"><span class="idl">#{</span>line.end_point.x<span class="idl">}</span></span><span class="dl">&quot;</span></span>
105
- puts <span class="s"><span class="dl">&quot;</span><span class="k">line.end_point.y = </span><span class="il"><span class="idl">#{</span>line.end_point.y<span class="idl">}</span></span><span class="dl">&quot;</span></span>
106
-
107
- two_line = <span class="co">TwoLine</span>.new
108
-
109
- <span class="c"># assign like as C language</span>
110
- two_line.lines[<span class="i">0</span>].begin_point.x = <span class="i">6</span>
111
- two_line.lines[<span class="i">0</span>].begin_point.y = <span class="i">16</span>
112
- two_line.lines[<span class="i">0</span>].end_point.x = <span class="i">26</span>
113
- two_line.lines[<span class="i">0</span>].end_point.y = <span class="i">36</span>
114
-
115
- two_line.lines[<span class="i">1</span>].begin_point.x = <span class="i">6</span>
116
- two_line.lines[<span class="i">1</span>].begin_point.y = <span class="i">16</span>
117
- two_line.lines[<span class="i">1</span>].end_point.x = <span class="i">26</span>
118
- two_line.lines[<span class="i">1</span>].end_point.y = <span class="i">36</span>
119
-
120
-
121
-
122
-
123
-
124
- </pre></div>
125
- </div>
126
-
127
- </div>
128
- </body>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head profile="http://gmpg.org/xfn/11" >
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
+ <title>CStruct:Examples:Struct member</title>
6
+ <style type="text/css">
7
+
8
+ .CodeRay {
9
+ background-color: #232323;
10
+ border: 1px solid black;
11
+ font-family: 'Courier New', 'Terminal', monospace;
12
+ color: #E6E0DB;
13
+ padding: 3px 5px;
14
+ overflow: auto;
15
+ font-size: 12px;
16
+ margin: 12px 0;
17
+ }
18
+ .CodeRay pre {
19
+ margin: 0px;
20
+ padding: 0px;
21
+ }
22
+
23
+ .CodeRay .an { color:#E7BE69 }
24
+ .CodeRay .c { color:#BC9358; font-style: italic; }
25
+ .CodeRay .ch { color:#509E4F }
26
+ .CodeRay .cl { color:#FFF }
27
+ .CodeRay .co { color:#FFF }
28
+ .CodeRay .fl { color:#A4C260 }
29
+ .CodeRay .fu { color:#FFC56D }
30
+ .CodeRay .gv { color:#D0CFFE }
31
+ .CodeRay .i { color:#A4C260 }
32
+ .CodeRay .il { background:#151515 }
33
+ .CodeRay .iv { color:#D0CFFE }
34
+ .CodeRay .pp { color:#E7BE69 }
35
+ .CodeRay .r { color:#CB7832 }
36
+ .CodeRay .rx { color:#A4C260 }
37
+ .CodeRay .s { color:#A4C260 }
38
+ .CodeRay .sy { color:#6C9CBD }
39
+ .CodeRay .ta { color:#E7BE69 }
40
+ .CodeRay .pc { color:#6C9CBD }
41
+
42
+ </style>
43
+ </head>
44
+ <body>
45
+ <div style="margin-left:auto;margin-right:auto;width:800px;">
46
+ <div class="CodeRay">
47
+ <div class="code"><pre><span class="c"># CStruct Examples</span>
48
+ require <span class="s"><span class="dl">'</span><span class="k">cstruct</span><span class="dl">'</span></span>
49
+
50
+ <span class="c"># example:</span>
51
+ <span class="c"># struct Point in C\C++ (32-bit platform): </span>
52
+ <span class="c">#</span>
53
+ <span class="c"># struct Point</span>
54
+ <span class="c"># {</span>
55
+ <span class="c"># int x;</span>
56
+ <span class="c"># int y;</span>
57
+ <span class="c"># }; </span>
58
+ <span class="c">#</span>
59
+ <span class="c"># struct Line in C\C++ (32-bit platform): </span>
60
+ <span class="c">#</span>
61
+ <span class="c"># struct Line</span>
62
+ <span class="c"># {</span>
63
+ <span class="c"># Point begin_point;</span>
64
+ <span class="c"># Point end_point;</span>
65
+ <span class="c"># }; </span>
66
+
67
+ <span class="c"># struct TwoLine in C\C++ (32-bit platform): </span>
68
+ <span class="c">#</span>
69
+ <span class="c"># struct TwoLine</span>
70
+ <span class="c"># {</span>
71
+ <span class="c"># Line lines[2];</span>
72
+ <span class="c"># }; </span>
73
+
74
+
75
+
76
+ <span class="c"># struct Point , Line and TwoLine in Ruby: </span>
77
+ <span class="r">class</span> <span class="cl">Point</span> &lt; <span class="co">CStruct</span>
78
+ int32<span class="sy">:x</span>
79
+ int32<span class="sy">:y</span>
80
+ <span class="r">end</span>
81
+
82
+ <span class="r">class</span> <span class="cl">Line</span> &lt; <span class="co">CStruct</span>
83
+ <span class="co">Point</span><span class="sy">:begin_point</span>
84
+ <span class="co">Point</span><span class="sy">:end_point</span>
85
+ <span class="r">end</span>
86
+
87
+ <span class="r">class</span> <span class="cl">TwoLine</span> &lt; <span class="co">CStruct</span>
88
+ <span class="co">Line</span><span class="sy">:lines</span>,[<span class="i">2</span>]
89
+ <span class="r">end</span>
90
+
91
+
92
+ line = <span class="co">Line</span>.new
93
+
94
+ <span class="c"># assign like as C language</span>
95
+ line.begin_point.x = <span class="i">0</span>
96
+ line.begin_point.y = <span class="i">0</span>
97
+ line.end_point.x = <span class="i">20</span>
98
+ line.end_point.y = <span class="i">30</span>
99
+
100
+
101
+ puts <span class="s"><span class="dl">&quot;</span><span class="k">sizeof(Line) = </span><span class="il"><span class="idl">#{</span><span class="co">Line</span>.__size__<span class="idl">}</span></span><span class="dl">&quot;</span></span> <span class="c"># &quot;__size__&quot; is alias of &quot;size&quot;</span>
102
+ puts <span class="s"><span class="dl">&quot;</span><span class="k">line.begin_point.x = </span><span class="il"><span class="idl">#{</span>line.begin_point.x<span class="idl">}</span></span><span class="dl">&quot;</span></span>
103
+ puts <span class="s"><span class="dl">&quot;</span><span class="k">line.begin_point.y = </span><span class="il"><span class="idl">#{</span>line.begin_point.y<span class="idl">}</span></span><span class="dl">&quot;</span></span>
104
+ puts <span class="s"><span class="dl">&quot;</span><span class="k">line.end_point.x = </span><span class="il"><span class="idl">#{</span>line.end_point.x<span class="idl">}</span></span><span class="dl">&quot;</span></span>
105
+ puts <span class="s"><span class="dl">&quot;</span><span class="k">line.end_point.y = </span><span class="il"><span class="idl">#{</span>line.end_point.y<span class="idl">}</span></span><span class="dl">&quot;</span></span>
106
+
107
+ two_line = <span class="co">TwoLine</span>.new
108
+
109
+ <span class="c"># assign like as C language</span>
110
+ two_line.lines[<span class="i">0</span>].begin_point.x = <span class="i">6</span>
111
+ two_line.lines[<span class="i">0</span>].begin_point.y = <span class="i">16</span>
112
+ two_line.lines[<span class="i">0</span>].end_point.x = <span class="i">26</span>
113
+ two_line.lines[<span class="i">0</span>].end_point.y = <span class="i">36</span>
114
+
115
+ two_line.lines[<span class="i">1</span>].begin_point.x = <span class="i">6</span>
116
+ two_line.lines[<span class="i">1</span>].begin_point.y = <span class="i">16</span>
117
+ two_line.lines[<span class="i">1</span>].end_point.x = <span class="i">26</span>
118
+ two_line.lines[<span class="i">1</span>].end_point.y = <span class="i">36</span>
119
+
120
+
121
+
122
+
123
+
124
+ </pre></div>
125
+ </div>
126
+
127
+ </div>
128
+ </body>
@@ -1,9 +1,9 @@
1
- pre {
2
- word-wrap:break-word; /* Internet Explorer 5.5+ */
3
- }
4
- a span,
5
- #submitbox #submit,
6
- #searchbox .button,
7
- #subscribe li a {
8
- cursor:hand;
1
+ pre {
2
+ word-wrap:break-word; /* Internet Explorer 5.5+ */
3
+ }
4
+ a span,
5
+ #submitbox #submit,
6
+ #searchbox .button,
7
+ #subscribe li a {
8
+ cursor:hand;
9
9
  }