summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-06-15 23:16:56 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 18:25:43 -0300
commitc7d377efd3f7612c8eb89c0ce0b4da29978665ca (patch)
tree11736b19ef7b1bbb6d2ec2f44ef3f332399cbda8
parent1d9dec7c3a211fc93c6b840fbdc906d7e6d60860 (diff)
efl_mono: add example for function pointer binding
-rw-r--r--configure.ac1
-rw-r--r--src/Makefile_Efl_Mono.am7
-rw-r--r--src/examples/efl_mono/.gitignore1
-rw-r--r--src/examples/efl_mono/FunctionPointer01.cs45
-rw-r--r--src/examples/efl_mono/FunctionPointer01.sh.in3
-rw-r--r--src/examples/efl_mono/example_numberwrapper.eo17
-rw-r--r--src/examples/efl_mono/libefl_mono_native_example.c29
7 files changed, 103 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index dfdb1c4ba1..a654ba6af6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5629,6 +5629,7 @@ src/examples/efl_mono/EinaBinbuf01.sh
5629src/examples/efl_mono/EinaError01.sh 5629src/examples/efl_mono/EinaError01.sh
5630src/examples/efl_mono/EinaHash01.sh 5630src/examples/efl_mono/EinaHash01.sh
5631src/examples/efl_mono/EoInherit01.sh 5631src/examples/efl_mono/EoInherit01.sh
5632src/examples/efl_mono/FunctionPointer01.sh
5632elm_intro.h 5633elm_intro.h
5633spec/efl.spec 5634spec/efl.spec
5634pc/evil.pc 5635pc/evil.pc
diff --git a/src/Makefile_Efl_Mono.am b/src/Makefile_Efl_Mono.am
index 57d4f2b0f2..8b542a42d9 100644
--- a/src/Makefile_Efl_Mono.am
+++ b/src/Makefile_Efl_Mono.am
@@ -253,6 +253,13 @@ examples/efl_mono/EoInherit01.exe$(EXEEXT): $(examples_efl_mono_EoInherit01_exe_
253 @rm -f examples/efl_mono/EoInherit01_exe$(EXEEXT) 253 @rm -f examples/efl_mono/EoInherit01_exe$(EXEEXT)
254 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll -r:$(abs_top_builddir)/src/examples/efl_mono/libefl_mono_example.dll -out:$@ $(filter %.cs, $(^)) 254 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll -r:$(abs_top_builddir)/src/examples/efl_mono/libefl_mono_example.dll -out:$@ $(filter %.cs, $(^))
255 255
256bin_PROGRAMS += examples/efl_mono/FunctionPointer01.exe
257examples_efl_mono_FunctionPointer01_exe_SOURCES = examples/efl_mono/FunctionPointer01.cs
258examples/efl_mono/FunctionPointer01.exe$(EXEEXT): $(examples_efl_mono_FunctionPointer01_exe_SOURCES) examples/efl_mono/$(am__dirstamp) lib/efl_mono/libefl_mono.dll examples/efl_mono/libefl_mono_example.dll
259 @rm -f examples/efl_mono/FunctionPointer01_exe$(EXEEXT)
260 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll -r:$(abs_top_builddir)/src/examples/efl_mono/libefl_mono_example.dll -out:$@ $(filter %.cs, $(^))
261
262
256SUFFIXES += .eo.cs 263SUFFIXES += .eo.cs
257 264
258lib/eo/%.eo.cs: lib/eo/%.eo $(_EOLIAN_MONO_DEP) 265lib/eo/%.eo.cs: lib/eo/%.eo $(_EOLIAN_MONO_DEP)
diff --git a/src/examples/efl_mono/.gitignore b/src/examples/efl_mono/.gitignore
index d72e4679c7..f418588f42 100644
--- a/src/examples/efl_mono/.gitignore
+++ b/src/examples/efl_mono/.gitignore
@@ -5,3 +5,4 @@
5/EinaError01.sh 5/EinaError01.sh
6/EinaHash01.sh 6/EinaHash01.sh
7/EoInherit01.sh 7/EoInherit01.sh
8/FunctionPointer01.sh
diff --git a/src/examples/efl_mono/FunctionPointer01.cs b/src/examples/efl_mono/FunctionPointer01.cs
new file mode 100644
index 0000000000..7f9fca7720
--- /dev/null
+++ b/src/examples/efl_mono/FunctionPointer01.cs
@@ -0,0 +1,45 @@
1using static System.Console;
2
3public class ExampleFunctionPointer01
4{
5 private static bool static_called = false;
6
7 private static int twiceCb(int n)
8 {
9 static_called = true;
10 return n * 2;
11 }
12
13 public static void Main()
14 {
15 eina.Config.Init();
16 efl.eo.Config.Init();
17
18 var obj = new example.NumberwrapperConcrete();
19
20 // Set internal value
21 obj.number_set(12);
22
23 // With static method
24 obj.number_callback_set(twiceCb);
25
26 var ret = obj.callback_call();
27
28 WriteLine($"Callback called? {static_called}.");
29 WriteLine($"Returned value: {ret}.\n");
30
31 // With lambda
32 bool lamda_called = false;
33
34 obj.number_callback_set(n => {
35 lamda_called = true;
36 return n * 3;
37 });
38
39 ret = obj.callback_call();
40
41 WriteLine($"Lambda called? {lamda_called}.");
42 WriteLine($"Returned value: {ret}.\n");
43 }
44}
45
diff --git a/src/examples/efl_mono/FunctionPointer01.sh.in b/src/examples/efl_mono/FunctionPointer01.sh.in
new file mode 100644
index 0000000000..bf84af3c65
--- /dev/null
+++ b/src/examples/efl_mono/FunctionPointer01.sh.in
@@ -0,0 +1,3 @@
1#!/bin/sh
2export MONO_PATH="@abs_top_builddir@/src/lib/efl_mono:${LD_LIBRARY_PATH_APPEND}"
3mono --config "@abs_top_builddir@/src/examples/efl_mono/examples_mono.config" "@abs_top_builddir@/src/examples/efl_mono/FunctionPointer01.exe"
diff --git a/src/examples/efl_mono/example_numberwrapper.eo b/src/examples/efl_mono/example_numberwrapper.eo
index 077b804154..85f2ce4a4d 100644
--- a/src/examples/efl_mono/example_numberwrapper.eo
+++ b/src/examples/efl_mono/example_numberwrapper.eo
@@ -1,3 +1,10 @@
1function NumberCb {
2 params {
3 n: int;
4 }
5 return: int;
6};
7
1class Example.Numberwrapper (Efl.Object) { 8class Example.Numberwrapper (Efl.Object) {
2 methods { 9 methods {
3 @property number { 10 @property number {
@@ -9,5 +16,15 @@ class Example.Numberwrapper (Efl.Object) {
9 n: int; 16 n: int;
10 } 17 }
11 } 18 }
19
20 number_callback_set {
21 params {
22 cb: NumberCb;
23 }
24 }
25
26 callback_call {
27 return: int;
28 }
12 } 29 }
13} 30}
diff --git a/src/examples/efl_mono/libefl_mono_native_example.c b/src/examples/efl_mono/libefl_mono_native_example.c
index 6f7aab0dfe..e08e995f81 100644
--- a/src/examples/efl_mono/libefl_mono_native_example.c
+++ b/src/examples/efl_mono/libefl_mono_native_example.c
@@ -37,6 +37,9 @@
37typedef struct Example_Numberwrapper_Data 37typedef struct Example_Numberwrapper_Data
38{ 38{
39 int number; 39 int number;
40 NumberCb cb;
41 void *cb_data;
42 Eina_Free_Cb free_cb;
40} Example_Numberwrapper_Data; 43} Example_Numberwrapper_Data;
41 44
42// ##################### // 45// ##################### //
@@ -54,5 +57,31 @@ int _example_numberwrapper_number_get(EINA_UNUSED Eo *obj, Example_Numberwrapper
54 return pd->number; 57 return pd->number;
55} 58}
56 59
60
61void _example_numberwrapper_number_callback_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, NumberCb cb, void *cb_data, Eina_Free_Cb cb_free_cb)
62{
63 if (pd->free_cb)
64 pd->free_cb(pd->cb_data);
65
66 pd->cb = cb;
67 pd->cb_data = cb_data;
68 pd->free_cb = cb_free_cb;
69}
70
71
72int _example_numberwrapper_callback_call(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd)
73{
74 if (!pd->cb)
75 {
76 static Eina_Error no_cb_err = 0;
77 if (!no_cb_err)
78 no_cb_err = eina_error_msg_static_register("Trying to call with no callback set");
79 eina_error_set(no_cb_err);
80 return -1;
81 }
82
83 return pd->cb(pd->cb_data, pd->number);
84}
85
57#include "example_numberwrapper.eo.c" 86#include "example_numberwrapper.eo.c"
58 87