1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<!-- ##### SECTION Title ##### -->
Creating native functions
<!-- ##### SECTION Short_Description ##### -->
C functions as first-class JavaScript objects
<!-- ##### SECTION Long_Description ##### -->
<para>
Exposing native C functions to JavaScript is one of the fundamental use cases for libseed when used in an embedding environment; if your application cannot be introspected, or you only have a small number of functions to expose, this is the simplest way to do that.
</para>
<para>
All native C callbacks should have the prototype of SeedFunctionCallback().
</para>
<example>
<title>Simple C program which embeds Seed with one exposed function</title>
<programlisting>
#include <glib.h>
#include <seed.h>
/* Our function, with the signature of SeedFunctionCallback(); say hello! */
SeedValue hello_world(SeedContext ctx,
SeedObject function,
SeedObject this_object,
gsize argument_count,
const SeedValue arguments[],
SeedException *exception)
{
g_print("Hello, World!\n");
return seed_make_null(ctx);
}
int main(gint argc, gchar ** argv)
{
SeedEngine * eng;
/* Initialize the Seed engine */
eng = seed_init(&argc, &argv);
/* Expose a C function to JavaScript */
seed_create_function(eng->context, "hello_world",
(SeedFunctionCallback)hello_world,
eng->global);
/* Call the newly created JavaScript function */
seed_simple_evaluate(eng->context, "hello_world()", NULL);
return 0;
}
</programlisting>
</example>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### SECTION Image ##### -->
<!-- ##### USER_FUNCTION SeedFunctionCallback ##### -->
<para>
</para>
@ctx:
@function:
@this_object:
@argument_count:
@arguments:
@exception:
@Returns:
<!-- ##### FUNCTION seed_make_function ##### -->
<para>
</para>
@ctx:
@func:
@name:
@Returns:
<!-- ##### FUNCTION seed_create_function ##### -->
<para>
</para>
@ctx:
@name:
@func:
@obj:
|