cstruct 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +81 -0
- data/cstruct.gemspec +10 -0
- data/doc/examples/anonymous_struct.rb.html +94 -94
- data/doc/examples/anonymous_union.rb.html +93 -93
- data/doc/examples/array_member.rb.html +79 -79
- data/doc/examples/file_io.rb.html +87 -87
- data/doc/examples/first_example.rb.html +104 -104
- data/doc/examples/get_system_info.rb.html +114 -114
- data/doc/examples/get_versionex.rb.html +97 -97
- data/doc/examples/global_memory.rb.html +102 -102
- data/doc/examples/inner_struct.rb.html +79 -79
- data/doc/examples/inner_union.rb.html +77 -77
- data/doc/examples/namespace.rb.html +80 -80
- data/doc/examples/show_processes.rb.html +95 -95
- data/doc/examples/struct_member.rb.html +128 -128
- data/doc/stylesheets/ie.css +8 -8
- data/examples/anonymous_struct.rb +6 -6
- data/examples/anonymous_union.rb +5 -5
- data/examples/array_member.rb +1 -1
- data/examples/file_io.rb +22 -23
- data/examples/first_example.rb +4 -4
- data/examples/inner_struct.rb +5 -5
- data/examples/inner_union.rb +4 -4
- data/examples/namespace.rb +15 -15
- data/examples/win32/get_system_info.rb +31 -31
- data/examples/win32/get_versionex.rb +12 -12
- data/examples/win32/global_memory.rb +9 -9
- data/examples/win32/show_processes.rb +28 -28
- data/lib/cstruct.rb +1 -523
- data/lib/cstruct/cstruct.rb +457 -0
- data/lib/cstruct/field.rb +45 -0
- data/lib/cstruct/utils.rb +53 -0
- data/lib/cstruct/win32struct.rb +84 -0
- data/lib/cstruct/win64struct.rb +5 -0
- data/lib/win32struct.rb +3 -90
- data/lib/win64struct.rb +3 -13
- data/spec/cstruct_spec.rb +240 -0
- metadata +62 -73
@@ -1,79 +1,79 @@
|
|
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:Array 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 T in C\C++ (32-bit platform): </span>
|
52
|
-
<span class="c"># </span>
|
53
|
-
<span class="c"># struct T</span>
|
54
|
-
<span class="c"># {</span>
|
55
|
-
<span class="c"># int element[8];</span>
|
56
|
-
<span class="c"># }; </span>
|
57
|
-
|
58
|
-
<span class="c"># struct T in Ruby: </span>
|
59
|
-
<span class="r">class</span> <span class="cl">T</span> < <span class="co">CStruct</span>
|
60
|
-
int32<span class="sy">:elements</span>,[<span class="i">8</span>]
|
61
|
-
<span class="r">end</span>
|
62
|
-
|
63
|
-
<span class="c"># create a T's instance</span>
|
64
|
-
t_array = <span class="co">T</span>.new
|
65
|
-
|
66
|
-
(<span class="i">0</span>..<span class="i">7</span>).each <span class="r">do</span> |i|
|
67
|
-
t_array.elements[i] = i <span class="c"># assign like as C language</span>
|
68
|
-
<span class="r">end</span>
|
69
|
-
|
70
|
-
<span class="c"># output</span>
|
71
|
-
(<span class="i">0</span>..<span class="i">7</span>).each {|i| puts <span class="s"><span class="dl">"</span><span class="k">t_array.elements[</span><span class="il"><span class="idl">#{</span>i<span class="idl">}</span></span><span class="k">] = </span><span class="il"><span class="idl">#{</span>t_array.elements[i]<span class="idl">}</span></span><span class="dl">"</span></span> }
|
72
|
-
|
73
|
-
|
74
|
-
<span class="c"># Actually,t_array.elements.class is Array. So..</span>
|
75
|
-
t_array.elements.each {|element| puts element }</pre></div>
|
76
|
-
</div>
|
77
|
-
|
78
|
-
</div>
|
79
|
-
</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:Array 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 T in C\C++ (32-bit platform): </span>
|
52
|
+
<span class="c"># </span>
|
53
|
+
<span class="c"># struct T</span>
|
54
|
+
<span class="c"># {</span>
|
55
|
+
<span class="c"># int element[8];</span>
|
56
|
+
<span class="c"># }; </span>
|
57
|
+
|
58
|
+
<span class="c"># struct T in Ruby: </span>
|
59
|
+
<span class="r">class</span> <span class="cl">T</span> < <span class="co">CStruct</span>
|
60
|
+
int32<span class="sy">:elements</span>,[<span class="i">8</span>]
|
61
|
+
<span class="r">end</span>
|
62
|
+
|
63
|
+
<span class="c"># create a T's instance</span>
|
64
|
+
t_array = <span class="co">T</span>.new
|
65
|
+
|
66
|
+
(<span class="i">0</span>..<span class="i">7</span>).each <span class="r">do</span> |i|
|
67
|
+
t_array.elements[i] = i <span class="c"># assign like as C language</span>
|
68
|
+
<span class="r">end</span>
|
69
|
+
|
70
|
+
<span class="c"># output</span>
|
71
|
+
(<span class="i">0</span>..<span class="i">7</span>).each {|i| puts <span class="s"><span class="dl">"</span><span class="k">t_array.elements[</span><span class="il"><span class="idl">#{</span>i<span class="idl">}</span></span><span class="k">] = </span><span class="il"><span class="idl">#{</span>t_array.elements[i]<span class="idl">}</span></span><span class="dl">"</span></span> }
|
72
|
+
|
73
|
+
|
74
|
+
<span class="c"># Actually,t_array.elements.class is Array. So..</span>
|
75
|
+
t_array.elements.each {|element| puts element }</pre></div>
|
76
|
+
</div>
|
77
|
+
|
78
|
+
</div>
|
79
|
+
</body>
|
@@ -1,87 +1,87 @@
|
|
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:File IO</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"># struct Point in Ruby: </span>
|
51
|
-
<span class="r">class</span> <span class="cl">Point</span> < <span class="co">CStruct</span>
|
52
|
-
int32<span class="sy">:x</span>
|
53
|
-
int32<span class="sy">:y</span>
|
54
|
-
<span class="r">end</span>
|
55
|
-
|
56
|
-
<span class="c"># struct PointF in Ruby: </span>
|
57
|
-
<span class="r">class</span> <span class="cl">PointF</span> < <span class="co">CStruct</span>
|
58
|
-
double<span class="sy">:x</span>
|
59
|
-
double<span class="sy">:y</span>
|
60
|
-
<span class="r">end</span>
|
61
|
-
|
62
|
-
<span class="c"># write file</span>
|
63
|
-
<span class="co">File</span>.open(<span class="s"><span class="dl">"</span><span class="k">point.bin</span><span class="dl">"</span></span>,<span class="s"><span class="dl">"</span><span class="k">wb</span><span class="dl">"</span></span>)<span class="r">do</span> |f|
|
64
|
-
point = <span class="co">Point</span>.new {|st| st.x = <span class="i">100</span>; st.y =<span class="i">200</span> }
|
65
|
-
point_f = <span class="co">PointF</span>.new{|st| st.x = <span class="fl">20.65</span>; st.y =<span class="fl">70.86</span> }
|
66
|
-
|
67
|
-
f.write point.data
|
68
|
-
f.write point_f.data
|
69
|
-
<span class="r">end</span>
|
70
|
-
|
71
|
-
<span class="c">#read file</span>
|
72
|
-
<span class="co">File</span>.open(<span class="s"><span class="dl">"</span><span class="k">point.bin</span><span class="dl">"</span></span>,<span class="s"><span class="dl">"</span><span class="k">rb</span><span class="dl">"</span></span>)<span class="r">do</span> |f|
|
73
|
-
point = <span class="co">Point</span>.new
|
74
|
-
point_f = <span class="co">PointF</span>.new
|
75
|
-
|
76
|
-
point << f.read(<span class="co">Point</span>.size)
|
77
|
-
point_f << f.read(<span class="co">PointF</span>.size)
|
78
|
-
|
79
|
-
puts point.x
|
80
|
-
puts point.y
|
81
|
-
puts point_f.x
|
82
|
-
puts point_f.y
|
83
|
-
<span class="r">end</span></pre></div>
|
84
|
-
</div>
|
85
|
-
|
86
|
-
</div>
|
87
|
-
</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:File IO</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"># struct Point in Ruby: </span>
|
51
|
+
<span class="r">class</span> <span class="cl">Point</span> < <span class="co">CStruct</span>
|
52
|
+
int32<span class="sy">:x</span>
|
53
|
+
int32<span class="sy">:y</span>
|
54
|
+
<span class="r">end</span>
|
55
|
+
|
56
|
+
<span class="c"># struct PointF in Ruby: </span>
|
57
|
+
<span class="r">class</span> <span class="cl">PointF</span> < <span class="co">CStruct</span>
|
58
|
+
double<span class="sy">:x</span>
|
59
|
+
double<span class="sy">:y</span>
|
60
|
+
<span class="r">end</span>
|
61
|
+
|
62
|
+
<span class="c"># write file</span>
|
63
|
+
<span class="co">File</span>.open(<span class="s"><span class="dl">"</span><span class="k">point.bin</span><span class="dl">"</span></span>,<span class="s"><span class="dl">"</span><span class="k">wb</span><span class="dl">"</span></span>)<span class="r">do</span> |f|
|
64
|
+
point = <span class="co">Point</span>.new {|st| st.x = <span class="i">100</span>; st.y =<span class="i">200</span> }
|
65
|
+
point_f = <span class="co">PointF</span>.new{|st| st.x = <span class="fl">20.65</span>; st.y =<span class="fl">70.86</span> }
|
66
|
+
|
67
|
+
f.write point.data
|
68
|
+
f.write point_f.data
|
69
|
+
<span class="r">end</span>
|
70
|
+
|
71
|
+
<span class="c">#read file</span>
|
72
|
+
<span class="co">File</span>.open(<span class="s"><span class="dl">"</span><span class="k">point.bin</span><span class="dl">"</span></span>,<span class="s"><span class="dl">"</span><span class="k">rb</span><span class="dl">"</span></span>)<span class="r">do</span> |f|
|
73
|
+
point = <span class="co">Point</span>.new
|
74
|
+
point_f = <span class="co">PointF</span>.new
|
75
|
+
|
76
|
+
point << f.read(<span class="co">Point</span>.size)
|
77
|
+
point_f << f.read(<span class="co">PointF</span>.size)
|
78
|
+
|
79
|
+
puts point.x
|
80
|
+
puts point.y
|
81
|
+
puts point_f.x
|
82
|
+
puts point_f.y
|
83
|
+
<span class="r">end</span></pre></div>
|
84
|
+
</div>
|
85
|
+
|
86
|
+
</div>
|
87
|
+
</body>
|
@@ -1,104 +1,104 @@
|
|
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:First sample</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
|
-
|
59
|
-
<span class="c"># struct Point in Ruby: </span>
|
60
|
-
<span class="r">class</span> <span class="cl">Point</span> < <span class="co">CStruct</span>
|
61
|
-
int32<span class="sy">:x</span>
|
62
|
-
int32<span class="sy">:y</span>
|
63
|
-
<span class="r">end</span>
|
64
|
-
|
65
|
-
<span class="c"># create a Point's instance</span>
|
66
|
-
point = <span class="co">Point</span>.new
|
67
|
-
|
68
|
-
<span class="c"># assign like as C language</span>
|
69
|
-
point.x = <span class="i">10</span>
|
70
|
-
point.y = <span class="i">20</span>
|
71
|
-
|
72
|
-
puts <span class="s"><span class="dl">"</span><span class="k">point.x = </span><span class="il"><span class="idl">#{</span>point.x<span class="idl">}</span></span><span class="k">,point.y = </span><span class="il"><span class="idl">#{</span>point.y<span class="idl">}</span></span><span class="dl">"</span></span>
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
<span class="c"># struct PointF in C\C++ (32-bit platform): </span>
|
77
|
-
<span class="c">#</span>
|
78
|
-
<span class="c"># struct PointF</span>
|
79
|
-
<span class="c"># {</span>
|
80
|
-
<span class="c"># double x;</span>
|
81
|
-
<span class="c"># double y;</span>
|
82
|
-
<span class="c"># }; </span>
|
83
|
-
|
84
|
-
<span class="c"># struct PointF in Ruby: </span>
|
85
|
-
<span class="r">class</span> <span class="cl">PointF</span> < <span class="co">CStruct</span>
|
86
|
-
double<span class="sy">:x</span>
|
87
|
-
double<span class="sy">:y</span>
|
88
|
-
<span class="r">end</span>
|
89
|
-
|
90
|
-
<span class="c"># create a PointF's instance</span>
|
91
|
-
<span class="c"># use 'block' to initialize the fields</span>
|
92
|
-
point2 = <span class="co">PointF</span>.new <span class="r">do</span> |st|
|
93
|
-
st.x = <span class="fl">10.56</span>
|
94
|
-
st.y = <span class="fl">20.78</span>
|
95
|
-
<span class="r">end</span>
|
96
|
-
|
97
|
-
puts <span class="s"><span class="dl">"</span><span class="k">sizeof(PointF) = </span><span class="il"><span class="idl">#{</span><span class="co">PointF</span>.size<span class="idl">}</span></span><span class="dl">"</span></span>
|
98
|
-
puts <span class="s"><span class="dl">"</span><span class="k">point2.x = </span><span class="il"><span class="idl">#{</span>point2.x<span class="idl">}</span></span><span class="k">,point2.y = </span><span class="il"><span class="idl">#{</span>point2.y<span class="idl">}</span></span><span class="dl">"</span></span>
|
99
|
-
|
100
|
-
</pre></div>
|
101
|
-
</div>
|
102
|
-
|
103
|
-
</div>
|
104
|
-
</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:First sample</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
|
+
|
59
|
+
<span class="c"># struct Point in Ruby: </span>
|
60
|
+
<span class="r">class</span> <span class="cl">Point</span> < <span class="co">CStruct</span>
|
61
|
+
int32<span class="sy">:x</span>
|
62
|
+
int32<span class="sy">:y</span>
|
63
|
+
<span class="r">end</span>
|
64
|
+
|
65
|
+
<span class="c"># create a Point's instance</span>
|
66
|
+
point = <span class="co">Point</span>.new
|
67
|
+
|
68
|
+
<span class="c"># assign like as C language</span>
|
69
|
+
point.x = <span class="i">10</span>
|
70
|
+
point.y = <span class="i">20</span>
|
71
|
+
|
72
|
+
puts <span class="s"><span class="dl">"</span><span class="k">point.x = </span><span class="il"><span class="idl">#{</span>point.x<span class="idl">}</span></span><span class="k">,point.y = </span><span class="il"><span class="idl">#{</span>point.y<span class="idl">}</span></span><span class="dl">"</span></span>
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
<span class="c"># struct PointF in C\C++ (32-bit platform): </span>
|
77
|
+
<span class="c">#</span>
|
78
|
+
<span class="c"># struct PointF</span>
|
79
|
+
<span class="c"># {</span>
|
80
|
+
<span class="c"># double x;</span>
|
81
|
+
<span class="c"># double y;</span>
|
82
|
+
<span class="c"># }; </span>
|
83
|
+
|
84
|
+
<span class="c"># struct PointF in Ruby: </span>
|
85
|
+
<span class="r">class</span> <span class="cl">PointF</span> < <span class="co">CStruct</span>
|
86
|
+
double<span class="sy">:x</span>
|
87
|
+
double<span class="sy">:y</span>
|
88
|
+
<span class="r">end</span>
|
89
|
+
|
90
|
+
<span class="c"># create a PointF's instance</span>
|
91
|
+
<span class="c"># use 'block' to initialize the fields</span>
|
92
|
+
point2 = <span class="co">PointF</span>.new <span class="r">do</span> |st|
|
93
|
+
st.x = <span class="fl">10.56</span>
|
94
|
+
st.y = <span class="fl">20.78</span>
|
95
|
+
<span class="r">end</span>
|
96
|
+
|
97
|
+
puts <span class="s"><span class="dl">"</span><span class="k">sizeof(PointF) = </span><span class="il"><span class="idl">#{</span><span class="co">PointF</span>.size<span class="idl">}</span></span><span class="dl">"</span></span>
|
98
|
+
puts <span class="s"><span class="dl">"</span><span class="k">point2.x = </span><span class="il"><span class="idl">#{</span>point2.x<span class="idl">}</span></span><span class="k">,point2.y = </span><span class="il"><span class="idl">#{</span>point2.y<span class="idl">}</span></span><span class="dl">"</span></span>
|
99
|
+
|
100
|
+
</pre></div>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
</div>
|
104
|
+
</body>
|