summaryrefslogtreecommitdiff
path: root/libseed/seed-module.h
blob: e8b7fd624d531b7519b3da73f5d27ee5e306abcd (plain)
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
/* -*- mode: C; indent-tabs-mode: t; tab-width: 8; c-basic-offset: 2; -*- */

/*
 * This file is part of Seed, the GObject Introspection<->Javascript bindings.
 *
 * Seed is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2 of
 * the License, or (at your option) any later version.
 * Seed is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License
 * along with Seed.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright (C) Robert Carr 2009 <carrr@rpi.edu>
 */

#ifndef _SEED_MODULE_H_
#define _SEED_MODULE_H_

#include "../libseed/seed.h"

// TODO: Move [example sqlite canvas Multiprocessing
//             os sandbox dbus libxml cairo]
//       towards utilization of this header.

/**
 * CHECK_ARG_COUNT:
 * @name: The name of the function being called from, pretty-printed
 * @argnum: The number of arguments which should be passed into the function
 *
 * Check that the required number of arguments were passed into a
 * #SeedFunctionCallback. If this is not true, raise an exception and
 * return %NULL. This requires the callback to use "argument_count",
 * "ctx", and "exception" as the names of the various function arguments.
 *
 * @name should be of form "namespace.function_name"
 *
 * At the moment, there is no way to specify more than one acceptable
 * argument count.
 *
 */

#define CHECK_ARG_COUNT(name, argnum) \
	if ( argument_count != argnum ) \
	{ \
		seed_make_exception (ctx, exception, "ArgumentError", \
		                     "wrong number of arguments; expected %s, got %Zd", \
		                     #argnum, argument_count); \
		return seed_make_undefined (ctx); \
	}

/**
 * DEFINE_ENUM_MEMBER:
 * @holder: The object on which to define the enum member
 * @member: The enum member, as it is named in C
 *
 * Defines a property on @holder which is named the same as @member, and
 * is assigned the value that @member has in C.
 *
 * This macro works for defining properties from constants and
 * &num;defines as well.
 *
 */
#define DEFINE_ENUM_MEMBER(holder, member) \
	seed_object_set_property(ctx, holder, #member, \
	                         seed_value_from_long(ctx, member, NULL))

/**
 * DEFINE_ENUM_MEMBER_EXT:
 * @holder: The object on which to define the enum member
 * @name: The enum member, as it should be named in JavaScript
 * @val: The enum member, as it is named in C
 *
 * Defines a property on @holder which is named @name, and is assigned the
 * value that @member has in C. This allows for an override of the enum
 * member's name, most often to remove a common prefix. For example, to declare
 * a property named VERSION_MAJOR on the namespace from mfpr's version
 * constant MPFR_VERSION_MAJOR:
 *
 * <programlisting>
 * DEFINE_ENUM_MEMBER_EXT(ns, "VERSION_MAJOR", MPFR_VERSION_MAJOR);
 * </programlisting>
 *
 */
#define DEFINE_ENUM_MEMBER_EXT(holder, name, val) \
	seed_object_set_property(ctx, holder, name, \
	                         seed_value_from_long(ctx, val, NULL))

#endif