
is [C routine]
We can import a c function/routine into e and use it as regular e method. There are two ways to this.
Syntax
- Local Method :e-method-name(param,...)[:result-type] is C routine c-routine-name
- Global Method :routine e-routine-name(param, ...) [:result-type] [is C routine c-routine-name]
| ||||||||
Example-Global routine | ||||||||
Below is the c file which prints 'Hello World' |
1 #include
2
3 void hello() {
4 printf("Hello World\n");
5 }
Below is e code which uses the above c function. |
. |
1 <'
2 routine hello_world() is C routine hello;
3
4 extend sys {
5 run() is also {
6 hello_world();
7 };
8 };
9 '>
Compiling the example | ||
. | ||
Operation | Commands | Â |
Create c object file | gcc -c -o hello.o hello.c | Â |
Link c to e | sn_compile.sh -l hello.o methods_ex2.e -o hello | Â |
Simulate | hello -c "test" | Â |
Example-Local routine | ||
. |
1 <'
2 extend sys {
3 hello_world() is C routine hello;
4 run() is also {
5 hello_world();
6 };
7 };
8 '>
is also
"is also" is used for extending existing method/TCM. When we use "is also" it adds new lines of code/functionality after the existing code as shown in below example.
1 <'
2 struct hello {
3 say_hello() is {
4 out ("Hello World");
5 };
6 };
7 // Extend the orginal struct so
8 // That we can extend the method
9 extend hello {
10 say_hello() is also {
11 out("This is Deepak");
12 };
13 };
14
15 extend sys {
16 hello : hello;
17 run() is also {
18 hello.say_hello();
19 };
20 };
21 '>
is first
"is first" is used for extending existing method/TCM. When we use "is first" it adds new lines of code/functionality before existing code shown in below example.
1 <'
2 struct hello {
3 say_hello() is {
4 out ("Hello World");
5 };
6 };
7 // Extend the orginal struct so
8 // That we can extend the method
9 extend hello {
10 say_hello() is first {
11 out("I Want To Say");
12 };
13 };
14
15 extend sys {
16 hello : hello;
17 run() is also {
18 hello.say_hello();
19 };
20 };
21 '>
is only
"is only" is used for over riding existing method/TCM. When we use "is only" it over rides the existing code/functionality before existing code and replaces with new code as shown in below example. This basically over rides any previously used "is also" and "is first" extensions.
1 <'
2 struct hello {
3 say_hello() is {
4 out ("Hello World");
5 };
6 };
7 // Extend the orginal struct so
8 // That we can extend the method
9 extend hello {
10 say_hello() is only {
11 out("Hell With The World");
12 };
13 };
14
15 extend sys {
16 hello : hello;
17 run() is also {
18 hello.say_hello();
19 };
20 };
21 '>
is empty/undefines
Declares an abstract regular method or an abstract TCM with no defined functionality. Abstract methods are place holders that you can extend at a later point. A TCM is a time-consuming method that is distinguished from a regular method by the presence of @event and can use time-consuming actions such as sync and wait.
Note : Following restrictions apply for a abstract methods.
- The maximum number of parameters you can declare for a TCM is 14.
- You cannot define methods with variable argument lists.
undefined
No action block is defined for the method yet; an action block must be defined in a subsequent module before this method is called. Calling the method before it is defined is illegal.
1 <'
2 struct hello {
3 say_hello() is undefined ;
4 };
5 // Extend the orginal struct
6 // So that we can define functionality for method
7 extend hello {
8 say_hello() is {
9 out("Hello World");
10 };
11 };
12
13 extend sys {
14 hello : hello;
15 run() is also {
16 hello.say_hello();
17 };
18 };
19 '>
empty
The action block is empty; however, calling the method before it is defined is legal. Empty value-returning methods return the default value for the type.
1 <'
2 struct hello {
3 say_hello() is empty ;
4 };
5 // Extend the orginal struct
6 // So that we can define functionality for method
7 extend hello {
8 say_hello() is {
9 out("Hello World");
10 };
11 };
12
13 extend sys {
14 hello : hello;
15 run() is also {
16 hello.say_hello();
17 };
18 };
19 '>
Bạn Có Đam Mê Với Vi Mạch hay Nhúng - Bạn Muốn Trau Dồi Thêm Kĩ Năng
Mong Muốn Có Thêm Cơ Hội Trong Công Việc
Và Trở Thành Một Người Có Giá Trị Hơn
Mong Muốn Có Thêm Cơ Hội Trong Công Việc
Và Trở Thành Một Người Có Giá Trị Hơn