Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_ffi_c_module_blocks.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import core::kernel
16
17 in "C Header" `{
18 // C types of public Nit classes must be in the C header block
19 struct pub {long x;};
20 `}
21
22 in "C" `{
23 // C types of private Nit classes can be in the C body block
24 struct priv {long x;};
25 `}
26
27 extern class Pub `{ struct pub* `}
28 new `{
29 struct pub *res = malloc(sizeof(struct pub));
30 res->x = 1234;
31 return res;
32 `}
33
34 fun foo `{ printf("%ld\n", self->x); `}
35 end
36
37 private extern class Priv `{ struct priv* `}
38 new `{
39 struct priv *res = malloc(sizeof(struct priv));
40 res->x = 2345;
41 return res;
42 `}
43
44 fun foo `{ printf("%ld\n", self->x); `}
45 end
46
47 (new Pub).foo
48 (new Priv).foo