[seed] [docs] Native function example
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] [docs] Native function example
- Date: Sun, 12 Jul 2009 22:03:47 +0000 (UTC)
commit c86a963cc8ad8ac6b336439d5177e1709a1a9175
Author: Tim Horton <hortont424 gmail com>
Date: Sun Jul 12 18:03:19 2009 -0400
[docs] Native function example
doc/reference/tmpl/seed-nativefuncs.sgml | 38 ++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/doc/reference/tmpl/seed-nativefuncs.sgml b/doc/reference/tmpl/seed-nativefuncs.sgml
index 912eb4b..a915c61 100644
--- a/doc/reference/tmpl/seed-nativefuncs.sgml
+++ b/doc/reference/tmpl/seed-nativefuncs.sgml
@@ -13,6 +13,44 @@ Exposing native C functions to JavaScript is one of the fundamental use cases fo
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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]